Search This Blog

Wednesday, March 26, 2025

Basic Linux Commands Cheat Sheet

 


Files & Navigation

Command Description
ls List directory contents.
ls -l Long format listing.
ls -la Show hidden files as well.
cd dir Change to specified directory.
cd .. Move up one directory level.
cd ./dir Change to a directory within the current location.
cd ~ Go to home directory.
pwd Show current directory path.
mkdir dir Create a new directory.
rm file Delete a file.
rm -f file Force delete a file.
rm -r dir Delete a directory and its contents.
rm -rf dir Force delete a directory recursively.
cp file1 file2 Copy file1 to file2.
mv file1 file2 Rename or move file1 to file2.
mv file1 dir/ Move file to a directory.
touch file Create an empty file or update its timestamp.
cat file View file contents.
cat > file Write standard input to a file (overwrite).
cat >> file Append standard input to a file.
tail -f file Show file contents as it updates (useful for logs).

System Info

Command Description
date Show current date and time.
uptime Show system uptime.
whoami Show current logged-in user.
w Display currently logged-in users.
cat /proc/cpuinfo Display CPU details.
cat /proc/meminfo Display memory details.
free -h Show memory and swap usage.
du -sh Show directory size in human-readable format.
df -h Show disk space usage.
uname -a Show system and kernel details.

Networking

Command Description
ping host Ping a host to check connectivity.
whois domain Get WHOIS information about a domain.
dig domain Get DNS records for a domain.
dig +x host Perform a reverse DNS lookup.
wget file Download a file from a URL.
wget -c file Resume a stopped download.
wget -r url Recursively download an entire site.
curl url Fetch content from a URL.
curl -o file url Save the output of a URL to a file.
ssh user@host Connect to a remote server via SSH.
ssh -p port user@host SSH with a specific port.
ssh -D user@host Connect via SSH and use a bind port.

Processes Management

Command Description
ps Show currently active processes.
ps aux Show all running processes with details.
kill pid Kill a process using its PID.
killall proc Kill all processes by name.

File Compression & Extraction

Command Description
tar -cf file.tar files Create a tar archive.
tar -xf file.tar Extract a tar archive.
tar -tf file.tar Show contents of a tar file.

Tar Compression Options

Option Description
c Create archive.
t List contents.
x Extract archive.
z Use gzip compression.
j Use bzip2 compression.
f Specify filename.
v Show verbose output.
w Ask for confirmation.

File Permissions

Command Description
chmod octal file Change file permissions using octal values.
chmod 777 file Full read/write/execute permissions for all.
chmod 755 file Owner: rwx, Group & Others: r-x.

Octal Permission Values

Value Permission
4 Read (r)
2 Write (w)
1 Execute (x)
Format: owner/group/world Example: chmod 755 file

Miscellaneous Commands

Command Description
grep pattern file Search for a pattern in a file.
grep -r pattern dir/ Search for a pattern recursively in a directory.
locate file Find a file by name.
whereis app Find possible locations of an application.
man command Show the manual page for a command.