Enroll Course Now
Linux command is a set of instructions for carrying out a certain action in Linux. In this article, I will illustrate a basic Linux commands cheat sheet to make your journey with the Linux command line easier. Type these commands into the terminal to handle everything from files and directories to processes and more.
Table of Contents
Available Download Options
Most Popular
Combo Pack
A Linux command is a text-based interface that allows you to communicate with the Linux operating system. The commands are inserted into a terminal which is then passed to a shell that tells the operating system what to do. Linux command is a great alternative to Graphical User Interface (GUI) as it is much faster and more efficient. You can perform all tasks with commands that can be done using the GUI.
Here I have categorized all the basic commands in Linux. You can also find that some commands are mentioned with their necessary options. For your better understanding, the structure of a Linux command is
Command -options arguments parameters
In this category, you will find commands that can be used to copy, make, and remove files; create directories; and navigate through these.
Command | Description |
---|---|
cp | Copies files and directories |
pwd | Prints the current working directory |
cd | Changes current directory |
cd.. | Changes to the parent directory |
cd – | Changes to the previous directory |
cd ~ | Changes to the home directory |
ls | Lists contents of the current directory |
ls -l | Lists the files and directories in the current working directory in long format |
ls -a | Lists all files and directories including the hidden ones |
ls -r | Lists files/directories in reverse |
mkdir | Creates a new directory |
rmdir | Removes an empty directory |
mv | Moves or renames a file /directory |
rm | Removes a file/directory |
rm -i | Prompts system confirmation before deleting |
rm -r | Deletes a file/directory recursively |
rm -d | Deletes empty folders |
Under this section, you can find commands which will assist you in editing your files and show contents in your desired ways.
Command | Description |
---|---|
touch | Creates an empty file/modify timestamp |
cat | Concatenates and prints file contents |
cat -n | Displays the contents of a file along with line numbers |
tac | Concatenates and prints file contents in reverse order |
less | Shows contents in a scrollable manner |
head | Displays the first ten lines of a file |
tail | Displays the last ten lines of a file |
grep | Searches for a specified pattern in one or more files |
nano | Edits and creates files |
diff | Compares two text files |
sort | Sorts lines of a text file |
sort -r | Sorts file reversely |
sort -u | Removes duplicates and sorts unique values |
Here, you will get to know how you can change the permission of a file or directory:
Command | Description |
---|---|
chmod | Modifies a file or directory’s read, write, and execute permissions |
chown | Changes the ownership of a file, directory, or symbolic link to a specified username. |
chgrp | Changes the group ownership of a file or directory |
This section consists of commands that can be used to control the operating system just by using the command line.
Command | Description |
---|---|
poweroff | Shuts down the system |
reboot | Restarts the system |
shutdown | Shuts down or reboots the system |
Commands for system and process management are:
Command | Description |
---|---|
sudo | Allows a user to run a command with the privileges of another user |
ps | Lists the running processes on a system |
kill | Terminates running processes on a system |
killall | Terminates all processes with a specified name |
df | Displays the amount of disk space used and available on a file system |
du | Estimates file space usage |
Commands for package installation are:
Command | Description |
---|---|
apt install [package] | Installs software packages from the Ubuntu package repository |
apt-get install | Performs package management tasks such as installing, upgrading, and removing packages |
Commands for file compression are:
Command | Description |
---|---|
tar | Creates, views, and extracts files from an archive file |
zip | Creates, views, and extracts files from a compressed archive file |
unzip | Extracts files from a compressed archive file in the ZIP format |
gzip | Compresses files or directories to reduce their size |
bzip2 | Compresses files or directories to reduce their size |
If you are searching for a pattern in a file content or want to locate files in your system these basic commands are here to help you.
Command | Description |
---|---|
grep ‘pattern’ files | Searches for a specified pattern or regular expression in one or more files and display the matching lines |
grep -r pattern dir | Searches for a specified pattern or regular expression recursively in a directory and its subdirectories, and display the matching lines. |
locate | Locates files and directories on the system |
find | Locates files and directories on the system |
find -empty | Searches for empty files |
Linux has huge commands and options to offer. It’s ok if you can’t memorize all these. Use the built-in documentation command to get help.
Command | Description |
---|---|
man | Displays the manual page of a command or utility |
Commands to get system information are:
Command | Description |
---|---|
date | Displays and sets system date and time |
cal or ncal | Displays the calendar of the current month |
who | Displays information about currently logged-in user |
whoami | Displays the user name of the current user logged in |
uname | Displays information about the current system and operating system |
hostname | Displays or set the hostname of the current system |
hostnamectl | Queries or modifies the hostname and related settings of the current system |
history | Displays a list of previously executed commands in the terminal |
history -c | Clears the history list of previously executed commands |
df | Shows information about both total and available space on a file system |
You can easily add or remove a user in your system using the following commands.
Command | Description |
---|---|
useradd | Creates a new user account on the system |
userdel | Deletes a user account from the system |
passwd | Changes a user’s password |
groupadd | Adds a new group to the system |
groupdel | Deletes an existing group from the system |
Id | Displays the user and group IDs associated with the current user |
su | Switches to another user account |
Finally, we have listed more commands that may help you in your Linux journey.
Command | Description |
---|---|
echo | Displays a line of text or a variable value on the command line |
clear | Clears the terminal window |
wc | Counts the number of lines, words, and characters in a file |
vim | Texts editor for editing text files |
ping | Checks the connectivity between two network devices |
exit | Exits the current shell session |
htop | Displays the system’s process real-time process activity |
shred | Securely deletes the files by overwriting multiple times |
w | Displays information about the currently logged-in users and their activities |
ps | Displays the running processes |
whatis | Displays a brief description of a command |
wget | Downloads files from the internet |
If you are just starting or are still in the learning phase with Linux, these are a few basic commands you will need to know. Furthermore, these commands were comprehensive enough to cover virtually every job performed from the Linux command line.
Some basic Linux commands are as follows:
In Linux, sudo stands for superuser do, it allows users to execute commands as a superuser. And superuser is the root user in the Linux system having the administrative privileges to perform different actions that regular users can not do.
There is no straightforward answer to this question. In fact, it depends on your project’s needs and your personal preferences. Some popular Linux distributions include Ubuntu, Fedora, Arch Linux, CentOS, etc.