Linux Commands
Linux Commands
head - The head command is used to view the first lines of any text file. By default,
it will show the first ten lines, but you can change this number to your liking.
For example, if you only want to show the first five lines, type head -n 5
filename.ext.
tail - The tail command is similar to the head command, but instead of showing
the first lines, the tail command will display the last ten lines of a text file. For
example,
tail -n 3 filename.ext.
diff - Thediff command compares the contents of two files line by line. After
analyzing the files, it will output the lines that do not match. Programmers
often use this command when they need to make program alterations instead
of rewriting the entire source code.
ping - The ping command to check your connectivity status to a server. For
example, by simply entering ping google.com, the command will check
whether you’re able to connect to Google and also measure the response
time.
ping 8.8.8.8, ping sssihl.edu.in
ifconfig - Prints the IP(Internet Protocol) address of the system.
wget -download files from the internet with the help of the command.
To do so, simply type wget followed by the download link.
uname - Theuname command, short for Unix Name, will print detailed information
about your Linux system like the machine name, operating system, kernel, and
so on.
uname -i
uname -a
top - Asa terminal equivalent to Task Manager in Windows, the top command will
display a list of running processes and how much CPU each process uses. It’s
very useful to monitor system resource usage, especially knowing which
process needs to be terminated because it consumes too many resources.
history - When you’ve been using Linux for a certain period of time, you’ll quickly
notice that you can run hundreds of commands every day. As such,
running history command is particularly useful if you want to review the
commands you’ve entered before.
history > filename copies history into the file
man command
Confused about the function of certain Linux commands? Don’t worry, you can easily learn how to use them right from
Linux’s shell by using the man command. For instance, entering man tail will show the manual instruction of the tail
command.
man tail
man ls
echo - This command is used to move some data into a file. For example, if you want to add
the text, “Hello, my name is John” into a file called name.txt, you would type
To remove a user is very similar to adding a new user. To delete the users account type, userdel
userName
passwd - changes the password for a user
kill command
If you have an unresponsive program, you can terminate it manually by using the kill command. It will
send a certain signal to the misbehaving app and instructs the app to terminate itself.
There is a total of sixty-four signals that you can use, but people usually only use two signals:
SIGTERM (15) — requests a program to stop running and gives it some time to save all of its
progress. If you don’t specify the signal when entering the kill command, this signal will be used.
SIGKILL (9) — forces programs to stop immediately. Unsaved progress will be lost.
Besides knowing the signals, you also need to know the process identification number (PID) of the
program you want to kill. If you don’t know the PID, simply run the command ps ux or top
After knowing what signal you want to use and the PID of the program, enter the following syntax:
grep - It lets you search through all the text in a given file.
grep blue notepad.txt will search for the word blue in the notepad file. Lines
that contain the searched word will be displayed fully.
touch - allows you to create a blank new file through the Linux command line.
touch prog.c
locate command
You can use this command to locate a file, just like the search command in Windows. What’s more,
using the -i argument along with this command will make it case-insensitive, so you can search for a file
even if you don’t remember its exact name.
To search for a file that contains two or more words, use an asterisk (*). For example, locate -i
school*note command will search for any file that contains the word “school” and “note”, whether it is
uppercase or lowercase.
find command
Similar to the locate command, using find also searches for files and directories. The difference is, you
use the find command to locate files within a given directory.
As an example, find /home/ -name notes.txt command will search for a file called notes.txt within the
home directory and its subdirectories.