LINUX COMMANDS CHEAT SHEET

 Linux Command Cheat Sheet



1. System


Commands:

uname -a: Displays system information (kernel version, architecture, hostname, etc.)

uptime: Shows system uptime, load averages, and current time.

free -h: Prints memory usage.

df -h: Shows disk usage (human-readable) for mounted filesystems.

cat /proc/cpuinfo: Displays CPU information.

Example: uname -a might output Linux debian 5.15.0-1028-amd64 #1 SMP Debian 5.15.18-1 (amd64) x86_64 GNU/Linux.


2. Hardware


Commands:

lshw: Lists hardware information (CPU, memory, network, etc.).

lspci: Displays PCI devices and their resources.

lsblk: Shows block devices (disks, partitions).

sensors: Monitors hardware sensors (temperature, fan speed, etc.).

Example: lshw -C network might output details about network interfaces.


3. Users


Commands:

whoami: Prints the current user's username.

passwd: Changes the current user's password.

useradd user_name: Creates a new user.

userdel user_name: Deletes a user.

groups: Lists user groups.

Example: useradd john -m -g accounting creates a new user john with a home directory and assigns them to the accounting group.


4. File Commands


Commands:

ls: Lists directory contents.

cd directory_name: Changes the current directory.

mkdir directory_name: Creates a new directory.

rmdir directory_name: Removes an empty directory.

touch file_name: Creates an empty file.

cat file_name: Displays file contents.

more file_name: Displays file contents page by page.

less file_name: Similar to more but allows scrolling and searching.

Example: ls -l /usr/bin lists files in the /usr/bin directory with detailed information about permissions, owner, size, etc.


5. Process Related


Commands:

ps aux: Shows all running processes with details (user, PID, CPU usage, etc.).

top: Provides a dynamic real-time view of running processes.

pidof process_name: Finds the PID of a running process.

kill pid: Kills a process by its PID.

htop: Interactive process viewer and manager.

Example: ps aux | grep firefox might display processes related to the Firefox web browser.


6. File Permission Related


Commands:

ls -l: Shows file permissions (user, group, others, read, write, execute).

chmod permissions file_name: Changes file permissions.

chown owner file_name: Changes file owner.

chgrp group file_name: Changes file group.

Example: chmod 755 my_file makes my_file readable and executable by owner, group, and others.


7. Network


Commands:

ip addr: Shows network interface information (IP addresses, netmasks, etc.).

ping hostname: Checks network connectivity to a host.

traceroute hostname: Maps the route packets take to reach a host.

netstat -a: Shows network connections and listening ports.

dig hostname: Queries DNS for hostname information.

Example: ping google.com ping checks connectivity to Google.


8. Compression / Archive


Commands:

gzip file_name: Compresses a file with gzip.

gunzip file_name.gz: Decompresses a gzip-compressed file.

tar -cvf archive.tar files: Creates an archive (tar) of files.

tar -xvf archive.tar: Extracts files from an archive.

zip file_name.zip: Compresses a file with zip.

`unzip file


9. Install Package:


Commands:

Debian/Ubuntu: sudo apt install package_name

Fedora/CentOS: sudo yum install package_name

Arch Linux: sudo pacman -S package_name

Example: sudo apt install python3 (installs Python 3 on Debian/Ubuntu).


10. Install from Source:


Steps:

Download source code.

Extract/configure/build/install (./configure, make, make install).

May require dependencies (sudo apt install build-essential for development tools).

Example: Installing wget from source:

wget https://ftp.gnu.org/gnu/wget/wget-latest.tar.gz

tar xvf wget-latest.tar.gz

cd wget-latest

./configure

make

sudo make install


11. Search:


Commands:

File contents: grep search_term filename

Directory contents: find directory_path -name search_term

Man pages: man search_term

Online: search_term site:example.com

Example: grep -r error /var/log/* (searches for "error" in all log files).


12. Login (SSH and TELNET):


Commands:

SSH: ssh username@hostname

TELNET: telnet hostname port (not recommended due to security concerns)

Example: ssh john@server.example.com (logs in to server.example.com as user john).


13. File Transfer:


Commands:

SCP (secure copy): scp source_file username@hostname:destination_directory

SFTP (secure FTP): sftp username@hostname (use put and get commands)

RSYNC (efficient synchronization): rsync source_directory username@hostname:destination_directory

Example: scp report.txt john@server.example.com:/home/john/reports (transfers report.txt to a remote server).


14. Disk Usage:


Commands:

df -h: Shows disk usage by mount point.

du -sh directory_path: Shows disk usage recursively for a directory.

ncdu: Interactive ncurses-based disk usage analyzer.

Example: df -h / (shows disk usage for the root filesystem).


15. Directory Traverse:


Commands:

cd directory_name: Change directory.

cd ..: Move up one directory level.

cd ~: Go to the home directory.

pwd: Show the current working directory.

ls -l: List directory contents with details.

Example: cd Documents ; ls -l (changes to the Documents directory and lists files)

No comments:

Post a Comment

LINUX COMMANDS CHEAT SHEET

  Linux Command Cheat Sheet 1. System Commands: uname -a: Displays system information (kernel version, architecture, hostname, etc.) uptime:...