Mastering Linux Commands
Learn the art of using commands to execute your daily needs.
Table of contents
Introducing Linux
Hello Reader! Today we'll be getting over linux commands that will be helpful in many different aspects of Computer Science.
So basically, Linux is a kernel when combined with various software components and graphical user interfaces, it forms a complete and functional Operating System.
What makes Linux diverse is the availability of different versions, known as distributions. These distributions vary in terms of the softwares they include, the user interfaces they offer, and the features they provide. Some are even categorized based on the user needs like:
Ubuntu and Fedora for normal day-to-day user's needs.
Kali and Black Arch Linux for security professionals and penetration testers.
Arch Linux for more customization and control over operating system and computer hardware.
and many more
Using Command Line Interface
Almost all the distributions of linux can be used and managed by 2 ways:
- Graphical User Interface
This is the snapshot of a typical Ubuntu Linux Desktop Environment. This contains all the applications and softwares currently presented in the machine.
- Command Line Interface
This the typical image of ubuntu terminal through which you can do almost all the task which can be done by GUI (Graphical User Interface).
But there is something needs to be covered, and that is the commands which would be executing these tasks. We'll be going through it in some time.
Commands
man | It is used for user manual, getting information about any command. |
pwd | It is used for getting information about the current working directory. |
cd | It is used for changing or navigating through any directory. |
ls | It is used to get the list of contents in that directory. |
ls -a | It is used to show all the files including hidden ones. |
ls -R | It is used to get all the sub-directories (works recursively). |
ls -l | It is used to get all the information of the files apart from names in tabular format. |
ls -la | This will include both features of l and a. |
ls -lah | It is used to get the size of files in kb, mb formats. |
clear | It is clearing the terminal by removing all the previous commands. |
mkdir | It is used to create a new directory. |
rmdir | It is used to remove a directory. |
mkdir -p folder1/folder2/folder3 | It is used to create a directory within a directory in a single command. Basically, a directory tree. |
rmdir -p folder1/folder2/folder3 | It is used to delete a non-empty directory tree. |
rm <file name> | It is used to delete a file. |
rm -i | It is used to ask permission to delete a file (type yes to actually delete). |
rm -R | It is used to delete the directory. |
rm -rf | It is used to forcefully delete the directory. |
touch | It is used to create a new file (more than one file can be created by space between names). |
file | It is used to get information/type of a file. |
mv <file1> <file2> | It is used to rename a file within the same directory. |
head | It is used to print initial content/lines to give an overview of the file. |
tail | It is used to print the last content/lines of a file. |
more | It is used to display content page by page. (use spacebar to navigate to different pages). |
open <file name> | It is used to open file or directory. |
df -m | It is used to check disk space in mb. |
df -hg | It is used to check disk space in human readable Gb format. |
cat | It is used to print all the contents in a file. |
cat <file name> > <new name> | It is used to rename the file. |
cat > <file name> | It is used to write something in the file. Type ctrl+D to save and exit the writing window. |
echo <content>><file name> | It is used to write a content to an existing file or create a new one if it did not existed earlier. |
ifconfig | It is used to show the network information like IP, domain, etc. |
sudo | superuser do. It is used to access and execute restricted files and operations. |
apt | It is to install an update package (advanced package management tool). |
sudo apt update | It is used to update the packages from the repository. |
sudo apt upgrade | It is used to upgrade the packages and caches. |
apt list --upgradable | This will list all the packages that are about to upgrade. |
sudo apt install "package name" | It is used to install packages which were downloaded from snap store. |
cp <file name> <location> <new name> | It is used to copy a file in a different directory. |
mv <file name> <path/new name> | It is used to move and rename at the same time. |
sudo apt remove "package name" | It is used to uninstall the package. |
diff <file 1> <file 2> | It is used to compare the difference between 2 files and display them. |
locate “*.txt” | It is used to locate all the files with the name .txt. |
find . | It is used to find the files in the current directory (.. for the previous directory). |
chmod u=rwx,g=rx,o=r <file name> [u=user, g=group, o=others] | It is used to change the permission for the file. |
whoami | It is used to check the person who is logged in as. |
sudo chown root <file name> | It is used to change the owner permission (here giving the root access). |
grep “text to find” <file name> | It is used to find the text within the file in the system. Prints it if it exists over there. (Case-Sensitive) |
grep -w “text” <file name> | It is used to print the full text. Use iw to use as not case sensitive. |
grep -win “text”./*.txt | It is used to search for text in all the files and prints its location, line number and text if it exists. |
history | It is used to show all the previously used commands. |
wget | It is used to install files from the internet. |
alias | It is used to show all the short forms of the commands. You can set the aliases, then it will work for that session only. |
top | It is used to see all the processes are running and their resources consuming. |
zip <destination file> <source file> | It is used to compress and zip the files. Unzip is the reverse. |
lscpu | It is used to get the CPU details. |
nslookup | It is used to get the information of server and address. |
“command 1” & “command 2” | It is used to run 2 commands simultaneously by running one in the background. |
echo “first” && echo “second” | It is used to execute the second command only when the first has been executed. (Like if else statement) |
Conclusion
As you journey through the realm of Linux commands, remember that practice makes perfect. Although this will cover most of the commands which can be used in day-to-day task. But still, I would recommend you to explore more commands to become a Linux Wizard and flex in front of your friends.
In conclusion, diving into the world of Linux commands is similar to unlocking a treasure of efficiency and power. With each command mastered, you not only enhance your technical powers but also open doors to endless possibilities in system administration, development, and beyond.
As you bid farewell to this guide, let it be a catalyst for your ongoing search for Linux mastery. Let your command line journey be filled with discovery, innovation, and the satisfaction of true expertise. The Linux universe awaits ahead and make it your own.