Skip to main content

Linux for beginners: 10 commands to get you started at the terminal

Don't fear the command line. Embrace it with these 10 starter commands.
Image
10 commands to help you get started at the Linux terminal

Photo by Ann H from Pexels

So you are looking to learn Linux? Instead of rambling for the next two paragraphs about how the following commands are going to lay the metaphysical groundwork for the rest of your technical experience, I am going to jump right into it. No fluff, no expose—just commands and how they work. Let’s do it.

Note: I recommend having the GUI and CLI side by side as you make changes to files and directories to solidify that what you are doing in your terminal is, in fact, happening on the system.

Looking around

If you want to have a look around the filesystem, you will need to know how to list files and directories, move between directories, and see where you are currently.

When you open a terminal, you will see a prompt similar to this:

[tcarrigan@server ~]$

The only information provided is the user you are logged in as (tcarrigan), the hostname of the machine you are logged into (server), the directory you are currently in (noted by ~), and the access level ($ for user, # for root). If you are to have a look around, it helps to know where you are starting from. Also, if it’s your first time, ~ probably doesn’t mean much to you.

1. pwd - print working directory

The pwd command tells you the directory you are currently working in:

[tcarrigan@server ~]$ pwd
/home/tcarrigan

I am currently working in the /home/tcarrigan directory, as noted above. Now, what do you do if you want to see which file and directories are inside of /home/tcarrigan?

2. ls -l

The ls command will list any non-hidden files contained in a given directory. I recommend combining it with the -l option to make the output a bit more legible (and to get a little more information about the files and directories listed).

[tcarrigan@server ~]$ ls -l
total 0
drwxrwxr-x. 4 tcarrigan tcarrigan 50 Feb  6  2020 article_submissions
drwxrwxr-x. 2 tcarrigan tcarrigan 45 Aug 30 11:59 demo
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Desktop
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Documents
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Downloads
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Music
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Pictures
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Public
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Templates
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Videos

Now, as I said above, ls usually displays only NON-hidden files and directories. So what about the hidden stuff?

[ You might also like: Book review: The Linux Command Line ]

3. ls -al

The ls -a command is the answer you were looking for. Combine with the -l option as well for the same "pretty’"output you were looking at earlier, with the hidden files included.

[tcarrigan@server ~]$ ls -al
total 108
drwx------. 19 tcarrigan tcarrigan  4096 Oct 20 16:34 .
drwxr-xr-x.  9 root      root        106 Sep 15 22:56 ..
drwxrwxr-x.  4 tcarrigan tcarrigan    50 Feb  6  2020 article_submissions
-rw-------.  1 tcarrigan tcarrigan  2959 Oct 19 14:58 .bash_history
-rw-r--r--.  1 tcarrigan tcarrigan    18 Aug 30  2019 .bash_logout
-rw-r--r--.  1 tcarrigan tcarrigan   179 Feb 13  2020 .bash_profile
-rw-r--r--.  1 tcarrigan tcarrigan   312 Aug 30  2019 .bashrc
-rw-r--r--.  1 tcarrigan tcarrigan 12288 Feb 25  2020 .bashrc.swp
drwx------. 13 tcarrigan tcarrigan  4096 Apr 28 12:08 .cache
drwxrwxr-x.  3 tcarrigan tcarrigan    28 Feb 13  2020 .cargo
drwx------. 13 tcarrigan tcarrigan  4096 Feb  3  2020 .config
drwxrwxr-x.  2 tcarrigan tcarrigan    45 Aug 30 11:59 demo
drwxr-xr-x.  2 tcarrigan tcarrigan     6 Jan 27  2020 Desktop
*Output Omitted*

You will notice that there are many more entries in this output than before. Any file or directory that starts with the . character is now revealed.

Now, let’s navigate around the file system a bit. Let’s say you want to see a file inside /home/tcarrigan/article_submissions.

4. cd (dir) - change to (directory)

The change directory command is self-explanatory. It allows you to change your working directory.

[tcarrigan@server ~]$ cd article_submissions/
[tcarrigan@server article_submissions]$ pwd
/home/tcarrigan/article_submissions

You can see that we changed our working directory to ~/article_submissions. What if I wanted to get back to where I started?

5. cd - with no options

The cd command, when used with no additional options, will return you to the home directory of the user you are logged in as.

[tcarrigan@server article_submissions]$ cd
[tcarrigan@server ~]$ pwd
/home/tcarrigan

6. Going backward

If you need to go back to a previous directory, use the following:

[tcarrigan@server ~]$ pwd
/home/tcarrigan
[tcarrigan@server ~]$ cd ..
[tcarrigan@server home]$ pwd
/home

Making and removing

Now that you know how to move around, let’s look at creating and removing directories and files.

7. mkdir (X) - make (X) directory

To create a new directory, we use the mkdir command.

[tcarrigan@server ~]$ mkdir Test
[tcarrigan@server ~]$ ls -l
total 0
drwxrwxr-x. 4 tcarrigan tcarrigan 50 Feb  6  2020 article_submissions
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Desktop
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Documents
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Downloads
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Music
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Pictures
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Public
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Templates
drwxrwxr-x. 2 tcarrigan tcarrigan  6 Oct 20 17:05 Test
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Videos

What if we want to create a new file inside the newly created Test directory?

8. touch (file) - creates a new file (filename)

The touch command creates and updates individual files. To create a file called touch_test inside the Test directory:

[tcarrigan@server Test]$ touch touch_test
[tcarrigan@server Test]$ ls -l
total 0
-rw-rw-r--. 1 tcarrigan tcarrigan 0 Oct 20 17:12 touch_test

Ok, so we created a new directory, as well as a file within that directory. How do we get rid of them?

9. rm (file) - remove (filename)

First, the file:

[tcarrigan@server Test]$ rm touch_test 
[tcarrigan@server Test]$ ls -l
total 0

10. Now the directory: rm -r (directory)

[tcarrigan@server ~]$ rm -r Test/
[tcarrigan@server ~]$ ls -l
total 0
drwxrwxr-x. 4 tcarrigan tcarrigan 50 Feb  6  2020 article_submissions
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Desktop
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Documents
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Downloads
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Music
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Pictures
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Public
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Templates
drwxr-xr-x. 2 tcarrigan tcarrigan  6 Jan 27  2020 Videos

[ Download now: A sysadmin's guide to Bash scripting. ] 

What's next?

If today was your first time using Linux, congrats on making the leap. We looked at basic navigation, creation, and removal of files and directories. Keep an eye out for the next 10 commands, coming soon. We will look at moving and copying files, creating links, and the various ways to read files. In the meantime, keep practicing what we did today on your favorite virtual machine.

Author’s photo

Tyler Carrigan

Tyler is the Sr. Community Manager at Enable Sysadmin, a submarine veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a Red Hat Enterprise Linux-based combat system inside the USS Georgia Missile Control Center. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the Red Hat Developer program.