Top 30 Linux Commands for Everyday Use

Linux is a popular open-source operating system that is widely used by users and organizations around the world. In this article, we will discuss some of the most commonly used Linux commands and how to use them. Whether you are a new user looking to get started with Linux or an experienced user looking to brush up on your skills, this article has something for everyone!

Linux Commands

I've been self-managing all my websites for more than twelve years now. And for nine of those years, it has been on DigitalOcean servers. It's a lot cheaper and, in many ways, a lot more fun. I think many people are naturally scared of working with a Linux server alone.

But it's no different than sitting in your WordPress dashboard all day. The real key difference is that instead of clicking on things to perform an action, you type in a command. And such commands have been documented extensively. And this article will add to that.

I'm starting this reference off with the top 30 Linux commands you will use daily if Linux becomes your main operating system. And also, if you plan on renting VPS servers and things like that.

For each command - I have added the main syntax on how to use it and what the output should look like. I've also added links to my in-depth articles that cover specific commands in more detail.


Linux Commands for Everyday Use

  • ls - list the files and directories in a directory
  • cd - change the current directory
  • pwd - print the name of the current directory
  • mkdir - create a new directory
  • rmdir - remove an empty directory
  • touch - create a new file
  • cp - copy files and directories
  • mv - move or rename files and directories
  • rm - remove files and directories
  • sudo - run a command as a superuser
  • chmod - change the permissions of a file or directory
  • chown - change the owner of a file or directory
  • find - search for files and directories
  • grep - search for text within a file
  • cat - display the contents of a file
  • head - display the first few lines of a file
  • tail - display the last few lines of a file
  • less - view a file one page at a time
  • apt, yum, rpm - package managers (Distro-based)
  • sort - sort the lines of a file
  • uniq - remove duplicate lines from a file
  • wc - count the number of lines, words, and characters in a file
  • tar - create and extract archives
  • zip - compress or decompress files
  • unzip - decompress files compressed with zip
  • ssh - securely connect to a remote computer
  • scp - securely copy files between computers
  • rsync - efficiently copy or synchronize files between computers.

The ls command in Linux

The ls command is used to list the contents of a directory. Here is an example of how to use it:

ls [options] [directory]

For example, if you use the following command:

ls -l

then the ls command will output something like this:

The ls command in Linux

In this output, the first column indicates the file permissions, the second column indicates the number of links to the file, the third and fourth columns indicates the owner and group of the file, the fifth column indicates the file size, the sixth and seventh columns indicate the last modified date and time, and the last column indicates the file or directory name.


The cd command in Linux

The cd command is used to change the current directory in Linux. Here is an example of how to use it:

cd [directory]

# For example, if you want to change the current directory to /var/www/html, you can use the following command:

cd /var/www/html

# You can also use the cd command to navigate to the parent directory of the current directory. To do this, you can use the .. syntax, like this:

cd ..

# This command will change the current directory to the parent directory of the current directory. For example, if you are currently in the /home/user/documents directory, this command will change the current directory to /home/user.
The cd command in Linux

The pwd command in Linux

As you saw above, I used the pwd command, which is used to see the current directory.

The pwd command in Linux

The pwd command does not take any options, so you can simply run it as shown above to print the current working directory.


The mkdir command in Linux

The mkdir command is used to create directories.

mkdir mydirectory

# This command will create a new directory with the specified name, and you can then use the ls command to list the contents of the current directory and verify that the new directory has been created.
The mkdir command in Linux

The mkdir command does not produce any output by default, unless you specify the -v option, which will cause it to print the name of each directory it creates, like this:

mkdir -v /home/user/documents/mydirectory

This command will output the following:

mkdir: created directory '/home'
mkdir: created directory '/home/user'
mkdir: created directory '/home/user/documents'
mkdir: created directory '/home/user/documents/mydirectory'

The rmdir command in Linux

The rmdir command is used to remove directories.

For example, if you want to remove the mydirectory directory, you can use the following command:

rmdir mydirectory

You can use the -p option to remove a hierarchy of directories. For example, if you want to remove the mydirectory directory and all of its parent directories, you can use the following command:

rmdir -p /home/user/documents/mydirectory

This command will remove the mydirectory directory, as well as the parent directories documents and home, if they are empty. If any of the parent directories are not empty, the rmdir command will display an error message and will not remove the directory hierarchy.

