0% found this document useful (0 votes)
3 views

Linux Commands

The document provides a comprehensive guide on various Linux command-line operations, including user and group management, file and directory management, file permissions, disk management, process management, network management, system monitoring, text processing, package management, archiving, shutdown and reboot commands, task scheduling, and system diagnostics. Each section lists essential commands along with brief descriptions of their functions. This serves as a quick reference for users to perform administrative tasks in a Linux environment.

Uploaded by

Suraj Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Linux Commands

The document provides a comprehensive guide on various Linux command-line operations, including user and group management, file and directory management, file permissions, disk management, process management, network management, system monitoring, text processing, package management, archiving, shutdown and reboot commands, task scheduling, and system diagnostics. Each section lists essential commands along with brief descriptions of their functions. This serves as a quick reference for users to perform administrative tasks in a Linux environment.

Uploaded by

Suraj Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1.

​User and Group Management

●​ useradd - Add a new user​

●​ usermod - Modify user account​

●​ userdel - Delete a user​

●​ groupadd - Add a new group​

●​ groupdel - Delete a group​

a
●​ chgrp - Change group ownership of a file​
an
●​ passwd - Change user password​

●​ Who - Who is logged in

2. File and Directory Management


ay
●​ ls - List directory contents​

●​ cd - Change directory​
N

●​ pwd - Print working directory​

●​ mkdir - Make a new directory​

●​ rmdir - Remove a directory​

●​ rm - Remove files or directories​

●​ cp - Copy files or directories​

●​ mv - Move or rename files or directories​

1
●​ touch - Create empty files​

●​ find - Search for file in a directory hierarchy​

●​ locate- Find files by name

3. File Management

●​ cat - Concatenate and display file contents​

a
●​ more - View file content page by page​
an
●​ less - View file content with navigation​

●​ head - View the first part of a file​

●​ tail - View the last part of a file​


ay
●​ nano - Text editor to edit files​

●​ vi - Text editor to edit files​

●​ touch - Create an empty file or update file timestamp​


N

●​ ln - Create hard or symbolic links​

●​ file - Determine file type​

●​ stat - Display file or file system status​

●​ find - Search for files in a directory hierarchy​

●​ locate - Find files by name (using a database)​

2
●​ updatedb - Update the database used by locate​

●​ xargs - Build and execute command lines from standard


input

4. File Permissions and Ownership

●​ chmod - Change file permissions​

●​ chown - Change file owner and group​

a
●​ chgrp - Change group ownership​
an
●​ umask - Set file creation mask​

●​ getfacl - Get file access control lists (ACL)​

●​ setfacl - Set file access control lists (ACL)​


ay
●​ ls -l - List files with detailed permissions, owner, and group​

●​ stat - Display file or file system status​

●​ acl - View or modify Access Control Lists (ACL) on files


N

5. Disk Management

●​ df - Display free disk space​

●​ du - Estimate file space usage​

●​ fdisk - Partition table manipulator​

●​ parted - A tool for creating and managing disk partitions​

3
●​ lsblk - List information about block devices​

●​ blkid - Find or display block device attributes​

●​ mount - Mount a file system​

●​ umount - Unmount a file system​

●​ mkfs - Create a file system​

●​ fsck - Check and repair file systems​

●​ tune2fs - Adjust tunable file system parameters​

a
●​ resize2fs - Resize an ext2, ext3, or ext4 file system​
an
●​ lvcreate - Create a logical volume​

●​ vgcreate - Create a volume group​

●​ pvcreate - Prepare a physical volume for LVM​


ay
●​ lsattr - List file attributes on a file system​

●​ chattr - Change file attributes on a file system


N

6. Process Management

●​ ps - Display current processes​

●​ top - Display dynamic process information​

●​ htop - Interactive process viewer​

4
●​ kill - Terminate a process by ID​

●​ killall - Kill all processes by name​

●​ bg - Resume a suspended process in the background​

●​ fg - Bring a process to the foreground​

●​ nice - Set process priority​

●​ renice - Change the priority of running processes​

●​ jobs - List active jobs​

