Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learn Linux Quickly

You're reading from   Learn Linux Quickly A beginner-friendly guide to getting up and running with the world's most powerful operating system

Arrow left icon
Product type Paperback
Published in Aug 2020
Publisher Packt
ISBN-13 9781800566002
Length 338 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Ahmed AlKabary Ahmed AlKabary
Author Profile Icon Ahmed AlKabary
Ahmed AlKabary
Arrow right icon
View More author details
Toc

Table of Contents (24) Chapters Close

Preface 1. Your First Keystrokes 2. Climbing the Tree FREE CHAPTER 3. Meet the Editors 4. Copying, Moving, and Deleting Files 5. Read Your Manuals! 6. Hard versus Soft Links 7. Who Is Root? 8. Controlling the Population 9. Piping and I/O Redirection 10. Analyzing and Manipulating Files 11. Let's Play Find and Seek 12. You Got a Package 13. Kill the Process 14. The Power of Sudo 15. What's Wrong with the Network? 16. Bash Scripting Is Fun 17. You Need a Cron Job 18. Archiving and Compressing Files 19. Create Your Own Commands 20. Everyone Needs Disk Space 21. echo "Goodbye My Friend" 22. Assessments 23. Other Books You May Enjoy

Making directories

To create directories in Linux, we use the mkdir command, which is short for make directory.

In elliot's desktop, let's create a directory named games by running the mkdir games command:

elliot@ubuntu-linux:~/Desktop$ mkdir games 
elliot@ubuntu-linux:~/Desktop$ ls -l
total 8
drwxr-xr-x 2 elliot elliot 4096 Jan 20 20:20 games
-rw-r--r-- 1 elliot elliot 37 Jan 19 14:20 hello.txt
elliot@ubuntu-linux:~/Desktop$

Notice that my current working directory is /home/elliot/Destkop; that's why I was able to use a relative path.

Figure 12: games Directory Created on the Desktop

You can also create multiple directories at the same time. For example, you can create three directories – Music, Movies, and Books – on your desktop by running the mkdir Music Movies Books command:

elliot@ubuntu-linux:~/Desktop$ mkdir Music Movies Books 
elliot@ubuntu-linux:~/Desktop$ ls -l
total 20
drwxr-xr-x 2 elliot elliot 4096 Jan 21 01:54 Books
drwxr-xr-x 2 elliot elliot 4096 Jan 20 20:20 games
-rw-r--r-- 1 elliot elliot 37 Jan 19 14:20 hello.txt
drwxr-xr-x 2 elliot elliot 4096 Jan 21 01:54 Movies
drwxr-xr-x 2 elliot elliot 4096 Jan 21 01:54 Music
Figure 13: Directories Created on the Desktop

You can also use the -p option to create a whole path of directories. For example, you can create the path /home/elliot/dir1/dir2/dir3 by running the mkdir -p dir1/dir2/dir3 command:

elliot@ubuntu-linux:~$ pwd
/home/elliot
elliot@ubuntu-linux:~$ mkdir -p dir1/dir2/dir3
elliot@ubuntu-linux:~$ ls
blabla Desktop dir1
elliot@ubuntu-linux:~$ cd dir1
elliot@ubuntu-linux:~/dir1$ ls
dir2

elliot@ubuntu-linux:~/dir1$ cd dir2
elliot@ubuntu-linux:~/dir1/dir2$ ls
dir3

elliot@ubuntu-linux:~/dir1/dir2$ cd dir3
elliot@ubuntu-linux:~/dir1/dir2/dir3$ pwd

/home/elliot/dir1/dir2/dir3
elliot@ubuntu-linux:~/dir1/dir2/dir3$

It created dir1 in the /home/elliot directory, and then it created dir2 inside of dir1, and finally, it created dir3 inside of dir2.

You can use the recursive -R option to do a recursive listing on /home/elliot/dir1 and see all the files underneath /home/elliot/dir1 without the hassle of changing to each directory:

elliot@ubuntu-linux:~$ ls -R dir1 
dir1:

dir2

dir1/dir2:
dir3

dir1/dir2/dir3:
elliot@ubuntu-linux:~$

As you can see, it listed all the files under /home/elliot/dir1. It even displayed the hierarchy.

You can also create a new directory with multiple subdirectories by including them inside a pair of curly brackets and each subdirectory separated by a comma like in the following:

elliot@ubuntu-linux:~/dir1/dir2/dir3$ mkdir -p dir4/{dir5,dir6,dir7} 
elliot@ubuntu-linux:~/dir1/dir2/dir3$ ls -R dir4

dir4:
dir5 dir6 dir7

dir4/dir5:

dir4/dir6:


dir4/dir7:

As you can see, we created dir4, and inside it, we created three directories – dir5, dir6, and dir7.

You have been reading a chapter from
Learn Linux Quickly
Published in: Aug 2020
Publisher: Packt
ISBN-13: 9781800566002
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image