Just like with the mkdir command, you can use the -v option to show output.

Full guide: How to Delete Files & Folders in Linux


The touch command in Linux

The touch command is used to create files or update the timestamps of files. You can use it to create new empty files, or to update the timestamps of existing files without modifying their contents. You can also use the -a and -m options to modify the access time and modification time of a file, respectively. It does not produce any output by default, but you can use the -v option to see the names of the files it creates or updates.

The touch command in Linux

If you want to create a new file named myfile.txt, you can use the following command:

touch myfile.txt

If you want to update the access time and modification time of the myfile.txt file to the current time, you can use the following command:

touch -a -m myfile.txt

The cp command in Linux

The cp command in Linux

The cp command is used to copy files or directories from one location to another.

cp source_file destination_file

In this example, source_file is the file that you want to copy, and destination_file is the location where you want to copy the file.


The mv command in Linux

The mv command is used to move files or directories from one location to another. It can also be used to rename files or directories.

mv source_file destination_file

# In this example, source_file is the file or directory that you want to move, and destination_file is the location where you want to move the file or directory. If destination_file already exists, then source_file will be moved into it. If destination_file does not exist, then source_file will be renamed to destination_file.

Full guide: How to Rename Files in Linux


The rm command in Linux

The rm command in Linux

The rm command is used to delete files or directories.

rm file

The -r option is used with the rm command to delete directories and their contents, including any subdirectories and files.

rm -r directory

Important: The rm command is a powerful command and can be dangerous if used improperly. Be careful when using it, as it permanently deletes files and directories, and there is no way to recover them. It is always a good idea to double-check the files and directories that you are about to delete before using the rm command.

Full guide: How to Delete Files & Folders in Linux


The sudo command in Linux

The sudo command is used to execute a command as the superuser (also known as the "root" user), which has more privileges than a regular user. This is often necessary when performing tasks that require administrative privileges, such as installing software or modifying system files.

sudo command

Important: The sudo command can be dangerous if used improperly. Only use it if you are familiar with the command that you are executing and you understand the consequences of running it as the superuser. It is always a good idea to double-check the command that you are about to execute with sudo before running it.


The chmod command in Linux

The chmod command is used to change the permissions of a file or directory. Permissions control which users can read, write, or execute a file or directory.

Here is an example of how to use the chmod command:

chmod permission file

Note: The chmod command is a complex command with many different ways to specify permissions. If you are new to using chmod, I would recommend reading my full guide:

File & Folder Permissions in Linux


The chown command in Linux

The chown command is used to change the owner of a file or directory. The owner of a file or directory is the user that has the ability to modify the permissions of the file or directory.

Here is an example of how to use the chown command:

chown owner:group file

Note: The chown command is a complex command and there are many different ways to specify owners and groups. If you are new to using chown, I would recommend reading my full guide:

File & Folder Permissions in Linux


The find command in Linux

The find command is used to search for files or directories that match specified criteria.

find path -name pattern

In this example, path is the directory where the find command will start searching, and pattern is the pattern that the find command will use to match files or directories. The -name option specifies that the pattern should match the name of the file or directory.

Here is an example of using find to search for files with the .txt extension in the current directory and all of its subdirectories:

find . -name "*.txt"

This command would look like this in the terminal:

The find command in Linux

In this example, find starts its search in the current directory (indicated by .), and looks for files with names that end in .txt. The -name option is used to specify the pattern that the file names should match.

Note: I have written an entire tutorial on how to find and locate files in Linux, read it here:

How to Locate Any File in Linux


The grep command in Linux

The grep command is used to search for patterns in text files.

Here is an example of using grep to search for the string "hello" in the file myfile.txt:

grep "hello" myfile.txt

This command would look like this in the terminal:

The grep command in Linux

In this example, grep searches the file myfile.txt for the string "hello" and prints out any lines from the file that contain the string.

Like find, grep is a powerful command with many options for refining the search. For more information, you can type man grep in the terminal to view the grep manual page.


The cat command in Linux

The cat command is used to concatenate files and print their contents to the terminal. Here is an example of using cat to print the contents of the file myfile.txt:

cat myfile.txt

And the output is shown directly in the terminal:

$ cat myfile.txt
This is the contents of myfile.txt

One thing to note is that this command will fetch the entire file, and a better way to navigate files is either directly with an editor like nano or use the head and tail commands, which we will discuss next.

