Root to Linux, Hands-on Commands Part 1
One of the most intimidating parts of learning Linux is working with the Linux shell. The shell is a command line interpreter and gives a user the ability to execute programs which are also called commands.
In part 1 of this guide, you will learn and use some of the basic Linux commands to see your working directory, list directories and files, make new directories, and create text files.
You will need a Linux shell to work with to try these commands in this tutorial. If you do not have a Linux distro set up, you can use an online command shell to practice these commands. For this tutorial I used JSLinux.
Checking Current Directory
In Linux, a directory is a location on your computer that stores files. They are set up in a hierarchical system on your computer.
To see what directory you are currently in you can use the
While using JSLinux you will be in the
If you are using the Linux shell on your own computer you will likely be in the
Now that you know what directory you are in, you can start creating new directories and set up your own hierarchical structure.
In the image below. you will see several directories and files that are set up in a hierachy. These directories are named after the author Jane Austen, some of her books, and a few of the characters in those books.
In this section of the tutorial you will learn the commands to create each directory, change directories and list the directories that have been created.
The first directory you will create is
To create this directory you will use the
mkdir command which stands for make directory.
In the Linux shell type:
Note: If you type
Austenit will be different from
austen. The Linux shell sees these as two different directories. Be sure to pay attention to your capitalization and any spelling errors while creating directories or files.
To see if the directory was created you can use the
This command is short for list and will list out any directories or files that are in the current working directory.
In the image below you can see the
austen directory is listed along with a few default directories that come with JSLinux.
Creating Directories Under
Now you can create the next directories in the hierarchy. You will create the
You can create each directory one at a time with the
mkdir command like you did when creating the
or you can create several directories at a time like the image below.
mkdir command and separate each directory you would like to create. Here we create the
Pride_prejudice directories all at once.
Once you are done creating the directories you can use the
cd command, which stands for change directory, to move from the
home directory to the
From there you can use the
ls command to list all of your new directories and confirm they were successfully created.
To create the next directories in the hierarchy you will use the same
mkdir command. In the image below you will see an example of changing directories to the austen directory and creating the character name directories.
You must add them to the correct file path. For example, Knightly will go under the Emma directory so you will create it by including Emma in the file path like:
Repeat the same pattern with the other directories that need to be added.
Note: In the Linux shell you can press the tab key on your keyboard after you start a file path to auto-complete it. For example, if you type
Prthen hit the
tabkey it will auto complete to
Pride_prejudicefor you. This will save time as you create more directories.
Creating a Text File
In the directory hierarchy image you can see that there are two
.txt stands for a text file. To create text files you use the
Navigate to the Churchill directory with the
ls command to see if you were successful in creating a text file.
Follow the same steps to create a
partner.txt file under the
Once you have created both text files you should now have all of the directories and files from the first image.
In part 1 of this hands-on guide you learned the following basic commands:
pwdto see your current working directory
lsto list directories and files
mkdirto create a new directory
cdto change directories
touchto create a text file
In part 2 of this hands-on guide you will learn the commands to move a directory, copy a file, delete a file, and edit a file.
Take the time to go back through the commands you just learned before moving on to part 2.