0% found this document useful (0 votes)
5 views

Linux Commands

The document provides a comprehensive overview of various Linux commands, detailing their functions and usage. It covers commands for file management, system monitoring, user management, and more, along with examples for clarity. Additionally, it includes commands for viewing system information, manipulating text files, and managing processes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Linux Commands

The document provides a comprehensive overview of various Linux commands, detailing their functions and usage. It covers commands for file management, system monitoring, user management, and more, along with examples for clarity. Additionally, it includes commands for viewing system information, manipulating text files, and managing processes.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

ls List files in current directory

ls -l Lists files in “long” format


ls -a List all files, including “hidden” files. Hidden files are those files that begin with a
“.”, e.g. The .bash_history file in your home directory.
ls –al List hidden files in long format
ls –al |more

ls -R will list all the files in the sub-directories as well

ls *.c List all files with extention .c

mv Moves a file to a new location, or renames it.


rm Delete a file.
rm *.c Deletes all files with extention .c
mkdir Make Directory.
rmdir Remove Directory.
cd Change directory
cd .. Move up by one directory
cp Copies a file from one location to another.
mkdir sairam, cd sairam , cp file.txt /home/user/sairam
cp *.c /home/ usersairam
pwd path of the current working directory (folder) you’re in.
mkdir sairam, cd sairam , pwd = /home/user/sairam
date prints the current date and time
clear clears the secreen
df -h prints the disk space in human readable form ( h)
factor 10 factor command is used to show the prime factors of a number.
factor 8: 2 2 2,
factor 10: 2 5
factor 30: 2 3 5
cal The cal command print a calendar on the standard output.
cal 2020 prints calender year
cal jan 2022 prints January month of 2022
cal 11 2023 prints November month of 2023

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.

The simplest form of this command is diff file1.ext file2.ext

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

echo Hello, my name is John >> name.txt


echo “Om SriSai Ram”
useradd, userdel command
Since Linux is a multi-user system, this means more than one person can interact with the same system
at the same time. useradd is used to create a new user,

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:

kill [signal option] PID.

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.

Other variations when using the find are:

 To find files in the current directory use, find . -name notes.txt


 To look for directories use, / -type d -name notes. txt
cat command
cat (short for concatenate) is one of the most frequently used commands in Linux. It is used to list the
contents of a file on the standard output (sdout). To run this command, type cat followed by the file’s
name and its extension. For instance: cat file.txt.

Here are other ways to use the cat command:

 cat > filename creates a new file


 cat filename1 filename2 > filename3 joins two files (1 and 2) and stores the output
of them in a new file (3)
 to convert a file to upper or lower case use, cat filename | tr a-z A-Z >output.txt
 cat filename Show contents of a file
 cat -n filename Show contents of a file, with line number
wc file.txt - prints the number of lines , words, character in a file
wc -l - prints the number of lines
wc -w - prints the number of words
wc -c - prints the number of characters

chmod - change mode changes the file permissions


chmod +x file.txt

You might also like