Linux Commands,Common Linux commands, <code>Tip: Ctrl+F to quickly find Linux commands (click title to collapse/expand)</code>
| Command code | Description |
|---|---|
| arch | Show processor architecture of the machine (1) |
| uname -m | Show processor architecture of the machine (2) |
| uname -r | Show the kernel version in use |
| dmidecode -q | Show hardware system components - (SMBIOS / DMI) |
| hdparm -i /dev/hda | List disk architecture features |
| hdparm -tT /dev/sda | Perform a test read operation on the disk |
| cat /proc/cpuinfo | Show CPU info |
| cat /proc/interrupts | Show interrupts |
| cat /proc/meminfo | Check memory usage |
| cat /proc/swaps | Show which swap is being used |
| cat /proc/version | Show kernel version |
| cat /proc/net/dev | Show network adapters and statistics |
| cat /proc/mounts | Show mounted file systems |
| lspci -tv | List PCI devices |
| lsusb -tv | Show USB devices |
| date | Show system date |
| cal 2007 | Show calendar for 2007 |
| date 041217002007.00 | Set date and time - MMDDhhmmYYYY.ss |
| clock -w | Save time changes to BIOS |
| Command code | Description |
|---|---|
| shutdown -h now | Shutdown the system |
| init 0 | Shutdown the system |
| telinit 0 | Shutdown the system |
| shutdown -h hours:minutes & | Shutdown the system at a scheduled time |
| shutdown -c | Cancel a scheduled shutdown |
| shutdown -r now | Reboot |
| reboot | Reboot |
| logout | Logout |
| Command code | Description |
|---|---|
| cd /home | Enter '/ home' directory |
| cd .. | Go to the previous directory |
| cd ../.. | Go up two levels |
| cd | Go to the user's home directory |
| cd ~user1 | Go to the user's home directory |
| cd - | Return to the previous directory |
| pwd | Show current working directory |
| ls | List files in a directory |
| ls -F | List files in a directory |
| ls -l | Show detailed file and directory information |
| ls -a | Show hidden files |
| ls *[0-9]* | Show filenames and directories containing digits |
| tree | Show files and directories in a tree structure starting from root |
| lstree | Show files and directories in a tree structure starting from root |
| mkdir dir1 | Create a directory named 'dir1' |
| mkdir dir1 dir2 | Create two directories at the same time |
| mkdir -p /tmp/dir1/dir2 | Create a directory tree |
| rm -f file1 | Delete a file named 'file1' |
| rmdir dir1 | Delete a directory named 'dir1' |
| rm -rf dir1 | Delete a directory named 'dir1' and its contents |
| rm -rf dir1 dir2 | Delete two directories and their contents simultaneously |
| mv dir1 new_dir | Rename/move a directory |
| cp file1 file2 | Copy a file |
| cp dir/* . | Copy all files from a directory to the current working directory |
| cp -a /tmp/dir1 . | Copy a directory to the current working directory |
| cp -a dir1 dir2 | Copy a directory |
| ln -s file1 lnk1 | Create a symbolic link to a file or directory |
| ln file1 lnk1 | Create a hard link to a file or directory |
| touch -t 0712250000 file1 | Modify the timestamp of a file or directory - (YYMMDDhhmm) |
| iconv -l | List known encodings |
| iconv -f fromEncoding -t toEncoding inputFile > outputFile | Change character encoding |
| find . -maxdepth 1 -name *.jpg -print -exec convert | Batch resize files in the current directory and send them to a thumbnail directory (requires ImageMagick conversion) |
| Command code | Description |
|---|---|
| find / -name file1 | Search for files and directories starting from root |
| find / -user user1 | Search for files and directories belonging to user 'user1' |
| find /home/user1 -name \*.bin | Search in directory '/ home/user1' for files ending with '.bin' |
| find /usr/bin -type f -atime +100 | Search for executable files not accessed in the last 100 days |
| find /usr/bin -type f -mtime -10 | Search for files created or modified in the last 10 days |
| find / -name \*.rpm -exec chmod 755 '{}' \; | Search for files ending with '.rpm' and set permissions |
| find / -xdev -name \*.rpm | Search for files ending with '.rpm', ignoring removable devices like CD-ROMs, USB drives |
| locate \*.ps | Search for files ending with '.ps' - run 'updatedb' command first |
| whereis halt | Display the location of a binary, source, or man page |
| which halt | Show full path of a binary or executable file |
| Command code | Description |
|---|---|
| mount /dev/hda2 /mnt/hda2 | Mount a disk called hda2 - ensure directory '/ mnt/hda2' exists |
| umount /dev/hda2 | Unmount a disk called hda2 - first exit from mount point '/ mnt/hda2' |
| fuser -km /mnt/hda2 | Force unmount when device is busy |
| umount -n /mnt/hda2 | Perform unmount operation without writing to /etc/mtab - useful when file is read-only or disk is full |
| mount /dev/fd0 /mnt/floppy | Mount a floppy disk |
| mount /dev/cdrom /mnt/cdrom | Mount a CD-ROM or DVD-ROM |
| mount /dev/hdc /mnt/cdrecorder | Mount a CD-RW or DVD-ROM |
| mount /dev/hdb /mnt/cdrecorder | Mount a CD-RW or DVD-ROM |
| mount -o loop file.iso /mnt/cdrom | Mount a file or ISO image |
| mount -t vfat /dev/hda5 /mnt/hda5 | Mount a Windows FAT32 file system |
| mount /dev/sda1 /mnt/usbdisk | Mount a USB flash drive or storage device |
| mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share | Mount a Windows network share |
| Command code | Description |
|---|---|
| df -h | Show list of mounted partitions |
| ls -lSr |more | List files and directories sorted by size |
| du -sh dir1 | Estimate disk space used by directory 'dir1' |
| du -sk * | sort -rn | Show sizes of files and directories sorted by capacity |
| rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n | Show installed rpm packages sorted by size (Fedora, RedHat-like systems) |
| dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n | Show installed deb packages sorted by size (Ubuntu, Debian-like systems) |
| Command code | Description |
|---|---|
| groupadd group_name | Create a new user group |
| groupdel group_name | Delete a user group |
| groupmod -n new_group_name old_group_name | Rename a user group |
| useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 | Create a user belonging to the \"admin\" group |
| useradd user1 | Create a new user |
| userdel -r user1 | Delete a user ( '-r' excludes home directory) |
| usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 | Modify user attributes |
| passwd | Modify password |
| passwd user1 | Change a user's password (only allowed for root) |
| chage -E 2020-12-31 user1 | Set password expiration for a user |
| pwck | Check '/etc/passwd' file format, syntax, and existing users |
| grpck | Check '/etc/passwd' file format, syntax, and existing groups |
| newgrp group_name | Log into a new group to change the default group for new files created |
| Command code | Description |
|---|---|
| ls -lh | Show permissions |
| ls /tmp | pr -T5 -W$COLUMNS | Divide terminal into 5 columns |
| chmod ugo+rwx directory1 | Set read (r), write (w), and execute (x) permissions for owner (u), group (g), and others (o) on a directory |
| chmod go-rwx directory1 | Remove read, write, execute permissions for group (g) and others (o) on a directory |
| chown user1 file1 | Change the owner of a file |
| chown -R user1 directory1 | Change the owner of a directory and all files within it |
| chgrp group1 file1 | Change the group of a file |
| chown user1:group1 file1 | Change both owner and group of a file |
| find / -perm -u+s | List all files in the system that have SUID set |
| chmod u+s /bin/file1 | Set SUID bit on a binary file - users running the file get the same permissions as the owner |
| chmod u-s /bin/file1 | Disable SUID bit on a binary file |
| chmod g+s /home/public | Set SGID bit on a directory - similar to SUID but for directories |
| chmod g-s /home/public | Disable SGID bit on a directory |
| chmod o+t /home/public | Set sticky bit on a file - only the owner can delete the file |
| chmod o-t /home/public | Disable sticky bit on a directory |
| Command code | Description |
|---|---|
| chattr +a file1 | Allow file to be appended only (write in append mode) |
| chattr +c file1 | Allow file to be automatically compressed/decompressed by the kernel |
| chattr +d file1 | When performing file system backups, the dump program will ignore this file |
| chattr +i file1 | Set file as immutable; cannot be deleted, modified, renamed, or linked |
| chattr +s file1 | Allow a file to be securely deleted |
| chattr +S file1 | Once an application performs a write operation on this file, force the system to immediately write changes to disk |
| chattr +u file1 | If the file is deleted, allow recovery of the deleted file later |
| lsattr | Show special attributes |
| Command code | Description |
|---|---|
| bunzip2 file1.bz2 | Extract a file named 'file1.bz2' |
| bzip2 file1 | Compress a file named 'file1' |
| gunzip file1.gz | Extract a file named 'file1.gz' |
| gzip file1 | Compress a file named 'file1' |
| gzip -9 file1 | Maximum compression |
| rar a file1.rar test_file | Create an archive named 'file1.rar' |
| rar a file1.rar file1 file2 dir1 | Compress 'file1', 'file2', and directory 'dir1' together |
| rar x file1.rar | Extract a rar archive |
| unrar x file1.rar | Extract a rar archive |
| tar -cvf archive.tar file1 | Create an uncompressed tarball |
| tar -cvf archive.tar file1 file2 dir1 | Create an archive containing 'file1', 'file2', and 'dir1' |
| tar -tf archive.tar | Show contents of an archive |
| tar -xvf archive.tar | Extract an archive |
| tar -xvf archive.tar -C /tmp | Extract archive to /tmp directory |
| tar -cvfj archive.tar.bz2 dir1 | Create a bzip2 compressed archive |
| tar -jxvf archive.tar.bz2 | Extract a bzip2 compressed archive |
| tar -cvfz archive.tar.gz dir1 | Create a gzip compressed archive |
| tar -zxvf archive.tar.gz | Extract a gzip compressed archive |
| zip file1.zip file1 | Create a zip compressed archive |
| zip -r file1.zip file1 file2 dir1 | Compress multiple files and directories into a zip archive |
| unzip file1.zip | Extract a zip archive |
| Command code | Description |
|---|---|
| rpm -ivh package.rpm | Install an rpm package |
| rpm -ivh --nodeeps package.rpm | Install an rpm package ignoring dependency warnings |
| rpm -U package.rpm | Update an rpm package without changing its configuration files |
| rpm -F package.rpm | Update a definitely installed rpm package |
| rpm -e package_name.rpm | Remove an rpm package |
| rpm -qa | Display all installed rpm packages in the system |
| rpm -qa | grep httpd | Show all rpm packages containing \"httpd\" in their names |
| rpm -qi package_name | Get specific information about an installed package |
| rpm -qg "System Environment/Daemons" | Display the rpm package of a component |
| rpm -ql package_name | Show the list of files provided by an installed rpm package |
| rpm -qc package_name | Show the list of configuration files provided by an installed rpm package |
| rpm -q package_name --whatrequires | Display the dependency list of an rpm package |
| rpm -q package_name --whatprovides | Show the size occupied by an rpm package |
| rpm -q package_name --scripts | Display the scripts executed during installation/removal |
| rpm -q package_name --changelog | Show the modification history of an rpm package |
| rpm -qf /etc/httpd/conf/httpd.conf | Confirm which rpm package provides a given file |
| rpm -qp package.rpm -l | Show the file list provided by an rpm package that is not yet installed |
| rpm --import /media/cdrom/RPM-GPG-KEY | Import a public key digital certificate |
| rpm --checksig package.rpm | Verify the integrity of an rpm package |
| rpm -qa gpg-pubkey | Verify the integrity of all installed rpm packages |
| rpm -V package_name | Check file size, permissions, type, owner, group, MD5 checksum, and last modification time |
| rpm -Va | Check all installed rpm packages in the system - use with caution |
| rpm -Vp package.rpm | Confirm that an rpm package is not installed |
| rpm2cpio package.rpm | cpio --extract --make-directories *bin* | Run an executable file from an rpm package |
| rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm | Install a built package from an rpm source |
| rpmbuild --rebuild package_name.src.rpm | Build an rpm package from an rpm source |
| Command code | Description |
|---|---|
| yum install package_name | Download and install an rpm package |
| yum localinstall package_name.rpm | Install an rpm package using your own software repository to resolve all dependencies |
| yum update package_name.rpm | Update all installed rpm packages in the current system |
| yum update package_name | Update an rpm package |
| yum remove package_name | Remove an rpm package |
| yum list | List all installed packages in the current system |
| yum search package_name | Search for software packages in the rpm repository |
| yum clean packages | Clean rpm cache and delete downloaded packages |
| yum clean headers | Delete all header files |
| yum clean all | Delete all cached packages and header files |
| Command code | Description |
|---|---|
| dpkg -i package.deb | Install/update a deb package |
| dpkg -r package_name | Remove a deb package from the system |
| dpkg -l | Show all installed deb packages in the system |
| dpkg -l | grep httpd | Show all deb packages containing \"httpd\" in their names |
| dpkg -s package_name | Get information about a specific package installed in the system |
| dpkg -L package_name | Show the file list provided by an installed deb package |
| dpkg --contents package.deb | Show the file list provided by a not yet installed package |
| dpkg -S /bin/ping | Confirm which deb package provides a given file |
| Command code | Description |
|---|---|
| apt-get install package_name | Install/update a deb package |
| apt-cdrom install package_name | Install/update a deb package from CD-ROM |
| apt-get update | Upgrade packages from the list |
| apt-get upgrade | Upgrade all installed software |
| apt-get remove package_name | Remove a deb package from the system |
| apt-get check | Verify that the dependent software repository is correct |
| apt-get clean | Clean cache from downloaded packages |
| apt-cache search searched-package | Return package names containing the search string |
| Command code | Description |
|---|---|
| cat file1 | View the contents of a file forward from the first byte |
| tac file1 | View the contents of a file backward from the last line |
| more file1 | View the contents of a long file |
| less file1 | Similar to 'more' command, but allows backward movement like forward movement |
| head -2 file1 | View the first two lines of a file |
| tail -2 file1 | View the last two lines of a file |
| tail -f /var/log/messages | View real-time content being added to a file |
| Command code | Description |
|---|---|
| cat file1 | command( sed, grep, awk, grep, etc...) > result.txt | Merge detailed description text of a file and write the summary into a new file |
| cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt | Merge detailed description text of a file and write the summary into an existing file |
| grep Aug /var/log/messages | Search for the keyword \"Aug\" in the file '/var/log/messages' |
| grep ^Aug /var/log/messages | Search for words starting with \"Aug\" in the file '/var/log/messages' |
| grep [0-9] /var/log/messages | Select all lines containing digits in the file '/var/log/messages' |
| grep Aug -R /var/log/* | Search for the string \"Aug\" in the directory '/var/log' and subsequent directories |
| sed 's/stringa1/stringa2/g' example.txt | Replace \"string1\" with \"string2\" in the file example.txt |
| sed '/^$/d' example.txt | Delete all blank lines from the file example.txt |
| sed '/ *#/d; /^$/d' example.txt to delete all comments and blank lines from example.txt | Delete all comments and blank lines from the file |
| echo 'esempio' | tr '[:lower:]' '[:upper:]' | Merge upper and lower cell contents |
| sed -e '1d' result.txt | Exclude the first line from the file example.txt |
| sed -n '/stringa1/p' | View lines containing only the word \"string1\" |
| sed -e 's/ *$//' example.txt | Remove trailing whitespace characters from each line |
| sed -e 's/stringa1//g' example.txt | Delete only the word \"string1\" from the document and keep the rest |
| sed -n '1,5p;5q' example.txt | View content from the first line to line 5 |
| sed -n '5p;5q' example.txt | View line 5 |
| sed -e 's/00*/0/g' example.txt | Replace multiple zeros with a single zero |
| cat -n file1 | Number the lines of a file |
| cat example.txt | awk 'NR%2==1' | Delete all even-numbered lines from the file example.txt |
| echo a b c | awk '{print $1}' | View the first column of a line |
| echo a b c | awk '{print $1,$3}' | View the first and third columns of a line |
| paste file1 file2 | Merge the contents of two files or two columns |
| paste -d '+' file1 file2 | Merge the contents of two files or two columns, separated by \"+\" |
| sort file1 file2 | Sort the contents of two files |
| sort file1 file2 | uniq | Output the union of two files (keep only one copy of duplicate lines) |
| sort file1 file2 | uniq -u | Delete the intersection, leaving other lines |
| sort file1 file2 | uniq -d | Output the intersection of two files (keep only lines common to both files) |
| comm -1 file1 file2 | Compare two files and delete only the content contained in 'file1' |
| comm -2 file1 file2 | Compare two files and delete only the content contained in 'file2' |
| comm -3 file1 file2 | Compare two files and delete only the parts common to both files |
| Command code | Description |
|---|---|
| dos2unix filedos.txt fileunix.txt | Convert a text file format from MSDOS to UNIX |
| unix2dos fileunix.txt filedos.txt | Convert a text file format from UNIX to MSDOS |
| recode ..HTML < page.txt> page.html | Convert a text file to HTML |
| recode -l | more | Show all allowed conversion formats |
| Command code | Description |
|---|---|
| badblocks -v /dev/hda1 | Check for bad blocks on disk hda1 |
| fsck /dev/hda1 | Repair/check the integrity of a Linux file system on disk hda1 |
| fsck.ext2 /dev/hda1 | Repair/check the integrity of an ext2 file system on disk hda1 |
| e2fsck /dev/hda1 | Repair/check the integrity of an ext2 file system on disk hda1 |
| e2fsck -j /dev/hda1 | Repair/check the integrity of an ext3 file system on disk hda1 |
| fsck.ext3 /dev/hda1 | Repair/check the integrity of an ext3 file system on disk hda1 |
| fsck.vfat /dev/hda1 | Repair/check the integrity of a FAT file system on disk hda1 |
| fsck.msdos /dev/hda1 | Repair/check the integrity of a DOS file system on disk hda1 |
| dosfsck /dev/hda1 | Repair/check the integrity of a DOS file system on disk hda1 |
| Command code | Description |
|---|---|
| mkfs /dev/hda1 | Create a file system on the hda1 partition |
| mke2fs /dev/hda1 | Create a Linux ext2 file system on the hda1 partition |
| mke2fs -j /dev/hda1 | Create a Linux ext3 (journaling) file system on the hda1 partition |
| mkfs -t vfat 32 -F /dev/hda1 | Create a FAT32 file system |
| fdformat -n /dev/fd0 | Format a floppy disk |
| mkswap /dev/hda3 | Create a swap file system |
| Command code | Description |
|---|---|
| mkswap /dev/hda3 | Create a swap file system |
| swapon /dev/hda3 | Enable a new swap file system |
| swapon /dev/hda2 /dev/hdb3 | Enable two swap partitions |
| Command code | Description |
|---|---|
| dump -0aj -f /tmp/home0.bak /home | Make a full backup of the '/home' directory |
| dump -1aj -f /tmp/home0.bak /home | Make an interactive backup of the '/home' directory |
| restore -if /tmp/home0.bak | Restore an interactive backup |
| rsync -rogpav --delete /home /tmp | Synchronize directories on both sides |
| rsync -rogpav -e ssh --delete /home ip_address:/tmp | rsync over SSH |
| rsync -az -e ssh --delete ip_addr:/home/public /home/local | Synchronize a remote directory to a local directory via SSH with compression |
| rsync -az -e ssh --delete /home/local ip_addr:/home/public | Synchronize a local directory to a remote directory via SSH with compression |
| dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' | Perform a local disk backup on a remote host via SSH |
| dd if=/dev/sda of=/tmp/file1 | Back up disk contents to a file |
| tar -Puf backup.tar /home/user | Perform an interactive backup of the '/home/user' directory |
| ( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' | Copy directory contents to a remote directory via SSH |
| ( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' | Copy a local directory to a remote directory via SSH |
| tar cf - . | (cd /tmp/backup ; tar xf - ) | Copy a directory to another location locally, preserving original permissions and links |
| find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents | Find and copy all files ending with '.txt' from one directory to another |
| find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 | Find all files ending with '.log' and create a bzip package |
| dd if=/dev/hda of=/dev/fd0 bs=512 count=1 | Copy MBR (Master Boot Record) contents to a floppy disk |
| dd if=/dev/fd0 of=/dev/hda bs=512 count=1 | Restore MBR contents from a backup saved on a floppy disk |
| Command code | Description |
|---|---|
| cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force | Erase the contents of a rewritable optical disc |
| mkisofs /dev/cdrom > cd.iso | Create an ISO image of an optical disc on disk |
| mkisofs /dev/cdrom | gzip > cd_iso.gz | Create a compressed ISO image of an optical disc on disk |
| mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd | Create an ISO image of a directory |
| cdrecord -v dev=/dev/cdrom cd.iso | Burn an ISO image file |
| gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - | Burn a compressed ISO image file |
| mount -o loop cd.iso /mnt/iso | Mount an ISO image file |
| cd-paranoia -B | Rip audio tracks from a CD to wav files |
| cd-paranoia -- "-3" | Rip audio tracks from a CD to wav files (with parameter -3) |
| cdrecord --scanbus | Scan the bus to identify SCSI channels |
| dd if=/dev/hdc | md5sum | Verify the md5sum of a device, e.g., a CD |
| Command code | Description |
|---|---|
| dhclient eth0 | Enable 'eth0' network device in DHCP mode |
| ethtool eth0 | Show traffic statistics for network card 'eth0' |
| host www.example.com | Look up hostname to resolve name to IP address and vice versa |
| hostname | Display the hostname |
| ifconfig eth0 | Display the configuration of an Ethernet card |
| ifconfig eth0 192.168.1.1 netmask 255.255.255.0 | Control IP addresses |
| ifconfig eth0 promisc | Set 'eth0' to promiscuous mode for packet sniffing |
| ifdown eth0 | Disable a network device 'eth0' |
| ifup eth0 | Enable a network device 'eth0' |
| ip link show | Show the connection status of all network devices |
| iwconfig eth1 | Display the configuration of a wireless network card |
| iwlist scan | Show wireless networks |
| mii-tool eth0 | Show the connection status of 'eth0' |
| netstat -tup | Show all enabled network connections and their PIDs |
| netstat -tup1 | Show all listening network services in the system and their PIDs |
| netstat -rn | Display the routing table, similar to the 'route -n' command |
| nslookup www.example.com | Look up hostname to resolve name to IP address and vice versa |
| route -n | Display the routing table |
| route add -net 0/0 gw IP Gateway | Control the default gateway |
| route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 | Control the static route to the network '192.168.0.0/16' |
| route del 0/0 gw IP gateway | Delete a static route |
| echo “1”> /proc/sys/net/ipv4/ip_foward | Activate IP forwarding |
| tcpdump tcp port 80 | Show all HTTP loops |
| whois www.example.com | Look up in the Whois database |
| Command code | Description |
|---|---|
| mount -t smbfs -o username=user,password=pass //WinClient/share/mnt/share | Mount a Windows network share |
| nbtscan ip addr | NetBIOS name resolution |
| nmblookup -A ip addr | NetBIOS name resolution |
| smbclient -L ip addr/hostname | Display remote shares of a Windows host |
| smbget -Rr smb://ip addr/share | Download files from a Windows host via SMB like wget |
| Command code | Description |
|---|---|
| iptables -t filter -L | Show all chains in the filter table |
| iptables -t nae -L | Show all chains in the NAT table |
| iptables -t filter -F | Clear all rules based on the filter table |
| iptables -t nat -F | Clear all rules based on the NAT table |
| iptables -t filter -X | Delete all chains created by users |
| iptables -t filter -A INPUT -p tcp --dport telnet -j ACCEPT | Allow telnet access |
| iptables -t filter -A OUTPUT -p tcp --dport telnet -j DROP | Block telnet access |
| iptables -t filter -A FORWARD -p tcp --dport pop3 -j ACCEPT | Allow POP3 connections on the forward chain |
| iptables -t filter -A INPUT -j LOG --log-prefix | Log all dropped packets in all chains |
| iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | Set up PAT (Port Address Translation) on eth0 to masquerade outgoing packets |
| iptables -t nat -A POSTROUTING -d 192.168.0.1 -p tcp -m tcp --dport 22-j DNAT --to-destination 10.0.0.2:22 | Redirect packets destined for one host address to another host |
| Command code | Description |
|---|---|
| free -m | List RAM status in megabytes |
| kill -9 process id | Forcefully kill a process and terminate it |
| kill -1 process id | Force a process to reload its configuration |
| last reboot | Display reboot history |
| lsmod | List kernel modules and their status |
| lsof -p process id | List files opened by a process |
| lsof /home/user1 | List open files in a given system path |
| ps -eafw | List Linux tasks |
| ps -e -o pid,args --forest | List Linux tasks hierarchically |
| pstress | Display processes as a tree |
| smartctl -A /dev/hda | Monitor the reliability of a hard disk device by enabling SMART |
| smartctl -i /dev/hda | Check if SMART is enabled on a hard disk device |
| strace -c ls >/dev/null | List system calls made and received by a process |
| strace -f -e open ls >/dev/null | List library calls |
| tail /var/log/dmesg | Show internal events during kernel boot process |
| tail /val/log/messages | Show system events |
| top | List Linux tasks using the most CPU resources |
| watch -nl ‘cat /proc/interrupts’ | List real-time interrupts |
| Command code | Description |
|---|---|
| alias hh='history' | Set an alias for the command 'history' |
| apropos ...keyword | List commands including program keywords, useful when you know what a program does but don't remember the command |
| chsh | Change the shell command |
| chsh --list-shells | A useful command to know if you must connect remotely to another machine |
| gpg -c filel | Encrypt a file with GNU Privacy Guard |
| gpg filel.gpg | Decrypt a file with GNU Privacy Guard |