System information
arch or uname -m - display the architecture of your computer
uname -r - display the kernel version used
dmidecode -q - display hardware system components - (SMBIOS / DMI)
hdparm -i /dev/hda - show characteristics of your hard drive
hdparm -tT /dev/sda - test the hard disk read performance
cat /proc/user_beancounters - display information about beancounters (only on VPS)
cat /proc/cpuinfo - display the information about the processor
cat /proc/interrupts - show interruptions
cat /proc/meminfo - check memory usage
cat /proc/swaps - show swap file(s)
cat /proc/version - show the kernel version
cat /proc/net/dev - show network interfaces and their stats
cat /proc/mounts - show mounted file systems
lspci -tv - show the PCI devices in the tree view
lsusb -tv - show USB devices in the tree view
date - show system date
cal 2007 - show calendar table for 2007
date 041217002007.00* - set system date and time MMDDCHmmHmmYYYYYY.SS (MonthDayHhMinutesMinutesYear.Seconds)
Reboot the system
shutdown -h now - stop the system
shutdown -h hours:minutes & -schedule system shutdown for a specified time
shutdown -c - cancel scheduled system shutdown
shutdown -r now or reboot -to reboot the system
logout - log off the system
Files and directories
cd /home - go to the '/home' directory
cd . - go to the directory above
cd ../... - go to the directory two levels above
cd - go to home directory
cd ~user - go to user's home directory
cd - move to the directory we were in before we moved to the current directory
pwd - show current directory
ls - show content of current directory
ls -F - show the contents of the current directory, with appended type symbols in the names
ls -l - show detailed representation of files and directories in the current directory
ls -a -show hidden files and directories in the current directory
ls *[0-9]* - show files and directories with numbers in their names
tree or lstree - show the tree of files and directories, starting from the 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 named 'dir2', creating all intermediate directories ('dir1') if they do not exist.
rm -f file1 - delete file named 'file1'
rmdir dir1 - delete the directory named 'dir1'
rm -rf dir1 - delete the directory named 'dir1' and all its contents recursively
rm -rf dir1 dir2 - delete the two directories and their contents recursively
mv dir1 new_dir - move or rename file or directory
cp file1 file2 - copy file1 to file2
cp dir/* . - copy all files in dir directory to the current directory
cp -a /tmp/dir1 . - copy directory dir1 with all its contents into the current directory
cp -a dir1 dir2 - copy directory dir1 into directory dir2
ln -s file1 lnk1* - create a symbolic link to a file or directory
ln file1 lnk1 - to create a "hard" (physical) link to a file or directory
touch -t 0712250000 - modify date and time when file was created, if file is absent, create file with specified date and time (YYMMDDhhmm)
File Search
find / -name file1 - find files and directories named file1. Start search from the root (/)
find / -user user1 - find file and directory belonging to user user1. Start search from root (/)
find /home/user1 -name '*.bin' - find all files and directories with names ending with '. bin'. Start the search with '/home/user1'*
find /usr/bin -type f -atime +100 - find all files in '/usr/bin' which last accessed more than 100 days
find /usr/bin -type f -mtime -10 - find all files in '/usr/bin' which were created or changed during last 10 days
find / -name *.rpm -exec chmod 755 '{}' \; - find all files and directories, which names end with '.rpm', and change access rights to them
find / -xdev -name "*.rpm" - find all files and directories with names ending with '.rpm', ignoring removable media such as cdrom, floppy, etc.
locate "*.ps" - find all files with '.ps' in their names. It is recommended to execute 'updatedb' command beforehand
whereis halt - shows the location of binary files, source codes and manuals related to the 'halt' file
which halt - shows full path to file 'halt'
Mounting file systems
mount /dev/hda2 /mnt/hda2 - mounts partition 'hda2' to mount point '/mnt/hda2'. Make sure there is a mount point directory '/mnt/hda2'
umount /dev/hda2 - unmounts the 'hda2' partition. Before doing this, leave '/mnt/hda2'
fuser -km /mnt/hda2 - Forcibly unmounts the partition. This might be used if the partition is used by a user
umount -n /mnt/hda2 - unmount without writing information to /etc/mtab. Useful if you have a read-only file or insufficient space on the disk
mount /dev/fd0 /mnt/floppy - mount floppy disk
mount /dev/cdrom /mnt/cdrom - mount CD or DVD
mount /dev/hdc /mnt/cdrecorder - mount CD-R/CD-RW or DVD-R/DVD-RW(+-)
mount -o loop file.iso /mnt/cdrom - mount ISO image
mount -t vfat /dev/hda5 /mnt/hda5 - mount Windows FAT32 file system
mount -t smbfs -o username=user,password=pass //winclient/share /mnt/share - mount Windows network file system (SMB/CIFS)
mount -o bind /home/user/prg /var/ftp/user - "mount" a directory to a directory (binding). Available since kernel version 2.4.0. This is useful, for example, when ftp-server is running in a sandbox (chroot), where symlinking is not possible, to give the contents of the user's directory via ftp. Running this command will copy the contents of /home/user/prg to /var/ftp/user
Disk space
df -h - displays information about mounted partitions and displays total, available, and used space (Translator's note. The -h switch does not work on all *nix systems)
ls -lSr |more - gives a list of files and directories recursively sorted in ascending order of size and allows for page-by-page browsing
du -sh dir1 - calculates and displays the size occupied by the 'dir1' directory
du -sk * | sort -rn - displays the size and names of files and directories, sorted by size
rpm -q -a --qf '%10t%n' | sort -k1,1n - shows size of used disk space, occupied by rpm package files, sorted by size (fedora, redhat, etc.)
dpkg-query -W -f='${Installed-Size;10}t$n' | sort -k1,1n - shows the amount of disk space used by the deb-package files, sorted by size (ubuntu, debian, etc.)
Users and groups
groupadd group_name - create a new group named group_name
groupdel group_name - delete group_name group
groupmod -n new_group_name old_group_name - change group old_group_name into new_group_name
useradd -c "Nome Cognome" -g admin -d /home/user1 -s /bin/bash user1 - create user user user1, set /home/user1 as a home directory, /bin/bash as a shell, add him to the admin group and add the Nome Cognome comment
useradd user1 - create user user1
userdel -r user1 - delete user user1 and his home directory
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 - change user attributes
passwd - change password
passwd user1 - change password of user user1 (root only)
chage -E 2005-12-31 user1 - set the expiration date of the user1 account
pwck - check system account files for correctness. This checks the files /etc/passwd and /etc/shadow
grpck - checks system account files for correctness. Checks the /etc/group file
newgrp [-] group_name - changes the primary group for the current user. If "-" is specified, the situation will be identical to the one in which the user logged out and logged back in. If no group is specified, the primary group will be assigned from /etc/passwd
Verify/modify file permissions
ls -lh - view permissions for files and directories in the current directory
ls /tmp | pr -T5 -W$COLUMNS - display the contents of the /tmp directory and divide the output into five columns
chmod ugo+rwx directory1 - add permissions for directory1 ugo(User Group Other)+rwx(Read Write eXecute) - full rights for everybody. To do the same, chmod 777 directory1
chmod go-rwx directory1 - take all permissions to directory1 directory from the group and all others.
chown user1 file1 - make user1 the owner of file1
chown -R user1 directory1 - make user1 the owner of directory1 recursively
chgrp group1 file1 - change group-owner of file1 to group1
chown user1:group1 file1 - change the owner and group-owner of file1
find / -perm -u+s - find all files with SUID set beginning from the root
chmod u+s /bin/binary_file - assign an SUID bit to /bin/binary_file. This allows any user to execute the file with the authority of the file owner.
chmod u-s /bin/binary_file - removes the SUID bit from /bin/binary_file.
chmod g+s /home/public - assign an SGID bit to /home/public.
chmod g-s /home/public - remove the SGID bit from /home/public.
chmod o+t /home/public - assign a STIKY bit to /home/public. Allows only owners to remove files
chmod o-t /home/public - remove STIKY bit from /home/public directory
Special file attributes
chattr +a file1 - allows to open file for writing only in add mode
chattr +c file1 - allows kernel to automatically compress/decompress file contents.
chattr +d file1 - lets dump to ignore file in backup mode
chattr +i file1 - makes file inaccessible for any changes: editing, deleting, moving, creating links to it.
chattr +s file1 - allows to make file deletion safe, i.e. if s attribute is set it means that when deleting file the disk space occupied by the file is filled with zeros which prevents from data recovery.
chattr +S file1 - indicates that when you save the changes, it will be synchronized, as in the command sync
chattr +u file1 - this attribute indicates that when deleting a file its content will be saved and if necessary user will be able to restore it
lsattr - show file attributes
Archiving and compressing files
bunzip2 file1.bz2 - compresses 'file1.gz' file
gunzip file1.gz -
gzip file1 or bzip2 file1 - compresses 'file1' file
gzip -9 file1 - compresses file1 with maximal compression
rar a file1.rar test_file - create rar-archive 'file1.rar' and include file test_file in it
rar a file1.rar file1 file2 dir1 - create rar-archive 'file1.rar' and include file1, file2 and dir1 in it
rar x file1.rar - unpack the rar archive
unrar x file1.rar -
tar -cvf archive.tar file1 - create tar archive.tar tar archive with file1
tar -cvf archive.tar file1 file2 dir1 - create tar archive.tar archive containing file1, file2 and dir1
tar -tf archive.tar - show the archive content
tar -xvf archive.tar - unpack the archive
tar -xvf archive.tar -C /tmp - unpack the archive to /tmp
tar -cvfj archive.tar.bz2 dir1 - build the archive and compress it with bzip2 (Note: the -j switch might not work on some *nix systems)
tar -xvfj archive.tar.bz2 - uncompress and unpack the archive (Note: the -j switch does not work on all *nix systems)
tar -cvfz archive.tar.gz dir1 - create the archive and compress it with gzip
tar -xvfz archive.tar.gz - unpack the archive and unpack it
zip file1.zip file1 - create compressed zip archive
zip -r file1.zip file1 file2 dir1 - create a compressed zip archive and include several files and/or directories
unzip file1.zip - unzip and unzip the zip archive
RPM packages (Fedora, Red Hat and similar)
rpm -ivh package.rpm - install package with messages and progress bar
rpm -ivh --nodeps package.rpm - install package with messages and progress-bar without dependencies control
rpm -U package.rpm -update package without configuration files changes, in case of package absence, it will be installed
rpm -F package.rpm - update package only if it is installed
rpm -e package_name.rpm - remove package
rpm -qa - display list of all packages, installed in the system
rpm -qa | grep httpd - find among all packages installed in your system a package, containing "httpd" in its name
rpm -qi package_name - output the information about some specific package
rpm -qg "System Environment/Daemons" - display packages from the packages group
rpm -ql package_name - display list of files of package
rpm -qc package_name - display list of configuration files of the package
rpm -q package_name --whatrequires - output list of packages, needed for installing package by dependencies
rpm -q package_name --whatprovides - show capability provided by an rpm package
rpm -q package_name --scripts - display scripts which are used during package installation/removal
rpm -q package_name --changelog - show revision history of the package
rpm -qf /etc/httpd/conf/httpd.conf - check what package belongs to the specified file. You should specify full path and file name.
rpm -qp package.rpm -l - displays the list of files, that are included in package, but not installed into the system yet
rpm --import /media/cdrom/RPM-GPG-KEY - import public digital signature key
rpm --checksig package.rpm - check package signature
rpm -qa gpg-pubkey - check integrity of the installed package content
rpm -V package_name - check package size, permissions, type, owner, group, MD5 value and last modification date
rpm -Va -check contents of all packages installed into system. Perform with care!
rpm -Vp package.rpm - check package, which not installed into system yet
rpm2cpio package.rpm | cpio --extract --make-directories *bin* - extract files with name bin from package
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm - install package, built from source code
rpmbuild --rebuild package_name.src.rpm - build package from sources
Use the 'yum' utility to install (as well as remove and update) packages from network repositories. Unlike the lower-level 'rpm' utility, yum is able to automatically install additional packages on which the package being installed depends
YUM is a package updater (Fedora, RedHat, etc.)
yum install package_name - download and install package
yum update - updates all packages installed on your system
yum update package_name - upgrade package
yum remove package_name - remove the package
yum list - display all packages installed into the system
yum search package_name - find package in the repository
yum clean packages - remove downloaded packages from rpm-cache
yum clean headers - removes all file headers that the system uses for dependencies resolution
yum clean all - remove downloaded packages and headers from rpm-cache
DEB packages (Debian, Ubuntu and similar)
dpkg -i package.deb - install / update the package
dpkg -r package_name - remove the package from the system (this does not remove the configuration files, the package's settings remain in the system)
dpkg -P package_name - remove the package and its configuration files from your system
dpkg -l - show all packages installed into the system
dpkg -l | grep httpd - find among all packages installed in the system, the one containing "httpd" in its name
dpkg -s package_name - display information about a particular package
dpkg -L package_name - display the list of files, included in the package, installed into the system
dpkg --contents package.deb - display the list of files belonging to a package not yet installed on your system
dpkg -S /bin/ping - Find the package which contains the specified file.
aptitude - package management tool (Debian, Ubuntu, etc.)
aptitude install package_name - install / upgrade package
aptitude update - get updated package lists
aptitude safe-upgrade - upgrade packages installed on your system (the upgrade does NOT change the versions of packages, only fixes security bugs)
aptitude full-upgrade - upgrade packages installed on your system, it is possible to upgrade a package with a version change, if it is available in the repository. Use with caution.
aptitude remove package_name - remove a package installed on your system, keeping its configuration files
aptitude purge package_name - remove a package installed on your system by removing its configuration files
aptitude clean - remove downloaded packages archive files
aptitude autoclean - remove old packaging files
aptitude install -f - check package dependencies on the system and resolve them if needed. If it completes without output, there are no dependency problems.
aptitude search package_name - find a package that has "package_name" in its name
aptitude show package_name - display detailed information about the package
aptitude search ~c - find the list of packages that were removed in the system without removing configuration files (with aptitude remove package_name or dpkg -r)
aptitude search ~b - find damaged packages (with damaged dependencies)
Pacman - package management tool (Arch, Frugalware and alike)
pacman -S name - install package "name" with dependencies
pacman -R name - delete package "name" and all files of it
Browse the contents of the files
cat file1 - display the content of file1 on the standard output device
tac file1 - display the content of file1 on the standard output device in the reverse order (the last line becomes the first one, etc.)
more file1 - paginated output of file1 on the standard output device
less file1 - page output of file1 on the standard output device, but with the possibility of flipping in both directions (up-down), content searching etc.
head -2 file1 - output the first two lines of file1 to the standard output device. The default output format is 10 lines
tail -2 file1 - output the last two lines of file1 to standard output device. By default, ten lines will be printed
tail -f /var/log/messages - to output the /var/log/messages file to the standard output device as text appears.
Manipulations with text
cat file_originale | [operation: sed, grep, awk, grep, etc.] > result.txt - general syntax for performing actions to process the contents of a file and output the result to a new
cat file_originale | [operazione: sed, grep, awk, grep, etc.] >> result.txt - general syntax for processing file contents and outputting results to an existing file. If the file does not exist, it will be created
grep Aug /var/log/messages - from the file '/var/log/messages' select and output to the standard output device the lines containing 'Aug'
grep ^Aug /var/log/messages - From the file '/var/log/messages' select and output to the standard output device the lines that begin with "Aug"
grep [0-9] /var/log/messages - From the file '/var/log/messages' select and output the lines containing digits to the standard output device
grep Aug -R /var/log/* - is to select and display on the standard output device the lines containing "Aug" in all the files in the directory /var/log and below
sed 's/stringa1/stringa2/g' example.txt - change "string1" to "string2" in the file example.txt, output the result to the standard output device.
sed '/^$/d' example.txt - delete empty lines from the file example.txt
sed '/ *#/d; /^$/d' example.txt - delete empty lines and comments from the file example.txt
echo 'esempio' | tr '[:lower:]' '[:upper:]' - convert lower case letters to upper case
sed -e '1d' result.txt - remove the first line from the example.txt file
sed -n '/string1/p' - display only lines containing "string1"
sed -e 's/ *$//' example.txt - remove empty characters at the end of each line
sed -e 's/string1//g' example.txt - remove the line 'string1' from the text without changing the rest
sed -n '1,8p;5q' example.txt - take lines 1 through 8 from the file and print the first five from them
sed -n '5p;5q' example.txt - take the fifth line
sed -e 's/0*/0/g' example.txt - change the sequence of any number of zeros with one zero
cat -n file1 - number the lines when outputting the file contents
cat example.txt | awk 'NR%2==1' - do not output the even numbered lines of the file
echo a b c | awk '{print $1}' - print the first column. Split, by default, by whitespace/spaces or tab character/characters
echo a b c | awk '{print $1,$3}' - print first and third columns. Split, by whitespace/spaces or tab characters by default
paste file1 file2 - merge contents of file1 and file2 into table: row 1 of file1 = row 1 column 1-n, row 1 of file2 = row 1 column n+1-m
paste -d '+' file1 file2 - merge the contents of file1 and file2 as a table separated by '+'
sort file1 file2 - sort the content of the two files
sort file1 file2 | uniq - sort the contents of the two files without showing the duplicates
sort sort file1 file2 | uniq -u - sort the content of the two files, displaying only unique strings (strings, occurring in both files, are not printed to the standard output device)
sort file1 file2 | uniq -d - sort the content of the two files, displaying only duplicated strings
comm -1 file1 file2 - compare the contents of the two files, without displaying the strings belonging to 'file1'
comm -2 file1 file2 - compare the contents of two files, ignoring the lines belonging to 'file2' file
comm -3 file1 file2 - compare the contents of two files, removing strings that belong to both files
Read more: sed and awk Grep
Converting character sets and file formats
dos2unix filedos.txt fileunix.txt - convert text format file from MSDOS to UNIX (difference in carriage return characters)
unix2dos fileunix.txt filedos.txt - convert UNIX to MSDOS text format file (difference in carriage return characters)
recode ..HTML < page.txt >page.html - convert content of test page.txt file to html page.html
recode -l | more - output the list of available formats
Analysis of file systems
badblocks -v /dev/hda1 - check hda1 partition for badblocks
fsck /dev/hda1 - check/restore integrity of hda1 linux filesystem
fsck.ext2 /dev/hda1 or e2fsck /dev/hda1 - check/restore the integrity of the ext2 file system on hda1
e2fsck -j /dev/hda1 - check/restore the integrity of the ext3 file system on hda1 partition, indicating that the journal is located there too
fsck.ext3 /dev/hda1 - check/restore integrity of the ext3 file system on hda1
fsck.vfat /dev/hda1 or fsck.msdos /dev/hda1 or dosfsck /dev/hda1 - check/restore integrity of the fat file system on hda11
Formatting file systems
mkfs /dev/hda1 - create a linux file system on partition hda1
mke2fs /dev/hda1 - create an ext2 file system on partition hda1
mke2fs -j /dev/hda1 - create an ext3 journaling file system on partition hda1
mkfs -t vfat 32 -F /dev/hda1 - create a FAT32 file system on partition hda1
fdformat -n /dev/fd0 - format the floppy disk without checking
mkswap /dev/hda3 - create swap space on partition hda3
swap space
mkswap /dev/hda3 - create swap space on partition hda3
swapon /dev/hda3 - activate swap space on partition hda3
swapon /dev/hda2 /dev/hdb3 - activate swap-spaces located on partitions hda2 and hdb3
Backup creation (backup)
dump -0aj -f /tmp/home0.bak /home - create a full backup copy of /home directory to /tmp/home0.bak file
dump -1aj -f /tmp/home0.bak /home - create an incremental backup of /home directory to the file /tmp/home0.bak
restore -if /tmp/home0.bak - restore from the /tmp/home0.bak backup copy
rsync -rogpav --delete /home /tmp - synchronize /tmp with /home
rsync -rogpav -e ssh --delete /home ip_address:/tmp - synchronize via SSH-tunnel
rsync -az -e ssh --delete ip_addr:/home/public /home/local - synchronize local directory with remote directory via ssh tunnel with compression
rsync -az -e ssh --delete /home/local ip_addr:/home/public - synchronize remote directory with local directory through ssh-tunnel with compression
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' - make "snapshot" of local disk into file on remote computer through ssh-tunnel
tar -Puf backup.tar /home/user - make an incremental backup of the '/home/user' directory into backup.tar file with preserved permissions
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' - copy contents of /tmp/local to a remote computer via ssh-tunnel into /home/share/
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' - copy the contents of /home to a remote computer via an ssh tunnel into /home/backup-home
tar cf - . | (cd /tmp/backup ; tar xf - ) - copying one directory to another with saved permissions and links
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents - find all the files in /home/user1 whose names end with '.txt' and copy them to another directory
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 - search /var/log for all files with names ending with '.log' and create a bzip archive from them
dd if=dev/hda of=dev/fd0 bs=512 count=1 - Create a copy of the MBR (Master Boot Record) from /dev/hda to a floppy disk
dd if=dev/fd0 of=dev/hda bs=512 count=1 - restore MBR from the floppy disk to /dev/hda
Network
ifconfig eth0 - show the configuration of the network interface eth0
ifup eth0 - activate (raise) the eth0 interface
ifdown eth0 - deactivate (lower) eth0 interface
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 - set ip-address and netmask for eth0
ifconfig eth0 promisc - set eth0 interface into promiscuous-mode for sniffing
ifconfig eth0 -promisc - disable promiscuous mode on eth0 interface
dhclient eth0 -make eth0 interface active in dhcp-mode.
route -n
netstat -rn - output local routing table
route add -net 0/0 gw IP_Gateway - set the ip-address of the default gateway
route add -net 192.168.0.0 netmask 255.255.255.0.0 gw 192.168.1.1 - add static route in network 192.168.0.0/16 through the gateway with ip-address 192.168.1.1
route del 0/0 gw IP_gateway - remove the ip address of the default gateway
echo "1" > /proc/sys/net/ipv4/ip_forward allows forwarding
hostname - show host name
host http://www.linuxguide.it or host 62.149.140.85 - allow hostname http://www.linuxguide.it in ip-address and vice versa
ip link show - show state of all interfaces
mii-tool eth0 - shows the status and connection type for the eth0 interface
ethtool eth0- shows the statistics of the eth0 interface with information like the supported and current connection modes
netstat -tupn - displays all established TCP and UDP network connections, without resolving names into IP-addresses and PIDs, and the names of the processes making the connections
netstat -tupln - displays all network connections through TCP and UDP protocols without allowing names to be resolved to the ip-addresses and PIDs, and the names of the processes listening to the ports
tcpdump tcp port 80 - displays all traffic on TCP port 80 (usually HTTP)
iwlist scan - scan the airwaves for wireless access points
iwconfig eth1 - show the configuration of the wireless network interface eth1
Microsoft Windows networks(SAMBA)
nbtscan ip_addr
nmblookup -A ip_addr - allow netbios name nbtscan is not default on all systems, you might have to install it manually. nmblookup is included in the samba package.
smbclient -L ip_addr/hostname - display the resources shared on the windows machine
smbget -Rr smb://ip_addr/share - like wget can get files from the windows machines through the smb protocol
mount -t smbfs -o username=user,password=pass //winclient/share /mnt/share - mount the smb resource provided on the windows machine to the local file system
IPTABLES (firewall)
iptables -t filter -nL
iptables -nL - show all rule chains
iptables -t nat -L - show all rule chains in the NAT table
iptables -t filter -F or iptables -F - clear all rule chains in filter-table
iptables -t nat -F - clear all rule chains in the NAT table
iptables -t filter -X - delete all user-defined rule chains in the filter-table
iptables -t filter -A INPUT -p tcp --dport telnet -j ACCEPT - allow incoming telnet connections
iptables -t filter -A OUTPUT -p tcp --dport http -j DROP - block outgoing HTTP connections
iptables -t filter -A FORWARD -p tcp --dport pop3 -j ACCEPT - allow forward POP3 connections
iptables -t filter -A INPUT -j LOG --log-prefix "DROP INPUT" - let the kernel log the packets which go through the INPUT chain and add "DROP INPUT" prefix to the message
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE - enable NAT (Network Address Translate) of outgoing packets to eth0 interface. Acceptable when used with dynamically allocated ip addresses.
iptables -t nat -A PREROUTING -d 192.168.0.1 -p tcp -m tcp --dport 22 -j DNAT --to-destination 10.0.0.2:22 - redirect packets addressed to one host to another host
Monitoring and debugging
top - display running processes, the resources they use and other useful information (with automatic data update)
ps -eafw - show running processes, the resources they use and other useful information (one time)
ps -e -o pid,args --forest - display PIDs and processes in tree view
pstree - show process tree
kill -9 98989 or kill -KILL 98989 - "kill" the process with PID 98989 "to death" (without integrity of data)
kill -TERM 98989 - to correctly terminate the process with PID 98989
kill -1 98989 or kill -HUP 98989 - to force the process with PID 98989 to reread the configuration file
lsof -p 98989 - to list the files opened by the process with PID 98989
lsof /home/user1 - displays the list of open files in /home/user1
strace -c ls >/dev/null - displays the list of system calls created and received by the ls process
strace -f -e open ls >/dev/null - display calls of the libraries
watch -n1 'cat /proc/interrupts' - display interruptions in real time
last reboot - display the history of reboots of the system
last user1 - display the logging history of user user1 in the system and the time he logged in
lsmod - show loaded kernel modules
free -m - show the state of RAM in megabytes
smartctl -A /dev/hda - check the status of the /dev/hda hard disk through SMART
smartctl -i /dev/hda - check SMART availability on /dev/hda hard disk
tail /var/log/dmesg - print the ten latest kernel boot log entries
tail /var/log/messages - print the last ten entries of the system log
Other useful commands
apropos ...keyword - displays a list of commands that somehow relate to keywords. Useful when you know what the program does, but can't remember the command
man ping - calls the manual of the program, in this case - ping
whatis ...keyword - displays the description of the actions of the specified program
mkbootdisk --device /dev/fd0 `uname -r` - creates a bootable floppy disk
gpg -c file1 - encrypts file1 with GNU Privacy Guard
gpg file1.gpg - decrypts file1 with GNU Privacy Guard
wget -r http://www.example.com - Recursively downloads the contents of http://www.example.com
wget -c http://www.example.com/file.iso - Download the file http://www.example.com/file.iso with an option to stop and continue afterwards
echo 'wget -c http://www.example.com/files.iso' | at 09:00 - start download at the specified time
ldd /usr/bin/ssh - print list of libraries needed for ssh
alias hh='history' - set alias hh to the history command
whereis ping - print the full path to the executable file of the program and its help.</page.txt>