DEV Community

Cover image for 13 Terminal commands in Linux that you *must* know!
Asif Zubayer Palak
Asif Zubayer Palak

Posted on

13 Terminal commands in Linux that you *must* know!

Linux is a popular operating system that majority of the web servers use. If you are a web developer, your website is most likely being hosted on a Linux environment and using some of its tools.

Although you may not need to interact much with Linux - as a developer, it is powerful for you to know how to get around in a Linux environment.

Below are some of the commonly used Linux Terminal commands used for basic operations:

< ls >

ls is a terminal command used to display the list of files and sub-directories in the current directory.

The syntax of this command is

ls [flag] [File]

Some of the commonly used flags are
ls -a
list all files including hidden files.

ls -l
list with long format - shows permissions.

Image description

< cd >

cd stands for change directory and is used to move to another directory from your current directory.

The syntax of the command is

cd [directory_name]

cd / can be used to move to the root directory
cd a/b/c can be used to move to a nested directory. Here, c is inside b and b is inside a.
cd ~ or just cd can be used to move to the home directory.
cd .. can be used to move up one directory (previous directory).
cd "new folder" is the format used to change to a directory which has a blankspace in its name.

< man >

man command shows the user manual of any command that we can run on
the terminal. The manual contains NAME, SYNOPSIS, DESCRIPTION, OPTIONS etc. related to the command.
This is one of the most useful commands in Linux because it helps you learn to use other commands.

The syntax of the command is

man [command_name]

Entering man nmap gave out this result:
Image description

< touch >

The touch command primarily serves two purposes: create a file and modify a file's timestamp.

The syntax of the command is

touch <flag> <file_name>

Simply using touch <file_name> will let you create a file if it doesn't exist.
If a file of that name exists, it will update its timestamp to current time.

You can create multiple files together using touch by touch <file1> <file2> ... <filex>

You can create multiple ordered files using touch by touch <filename{<start>..<finish>}>
Example: touch file{1..10} or touch file{a..z}

< mkdir >

mkdir is a command that is used to create new directories.

The syntax of the command is

mkdir [flag] [directory]

The command mkdir folder1 is used to create a folder named folder1. You can create multiple folder simultaneously by mkdir folder1 folder2 folder3 ...

You can also create nested directories:
mkdir -p a/b/c

if folder a and folder b do not exist, they will be created before creating folder c.

< pwd >

pwd stands for present working directory and it displays the path of the directory you are currently in.

The syntax is simply pwd

< clear >

clear command clears the terminal. If your terminal is cluttered with commands and outputs, clear command is used to erase them.

The syntax is simply clear

< mv >

mv command can be used to either move one or more files or directories from one place to another or rename a file or folder.

The syntax for this command is

mv [flag] [source] [destination]

mv a.txt b.txt is an example where mv was used to rename a.txt to b.txt

mv a.txt folder1 is an example where mv was used to move a.txt was moved to a folder named folder1

< cp >

cp is used for copying files or directories from one location to another.

The syntax for using this command is

cp [source] [destination]

This can be used to move a file into a folder or a folder into a folder.

< rm >

rm is used to remove files in a directory, although they cannot delete directories by default. But with some flags, they can delete directories as well.

The syntax for the command is

rm [flag] [file]

you can remove multiple files consecutively.

To delete directories, you will need to use rm -rf folder1.

This is mostly helpful if the folder has nested folders and files in them.

< rmdir >

rmdir is similar to rm -rf however, it can only remove directories that are empty.

The syntax for this command is

rmdir folder1

< grep >

grep is globar regular expression print, which is used to search for a particular string or pattern in files.

The syntax for this command is

grep [flag] [pattern] [file]

Example: grep Username Records.txt
can help find the line containing "Username" from the "Records.txt" file and output the line.

< package managers >

There are different package managers based on what distro of linux you are using. Debian based distros use the apt package manager whereas the Arch based distros use pacman.

These package managers are important as they allow you to install, uninstall, reinstall and update packages and software.

The syntax for apt is

sudo apt [command] [package_name]

Commonly used commands are update to update a package, install to install a package, remove to uninstall and search to look for that package in the software repositories.

sudo is added to the beginning of the command because making changes to the packages requires root level permissions.

Entering sudo apt update gave the following result:
Image description

Now, the syntax for pacman is

sudo pacman [flag] [package_name]

Here the flags most commonly used are
-S to install a package, -Rs or -R to remove a package with and without its dependencies respectively.
-Ss to look for a package from the repositories.
-Suy is a flag that is used without the package_name, and it is used to upgrade all the packages in your system.

You can also install local or remote packages using -U flag and including the path to the file in [package_name] section.
Make sure the file ends in .pkg.tar.xz

So this brings you to a conclusion on the most commonly used linux commands, although they might seem daunting at first - by using them over time will make them seem like second nature!

Top comments (0)