Lastly, cat can also be used to create new files and concatenate multiple files into one. For more information, you can type man cat in the terminal to view the cat manual page.


The head command in Linux

The head command is used to display the beginning of a file.

Here is an example of using head to print the first 10 lines of the file myfile.txt:

head -n 10 myfile.txt

And the output would be:

The head command in Linux

For more information about the head command, you can type man head in the terminal to view the head manual page.


The tail command in Linux

The tail command is used to print the last few lines of a file to the terminal.

Here is an example of using tail to print the last 10 lines of the file myfile.txt:

tail -n 10 myfile.txt

And the output:

The tail command in Linux

This command is particularly useful when you want to do things like check the last couple of lines from your error.log file, or similar files that might have a lot of lines in them.


The less command in Linux

The less command is a utility in Linux that allows you to view the contents of a file or command output one page at a time. This can be useful when the output is too long to fit on a single screen.

less myfile.txt

This will open the myfile.txt file in less, and you will be able to use the up and down arrow keys to scroll through the file one page at a time. You can also use the spacebar to move forward one page, and the b key to move backward one page.

You'll want to use this command when you're working with files that have extremely long lines, for example - the access.log file. Without the less command, you'd have to manually scroll each line which is unproductive.

Here is an example that uses less to view the output of the ls command, which lists the contents of a directory:

ls -al | less

In the terminal, this might look something like this:

The less command in Linux

This command first runs ls -al, which lists the contents of the current directory in long format (including hidden files), and then pipes the output to less. This allows you to view the output one page at a time, rather than having it scroll off the screen.


The apt, yum, rpm commands in Linux

In Linux, package managers are tools that allow you to easily install, update, and manage software packages. There are several different package managers available for Linux, and they're generally Distro-based.

Here is an example of the three most popular package managers in Linux: apt, yum, and rpm:

# To install a package using apt:
sudo apt-get install <package_name>

# To update all packages using yum:
sudo yum update

# To install a package using rpm:
sudo rpm -i <package_name>

The apt package manager is commonly used in Debian-based Linux distributions, such as Ubuntu, while yum is used in Red Hat-based distributions, such as CentOS. The rpm package manager is used in a variety of different Linux distributions.


The sort command in Linux

The sort command allows you to sort the lines of text in a file or standard input in a particular order.

sort filename

This command will sort the lines of text in the file filename and print the result to the standard output.

But you can do more than just that. Here are some other examples:

# sort lines of text in reverse alphabetical order
sort -r filename

# sort lines of text numerically
sort -n filename

# ignore leading whitespace when sorting
sort -b filename

# sort lines of text based on the second field (delimited by whitespace)
sort -k 2 filename

# sort lines of text based on the third field (delimited by ":" character)
sort -t : -k 3 filename

# sort lines of text based on the length of each line
sort -n -s -k 1.1,1.100 filename

# sort lines of text case-insensitively
sort -f filename

# randomly shuffle the lines of text in a file
sort --random-sort filename

The sort command is also often used together with the grep command.

# this will give you a clear view of your access.log file by showing you referral sources and how many hits you have gotten from the said source

grep "200 " access.log   | cut -d '"' -f 4   | sort   | uniq -c   | sort -rn   | grep -v "example.com"   | less

The uniq command in Linux

The uniq command allows you to remove duplicate lines from a file or standard input, while also optionally counting the number of times each line appears.

uniq filename

This command will remove any duplicate lines from the file filename and print the result to the standard output.

You can also use it to do things like:

# count and print the number of times each line appears in the input
uniq -c filename

# ignore leading whitespace when comparing lines
uniq -b filename

# compare only the first N characters of each line
uniq -w 10 filename

The wc command in Linux

The wc command allows you to count the number of lines, words, and characters in a file or standard input.

wc filename

This command will count the number of lines, words, and characters in the file filename and print the result to the standard output.

12      38     286 filename

# In this example, the wc command has counted 12 lines, 38 words, and 286 characters in the file filename.

You can also use the wc command to count the number of lines, words, and characters in multiple files at the same time. For example, the following command would count the number of lines, words, and characters in the files filename1 and filename2:

wc filename1 filename2

# and the output would look like this:

6      19     143 filename1
6      19     143 filename2
12      38     286 total

You can also use options to do specific counts:

# only count the number of lines in the input
wc -l filename

