Linux-Bash Commands
Linux-Bash Commands
ls -l: Long
format
listing. ls -l
-a: Include displays files and directories with detailed
hidden information.
List files and files ls -a
directories. hidden shows all files and directories, including
ones ls -lh
-h: displays file sizes in a human-readable
Human- format.
readable
file sizes.
cd cd /path/to/directory
Change
changes the current directory to the
directory.
specified path.
cp cp -r directory destination
-r: copies the directory “directory” and its
Copy files and Copy contents to the specified destination.
directories. directories cp file.txt destination
recursively. copies the file “file.txt” to the specified
destination.
mv mv file.txt new_name.txt
renames the file “file.txt” to
Move/rename
“new_name.txt”.
files and
mv file.txt directory
directories.
moves the file “file.txt” to the specified
directory.
touch Create an
empty file or touch file.txt
update file creates an empty file named “file.txt”.
timestamps.
find -name:
Search by
Search for files find /path/to/search -name “*.txt”
filename.
and searches for all files with the extension
-type:
directories. “.txt” in the specified directory.
Search by
file type.
chmod u:
User/owner
permissions.
g: Group
permissions.
Change o: Other
chmod u+rwx file.txt
file permissions.
grants read, write, and execute
permission +: Add
permissions to the owner of the file.
s. permissions.
–: Remove
permissions.
=: Set
permissions
explicitly.
ps ps aux
Display shows all running
-aux: Show all
running processes with detailed
processes.
processes. information.
top top
Monitor
displays a dynamic
system
view of system
processes
processes and their
in real-time.
resource usage.
kill
kill PID
Terminate a -9: Forcefully kill a terminates the process
process. process. with the specified
process ID.
Commands Descriptio Options Examples
n
pkill
Terminate pkill process_name
processes terminates all
based on processes with the
their name. specified name.
pgrep
List pgrep process_name
processes lists all processes with
based on the specified name.
their name.
uname
uname -a
Print system -a: All system
displays all system
information. information.
information.
whoami
Display current whoami
username. shows the current username.
df
df -h
Show disk space -h: Human-
displays disk space usage in a
usage. readable sizes.
human-readable format.
du -h: Human-
du -sh directory/
Estimate file and readable sizes.
provides the total size of the
directory sizes. -s: Display total
specified directory.
size only.
sudComma Description Options Examples
nd
free
uptime uptime
Show system
shows the current system
uptime.
uptime.
lscpu lscpu
Display CPU provides detailed CPU
information. information.
lspci lspci
List PCI devices.
List PCI devices.
6. Networking Commands
In Linux, there are several networking commands available to manage and
troubleshoot network connections. Here are some commonly used
networking commands:
ss ss -tuln
Display network
shows all listening TCP and UDP connections.
socket information.
7. IO Redirection Commands
In Linux, IO (Input/Output) redirection commands are used to redirect the
standard input, output, and error streams of commands and processes. Here
are some commonly used IO redirection commands:
Command Description
cmd1
Output of cmd2 is used as the input file for cmd1.
<(cmd2)
cmd >
Discards the stdout of cmd by sending it to the null device.
/dev/null
Command Description
export
Sets the value of an environment variable.
VARIABLE_NAME=value
Command Description
sudo adduser Create a new user account on the system with the
username specified username.
sudo usermod -a -G Add an existing user to the specified group. The user
GROUPNAME is added to the group without removing them from
USERNAME their current groups.
10. Shortcuts Commands
There are many shortcuts commands in Linux that can help you be more
productive. Here are a few of the most common ones:
Cut/delete
from the
Move to the Search command
Ctrl + cursor position Ctrl +
Ctrl + A beginning history (reverse
U to the R
of the line. search).
beginning of
the line.
Cut/delete
Move to the from the Escape from
Ctrl + Ctrl +
Ctrl + E end of the cursor position history search
K G
line. to the end of mode.
the line.
Move
Alt + F forward one
word.
Search
Cut/delete from
Scroll up for a
Ctrl + Save Ctrl + Ctrl the cursor Ctrl +
one string
O the file. Y +K position to the W
page. in the
end of the line.
text.
Search
Exit
and
Nano Scroll
replace
Ctrl + (prompt Ctrl + down Ctrl Uncut/restore the Alt +
a
X to save if V one +U last cut text. W
string
modified page.
in the
).
text.
Read a
Go to a Repeat
file into Mark a block of
Ctrl + specific Ctrl the
the Alt + \ text for copying Alt + R
R line +6 last
current or cutting.
number. search.
buffer.
Go to
Justify
the
the Cut/delete the
Ctrl + beginnin Ctrl
current Alt + , marked block of
J g of the +K
paragrap text.
current
h.
line.
Go to
the end
Alt + Copy the marked
Alt + . of the
6 block of text.
current
line.
Change the current word. Deletes from the cursor position to the end
cw
of the current word and switches to insert mode.
o Insert a new line below the current line and switch to insert mode.
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.
Replace the character under the cursor with a new character entered
r
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.
Restore the current line to its original state before any changes were
U
made.
Comma Description
nd
Delete from the cursor position to the end of the line and switch to
C
insert mode.
Enter insert
mode at the Save the Enter visual mode
i :w v
current cursor file. to select text.
position.
Delete the
Copy the selected
x character under :q Quit Vim. y
text.
the cursor.
Quit Vim
Delete the without Delete the selected
dd :q! d
current line. saving text.
changes.
:wq
Copy the or Save and Paste the copied or
yy p
current line. quit Vim. deleted text.
:x:x
:set nu
or Display
Undo the last
u line
change. :set numbers.
number