Wednesday, 4 March 2015

Helpful command-line tips for Linux users part 6: working with directories - rmdir

list of all commands
explanation of the convention:
[] : values in square brackets are optional

rmdir BASIC USAGE 
rmdir [OPTION] DIRECTORY- remove empty directory/directories

for example this will remove a directory fps from /home/ishtar/games if it is empty
> cd /home/ishtar/games
> rmdir fps
this will do exactly the same, but when you're in a different dir, but it has to be empty, otherwise you will see this.
> cd /
> rmdir /home/ishtar/games
rmdir: failed to remove ‘/home/ishtar/games/’: Directory not empty
Removing many empty directories in one go (two ways):
> cd /home/ishtar/games
~/games > ls
mmos puzzle rpg strategy
~/games > rmdir mmos puzzle
rmdir: failed to remove ‘mmos’: Directory not empty
~/games > ls
mmos  rpg  strategy
As you can see the empty directory has been deleted, but the one which had some content wasn't.
> cd /home/ishtar/games
~/games > rmdir mmos/screenshots/2015/wow/ mmos/screenshots/2015/ mmos/screenshots/ mmos/
~/games > ls 
rpg  strategy
This will only work if all those directories are empty so to remove them nested that way you will either have to go with the last method above, or to save time use option -p:
~/games > rmdir -p mmos/screenshots/2015/wow
~/games > ls
rpg strategy
This is a safe option, because it deletes only directories which are empty.

Tuesday, 3 March 2015

Helpful command-line tips for Linux users part 5: working with directories - mkdir

list of all commands
explanation of the convention:
[] : values in square brackets are optional

mkdir BASIC USAGE 
mkdir [OPTION] DIRECTORY- make a new DIRECTORY

for example this will create a directory games in /home/ishtar/
> cd /home/ishtar
> mkdir games
this will do exactly the same, but when you're in a different dir.
> cd /
> mkdir /home/ishtar/games
Creating many directories in one go:
> cd /home/ishtar/games
~/games > ls
~/games >
~/games > mkdir mmos puzzle rpg strategy fps
~/games > ls 
fps  mmos  puzzle  rpg  strategy
As you can see this creates only one level of directories, but if you want to create a whole tree then that's possible as well with -p option:
~/games > mkdir -p mmos/screenshots/2015/wow
~/games > ls -R mmos/
mmos/:
screenshots

mmos/screenshots:
2015

mmos/screenshots/2015:
wow

mmos/screenshots/2015/wow:
as you can see if a directory exists (mmos) it will not get created, and no error will show up, the other directories are created.
Real Time Web Analytics