Skip to main content

30+ Standard Linux Commands for Beginner or Intermediate Users

Linux, Networking & Security are the domains of my interest.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

Introduction to Linux

Linux is a free, open-source operating system used both on personal computers and on servers. Most of the devices and embedded systems in the world implement one or the other distributions of Linux. Its security features and stability make it stand out among other proprietary operating systems available in the market.

The most popular Linux “distros” include:

  • Ubuntu (my personal favorite)
  • Red Hat Enterprise
  • Linux Mint
  • Debian
  • Fedora
  • Arch

And the list goes on and on.

Why Learn Linux Commands?

Bash skills are popular and pay handsomely.

Linux commands

Linux commands

Linux Commands

Before we begin, just remember two things:

  1. Everything in Linux is a file.
  2. Linux file system is represented as an upside-down tree.

Note: I have kept everything simple and concise but if you want to know more about the command you can always use “man <command>” which opens up the manual page for that command.

whoami

Print the user name associated with the current effective user ID (or simply the person who is currently logged in to the terminal session).

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

Note: "id -un" can be used instead of "whoami" to get the username.

man

man stands for Manual

If you want to look for any command in detail then man will help you in doing that by opening up a reference manual page for that command.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1
30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

clear

It simply clears your terminal screen.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1
30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

Note: You can use “Ctrl+l” as a shortcut to “clear +x” command.

pwd

pwd stands for Print Working Directory

Print name of present/current working directory.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

ls

ls stands for list.

List information about the files present in the current working directory by default.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

Arguments can be added to enhance the output of this command.

Ex.1 the “ls -al” command will print the directory’s content in long list (‘l’ arg) format including the hidden files (files starting with ‘.’)(‘a’ arg) .

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

Ex.2 the “ls /usr” format can be used to list the content of any particular directory.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

cd

cd means Change Directory.

This command is used to move to any directory in your file system. (using absolute and relative path)

“cd ..” is used to move to the directory which is just outside of your working directory (“..” special path is used to indicate the parent folder).

“cd” is used to move directly to your home directory (~) no matter where you are currently present.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

mkdir

mkdir stands for make directory / create directory.

Create the directory(ies), if they do not already exist.

Ex. We want to create 2 directories named “dir1” and “dir2”.

You can create multiple nested folders by adding the ‘-p’ option:

Ex. mkdir -p dir1/dir3

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1
30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

touch

It’s used to create a new file & if a file already exists with the same name then it opens the file in write mode and update the access and modification times of each FILE to the current time.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

rmdir

rmdir stands for remove directory.

you can delete a folder (not a file) using rmdir

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

rm

rm stands for remove.

This command removes each specified file. By default, it doesn’t remove directories.

"rm -r" is used to remove folders ( as it recursively deletes all the files from the innermost directory in the tree hierarchy and moves up until it reaches the directory you mentioned ).

"rm -r" is used to remove folders ( as it recursively deletes all the files from the innermost directory in the tree hierarchy and moves up until it reaches the directory you mentioned ).

open

This command opens up your file or the directory you mentioned outside of the terminal in GUI format.

open <filename> or open <directory name>

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1
30-standard-linux-commands-for-beginner-or-intermediate-users-part-1
30-standard-linux-commands-for-beginner-or-intermediate-users-part-1
30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

mv

mv stands for move.

Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

Moving a file from the present directory to another

Moving a file from the present directory to another

Renaming of a text file from "text2" to "text1"

Renaming of a text file from "text2" to "text1"

cp

This can be used to copy a file & folder from one directory (source) to the other (destination).

copying files from the current directory to another directory

copying files from the current directory to another directory

Note: Add the ‘-r’ option to recursively copy the whole content of the directory

prints the first part of the files. (by default first 10 lines)

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1
Use the "-n" parameter and specify the no. of lines you want to print from the beginning of the file.

Use the "-n" parameter and specify the no. of lines you want to print from the beginning of the file.

tail

output the last part of files (by default last 10 lines)

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1
Use the "-n" parameter and specify the no. of lines you want to print from the end of the file.

Use the "-n" parameter and specify the no. of lines you want to print from the end of the file.

date

This might look like a simple command at first as it only prints the current time, date, and day.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

But what if we can add something to the date command and redirect its output to a file (using ‘>’) that we can use in our bash scripts?

Let’s do it !!!!

We have redirected the output of the date from the terminal to a file "current_time_and_date.txt".

We have redirected the output of the date from the terminal to a file "current_time_and_date.txt".

WARNING: ‘>’ will replace the entire content of the file. So in order to append to a file instead of overwriting it ">>" is used.

The output of the "pwd" command is appended instead of overwriting.

The output of the "pwd" command is appended instead of overwriting.

cat

concatenate files and print on the standard output

