Friday, 8 November 2013

mkdir, rmdir, rm : creating and removing directories

mkdir : creating a directory

This command creates a new directory.
mkdir D
Directory D will be created inside current directory.
mkdir D/E
Directory E will be created inside D.
mkdir –p A/B/C
with –p option it will create directory structure like C inside B inside A inside current directory.
mkdir –m 744 J
Directory J will be created with permission 744 means read, write, execute permission to the owner and only read permission to group and others.
mkdir –v <dir_name>
This is verbose mode option. It gives the message of newly created directory and existing directory. It protects us from overwriting if directory is always present with the same name.


rm : Removing Directories as well as files

rm <file_name>
Remove files.
rm -f <file_name>
Remove files forcefully.
rm –r <dir_name>
rm –R <dir_name>

Removes files and directories recursively i.e. removes directories with its subdirectories and files.
rm *
* means all so it removes all directories and files inside current directories.
rm –r *
Removes all the files and directories along with subdirectories inside current directory recursively.
rm –rf *
Removes all the files and directories along with subdirectories inside current directory recursively and forcefully.
rm –i <file_name>
Interactive mode, it will ask before removing the file.
rm .[!l][!o][!g]
It will delete all files except the extension .log

rmdir : removing directory

rmdir –p A/B/C
It will remove the directory structure.
Rest, it works as rm command !

No comments:

Post a Comment