Directory Operations and Manipulations In Linux

By -


In the Previous tutorial we got to know about the very basic commands used in file generation and manipulation in Linux environment. Now in this tutorial we are going to discuss about the directories in Linux and will learn the basic commands to create rename copy move and delete Directories in Linux using command line interface also known as CLI. So lets get started.

A Directory is a location where we can put our files in an organized manner. The data or information is stored in files in order to keep the data organized, similarly all such files are stored in a place or location called Directory. Although a Directory is meant to store the files residing inside the system but it does not mean that a Directory cant be empty, its purely up to our wish whether we store any file in that Directory or not.

Creating a Directory in Linux:

The process of creating the Directory is pretty simple in graphical mode, you just have to navigate to the place you want to create the Directory, simply right click there and there you will get an option to create a Directory, but when we do not have graphical console or say when we are using the command line interface then we must know the appropriate command. The command for creating a Directory is “mkdir” followed by the the desired Directory name. lets have an example.

$<mkdir> <DirectoryName>
$<mkdir> <RareInput>

also we can provide the path where we want to create the Directory. Say for example we want to create a Directory in the “Downloads” Directory then we will have to do some thing like this

$<mkdir> </root/Downloads/RareInput>

Copying a Directory

Copying a Directory is very much similar according to copying file in linux. The only difference is that a file is a single entity, but a Directory consists of various files as well as Directories inside it. Hence while copying a Directory we take care of this thing and hence we use two arguments ‘r’ and ‘f’. Where ‘r’ stands for recursive and ‘f” stands for forceful. Things will be clear after this example.

$<cp> <path-of-directory-to-be-copied> <path-where-directory-is-to-be-pasted>

$<cp> <-r> <path-of-directory-to-be-copied> <path-where-directory-is-to-be-pasted>

Moving and Renaming a Directory


Moving a Directory in Linux means to cut the Directory from its original location and pasting it somewhere else. Move and rename both of are done using the same “mv” command in Linux but the syntax of the command differs.
the following example will illustrate the move operation

$<mv> <path-of-directory-to-be-copied> <path-where-directory-is-to-be-pasted>

$<mv> <-r> <path-of-directory-to-be-copied> <path-where-directory-is-to-be-pasted>


The renaming operation on a Directory is done exactly same as it is done n files.
the typical example would be

$<mv> <Old-Directry-Name> <New-Directory-Name>


The move and rename operation can be done in just one command. What I mean to say is, you can rename the Directory that you are moving from one place with old name and paste it on some another location with a new name. This example will explain things a bit.

$<mv> </root/Desktop/RareInput> </root/Downloads/saurabh>

Deleting a Directory

The deletion of a Directory is again similar as that of deletion of a file in Linux, the only difference is that a directory sometimes may be empty and sometime it may not be empty. When thee Directory is empty we use “rmdir” command to delete an empty Directory.

$<rmdir> <Documents>

but most of the times Directories are not empty, in that case we use “rm” command with “r” and “f” arguments.

$<rm> <-rf> <Documents>.

So this is all about the Directory operations in Linux.
your feedback are welcome in the comments. Read and share.



An avid technologist with some abnormal cravings for Linux. Active contributor to opensource world. System Administrator by profession. He can do anything for Linux. Currently He holds three Global Certifications in Linux by Redhat Inc. RHC{VA,E,SA}. His aim is to impart free and quality knowledge in Linux.

1 Comment to Directory Operations and Manipulations In Linux

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>