Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

Creating a Directory with mkdir


To create an empty directory called newdirectory within your current
directory, use this command:


Click here to view code image
matthew@seymour:~$ mkdir newdirectory


If you are the user matthew, you can create a directory in a different
location by changing what is after mkdir. To create a new directory in
/home/matthew/music, if you are already in your /home directory, you
can use the following:


Click here to view code image
matthew@seymour:~$ mkdir music/newdirectory


Or from anywhere using an absolute path, you can use this:


Click here to view code image
matthew@seymour:~$ mkdir /home/matthew/music/newdirectory


Or from anywhere using a path shortcut, you can use the following command:


Click here to view code image
matthew@seymour:~$ mkdir ~/music/newdirectory


The -p option is valuable. It enables you to create a directory and its parent
directories at the same time, if they do not already exist. This can be a real
time saver. If the parent directories exist, the command works normally. For
example, suppose you want to make a new directory with two layers of
subdirectories. In this example, music and newdirectory already exist,
but subdir1 and subdir2 are to be created:


Click here to view code image
matthew@seymour:~$ mkdir -p ~/music/newdirectory/subdir1/subdir2


Deleting a Directory with rmdir


If you are the user matthew, to delete an empty directory named
directoryname, use the following command:


Click here to view code image
matthew@seymour:~$ rmdir directoryname


You can remove a directory in a different location by changing what is after
rmdir. To remove a directory in /home/matthew/music, if you are

Free download pdf