30+ Standard Linux Commands for Beginner or Intermediate Users

7 hours ago 8
BOOK THIS SPACE FOR AD
ARTICLE AD

Ashutosh Singh Patel

Master 30+ essential Linux commands for beginners and intermediate users to enhance your Linux proficiency.

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 EnterpriseLinux MintDebianFedoraArch

And the list goes on and on.

Bash skills are popular and pay handsomely.

Linux commands

Before we begin, just remember two things:

Everything in Linux is a file.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.

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

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

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.

It simply clears your terminal screen.

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

pwd stands for Print Working Directory

Print name of present/current working directory.

ls stands for List.

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

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) .

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

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.

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

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.

rmdir stands for remove directory.

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

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 ).

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

open <filename> or open <directory name>

mv stands for move.

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

Moving a file from the present directory to another
Renaming of a text file from “text2” to “text1”

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

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)

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

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

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

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

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”.

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

The output of the “pwd” command is appended instead of overwriting.

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.
Concatenation of output if multiple files are present.

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

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

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

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

here PWD is an environment variable

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
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 lines of a text file (in chronological order by default)

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

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.

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’.

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”).

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.
In the current directory search for directories (‘-type d’) with case insensitive name (-iname) and contains hello in between its name (*hello*).

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.
grep with the ‘ -r ‘ option searches recursively for the pattern inside the current directory.

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.

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

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.

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

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.

ps stands for process status.

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

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

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.

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.

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.

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.

(YouTube channels I have been following for the past 5 years)

DistroTube (For Linux Distribution related knowledge)David Bombal & NetworkChuck (Linux, networking, hacking….)Learn Linux Tv (Must follow)

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.

© 2024 Ashutosh Singh Patel

Read Entire Article