Linux, Networking & Security are the domains of my interest.
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
And the list goes on and on.
Why Learn Linux Commands?
Bash skills are popular and pay handsomely.
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 “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.
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.
This can be used to copy a file & folder from one directory (source) to the other (destination).
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)
output the last part of files (by default last 10 lines)
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 !!!!
WARNING: ‘>’ will replace the entire content of the file. So in order to append to a file instead of overwriting it ">>" is used.
concatenate files and print on the standard output
It shows the content of a file, in a nice and interactive UI. (better than cat command)
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.
wc stands for word count.
print newline, word, and byte count for each file or input it receives via pipes.
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
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.
Note: Don’t miss quotes around special characters like ‘ * ’.
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.
du stands for Disk Usage.
Using this you can estimate file space usage.
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.
top stands for a table of processes.
It provides a dynamic real-time view of a running system.
Helpful in terminating processes manually.
kill command sends a signal to a process that terminates the process. (by default the signal sent is TERM)
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.
Bonus Resources to learn more about Linux
- Pipelining of commands (must watch)
- Linux Directories in 100 sec
- https://linuxjourney.com/ (for theory)
- https://overthewire.org/wargames/bandit/ (for practicing)
- Hackersploit Linux series (solution to above wargames and much more on Linux)
(Youtube Channels I have been following for the past 3 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.
© 2022 Ashutosh Singh Patel