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.

No comments:

Post a Comment

Real Time Web Analytics