How to Create, Delete, Copy, Rename and Move Directories in Linux / Unix





Create(Make) Directories:

In Linux and Unix mkdir command is used to create a directories or sub-directories. Lets see Some mkdir commands.


[root@rahul ~]# mkdir emaildir



How to create multiple directories at one time :

This command creates Three new sub-directories into the current directory:


[root@rahul ~]# mkdir dir1 dir2 dir3


How to create multiple directories inside a directory :

Let us make some directories to following format in one command.
Music:
            Hindi   :
                        Old, New
            English :
                        Old, New

[root@rahul ~]# mkdir –p music/{Hindi/{Old,New},English/{Old,New}}


For O/P Use tree Command


[root@rahul ~]# tree music/


Copy directories from one location to other :

#cp –rvfp <dir name> <destinationdir name>


[root@rahul ~]# cp –rvfp dir1 dir2


Move a Directory from one location to other :

#mv <dir name> <destination dir name>


[root@rahul ~]# mv dir1 dir4


Rename a Directory :

# mv <old dir name> <new dir name>


[root@rahul ~]# mv dir1 moviesdir


Remove (Delete) a directory:

Removing an empty directory :
# rmdir dirname


[root@rahul ~]# rmdir dir2


Removing a directory with files or inside directories :

A dir which is having some contents inside it cannot be removed by rmdir command. There are two ways to delete the directory with contents.
1.      Remove the contents inside the directory and then run rmdir command.
2.      Ron # rm –rf dirname (where r stands for recursive and f stands for forcefully.)


[root@rahul ~]# rm –rf dir4


Post a Comment