Linux beginners may get overwhelmed by the sheer number of commands that are available in the terminal, but most users will find themselves executing the same few commands over and over. If you are looking to get started with the Linux command line, we have listed 20 of the most important and basic commands that you should know. These basic commands are the most essential to learn, and also the ones you will likley find yourself using the most.
Every Linux distro has inherent access to a terminal, though the interface may look different depending on your desktop environment or configuration. Join us in this tutorial to learn about the 20 of the most basic Linux commands. By the end, you will know enough to begin navigating your Linux terminal.
In this tutorial you will learn:
- Top 20 basic Linux commands you must know
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Basic Linux Commands
These are our top picks for the most basic Linux commands that ever beginner should familiarize yourself with. Once you are used to these, it is easy to pick up other commands as you go along. Let’s dive in!
One of the most essential commands in Linux is the change directory command or
cd command. This is how you will navigate to different directories throughout your system. Using this command will change your current working directory to a different one you specify.
Navigate to any directory with the following syntax:
$ cd /path/to/directory
Or navigate to your user’s home directory:
See more: cd command in Linux with examples
pwd command in Linux is short for present working directory. When it comes to Linux commands, this has to be one of the simplest. It’s only function is to print the present working directory of your terminal. It comes in handy when you’re not exactly sure what directory you’re in, or when you need to pass the present working directory inside of a Bash script, for example.
The syntax requires no further options:
See also: pwd command in Linux with examples
ls is short for list, and is used to list the files in your present working directory or some other directory if you specify one. What makes
ls so essential is that it allows you to see what files are in a directory. You’ll be using it constantly to list directory contents.
It is common to use it with no further options in order to show what’s in your present working directory:
To get a list format, with one file per line, add the
$ ls -l
See more: ls command in Linux with examples
cat command in Linux is our primary tool for viewing the contents of text files. Whether we are talking about Linux log files or configuration files, they are all simple ASCII text files. Therefore, the skills to be able to read the content of such text files is imperative.
You will most commonly use the
cat command to read the contents of a particular file:
$ cat file.txt
See more: Cat command in Linux with examples
echo command can be used to read variables and direct output. It is especially common to use echo inside of Bash scripts.
$ echo "some text" > file.txt $ echo "Hello World" $ echo $variable
See also: Bash Scripting Tutorial for Beginners
mv command in Linux is short for move. As you can probably guess or may already know, the command is used to move files and directories from one location to the other. Users that are more accustomed to a GUI might know this action better as “cutting and pasting.” The
mv command is just the command line equivalent of that action.
Move a file to a different directory:
$ mv /home/linuxconfig/Downloads/linux.iso /home/linuxconfig/Desktop
mv command can also rename files:
$ mv old-name new-name
See more: mv command in Linux with examples
To see what directory a command belongs to, you can use the
which command. This is a good way to verify whether a command is usable, and makes for a good troubleshooting tool when you need to determine the absolute path to a command.
$ which date /bin/date
If you need to search for one or more particular files or directories, the
find command in Linux is the perfect tool for the job. The
find command can search for a file with a specific name, but you can also search for files that follow certain naming patterns. This can be broadened all the way to finding files based on file size, file extension, or a lot of other options.
Most basic syntax:
$ find . -name "example.txt"
A plethora of other options exist, in order to search for specific naming patterns. See more: find command in Linux with examples
On a Linux system, the need to search one or multiple files for a specific text string can arise quite often. On the command line, the
grep command has this function covered very well.
To search a file for a text string, use the following command syntax:
$ grep string filename
chmod command in Linux is used to manage file permissions. It’s an essential command that pretty much every user will find the need to utilize at least every once in a while. Linux file permissions involve read, write, and execute permissions.
chmod uses the u, g, and o options to change the permissions for the owning user, group, and others respectively. Take a look at how it works.
$ chmod g+w somefile.txt
See more: chmod command in Linux with examples
chown command changes the user ownership of a file. This command goes hand in hand with
chmod mentioned above. You will often need to make the root account or a normal user account the owner of a file, and then apply permissions specifically to the owner.
Here is the syntax:
$ chown username:username file
head command prints the first x number of lines in a specific file. By default, it will display the first 10 lines of the specified file. The purposes of the options you can use with the
head command are displaying contents in a file in different ways depending on the situation.
$ head file.txt
See more: head command in Linux with examples
tail command is used to print the last 10 lines of multiple files or a specified file.
tail, with it’s interesting and convenient functions, can be used to monitor changes that are made to files.
$ tail file.txt
Or to monitor continuous changes to a file:
$ tail -f apache.log
One of the most basic commands in Linux is the
cpor copy command. The most basic way to use this command is to copy a file or multiple files. The
cpcommand is one of the first commands you should learn as a newcomer to Linux, as copying files and directories is something you’ll do often.
$ cp file01 file01-copy
See more: cp command in Linux with examples
rm command is one of the most common and basic commands in Linux. Even if you have a limited amount of experience with Linux, you’ve most likely heard of it. The main purpose of this command is to remove files and directories. Using this command to remove files and directories cannot be undone.
rm to delete a file by following the command with the name of the file:
$ rm file.txt
You will need to use the
-r option when deleting a directory.
$ rm -r directory01
See more: rm command in Linux with examples
Everything that’s running on a Linux system – a service, script, or anything else – is considered a “process.” If you need to end a running process on Linux, the
kill command is sure to do the job.
Once you’ve determined the PID of the process you wish to end, you can specify it as an argument to the
kill command. For example, to end a process with a PID of 1234:
# kill 1234
See also: How to Kill a Running Process on Linux
history command allows us to see all of the recently executed commands on our system. To visualize the current content of the shell history, we can use the
history command, without passing any argument or option. Each line in the output produced by it, is prefixed by number:
$ history 1 echo "linuxconfig.org" 2 cat /etc/hostname 3 ls -l /etc/hostname 4 history
See also: How to manage Bash history
touch command in Linux is used to alter the access and modification times for a given file or set of files. It’s also a super handy way to create an empty file very quickly, if you are running the
touch command and specify a file that doesn’t already exist.
The syntax is very simple – just specify the file name you wish to create or update the modification time for:
$ touch document.txt
See also: touch command in Linux with examples
df utility is used to display, among the other things, filesystems available and used disk space. If the program is called without any argument, all mounted filesystem are included in the report:
$ df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 2908316 0 2908316 0% /dev tmpfs 2930156 28392 2901764 1% /dev/shm tmpfs 2930156 1792 2928364 1% /run /dev/mapper/fingolfin_vg-root_lv 35862048 7210616 26800040 22% / tmpfs 2930156 124 2930032 1% /tmp /dev/sda1 1032088 161664 817996 17% /boot /dev/mapper/fingolfin_vg-home_lv 25671908 1515396 22829408 7% /home /dev/mapper/fingolfin_vg-data_lv 152737296 90208196 54700828 63% /mnt/data
Knowing how to use the
man command in Linux will grant you the instant ability to learn how to use any other Linux command. Best of all, you don’t have to use Google to learn about a command or any other third party source – you can just get the information you need from the Linux command line.
Normally, you won’t specify any extra options with the
man command. All you need to do is specify the name of the command for which you’d like to view instructions:
$ man cat
See more: Man command in Linux with Examples
In this tutorial, we saw 20 of the most basic and essential commands that beginners need to learn on a Linux system. These commands are meant to teach you basic file system navigation and file manipulation tasks, so you can get started with modifying files and feeling more comfortable inside of the command line terminal. These commands will be enough to get you started, but there are lots more to learn!