Linux commands
Advanced Linux Commands
System Monitoring and Performance
1. top - Displays real-time system processes and performance information.
1 top
2. htop - An interactive process viewer, similar to top , but with a more user-friendly interface.
1 htop
3. iostat - Reports CPU and I/O statistics.
1 iostat
4. vmstat - Reports virtual memory statistics.
1 vmstat
5. nmon - Performance monitoring tool for Linux.
1 nmon
Networking
1. ifconfig - Displays or configures network interfaces.
1 ifconfig
2. ip - Shows/manipulates routing, devices, policy routing, and tunnels.
1 ip a
2 ip r
3. netstat - Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
1 netstat -tuln
4. ss - Utility to investigate sockets.
1 ss -tuln
5. tcpdump - Captures and analyzes network traffic.
1 tcpdump -i eth0
6. nmap - Network exploration tool and security/port scanner.
1 nmap -A 192.168.1.1
Disk Usage and Management
1. df - Reports file system disk space usage.
1 df -h
2. du - Estimates file space usage.
1 du -sh /path/to/directory
3. lsblk - Lists information about all available or the specified block devices.
1 lsblk
4. blkid - Locates/prints block device attributes.
1 blkid
5. lsof - Lists open files.
1 lsof +D /path/to/directory
File Operations
1. rsync - Fast, versatile, remote (and local) file-copying tool.
1 rsync -avz /source/directory/ user@remote:/destination/directory/
2. tar - Archives multiple files into a single file and extracts files from an archive.
1 tar -cvf archive.tar /path/to/directory
2 tar -xvf archive.tar
3. find - Searches for files in a directory hierarchy.
1 find /path/to/search -name "filename"
4. grep - Searches for patterns in files.
1 grep -r "search_term" /path/to/directory
5. awk - Pattern scanning and processing language.
1 awk '{print $1}' file.txt
6. sed - Stream editor for filtering and transforming text.
1 sed -i 's/old_string/new_string/g' file.txt
User and Permissions Management
1. chown - Changes file owner and group.
1 chown user:group filename
2. chmod - Changes file modes or Access Control Lists.
1 chmod 755 filename
3. usermod - Modifies a user account.
1 usermod -aG groupname username
4. sudo - Executes a command as another user.
1 sudo command
System and Process Management
1. systemctl - Manages systemd services.
1 systemctl start/stop/restart/status service_name
2. journalctl - Queries and displays messages from the journal.
1 journalctl -u service_name
3. crontab - Schedules periodic background jobs.
1 crontab -e
4. at - Schedules commands to run at a particular time.
1 at 14:00
5. screen - Terminal multiplexer that allows for persistent sessions.
1 screen
6. tmux - Terminal multiplexer, an alternative to screen .
1 tmux
Security and Access Control
1. ufw - Uncomplicated Firewall, a frontend for iptables.
1 ufw allow/deny port
2 ufw enable
2. fail2ban - Bans IPs that show malicious signs.
1 fail2ban-client status
3. ssh-keygen - Generates, manages, and converts authentication keys for SSH.
1 ssh-keygen -t rsa
4. gpg - Encrypts and signs data and communications.
1 gpg --gen-key
2 gpg --encrypt --recipient user@example.com file.txt
Package Management
1. apt-get (Debian/Ubuntu) - Command-line tool for handling packages.
1 sudo apt-get update
2 sudo apt-get upgrade
3 sudo apt-get install package_name
2. yum (CentOS/RHEL) - Package manager for RPM-based distributions.
1 sudo yum update
2 sudo yum install package_name
3. dnf (Fedora) - Modern package manager for RPM-based distributions.
1 sudo dnf update
2 sudo dnf install package_name
4. snap - Universal package management system.
1 sudo snap install package_name
System Information and Configuration
1. uname - Prints system information.
1 uname -a
2. hostnamectl - Controls the system hostname.
1 hostnamectl set-hostname new_hostname
3. timedatectl - Controls the system time and date.
1 timedatectl set-time "YYYY-MM-DD HH:MM:SS"
2 timedatectl set-timezone America/New_York
4. lsmod - Shows the status of modules in the Linux Kernel.
1 lsmod
5. modprobe - Adds or removes modules from the Linux kernel.
1 sudo modprobe module_name
File Systems and Disk Management
1. mkfs - Builds a Linux file system on a device.
1 sudo mkfs.ext4 /dev/sdX1
2. fsck - Checks and repairs a Linux file system.
1 sudo fsck /dev/sdX1
3. mount - Mounts a file system.
1 sudo mount /dev/sdX1 /mnt
4. umount - Unmounts a file system.
1 sudo umount /mnt
5. dd - Converts and copies a file.
1 sudo dd if=/dev/sdX of=/path/to/backup.img bs=4M
Advanced Networking
1. traceroute - Tracks the route packets take to a network host.
1 traceroute google.com
2. mtr - Combines the functionality of traceroute and ping .
1 mtr google.com
3. iptable - Linux firewall and NAT tool.
1 sudo iptables -L
2 sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
4. curl - Transfers data from or to a server.
1 curl -O <http://example.com/file.txt>
2 curl -X POST -d "param1=value1¶m2=value2" <http://example.com/resource>
5. wget - Non-interactive network downloader.
1 wget <http://example.com/file.txt>
Advanced Process Management
1. nohup - Runs a command immune to hangups.
1 nohup command &
2. nice - Runs a command with a modified scheduling priority.
1 nice -n 10 command
3. renice - Alters the priority of running processes.
1 sudo renice -n 10 -p PID
4. xargs - Builds and executes command lines from standard input.
1 cat file.txt | xargs -n 1 -P 4 command
5. pkill - Signals processes based on name and other attributes.
1 pkill -9 process_name
User and Group Management
1. groupadd - Adds a new group to the system.
1 sudo groupadd group_name
2. usermod - Modifies a user account.
1 sudo usermod -aG group_name user_name
3. passwd - Changes a user's password.
1 sudo passwd user_name
4. chage - Changes the user password expiry information.
1 sudo chage -l user_name
Advanced Scripting and Automation
1. cron - Schedules jobs to run periodically at fixed times, dates, or intervals.
1 crontab -e
2 # Add a new cron job:
3 # * * * * * /path/to/script.sh
2. at - Schedules commands to run once at a specified time.
1 echo "command" | at 10:00
3. inotifywait - Watches for changes to files and directories.
1 inotifywait -m /path/to/watch
4. expect - Automates interactive applications.
1 expect script.exp