It simply prints out the content of a file (if it's a text file) to the standard output.

It simply prints out the content of a file (if it's a text file) to the standard output.

Concatenation of output if multiple files are present.

Concatenation of output if multiple files are present.

less

It shows the content of a file, in a nice and interactive UI. (better than cat command)

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1
We can use some of the vi's (text editor) key binding inside this window

We can use some of the vi's (text editor) key binding inside this window

echo

This is the simplest of all commands. It prints the string passed to it as an argument to standard output.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

we can insert values of environment variables in a string with this command.

here PWD is an environment variable

here PWD is an environment variable

wc

wc stands for word count.

print newline, word, and byte count for each file or input it receives via pipes.

The file has "2 newlines", "8 words", and "64 bytes" content in total

The file has "2 newlines", "8 words", and "64 bytes" content in total

Extra parameters like "-l" or "-w" can be added to get specific output like, the no. of lines or the no. of words in the files.

Extra parameters like "-l" or "-w" can be added to get specific output like, the no. of lines or the no. of words in the files.

sort

sort lines of a text file (in chronological order by default)

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

Note: If you want to sort numbers in a file then use "sort -n filename" instead of just sort.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

uniq

It reports or omits repeated lines. (used in conjunction with sort command)

If only “uniq” is used alone then it removes only the adjacent duplicate values.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

diff

compare files line by line

"5a6" basically means that in the 2nd file "flowers2.txt" an additional line ('6') was added ('a') after the line '5'.

"5a6" basically means that in the 2nd file "flowers2.txt" an additional line ('6') was added ('a') after the line '5'.

find

This command helps in searching for files in a directory hierarchy using some particular search pattern.

Ex. Let’s find out the files in the current directory having .txt as their file extension.

The above find command searched for all (' * ') the files in the current directory (' . ') whose name ('-name') ends with (".txt").

The above find command searched for all (' * ') the files in the current directory (' . ') whose name ('-name') ends with (".txt").

Note: Don’t miss quotes around special characters like ‘ * ’.

Search for the file 'Wallpapers' inside the folder Pictures, it can be a file or a directory.

Search for the file 'Wallpapers' inside the folder Pictures, it can be a file or a directory.

In the current directory search for directories ('-type d') with case insensitive name (-iname) and contains hello in between its name (*hello*).

In the current directory search for directories ('-type d') with case insensitive name (-iname) and contains hello in between its name (*hello*).

grep (I use it quite often)

grep stands for “global regular expression print”.

It’s similar to find but it searches for the expression inside of a file.

searching for "nnoremap" inside a file ".vimrc". "-n" arg tells you the line number they are present at.

searching for "nnoremap" inside a file ".vimrc". "-n" arg tells you the line number they are present at.

grep with the ' -r ' option searches recursively for the pattern inside the current directory.

grep with the ' -r ' option searches recursively for the pattern inside the current directory.

du

du stands for Disk Usage.

Using this you can estimate file space usage.

the du command outputs the total size of the current directory. (-h) the argument is used to get human-readable output.

the du command outputs the total size of the current directory. (-h) the argument is used to get human-readable output.

Note: ' * ' is used to represent all the files.

df

df stands for disk free.

This command is a disk utility tool that helps us to identify the amount of free space available in our filesystem.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

history

Everytime you execute a command in the terminal it is saved in a file (/home/$USER/.bash_history) if you are using bash terminal.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

It is useful when you forget a command you executed earlier & wanna execute it now then you can search the history using pipelining and grep command.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

ps

ps stands for process status.

This command lists the user-initiated processes currently running in the current session.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1
argu. 'ax' is used to see every process on the system using BSD syntax

argu. 'ax' is used to see every process on the system using BSD syntax

top

top stands for a table of processes.

It provides a dynamic real-time view of a running system.

" top -o '%MEM' " which shows the memory usage of applications in descending order.

" top -o '%MEM' " which shows the memory usage of applications in descending order.

kill

Helpful in terminating processes manually.

kill command sends a signal to a process that terminates the process. (by default the signal sent is TERM)

" kill -l " lists down the available signals that can be sent to a process to terminate it.

" kill -l " lists down the available signals that can be sent to a process to terminate it.

SIGKILL Vs SIGTERM

SIGKILL Vs SIGTERM

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

How to kill a process?

“kill <PID>” where PID is the process ID (can be found in the first column of the top command)

Ex. If I want to kill the "blueman-manager" process with PID 36709, then I will simply execute the "kill 36709" or “kill -s TERM 36709" (if you want to specify the type of signal as well) command in the terminal.

30-standard-linux-commands-for-beginner-or-intermediate-users-part-1

killall

If you want to send a signal to a process just using its name.

'v' means verbose which is used to know what the command is doing when it's executed.

'v' means verbose which is used to know what the command is doing when it's executed.

Bonus Resources to learn more about Linux

Bonus

(Youtube Channels I have been following for the past 3 years)

This article is accurate and true to the best of the author’s knowledge. Content is for informational or entertainment purposes only and does not substitute for personal counsel or professional advice in business, financial, legal, or technical matters.

© 2022 Ashutosh Singh Patel