Of course! Here’s a handy list of basic Linux commands for you:
pwd
- Print the current working directory.
ls
- List directory contents.
cd
- Change directory.
touch
- Create an empty file.
cat
- Concatenate and display file content.
cp
- Copy files or directories.
mv
- Move or rename files or directories.
rm
- Remove files or directories.
mkdir
- Create a new directory.
rmdir
- Remove an empty directory.
chmod
- Change file permissions.
chown
- Change file owner and group.
File and Directory Operations Commands
Command | Description | Options | Examples |
ls | List files and directories. | -l (Long format listing), -a (Include hidden files), -h (Human-readable file sizes) | ls -l (Detailed info), ls -a (Includes hidden files), ls -lh (Human-readable sizes) |
cd | Change directory. | | cd /path/to/directory (Change to specified path) |
pwd | Print current working directory. | | pwd (Displays current directory) |
mkdir | Create a new directory. | | mkdir my_directory (Creates directory) |
rm | Remove files and directories. | -r (Recursively), -f (Forcefully) | rm file.txt (Delete file), rm -r my_directory (Delete directory and contents), rm -f file.txt (Force delete) |
cp | Copy files and directories. | -r (Recursively) | cp -r directory destination (Copy directory), cp file.txt destination (Copy file) |
mv | Move/rename files and directories. | | mv file.txt new_name.txt (Rename file), mv file.txt directory (Move file) |
touch | Create an empty file or update timestamps. | | touch file.txt (Create empty file) |
cat | View the contents of a file. | | cat file.txt (Display file content) |
head | Display the first few lines of a file. | -n (Number of lines) | head file.txt (First 10 lines), head -n 5 file.txt (First 5 lines) |
tail | Display the last few lines of a file. | -n (Number of lines) | tail file.txt (Last 10 lines), tail -n 5 file.txt (Last 5 lines) |
ln | Create links between files. | -s (Symbolic links) | ln -s source_file link_name (Create symbolic link) |
find | Search for files and directories. | -name (Filename), -type (File type) | find /path/to/search -name "*.txt" (Find .txt files) |
File Permission Commands
Command | Description | Options | Examples |
chmod | Change file permissions. | u (User), g (Group), o (Others), + (Add), - (Remove), = (Set) | chmod u+rwx file.txt (Add read, write, execute to user) |
chown | Change file ownership. | | chown user file.txt (Change owner) |
chgrp | Change group ownership. | | chgrp group file.txt (Change group) |
umask | Set default file permissions. | | umask 022 (Default permissions) |
File Compression and Archiving Commands
Command | Description | Options | Examples |
tar | Create or extract archive files. | -c (Create), -x (Extract), -f (File name), -v (Verbose), -z (gzip), -j (bzip2) | tar -czvf archive.tar.gz files/ (Create compressed tar) |
gzip | Compress files. | -d (Decompress) | gzip file.txt (Compress file) |
zip | Create compressed zip archives. | -r (Recursively) | zip archive.zip file1.txt file2.txt (Create zip archive) |
Process Management Commands
Command | Description | Options | Examples |
ps | Display running processes. | -aux (All processes) | ps aux (Show all processes) |
top | Monitor system processes in real-time. | | top (Dynamic process view) |
kill | Terminate a process. | -9 (Forcefully) | kill PID (Terminate process by ID) |
pkill | Terminate processes by name. | | pkill process_name (Terminate by name) |
pgrep | List processes by name. | | pgrep process_name (List by name) |
Command | Description | Options | Examples |
uname | Print system information. | -a (All info) | uname -a (All system info) |
whoami | Display current username. | | whoami (Current username) |
df | Show disk space usage. | -h (Human-readable) | df -h (Disk usage) |
du | Estimate file/directory sizes. | -h (Human-readable), -s (Total size) | du -sh directory/ (Directory size) |
free | Display memory usage. | -h (Human-readable) | free -h (Memory usage) |
uptime | Show system uptime. | | uptime (System uptime) |
lscpu | Display CPU information. | | lscpu (CPU details) |
lspci | List PCI devices. | | lspci (PCI devices) |
lsusb | List USB devices. | | lsusb (USB devices) |
Networking Commands
Command | Description | Examples |
ifconfig | Display network interfaces. | ifconfig (Interface details) |
ping | Send ICMP echo requests. | ping google.com (Check connectivity) |
netstat | Display network connections. | netstat -tuln (Listening TCP/UDP connections) |
ss | Display network sockets. | ss -tuln (Listening TCP/UDP sockets) |
ssh | Securely connect to a remote server. | ssh user@hostname (Connect via SSH) |
scp | Securely copy files between hosts. | scp file.txt user@hostname:/path/to/destination (Secure copy) |
wget | Download files from the web. | wget http://example.com/file.txt (Download file) |
curl | Transfer data to/from a server. | curl http://example.com (Retrieve webpage content) |
Environment Variable Commands
Command | Description |
export VARIABLE_NAME=value | Sets the value of an environment variable. |
echo $VARIABLE_NAME | Displays the value of a specific environment variable. |
env | Lists all environment variables currently set in the system. |
unset VARIABLE_NAME | Unsets or removes an environment variable. |
export -p | Shows a list of all currently exported environment variables. |
env VAR1=value COMMAND | Sets the value of an environment variable for a specific command. |
printenv | Displays the values of all environment variables. |
User Management Commands
Command | Description |
who | Show who is currently logged in. |
sudo adduser username | Create a new user account on the system with the specified username. |
finger | Display information about all the users currently logged into the system. |
sudo deluser USER GROUPNAME | Remove the specified user from the specified group. |
last | Show the recent login history of users. |
finger username | Provide information about the specified user. |
sudo userdel -r username | Delete the specified user account from the system, including their home directory. |
sudo passwd -l username | Lock the password of the specified user account. |
su – username | Switch to another user account with the user’s environment. |
sudo usermod -a -G GROUPNAME USERNAME | Add an existing user to the specified group. |
Bash Shortcuts Commands
Navigation | Description | Editing | Description | History | Description |
Ctrl + A | Move to the beginning of the line. | Ctrl + U | Cut/delete from cursor to beginning of line. | Ctrl + R | Search command history (reverse search). |
Ctrl + E | Move to the end of the line. | Ctrl + K | Cut/delete from cursor to end of line. | Ctrl + G | Escape from history search mode. |
Ctrl + B | Move back one character. | Ctrl + W | Cut/delete the word before the cursor. | Ctrl + P | Go to the previous command in history. |
Ctrl + F | Move forward one character. | Ctrl + Y | Paste the last cut text. | Ctrl + N | Go to the next command in history. |
Alt + B | Move back one word. | Ctrl + L | Clear the screen. | Ctrl + C | Terminate the current command. |
Alt + F | Move forward one word. | | | |
Nano Shortcuts Commands
File Operations | Description | Navigation | Description | Editing | Description | Search and Replace | Description |
Ctrl + O | Save the file. | Ctrl + Y | Scroll up one page. | Ctrl + K | Cut/delete from cursor to end of line. | Ctrl + W | Search for a string in the text. |
Ctrl + X | Exit Nano. | Ctrl + V | Scroll down one page. | Ctrl + U | Uncut/restore the last cut text. | Alt + W | Search and replace a string in the text. |
Ctrl + R | Read a file into the current buffer. | Alt + \ | Go to a specific line number. | Ctrl + 6 | Mark a block of text for copying/cutting. | Alt + R | Repeat the last search. |
Ctrl + J | Justify the current paragraph. | Alt + , | Go to the beginning of the line. | Ctrl + K | Cut/delete the marked block of text. | | |
| | Alt + . | Go to the end of the line. | Alt + 6 | Copy the marked block of text. | |
VI Shortcuts Commands
Command | Description |
cw | Change the current word. Deletes from cursor position to the end of the current word. |
dd | Delete the current line. |
x | Delete the character under the cursor. |
R | Enter replace mode. Overwrites characters starting from the cursor position until you press Esc. |
o | Insert a new line below the current line and switch to insert mode. |
u | Undo the last change. |
s | Substitute the character under the cursor and switch to insert mode. |
dw | Delete from cursor position to the beginning of the next word. |
D | Delete from the cursor position to the end of the line. |
4dw | Delete the next four words from the cursor position. |
A | Switch to insert mode at the end of the current line. |
S | Delete the current line and switch to insert mode. |
r | Replace the character under the cursor with a new character entered from the keyboard. |
i | Switch to insert mode before the cursor. |
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. |
~ | Switch the case of the character under the cursor. |
a | Switch to insert mode after the cursor. |
C | Delete from the cursor position to the end of the line and switch to insert mode. |
Vim Shortcuts Commands
Normal Mode | Description | Command Mode | Description | Visual Mode | Description |
i | Enter insert mode at the current cursor position. | :w | Save the file. | v | Enter visual mode to select text. |
x | Delete the character under the cursor. | :q | Quit Vim. | y | Copy the selected text. |
dd | Delete the current line. | :q! | Quit Vim without saving changes. | d | Delete the selected text. |
yy | Copy the current line. | :wq | Save and quit Vim. | p | Paste the copied or deleted text. |
p | Paste the copied or deleted text below the current line. | :s/old/new/g | Replace all occurrences of “old” with “new” in the file. | | |
u | Undo the last change. | :set nu or :set number | Display line numbers. | | |
Ctrl + R | Redo the last undo. | | | |
File Permissions
chmod 775 file
: Change mode of file
to 775
.
chmod -R 600 folder
: Recursively chmod folder
to 600
.
chown user:group file
: Change file owner to user
and group to group
.
File Permission Numbers First digit is owner permission, second is group, and third is everyone. Calculate permission digits by adding numbers below:
4
: read (r)
2
: write (w)
1
: execute (x)
————————————————————————————————————
Stay Connected
Thank you for reading my blog!
I hope you found the information and insights shared here helpful.
Subscribe to my newsletter
Read articles from Sayali Kokane directly inside your inbox. Subscribe to the newsletter, and don't miss out.