If you’ve just started out using Linux, you’ve probably heard about how powerful the command line can be. Indeed, it is powerful, but only if you know the commands to type into it. In this guide, we’ll run through the top 10 most essential commands that you need to learn right off the bat.
Bash is the default shell on all Linux distributions (or at least 99% of them), and you can access it by opening up a terminal on your system. Some Linux servers only have a terminal and lack a desktop environment entirely. You can imagine how important it is to know a few commands in that case.
Even with a desktop environment such as GNOME, KDE, etc, you’ll only unleash the true potential of Linux by mastering the command line. Knowing these 10 essential commands will put you on track for doing exactly that.
Essential Linux Commands
pwd command stands for “print working directory” and tells you what directory you are currently in. It will show the full path to your current directory and it’s not necessary to supply any options to the command.
cd command stands for “change directory” and is used to navigate to different places on a Linux system. All you need to do is tell
cd the path to the directory you wish to change into.
ls command is short for “list” and is used for listing a directory’s contents.
ls will list your current directory’s files. But you can also supply a path without having to navigate there first.
To see more information about the files, rather than simply listing them, you can append the
-l option. This will show some extra info like the owner of the file, the last time it was modified, and the permissions on it.
To see hidden files, you can use the
-a option. Feel free to combine this with the
-l flag as well, if you want.
We know how to change into directories and see what files are there, but how about moving the files? That’s where the
mv command comes in. It can be used for both files and directories. You can supply it with as little as two arguments: the file you want to move and where to move it to.
This command will move
some_file.txt to the ddt user’s desktop:
mv some_file.txt /home/ddt/Desktop
You can also move multiple files at once:
mv file1.txt file2.txt file3.txt /home/ddt/Desktop
mv command is also used to just rename files:
mv unpublished.txt published.txt
Short for “concatenate,” the
cat command is used to read files. It can also read multiple files at once and concatenate the output, hence the name.
Supply as many arguments as you want:
cat some_file.txt some_other_file.txt
Or it can be easier to just use a wildcard:
cp command is used to copy files or directories.
To copy a file to a different directory:
cp /dir1/file.txt /dir2
If you want to copy a directory and all its contents, you’ll need to include the
-r (recursive) option.
cp -r /dir1 /dir2
Short for “remove,” the
rm command can delete files from your system.
If you want to delete a directory, you’ll need to include the
-r (recursive) option. If the directory isn’t empty, you’ll also need the
-f (force) option, which tells
rm to attempt to remove the file or directory no matter what.
rm -rf /path/to/directory
Nano is a text editor. It’s one of several editors that are usually included on Linux installations by default. The vi editor and Emacs are also popular choices. However, nano is very user friendly and a good choice for beginners.
Nano’s controls are listed at the bottom. The
^ means the Ctrl key on your keyboard. So, to exit a file, just use Ctrl + X. You’ll be asked if you want to save your changes if you made any.
grep command is used to search files or terminal output for a pattern you specify. It’s probably easier to explain it through examples.
To search all the text documents in
/directory1 for text string “Daily Dose”:
grep "Daily Dose" /directory1/*.txt
The output from
grep indicates that our text string was found inside
It’s common to pipe standard output into
grep. For example, let’s use
ls piped to
grep to check for .txt documents inside
ls -l /directory1 | grep txt
grep has a lot of useful options. One of the most common is
-i, which tells
grep that the supplied pattern is case insensitive.
top command will show you a lot of useful information about your system – CPU and RAM usage, which processes are running, how long your system has been powered on, and more.
Many distributions also come with the more useful
htop command, which is the same thing but much easier to interpret.
You can exit either program at any time by pressing “q” on your keyboard. Both have the ability to kill processes and do other things. See the bottom of
htop‘s window to see what keys to use to perform various functions.
These commands should be enough to get you started with the Linux terminal, though we’ve barely scraped the surface of what’s possible. Some of these commands have a lot of options, which you can read about on the man pages. For example, to view the man page for
After mastering these basics, there will be many more commands to learn.