Thursday, 23 February 2012

Handling Folders and Files with Linux command Line[part2]

In the previous part I just explained 3 commands that will help you to navigate through files and folders in your system.In this section let us discuss how to perform some actions like create, rename, remove folders using command line.
Creating a folder using the command:
The command used to create a folder is mkdir .Open up the terminal and type :
                                 mkdir myfolder

 A new folder named myfolder will be there in your home directory.You can make folders anywhere in your system.But you must mention the directory address for your folder with folder name otherwise the folder will be created in the current directory.
Eg: to make a folder in the directory /tmp use the following command.

                                 mkdir /tmp/myfolder

Extra note : Normally your system will not display any message after creation of the folder. If you add the parameter -v to the mkdir command you will get a message after the creation of the folder (eg: mkdir myfolder -v)
Removing a file or folder
The Linux kernel consider folder and file as same .You can remove any file or folder using the command rm .
the usage of the command is rm  [option]  <file> .
Here are the important options you might use.
 -f    (forcefully removes file with no prompting)
 -v   (Explains what is being done)
 -r   (Removes files recursively in a directory.It is used when the folder contains subfolders.)
I just mentioned the syntax above. But you need just a single command to remove a folder that is
             rm  -rf  /tmp/myfolder

here '-rf' is the option with the command which says that files will be removed recursively and forcefully. And /tmp/myfolder will be the folder we want to delete.

No comments:

Post a Comment