a
●​ pgrep - Search for processes by name or other attributes​
an
●​ pkill - Kill processes by name or other attributes​

●​ pstree - Display processes in a tree format​

●​ lsof - List open files and the processes that opened them​
ay
●​ strace - Trace system calls and signals​

●​ timeout - Run a command with a time limit​

●​ watch - Execute a program periodically and show output


N

7. Network Management

●​ ifconfig - Display and configure network interfaces​

●​ ip a - Show all network interfaces and their IPs​

●​ ip r - Display the routing table​

5
●​ ip link set <interface> up/down - Enable or disable a
network interface​

●​ ping <host> - Send ICMP echo request to check connectivity​

●​ traceroute <host> - Trace the route packets take to a


network host​

●​ netstat -tulnp - Show open ports and listening services​

●​ ss -tulnp - Display socket statistics and listening services​

●​ hostname -I - Show the system’s IP address​

a
●​ dig <domain> - Query DNS records​
an
●​ nslookup <domain> - Lookup DNS details​

●​ whois <domain> - Get domain registration details​

●​ curl -I <URL> - Fetch HTTP headers from a website​

●​ wget <URL> - Download files from the web​


ay
●​ scp <file> user@host:/path - Securely copy files over
SSH​

●​ rsync -avz <src> <dest> - Sync files between local and


remote locations​
N

●​ tcpdump -i eth0 - Capture network packets on an interface​

●​ nmap <IP> - Scan a network for open ports

8. System and Monitoring

●​ uptime - Show system uptime and load average​

6
●​ dmesg - Print system boot and hardware logs​

●​ free -m - Display memory usage in MB​

●​ vmstat - Report system performance statistics​

●​ iostat - Display CPU and disk I/O statistics​

●​ mpstat - Show CPU usage per core​

●​ top - Display dynamic process and system information​

●​ htop - Interactive process and resource monitoring​

a
●​ sar -u 5 10 - Monitor CPU usage at 5-second intervals​
an
●​ iotop - Display disk read/write usage per process​

●​ lsof - List open files by processes​

●​ watch -n 2 <command> - Run a command every 2 seconds​


ay
●​ journalctl -xe - View system logs with extended details​

●​ systemctl status <service> - Check the status of a


service​

●​ service <service> status - View service status (legacy


N

systems)​

●​ df -h - Show disk space usage in a human-readable format​

●​ du -sh <directory> - Display the size of a directory​

●​ ps aux --sort=-%mem - List processes sorted by memory


usage​

●​ netstat -tulnp - Show active network connections and


listening services

7
9. Text Processing

●​ cat <file> - Display file contents​

●​ tac <file> - Display file contents in reverse order​

●​ head -n <num> <file> - Show the first <num> lines of a file​

●​ tail -n <num> <file> - Show the last <num> lines of a file​

●​ tail -f <file> - Continuously display new lines in a file​

a
●​ grep '<pattern>' <file> - Search for a pattern in a file​
an
●​ grep -r '<pattern>' <directory> - Recursively search
for a pattern in a directory​

●​ awk '{print $1, $2}' <file> - Process and extract


columns from a file​
ay
●​ sed 's/old/new/g' <file> - Replace text in a file​

●​ cut -d':' -f1 <file> - Extract specific fields from a file​

●​ sort <file> - Sort file contents​


N

●​ uniq <file> - Remove duplicate lines from a file​

●​ wc -l <file> - Count lines in a file​

●​ wc -w <file> - Count words in a file​

●​ wc -c <file> - Count bytes in a file​

●​ tr 'a-z' 'A-Z' <file> - Convert lowercase to uppercase​

●​ diff <file1> <file2> - Compare two files line by line​

8
●​ cmp <file1> <file2> - Compare two files byte by byte​

●​ tee <file> - Read from standard input and write to both a


file and standard output

10. Package Management

For Debian-based systems (Ubuntu, Debian)

●​ apt update - Update package lists​

●​ apt upgrade - Upgrade all installed packages​

a
●​ apt install <package> - Install a package​
an
●​ apt remove <package> - Remove a package​

●​ apt purge <package> - Remove a package and its config


files​

