The most important Linux commands for beginners

By

New to Linux or just rusty? These important commands will make your life easier on the terminal while improving your efficiency

Using the shell is one of the major benefits of a Linux system, as it gives you access to many specialized programs, which make it easy to complete even complex jobs.

This is the founding philosophy of Unix, the OS from which Linux got its design. Each of these simple tools or programs does one job and does it very well. It can also communicate with other programs through pipes, a very clever design that makes the Linux shell very powerful.

If you’re just starting out or if it’s been a while since you last worked on a shell, the following list of the most important commands will help you get back to speed. It’s important to note their use of lower case letters.

Linux commands quick reference

CommandDescription
1pwdPrint the working directory
2cdChange directory, defaults to home
3lsList items in the directory
4cpCopy a file from one directory to another
5mvMove a file from one directory to another
6rmRemove (delete) a file or directory
7touchCreate a new file
8catPrint the contents of a file to StdOut
9sudoPerform a task with Superuser rights
10find & locateSearch for a file on the system
11| (The pipe)Connect the output and input of programs
12grepFind patterns in a data set
13curlFetch a page from the internet
14historyList the recent command entries in the terminal
15kill & xkillStop a program from execution
16man & info <command>Display detailed manual/info of the given command

Most important Linux commands for beginners explained

1. pwd

The pwd command stands for “print working directory” and it’s used to know the current directory that the Linux shell is operating in. It can be a very helpful tool when you’re writing a script that needs to make sure of its working location before taking action.

Here is an example and what it does.

pwd             >              #show the current shell directory

2. cd

This command stands for “change directory”. You use it to switch from the current working directory to another. It accepts the desired new directory as an argument, which can either start with a forward slash for an absolute path or without a slash to reference the current working directory. Without an argument, it defaults to your home directory.

Here are some example and what they do.

cd                         >       #returns to user/username home directory

cd ~                       >      #also returns to home directory

cd Downloads       >     #switches to your downloads folder

cd /usr/bin              >     #changes to the /usr/bin directory

3. ls

This command lists all the files and folders in the current working directory. It also accepts quite a few commands to help customize its output. For instance, the -a command includes hidden files, while the -t command sorts by modification date and the -l command produce an elegant output.

Here is an example and what it does

ls -alt             >            #list all files & folders, including hidden ones, & sort by modification date

4. cp

You use this to copy a file from one location to another. Keep in mind that Linux file naming conventions apply here. So, if you append a forward slash, then you are working with an absolute path, else the program will reference from the current working directory.

Here are some example and what they do.

cp file_1 Desktop    >   #copy file_1 to your Desktop folder

cp file_1 /tmp          >   #copy file_1 to/tmp

5. mv

This is the move command and it works similar to the cp command, except that it completely removes the file from its original location and moves it somewhere else.

Here are some example and what they do.

mv file_1 Downloads        >    #move file_1 to your Downloads directory

mv file_1 file_2 /tmp          >   #move both files to the /tmp directory

6. rm

To delete files and directories, the rm (remove) command is the tool you need. You should be very careful, however, with this tool, because whatever it removes, is gone forever. This is especially important with removing directories. So, always check your current working directory to avoid mistakes.

Here are some examples and what they do

rm file_1                         >         #delete file_1 in your current directory

rm Downloads/file_1        >     #delete file_1 from your Downloads directory

rm -r Downloads                  >   #completely delete your Downloads directory

7. touch

The touch command lets you create a new file. It accepts the filename as an argument.

Here is an example and how it works.

touch file_1                >           #create a new file named file_1

8. cat

Reading text files in the shell is also possible. To do that, you use the cat command followed by the file you want to read. Its name “cat” stands for concatenate, so you can also use it to combine two files into one.

Here are examples and what they do.

cat file_1                            >     #display the contents of file_1 on the screen (standard out)

cat file_1 file_2 > file_3       > #combine the contents of file_1 and file_2 into file_3

9. sudo

Linux limits the privileges of regular user accounts to stop them from causing irreparable damage to the entire system. Still, it reserves the sudo command for a regular user to run programs that require Superuser (administrator) privileges. Sudo will ask for the Superuser password, and if correct, allows further program execution.

Here is an example and what it does.

sudo systemctl stop apache2 > #stop the apache2 web-server

10. locate & find

These two programs help you to search for one or many files on the system, but they do it differently. Find is the older program and it comes with very powerful search features. Locate, on the other hand, is newer and uses a database to perform very fast searches.

Here are examples and what they do

find / ubuntu         >       #find all file names containing ubuntu. The slash means from system root

locate ubuntu          >     #find all files on the system containing ubuntu

11. | (The pipe)

The find and locate programs above often return so many entries that filtering the results becomes important. Here, you can pass the search output through a pipe, to the input of a pattern recognition program like grep. This will filter the results to produce more concise feedback.

Here is an example and what it does.

locate ubuntu | grep .jpg           >          #find only jpeg pictures with ubuntu in their name

12. grep

Grep is an acronym for Global Regular Expressions Print. It’s used to find patterns in a dataset, which can include whole words, the first letter of the sentence, and so much more.

Here are examples and what they do.

grep foo file_1                    >               #print all lines in file_1 that contain foo

grep ^bar file_1                  >               #print only lines that start with bar

13. curl

cURL stands for Client URL and is a tool to transfer data between computers using different network protocols. It’s highly configurable and programmable, with its simplest use being to fetch a webpage.

Here is an example and what it does.

curl google.com                    >            #load google.com

14. history

The Linux shell remembers your recent command entries. Some systems offer a 500-command history, while others offer 1,000 by default. You are also free to change it.

Here is an example and what it does.

history | grep curl                >              #find recent commands that contain curl

15. kill & xkill

Kill and xkill are two methods of terminating processes on the system. With kill, you need to know and supply the process ID of the program you need to terminate. With xkill, you can terminate graphical programs by using the mouse to point and click on them.

16. man & info <command>

You can always enter man or info, followed by a command to get the user manual or info page entries for that command. You can also enter a command, followed by –help, to get more information on its usage.

Here are some examples and what they do.

man curl                              >              #display the Linux manpage entry for cURL

find –help                           >               #show usage information for the find command

Conclusion

Coming to the end of this list, keep in mind that these are the most important commands for beginners. There are many more commands for the Linux shell, including more complex and powerful ones.

It takes some time to learn these commands though and to be comfortable using them. But once you do, you’ll be glad you learned to use them.

Photo of author

Nnamdi Okeke

Nnamdi Okeke is a computer enthusiast who loves to read a wide range of books. He has a preference for Linux over Windows/Mac and has been using Ubuntu since its early days. You can catch him on twitter via bongotrax

Leave a Comment