Welcome!
Directory Commands in Linux
Here you will learn about some common Directory Commands in Linux.
If you are wondering, what is a directory - another name for directory is folder.
Directory commands are used to manage and manipulate directories and files in directories.
Some of the most common directory commands that you need to know are:
- pwd: Print Working Directory
- ls: List Directory Contents
- mkdir: Create New Folder(s)
- cd: Change Directory
- rmdir: Remove Folder(s)
© CyberShaolin. All rights reserved.
Congratulations!
You've completed the scenario!
Scenario Rating
In this course, you have learned about some common directory (or folder) commands in Linux.
Your environment is currently being packaged as a Docker container and the download will begin shortly. To run the image locally, once Docker has been installed, use the commands
cat scrapbook_cybershaolin_intro-to-linux/linux-commands-directory_container.tar | docker load
docker run -it /cybershaolin_intro-to-linux/linux-commands-directory:
Oops!! Sorry, it looks like this scenario doesn't currently support downloads. We'll fix that shortly.

Steps
Directory Commands in Linux
Start
Here you will learn about some common Directory Commands in Linux.
If you are wondering, what is a directory - another name for directory is folder.
Directory commands are used to manage and manipulate directories and files in directories.
Some of the most common directory commands that you need to know are:
- pwd: Print Working Directory
- ls: List Directory Contents
- mkdir: Create New Folder(s)
- cd: Change Directory
- rmdir: Remove Folder(s)
pwd (Print Working Directory)
pwd
stands for Print Working Directory.
Some examples of directories in the Linux OS are /root, /boot, /bin, /opt, /run, /usr
and /home
.
The pwd
command tells you the current folder where you are.
The default directory that you start out with is the home directory of the user who is logged in.
If you are the root user, your first directory would be /
.
If you are a user named duke
, then your home directory would be /home/duke
ls (List Directory Contents)
ls
stands for list directory contents.
The ls
command displays the names of files contained within a directory, as well as any requested, associated information.
Type ls
and hit enter.
You should see several directories. One directory that is of interest that we will use for our learning is the cybershaolin
directory.
But do you see a folder called secrets
listed?
Hidden Files
Files that are named with a dot (.)
are hidden and not shown when you run the ls
command.
To see hidden files, we need to modify the ls
command with some additional information. This additional information that is added to a Linux command is called an operand.
Type ls -a
and press enter.
The -a
operands will list directory entries whose names begin with a dot (.) and are hidden.
You should see now see a directory called .secrets
.
Another operand that is often used with the ls
command is the -l
operand.
The -l
operand lists the file in long format. If the output is to a terminal, a total sum for all the file sizes is output on a line before the long listing.
Type ls -la
and press enter.
If the -l option is given, the following information is displayed for each file:
- file mode,
- number of links,
- owner name,
- group name,
- number of bytes in the file,
- abbreviated month,
- day-of-month file was last modified,
- hour file last modified,
- minute file last modified,
- and the pathname.
In addition, for each directory whose contents are displayed, the total number of 512-byte blocks used by the files in the directory is displayed on a line by itself, immediately before the information for the files in the directory.
cd (Change Directory)
cd
stands for Change Directory.
Type cd .secrets
and press enter.
NOTE: Don't forget the dot (.)
in front of the word secrets
.
What you just did was you changed your directory to the .secrets directory. You can check by typing pwd
and pressing enter.
You will now be in the /.secrets
directory.
Now type ls
and press enter and you will see that there is a text file in there called TopSecret
.
cd and ../(DotDotSlash))
In order to go to the previous folder, you can use the shortform ../
(DotDotSlash) along with the cd
command.
Since you are in the .secrets
directory now, you can go to the previous directory using the cd ../
command.
Type cd ../
and you will find yourself back at the /
directory.
By typing ls -la
, you will find that you are indeed in the /
directory.
mkdir (Make Directory)
mkdir
stands for Make Directory.
It is used to create a folder or directory so that you can be organized.
You can think of directories like a bookshelf. In the top shelf you may have your school books, the middle shelf may have some fiction books and the bottom shelf may contain some activity books. So also in a computer system, you can organize your files in directories.
Let us first create your directory. This directory will store your favorite game files in it.
Type mkdir myGames
and press enter.
What happened? It may seem like nothing happened if your command ran successfully.
To see if your directory was created successfully, you can use the ls
command which will list all the contents of the current directory where you are.
Type ls
and press enter.
You should see aa directory/folder called myGames
rmdir (Remove Directory)
rmdir
stands for Remove directory.
Sometimes you may want to or have to delete a directory or folder. Say you created a temporary directory called tmp
or a top secret folder called .secrets
that will hold some secret files for a short amount of time. Once you no longer need those files or the directory, you can delete (or remove) it. This is where the rmdir
command can help.
Now type cd myGames
to enter into the myGames
directory.
Once you are in the directory, if you type ls
and press enter, you will find that the directory is empty. There are no files to list.
Let us create some files. One of the easiest ways to create some files is to use the touch
command.
Type touch angrybirds.txt candycrush.txt fortnite.txt halo.txt borderlands.txt
and press enter.
Type ls -l
to make sure that those files were created.
Since you are in the myGames
directory, type cd ../
to go to its parent directory (e.g., /
) so that you can delete the myGames
directory that you created.
Now type rmdir myGames
and press enter.
Since you have the files that you created inside the directory, this command will fail and you will see something likermdir: failed to remove 'myGames/': Directory not empty
To delete directory that have content inside them, you can use the rm
command along with the operands called -rf
which will do a recursive flush.
Try rm -rf myGames
and press enter.
The DeathStars of the rm Commands
Never ever, never ever, never ever run the following commandrm -rf *.*
unless you absolutely know that you are in the directory from which you want to delete ALL folders and files.
The *.*
here is a wildcard syntax to mean any files of any type.
End
In this course, you have learned about some common directory (or folder) commands in Linux.