Basic Linux Commands
Basic Linux Commands
Command Description
ls Lists all files and directories in the present working directory
ls -R Lists files in sub-directories as well
ls -a Lists hidden files as well
ls -al Lists files and directories with detailed information like permissions,size, owner, etc.
cd or cd ~ Navigate to HOME directory
cd .. Move one level up
cd To change to a particular directory
cd / Move to the root directory
cat > filename Creates a new file
cat filename Displays the file content
cat file1 file2 > file3 Joins two files (file1, file2) and stores the output in a new file (file3)
mv file "new file path" Moves the files to the new location
mv filename new_file_name Renames the file to a new filename
sudo Allows regular users to run programs with the security privileges of the superuser or root
rm filename Deletes a file
man Gives help information on a command
history Gives a list of all past commands typed in the current terminal session
clear Clears the terminal
mkdir directoryname Creates a new directory in the present working directory or a at the specified path
rmdir Deletes a directory
mv Renames a directory
pr -x Divides the file into x columns
pr -h Assigns a header to the file
pr -n Denotes the file with Line Numbers
lp -nc , lpr c Prints “c” copies of the File
lp-d lp-P Specifies name of the printer
apt-get Command used to install and update packages
mail -s 'subject'
-c 'cc-address'
Command to send email
-b 'bcc-address'
'to-address'
mail -s "Subject"
Command to send email with attachment
to-address < Filename
Networking command
Command Description
SSH username@ip-address or
login into a remote Linux machine using SSH
hostname
Ping hostname="" or ="" To ping and Analyzing network and host connections
dir Display files in the current directory of a remote computer
cd "dirname" change directory to “dirname” on a remote computer
put file upload ‘file’ from local to remote computer
get file Download ‘file’ from remote to local computer
quit Logout
Process command
Command Description
bg To send a process to the background
fg To run a stopped process in the foreground
top Details on all Active Processes
ps Give the status of processes running for a user
ps PID Gives the status of a particular process
pidof Gives the Process ID (PID) of a process
kill PID Kills a process
nice Starts a process with a given priority
renice Changes priority of an already running process
df Gives free hard disk space on your system
free Gives free RAM on your system
VI Editing Commands
Command Description
i Insert at cursor (goes into insert mode)
a Write after cursor (goes into insert mode)
A Write at the end of line (goes into insert mode)
ESC Terminate insert mode
u Undo last change
U Undo all changes to the entire line
o Open a new line (goes into insert mode)
dd Delete line
3dd Delete 3 lines
D Delete contents of line after the cursor
C Delete contents of a line after the cursor and insert new text. Press ESC key to end insertion.
dw Delete word
4dw Delete 4 words
cw Change word
x Delete character at the cursor
r Replace character
R Overwrite characters from cursor onward
s Substitute one character under cursor continue to insert
S Substitute entire line and begin to insert at the beginning of the line
~ Change case of individual character
• -l: Long • ls -l
format displays files and directories
listing. with detailed information.
• -a: Include • ls -a
List files and
hidden files shows all files and directories,
directories.
hidden ones including
• -h: Human- • ls -lh
readable file displays file sizes in a human-
ls sizes. readable format.
• cd /path/to/directory
Change directory. changes the current directory
cd to the specified path.
• pwd
Print current
displays the current working
working directory.
pwd directory.
Command Description Options Examples
• mkdir my_directory
Create a new
creates a new directory named
directory.
mkdir “my_directory”.
• rm [Link]
deletes the file named
• -r: Remove
“[Link]”.
directories
• rm -r my_directory
recursively.
Remove files and deletes the directory
• -f: Force
directories. “my_directory” and its
removal
contents.
without
• rm -f [Link]
confirmation.
forcefully deletes the file
rm “[Link]” without confirmation.
• cp -r directory destination
copies the directory “directory”
• -r: Copy and its contents to the
Copy files and
directories specified destination.
directories.
recursively. • cp [Link] destination
copies the file “[Link]” to the
cp specified destination.
• mv [Link] new_name.txt
renames the file “[Link]” to
Move/rename files “new_name.txt”.
and directories. • mv [Link] directory
moves the file “[Link]” to the
mv specified directory.
• cat [Link]
View the contents
displays the contents of the file
of a file.
cat “[Link]”.
• head [Link]
• -n: Specify shows the first 10 lines of the
Display the first the number file “[Link]”.
few lines of a file. of lines to • head -n 5 [Link]
display. displays the first 5 lines of the
head file “[Link]”.
Command Description Options Examples
• tail [Link]
• -n: Specify shows the last 10 lines of the
Display the last few the number file “[Link]”.
lines of a file. of lines to • tail -n 5 [Link]
display. displays the last 5 lines of the
tail file “[Link]”.
• ln -s source_file link_name
• -s: Create
Create links creates a symbolic link named
symbolic
between files. “link_name” pointing to
(soft) links.
ln “source_file”.
• u: User/owner
permissions.
• g: Group
permissions.
• o: Other
• chmod u+rwx [Link]
permissions.
Change file grants read, write, and
• +: Add
permissions. execute permissions to
permissions.
the owner of the file.
• –: Remove
permissions.
• =: Set
permissions
chmod explicitly.
ownership of “[Link]” to
the specified group.
• umask 022
sets the default file
Set default file permissions to read and
permissions. write for the owner, and
read-only for group and
umask others.
• -c: Create a
new archive.
• -x: Extract files
from an
archive.
• tar -czvf [Link]
• -f: Specify the
files/
archive file
Create or creates a compressed tar
name.
extract archive archive named
• -v: Verbose
files. “[Link]” containing
mode.
the files in the “files/”
• -z: Compress
directory.
the archive
with gzip.
• -j: Compress
the archive
tar with bzip2.
• gzip [Link]
Compress • -d: Decompress compresses the file
files. files. “[Link]” and renames it as
gzip “[Link]”.
• ps aux
shows all running
Display running • -aux: Show all
processes with
processes. processes.
detailed information.
ps
• top
Monitor system displays a dynamic
processes in real- view of system
time. processes and their
top resource usage.
• kill PID
Terminate a • -9: Forcefully kill terminates the
process. a process. process with the
kill specified process ID.
• pkill process_name
Terminate processes
terminates all
based on their
processes with the
name.
pkill specified name.
• pgrep
process_name
List processes based lists all processes
on their name. with the specified
name.
pgrep
containing
matches.
• -n: Display line
numbers
alongside
matching lines.
• -w: Match
whole words
only, rather
than partial
matches.
• -c: Count the
number of
matching lines
instead of
displaying them.
• -e: Specify
multiple
patterns to
search for.
• -A: Display lines
after the
matching line.
• -B: Display lines
before the
matching line.
• -C: Display lines
both before and
after the
matching line.
• uname -a
Print system • -a: All system
displays all system
information. information.
uname information.
• whoami
Display current
shows the current
username.
whoami username.
usage in a human-
readable format.
• free -h
Display memory • -h: Human- displays memory usage
usage information. readable sizes. in a human-readable
free format.
• uptime
Show system
shows the current
uptime.
uptime system uptime.
• lscpu
Display CPU provides detailed CPU
information. information.
lscpu
• lspci
List PCI devices.
lspci List PCI devices.
• lsusb
lists all connected USB
List USB devices.
devices.
lsusb
Networking Commands
In Linux, there are several networking commands available to manage and troubleshoot network
connections. Here are some commonly used networking commands:
• ping [Link]
Send ICMP echo requests
sends ICMP echo requests to “[Link]” to
to a host.
ping check connectivity.
Command Description Examples
Display network
• netstat -tuln
connections and
shows all listening TCP and UDP connections.
netstat statistics.
• ss -tuln
Display network socket
shows all listening TCP and UDP connections.
information.
ss
• ssh user@hostname
Securely connect to a
initiates an SSH connection to the specified
remote server.
ssh hostname.
• scp [Link]
Securely copy files user@hostname:/path/to/destination
between hosts. securely copies “[Link]” to the specified remote
scp host.
• curl [Link]
Transfer data to or from
retrieves the content of a webpage from the
a server.
curl specified URL.
VI Shortcuts Commands:
Command Description
Change the current word. Deletes from the cursor position to the end of the current word
cw
and switches to insert mode.
Enter replace mode. Overwrites characters starting from the cursor position until you press
R
the Escape key.
o Insert a new line below the current line and switch to insert mode.
Command Description
s Substitute the character under the cursor and switch to insert mode.
dw Delete from the cursor position to the beginning of the next word.
4dw Delete the next four words from the cursor position.
r Replace the character under the cursor with a new character entered from the keyboard.
3dd Delete the current line and the two lines below it.
ESC Exit from insert or command-line mode and return to command mode.
U Restore the current line to its original state before any changes were made.
C Delete from the cursor position to the end of the line and switch to insert mode.
Vim Shortcuts Commands:
Normal Command Visual
Mode Description Mode Description Mode Description
Replace all
Paste the copied or
occurrences of “old”
p deleted text below :s/old/new/g
with “new” in the
the current line.
file.
Ctrl +
Redo the last undo.
R
Nano Shortcuts Commands:
Search
File and
Operation Descriptio Navigatio Descriptio Editin Replac Descriptio
s n n n g Description e n
Cut/delete
from the
Search for
Save the Scroll up Ctrl + cursor Ctrl +
Ctrl + O Ctrl + Y a string in
file. one page. K position to W
the text.
the end of
the line.
Go to the
Justify the beginning Cut/delete
Ctrl +
Ctrl + J current Alt + , of the the marked
K
paragraph. current block of text.
line.
Go to the
Copy the
end of the
Alt + . Alt + 6 marked
current
block of text.
line.