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

Linux Essential Commands

The document provides an overview of essential Linux commands, including commands for navigating directories (ls, cd), manipulating files and folders (mkdir, cp, mv, rm), finding files (find), getting system information (uname, lscpu), checking disk usage (df, du), creating aliases (alias), searching for files/commands (whereis, which), comparing files (diff), viewing files (more, less), counting text (wc), extracting text (cut, grep, sed), and splitting files (split). The document is a useful reference for common Linux commands and their purposes.

Uploaded by

shafiq rehman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Linux Essential Commands

The document provides an overview of essential Linux commands, including commands for navigating directories (ls, cd), manipulating files and folders (mkdir, cp, mv, rm), finding files (find), getting system information (uname, lscpu), checking disk usage (df, du), creating aliases (alias), searching for files/commands (whereis, which), comparing files (diff), viewing files (more, less), counting text (wc), extracting text (cut, grep, sed), and splitting files (split). The document is a useful reference for common Linux commands and their purposes.

Uploaded by

shafiq rehman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

 

 
 

Essential Linux Commands 


Prepared By: Aamir Pinger 
 

 
 

  
fb.com/​AamirPingerOfficial  github.com/​AamirPinger 
   

 
linkedin.com/in/​AamirPinger 
 
 

 
 
LINUX ESSENTIAL COMMANDS    
 

Commands What it does

ls List down all the contents of a directory

cd /bin/ Changes directory and goes to bin directory

the tilde (~) sign signifies the user’s home dir – change dir
cd ~
to home directory

cd .. Means to change directory one level up

mkdir A command used to create directories

Short for present working directory. This command will


pwd
display the directory where you are currently in

Command to print all the contents of provided filename on


cat <filename>
the screen

cp /home/ /tmp/ Copy contents of /home/ to /tmp

mv Move the file file1.txt to the /newDirectoryName/ directory.


/directoryName/file1. You can also use this command to move the entire directory
txt to another
/newDirectoryName/ Directory

Delete the file file1.txt. Take extra precaution in using the rm


rm file1.txt
command, especially when you are logged in as root

The find command is a powerful tool that you can use when
searching using the command line. The command here will
find / -name “linux*”
search for any file or directory with a name that starts with
linux

This command displays information about the machine, the


uname -a
processor architecture, and the operating system details.


 
 
LINUX ESSENTIAL COMMANDS    
 

This command returns more information about the system


lscpu
such as the number of CPUs and the CPU speed

cat /proc/cpuinfo This is a file that contains more information than the one
displayed using the lscpu command

This command displays the disk space usage in all of the


mounted devices. The -h option presents the results in a
df -h
human readable output, using G for gigabytes or M for
megabytes sizes

This command displays all the files inside the specified


du ~/Downloads directory and their corresponding file sizes. You can also
specify a filename

The –s option provides the total file size of the specified


du ~/Downloads -sh
directory and -h makes it human readable form

Keys to
Purpose Example
Use

Shows online information about


info $ ​info uname
a command

Shows details (manual) of a


man $ ​man uname
command

Shows a short description of a


whatis $ ​whatis uname
specific keyword

Shows the location of a


type $ ​type uname
command file

Assign a command alias – $ ​alias t=type


alias
especially useful for long $ ​t uname


 
 
LINUX ESSENTIAL COMMANDS    
 

commands $ ​alias

unalias Remove command alias $ ​unalias t

pwd Displays the current directory $ ​pwd

$ ​ln -s [file]
Create links to files and
ln [soft-link-to-file]
directories
$ ​ln -s abc.txt newAbc.txt

To trigger a file stamp update


touch $ ​touch abc.txt
for a file

$ ​find [dir-path] -name


Search for a file based on the
find [filename]
name
$ ​find . -name ap.jpeg

whereis Search for executable files $ ​whereis uname

Search for files in the


which directories part of the PATH $ ​which uname
variable

$ ​dd conv=ucase
Type Hello world ​ctrl+d
$ ​echo “hello world > abc.txt
dd Copy lines of data
$ ​dd if=abc.txt of=newabc.txt
conv=ucase
$ ​cat newabc.txt

$ ​echo “hello world > abc.txt


$ ​echo “hello world > abc1.txt
Display the results of comparing
diff $ ​diff abc.txt abc1.txt -s
two files
$ ​echo “hello world123 > newabc.txt
$ ​diff abc.txt newabc.txt -s

Show a text file one page at a $ ​ls -R > abc.txt


more
time – display can only go $ ​more abc.txt


 
 
LINUX ESSENTIAL COMMANDS    
 

forward $ ​ls -R | more

Show a text file one page at a


$ ​less abc.txt
less time – display can only go
$ ​ls -R | less
forward and backwards

Display the count of the number


wc of characters, words, and $ ​wc abc.txt
lines in a file

$ ​cut -b 1 abc.txt
cut Get sections of text in a file $ ​cut -b 1-3 abc.txt
$ ​cut -b 1,3 abc.txt

$ ​cat abc.txt | grep Desktop


Display results of finding
grep $ ​cat abc.txt | grep -i desktop
expressions in a file
$ ​grep -i "desktop" abc.txt

First occurance in every line will be


changed
$ ​sed 's/Desktop/Dashboard/' abc.txt
Perform editing commands, 2nd occurance in every line will be
sed
then copy to a standard output changed
$ ​sed 's/Desktop/Dashboard/2' abc.txt
All occurances will be changed
$ ​sed 's/Desktop/Dashboard/g' abc.txt

$ ​split abc.txt
$ ​ls
Specify a size to break a file $ ​rm x*
split
into -l100 is 100 lines per file
$ ​split -l100 abc.txt
$ ​ls

sort Arrange the lines in a file $ ​sort abc.txt

Keep unique lines in a file and $ ​echo “Karachi


uniq
delete duplicates Karachi


 
 
LINUX ESSENTIAL COMMANDS    
 

Lahore
Islamabad
Islamabad
Lahore” > abc.txt
$ ​cat abc.txt
$ ​uniq abc.txt
$ ​uniq abc.txt -c
$ ​uniq abc.txt -d

Archive the file


Archive files with one or more $ ​tar -cf archive.tar file1 file2
tar
directories Extract the files
$ ​tar -xf archive.tar

$ ​cal
Show the calendar for the $ ​cal -3
cal
specified month or year $ ​cal -m 5
$ ​cal -y 2020

$ ​date
Show/Set the current date and Sets the system date and time to given
date
time date
$ ​date -s "11/20/2003 12:48:00"

Run a program or a process in


bg the background
$ ​bg %[PID]

free Check for the free memory $ ​free

kill Stop a process $ ​kill <PSID>

Run a program with a low


priority, niceness values range
$ ​nice -10 ls -R
nice from -20 to 19, with the former
$ ​nice --10 ls -R
being most favorable, while
latter being least

ps Show current running $ ​ps


 
 
LINUX ESSENTIAL COMMANDS    
 

processes

Show list of CPU and memory


top $ ​top
utilization of processes

reboot Restart the computer $ ​reboot

shutdo
Turn off computer $ ​shutdown
wn

Adding user from CLI need few steps/commands at CLI 


First, login as root by using the command​ su 

aamir@ap-linux:~$​ su
Password:
root@ap-linux:/home/a​amir#
● Add user by using following command syntax 

root@ap-linux:/home/aamir#​ ​/usr/sbin/useradd -c "Test User" test


● Once done with above command type ​passwd 

root@ap-linux:/home/aamir# ​passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@ap-linux:/home/aamir#

   


 
 
LINUX ESSENTIAL COMMANDS    
 

● To modify an account, use the ​usermod​ command 

● To delete the user account, use the /​ usr/sbin/userdel <username> 


command 

● To add a user group, you need to use the command ​groupadd 


<groupname> 

● For example, let’s create a group named office. To create this group,  

root@ap-linux:/home/aamir# ​groupadd office


● To add test user which we create recently to above created office group  

root@ap-linux:/home/aamir#​ ​usermod -G office test


● To delete the group, use the command groupdel office 
 
● A user and group account owns a Linux file or directory. To see the owner 
of a particular file 

aamir@ap-linux:~$​ ls -l <filename>
● To change the ownership of any file from one user to another user 

aamir@ap-linux:~$​ chown <newuser> <filename>


● To change the group owner of the file 

aamir@ap-linux:~$​ chgrp <newgroup> <filename>


 


 

You might also like