The Linux terminal is a powerful tool that can be used to perform a wide variety of tasks, from managing files and directories to configuring the system and troubleshooting problems. While there are many different Linux commands available, there are a few that are particularly useful for everyday use.
This article will introduce you to the top 50 most useful Linux terminal commands. These commands are grouped into the following categories:
- File and Directory Management
- System Administration
- Networking
- Text Processing
- Software Development
If a command shown does not work for you and returns an error, try to install the package needed for that command (tutorial on how to install packages in the System Administration section).
I used Ubuntu 22.04 LTS for all the screenshots, just because most of you are probably on Ubuntu or an Ubuntu-based distribution. But if you are not on Ubuntu, don’t worry! You can still use the commands we show here on your Linux distribution (besides the package manager commands, but don’t worry about that for now).
Managing Files and Directories (Folders) in Linux
The following commands are used to manage files and directories in Linux:
ls
: Lists the contents of a directory. [You won’t have the example file there. It was in the screenshot to show the different between the directories/folders (blue) and the files (white)].
cd
: Changes the current working directory.
mkdir
: Creates a new directory.
rmdir
: Removes a directory.
touch
: Creates a new file or updates the timestamp of an existing file.
cp
: Copies a file or directory. (ls ~
allows us to list the contents of the home directory without needing to cd
into it.)
mv
: Moves or renames a file or directory.
rm
: Removes a file or directory.
find
: Searches for files and directories in the filesystem. The .
means our current directory, the -name
is so we can search by name, and the *
before and after test means that we don’t care about what comes before or after test
. We just want the files that have “test
” in the name.
clear
: Clears the terminal window output.
pwd
: Prints the current directory you are in.
System Administration in Linux
The following commands are used to administer the Linux system:
sudo
: Allows a user to execute commands with root privileges (needed for tasks that require root privileges, such as creating or deleting files in the root directory /
). Type sudo
in front of the command you want to execute with root privileges. You’ll need to enter the root password in order to execute the command.
apt
: The package manager for Debian and Ubuntu-based distributions (this will not work on other Linux distributions). Type sudo apt install [name of package]
to install that package. Make sure to replace [name of package]
with the actual command you want to install. Type y
and hit the Enter
key (or the Return
key depending on your keyboard) when it asks “Do you want to continue? [Y/n] “.
dnf
: The package manager for Fedora-based distributions (this will not work on other Linux distributions). Type sudo dnf install [name of package]
to install that package. Make sure to replace [name of package]
with the actual command you want to install.
pacman
: The package manager for Arch Linux and derivatives (this will not work on other Linux distributions). Type sudo pacman -S [name of package]
to install that package. Make sure to replace [name of package]
with the actual command you want to install.
zypper
: The package manager for openSUSE (this will not work on other Linux distributions). Type sudo zypper install [name of package]
to install that package. Make sure to replace [name of package]
with the actual command you want to install.
ps
: Displays a list of running processes.
top
: Displays a real-time view of running processes. top
:
killall
: Terminates a running process.
service
: Manages system services (such as the ssh daemon).
systemctl
: Manages system services and units through the init system (Systemd only). sudo systemctl reboot
would restart your computer.
journalctl
: Displays the system journal. journalctl
:
Networking Commands
The following commands are used to manage network connections and troubleshoot networking problems:
ifconfig
: Displays information about network interfaces.
ping
: Tests network connectivity to a remote host, such as techniciansdepot.com
. If you can reach the server and get a response, that means you have a internet connection. (Press ctrl+c
to quit out of the command once you know you have an internet connection.)
netstat
: Displays information about network connections and routing tables. netstat
:
traceroute
: Traces the route that packets take to a remote host.
curl
: Transfers data over HTTP or HTTPS. curl https://www.techniciansdepot.com/
:
wget
: Downloads files from the internet. (The code gets saved to a file or folder in the current directory. You can check which directory you are in by typing the command pwd
.)
Text Processing
The following commands are used to process text files:
cat
: Concatenates and displays files. (I used cat
on a text file I had as an example.) cat example
:
less
: Displays files one page at a time. less example
:
head
: Displays the first few lines of a file.
tail
: Displays the last few lines of a file.
sort
: Sorts the lines of a file (usually in alphabetical order with the symbols and other characters at the top unless otherwise specified through flags).
uniq
: Removes duplicate lines from a file.
diff
: Compares two files and displays the differences.
grep
: Searches for patterns in text files.
awk
: A powerful text processing language.
sed
: A stream editor that can be used to perform simple text transformations.
vim
: A powerful modal text editor renowned for its efficiency and flexibility. It is a preferred choice among programmers and system administrators, yet it can be employed for various forms of text processing and is celebrated for its steep learning curve. However, don’t be concerned! You can read our article on the Vim Basics for Beginners to gain a deeper understanding of how to utilize this robust text editor and to appreciate the extensive functionality it offers (including the additional functionality you can incorporate through plugins, as Vim is highly extensible). You can also type the command vimtutor
after installing Vim if you don’t have it already (using the methods in the System Administration section) to get a quick tutorial on the basics of Vim.
vimtutor
:
nano
: A user-friendly text editor, offering a simpler alternative to Vim. While it may not possess the same extensive feature set or steep learning curve, Nano provides an accessible and straightforward platform for text editing. It’s an excellent choice for those seeking a more approachable text editor without the complexities associated with Vim. It shows all the keybinds and shortcuts (like Ctrl+X to exit) at the bottom of the terminal window, making it even easier for beginners to learn and use.
Software Development
The following commands are useful for software development:
gcc
: The GNU Compiler Collection, which can be used to compile C programs. Run the compiled binary with ./[name of file]
. Be sure to replace [name of file]
with the actual name of the binary file you specified with the -o
flag. If you didn’t use that flag, the name of the binary would be a.out
, so you can run that with ./a.out
.
g++
: The GNU C++ compiler. It is a part of the GNU Compiler Collection. Run the compiled binary with ./[name of file]
. Be sure to replace [name of file]
with the actual name of the binary file you specified with the -o
flag. If you didn’t use that flag, the name of the binary would be a.out
, so you can run that with ./a.out
.
make
: A tool for automating the build process of software projects. I will show you how to set up the make
command for C++. Start by creating a new file named makefile
using the text editor of your choice and write the following (make sure to hit tab on the second line before you write the g++
command):
Make sure to save that makefile
. Next, make sure you have the C++ file named main.cpp
ready that you want to compile. If not, create one now and save it as main.cpp
.
Finally, type the make
command and see it running the long command that you now no longer have to type!
We now have an executable file named main
. Run it with ./main
.
git
: A distributed version control system.
gdb
: A debugger used to step through and debug programs.
valgrind
: A tool for detecting memory leaks and other errors in programs. valgrind ls
:
Additional Tips for the Linux Terminal
Here are a few additional tips for using the Linux terminal:
Use the man
command to get help with any command. For example, to get help with the ls
command, type man ls
(this will work on most commands).
Use the -h
or --help
flag to get a brief overview of a command’s options. For example, to get help with the ls
command’s options, type ls --help
(-h
can sometimes conflict with other flags, so try to use --help
when possible; it is also recommend that you pipe this command through the less command like this: ls --help | less
).
Use the ~
character to refer to your home directory. For example, to cd
into your home directory, type cd ~
(typing cd
with no other arguments will also take you to your home directory).
Conclusion
This article has introduced you to the top 50 most useful Linux terminal commands. These commands are a good starting point for learning how to use the Linux terminal. Once you have mastered these basic commands, you can explore more advanced commands and techniques by reading our article on the Top 30 Linux Terminal Commands for Advanced Users.
Disclaimer: Unless otherwise indicated, all images featured in this piece belong to Technician’s Depot.
A great article for basic commands. Very thorough and easy to understand. It’s a real help to someone just starting out to Linux and does not have the grasp of the commands.