# only count the number of words in the input
wc -w filename

# only count the number of bytes in the input
wc -c filename

The tar command in Linux

The tar command allows you to create, extract, and manipulate archive files in the tar format. An archive file is a single file that contains multiple files and directories. This command is often used to create backups or to transfer multiple files.

Here's an example of how to use the tar command to create an archive file:

tar -cf archive.tar file1 file2 directory1

And to extract a tar file you can use this command:

tar -xf archive.tar

Some other useful options include:

# compress the archive using gzip
tar -czf archive.tar.gz file1 file2 directory1

# extract the contents of the archive to a specific directory
tar -xf archive.tar -C /path/to/directory

# list the contents of the archive
tar -tf archive.tar

The zip command in Linux

The zip command is similar to the tar command, but it uses a different archive format that is more commonly used on Windows systems.

zip archive.zip file1 file2 directory1

This command will create an archive file called archive.zip that contains the files file1 and file2 and the directory directory1.

For an in-depth review of the zip command, please read my full guide here:

How to use Zip & Unzip in Linux


The unzip command in Linux

The unzip command allows you to extract files from archive files in the zip format.

unzip archive.zip

This command will extract the contents of the archive.zip file into the current directory.

You can also use the unzip command to extract only certain files from an archive. For example, the following command will extract only the files file1 and file2 from the archive.zip file:

unzip archive.zip file1 file2

For an in-depth review of the unzip command, please read my full guide here:

How to use Zip & Unzip in Linux


The ssh command in Linux

The ssh command allows you to securely connect to a remote computer over an encrypted network connection. It is commonly used to remotely access and manage servers, but it can also be used to connect to other types of computers.

ssh username@hostname

Some things to know about the ssh command include:

  • ssh uses a secure encryption algorithm to protect the data transmitted between the local and remote computers. This ensures that an attacker cannot intercept or modify the data.
  • ssh supports various authentication methods, including passwords, public key authentication, and two-factor authentication.
  • ssh allows you to securely tunnel other network connections through the encrypted ssh connection. This can be useful for accessing network resources that are only available on the remote network, or for encrypting insecure network protocols.
  • ssh is commonly used to access and manage servers remotely, but it can also be used to connect to other types of computers, such as Raspberry Pi devices or home computers.
  • ssh is available on most Unix-like operating systems, including Linux and macOS. It is also available on Windows systems through third-party software.

The scp command in Linux

The scp command allows you to securely copy files between a local and a remote computer over an encrypted network connection. It uses the same underlying technology as the ssh command, but it is specifically designed for copying files.

Here's an example of how to use the scp command to copy a file from the local computer to a remote computer:

scp filename username@hostname:/path/to/destination

This command will copy the file filename from the local computer to the remote computer with the hostname hostname. The file will be placed in the /path/to/destination directory on the remote computer, and the username username will be used to authenticate the connection.

You can also use the scp command to copy a file from a remote computer to the local computer. For example, the following command will copy the file filename from the remote computer to the current directory on the local computer:

scp username@hostname:/path/to/filename .

The scp command is typically installed by default on most Unix-like operating systems, including Linux and macOS. On Windows systems, the scp command is not installed by default in versions earlier than 1809, but it is included in Windows 10 version 1809 and later. In earlier versions of Windows, you can install the scp command using third-party software such as PuTTY.


The rsync command in Linux

The rsync command allows you to efficiently copy and synchronize files between a local and a remote computer. It uses an algorithm that minimizes the amount of data transferred over the network by only copying the parts of files that have changed. This can make rsync much faster than other file transfer tools, especially when copying large files or when synchronizing large directories.

Here's an example of how to use the rsync command to synchronize a directory on the local computer with a directory on a remote computer:

rsync -avz /path/to/local/directory username@hostname:/path/to/remote/directory

This command will synchronize the contents of the /path/to/local/directory directory on the local computer with the /path/to/remote/directory directory on the remote computer with the hostname hostname. The -a and -v options enable archive mode and verbose output, respectively, and the -z option enables compression to reduce the amount of data transferred over the network. The username username will be used to authenticate the connection.

rsync is typically included by default on Unix-like operating systems, such as Linux and macOS, but it is not included on Windows by default. However, it is available for Windows through third-party software, such as Cygwin or cwRsync.


All the Published In-Depth Guides

The links below are all the currently published in-depth Linux command guides on this site: