In this article, I am going to show you the 10 useful Linux commands that every developer should know. I am sure after reading this article you will get to learn some of the stuff about Linux. Let's begin.
Linux is experiencing a tremendous rise in the present technology world, so Linux commands are also in demand. Linux will further continue to rise in the future as well due to its power, simplicity, security, and open-source nature.
Most of the Linux distributions are free and are much powerful than its competitive non-free platforms like Microsoft Windows and Apple Mac.
I like Linux because of its open-source nature and you can customize the source code as you want. There are tons of Linux distributions, you can check my best distro picks. If you are coming to this article, then I am sure that you are a also big fan or regular user of Linux.
Grep is one of the very useful Linux commands to find the Patterns inside the File. Suppose, you need to search a word or many words inside a file you can easily do that by the "grep" command.
Usage:
Let's say we have a file - sites.txt
with the content below
If we need to search ittwist from the file we can easily do it with the below command.
grep ittwist sites.txt
You can also search for multiple texts in a file by simply executing
grep -e ittwist -e google sites.txt
You can further explore this command by simply executing man grep
Linux is a very secure platform, you can deal with permissions by simply executing this command. Chmod
is used to change the read, write, and execute permissions of files and directories.
Before diving deep into this command we need to briefly understand the basics.
Also, we have different permissions like:
Now if you view the directory listing of a file, we have a different set of letters for each user, group, and owner. Each letter should contain different permissions of - Read (r), Write (w), Execute (x), and Denied (-).
<-d> <user_letters> <group_letters> <owner_letters> filename
Example:
ls -al
Coming back to chmod, we have another concept of octal digits for providing permission to a particular file in which Read has a value of (4), Write has a value of (2), and Execute has a value of (1).
Suppose we want to give read write and execute permission - We can easily give by summing up the values (octal digits).
No Permission = No Read + No Write + No Execute = 0 + 0 + 0 = 0
Only Read = Read + No Write + No Execute = 4 + 0 + 0 = 4
Read and Write = Read + Write + No Execute = 4 + 2 + 0 = 6
Read, Write and Execute = Read + Write + Execute + 4 + 2 + 1 =7
Pretty Simple right, just a simple mathematical calculation for giving permissions to a file.
In chmod
we can give permission to each User, Group and Others like
Demonstration, I want to give only read permission to sites.txt file, I can easily give by.
chmod 444 sites.txt
You can further explore this command by simply executing man chmod
chown
stands for ChangeOwner - which has a purpose to change an owner of a file. Let's say you have one book which is purchased by you but if you want to change the ownership of that book to someone you can do that by gifting that book to that person. Likewise in Linux, you can change the ownership of a file by executing this command.
Example:
chown gopal site.txt
This command will change the ownership of sites.txt file to user gopal.
You can further explore this command by simply executing man chown
If you have an unresponsive program, you can terminate that program by sending any signals. There are total 64 signals, but commonly used signals are:
Also, you need to have a Process Identification Number to kill a particular process which you can easily obtain by
ps ux
Then you can simply kill the program by:
kill [-signal] PID
Example:
For example, Let's stop the chromium browser by executing the kill command. First, we will obtain the Process Identification number by executing the ps ux
command.
Then you can simply execute kill <PID> , the PID in my case is 6332.
You can further explore this command by simply executing man kill
Watch command is used to execute a program periodically showing output on a full screen. Say, you want to real-time see the contents of a particular folder. You can combine watch
and ls
commands.
watch -n <TIME_INTERVAL in Seconds> Command
Output:
You can further explore this command by simply executing man watch
Wget is the non-interactive network downloader. Non-interactive means you can download a file from the web in the background, while the user is logged in. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies.
wget full_network_path_of_the_file
Let's download logo of ittwist website we can easily do that with wget.
wget https://ittwist.com/themes/ittwist-wp-theme/img/logo.png.webp
You can further explore this command by simply executing man wget
Curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.
curl https://www.google.com
This will transfer the content of google.com to your standard output screen.
curl -o content.txt https://www.google.com
This will transfer the contents of google.com and save it to content.txt locally.
You can further explore this command by simply executing man curl
The AWK command is useful for the manipulation of data files, text retrieval and processing, and prototyping and experimenting with algorithms. This is a very powerful command, you can even generate files or datasets with this command.
Lets learn by taking a simple example. Assume, we have a file name student_result.txt
with following records
RollNo StudentName StudentMarks
1 Gaurav 100
2 Gopal 100
3 Ram 100
Now, Let's assume we need to get only roll no and student name of student_results.txt
with no student marks we can easily do it with awk.
awk '{print $1 , $2 }' student_result.txt
You can further explore this command by simply executing man awk
Cat command is used to concatenate files and print on the standard output.
cat <filename>
You can further explore this command by simply executing man cat
Using find command we can easily search for files in a directory.
find <directory> -name <file>
Lets consider, We need to search a file student_record.txt
inside a my home directory. We can simply achieve this by executing find command.
You can further explore this command by simply executing man find
Hope you enjoyed this article about useful linux commands. Please feel free to ask questions or provide suggestions in the comment section below.
Leave a Comment