●​ dpkg -i <package>.deb - Install a .deb package​


ay
●​ dpkg -r <package> - Remove a package installed via dpkg​

●​ dpkg -l - List installed packages​

●​ apt-cache search <package> - Search for a package​


N

●​ apt autoremove - Remove unnecessary packages​

●​ apt clean - Clear the package cache​

For RHEL-based systems (CentOS, Rocky Linux, AlmaLinux,


Fedora)

●​ yum update - Update installed packages (for older systems)​

9
●​ dnf update - Update installed packages (for newer systems)​

●​ yum install <package> - Install a package​

●​ dnf install <package> - Install a package (newer distros)​

●​ yum remove <package> - Remove a package​

●​ dnf remove <package> - Remove a package (newer distros)​

●​ rpm -ivh <package>.rpm - Install an .rpm package​

●​ rpm -e <package> - Remove an installed .rpm package​

a
●​ yum list installed - List installed packages​
an
●​ dnf list installed - List installed packages (newer
distros)​

●​ yum search <package> - Search for a package​

●​ dnf search <package> - Search for a package (newer


ay
distros)​

●​ yum clean all - Clean cached package data

11. Archive and Compression


N

Working with tar files

●​ tar -cvf archive.tar <files> - Create a tar archive​

●​ tar -xvf archive.tar - Extract a tar archive​

●​ tar -tvf archive.tar - List files in a tar archive​

10
●​ tar -czvf archive.tar.gz <files> - Create a
compressed tar.gz archive​

●​ tar -xzvf archive.tar.gz - Extract a tar.gz archive​

●​ tar -cJvf archive.tar.xz <files> - Create a tar.xz


archive​

●​ tar -xJvf archive.tar.xz - Extract a tar.xz archive​

Working with zip files

●​ zip archive.zip <files> - Create a zip archive​

a
●​ unzip archive.zip - Extract a zip archive​
an
●​ unzip -l archive.zip - List contents of a zip file​

●​ zip -r archive.zip <directory> - Zip a directory​


ay
Working with gzip & bzip2

●​ gzip <file> - Compress a file using gzip​

●​ gunzip <file>.gz - Decompress a gzip file​


N

●​ bzip2 <file> - Compress a file using bzip2​

●​ bunzip2 <file>.bz2 - Decompress a bzip2 file

12. Shutdown and Reboot

●​ shutdown -h now - Shutdown the system immediately​

●​ shutdown -h +10 - Shutdown the system in 10 minutes​

11
●​ shutdown -h 22:00 - Schedule shutdown at 10:00 PM​

●​ shutdown -c - Cancel a scheduled shutdown​

●​ poweroff - Immediately power off the system​

●​ halt - Halt the system​

●​ reboot - Reboot the system immediately​

●​ shutdown -r now - Reboot the system immediately​

●​ shutdown -r +5 - Reboot the system in 5 minutes​

a
●​ systemctl reboot - Reboot using systemd
an
13. Task Scheduling

●​ crontab -e - Edit cron jobs for the current user​

●​ crontab -l - List scheduled cron jobs​


ay
●​ crontab -r - Remove all cron jobs for the current user​

●​ crontab -u <user> -l - List cron jobs for a specific user

●​ at <time> - Schedule a command to run at specified time


N

14. System Diagnostics and Troubleshooting

●​ journalctl -xe - View detailed system logs​

●​ journalctl -f - Follow live logs in real-time​

12
●​ journalctl --since "1 hour ago" - View logs from the
last hour​

●​ dmesg | less - View system boot logs​

●​ dmesg | grep error - Check for errors in system logs​

●​ cat /var/log/syslog - View general system logs


(Debian-based)​

●​ cat /var/log/messages - View general system logs


(RHEL-based)​

a
●​ uptime - Show system uptime and load​

●​ free -m - Display available and used memory in MB​


an
●​ top - Monitor real-time CPU, memory, and process usage​

●​ htop - Interactive system monitoring (if installed)​

●​ vmstat 1 5 - Display system performance stats​


ay
●​ iostat - Show CPU and disk usage statistics
N

13

You might also like