Linux commands Tips: Ctrl + F quickly find Linux commands (point title can shrink, expand)
Command Code | Notes |
---|---|
arch | Display the processor architecture of the machine (1) |
uname -m | Displays the processor architecture of the machine (2) |
uname -r | Display the kernel version in use |
dmidecode -q | Show hardware system components - (SMBIOS / DMI) |
hdparm -i /dev/hda | List the architectural characteristics of a disk |
hdparm -tT /dev/sda | Performs a test read operation on a disk |
cat /proc/cpuinfo | Display information about CPU info |
cat /proc/interrupts | Display interrupts |
cat /proc/meminfo | Verify memory usage |
cat /proc/swaps | Shows which swaps are being used |
cat /proc/version | Show kernel version |
cat /proc/net/dev | Show network adapters and statistics |
cat /proc/mounts | Show loaded filesystems |
lspci -tv | List PCI devices |
lsusb -tv | Show USB devices |
date | Show system date |
cal 2007 | Show Calendar 2007 |
date 041217002007.00 | Setting the Date and Time - Month Day Hour Minute Year. Seconds |
clock -w | Save time changes to BIOS |
Command Code | Explanation |
---|---|
shutdown -h now | Shut down the system |
init 0 | Shuts down the system |
telinit 0 | Shuts down the system |
shutdown -h hours:minutes & | Shuts down the system at the scheduled time |
shutdown -c | Cancelling the scheduled shutdown of the system |
shutdown -r now | Reboot |
reboot | Reboot |
logout | Logout |
Command Code | Explanation |
---|---|
cd /home | Go to '/ home' directory' |
cd .. | Return to the previous directory |
cd ../.. | Returns to the last two directories |
cd | Enter your home directory |
cd ~user1 | Go to your home directory |
cd - | Return to the last directory |
pwd | Show working path |
ls | Viewing files in a directory |
ls -F | Viewing files in a directory |
ls -l | Show file and directory details |
ls -a | Show hidden files |
ls *[0-9]* | Display file and directory names containing numbers |
tree | Displaying the tree structure of files and directories starting from the root directory |
lstree | Displaying the tree structure of files and directories starting from the root directory |
mkdir dir1 | Creates a directory called 'dir1'. |
mkdir dir1 dir2 | Creates two directories at the same time |
mkdir -p /tmp/dir1/dir2 | Create a directory tree |
rm -f file1 | Delete a file called 'file1'' |
rmdir dir1 | delete a directory called 'dir1'' |
rm -rf dir1 | Delete a directory called 'dir1' and its contents at the same time |
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 in a directory to the current working directory. |
cp -a /tmp/dir1 . | Copy a directory to the current working directory |
cp -a dir1 dir2 | Copying a directory |
ln -s file1 lnk1 | Create a soft link to a file or directory |
ln file1 lnk1 | Create a physical 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 the encoding of a character |
find . -maxdepth 1 -name *.jpg -print -exec convert | Batch resize files in the current directory and send them to a thumbnail directory (requires conversion from ImageMagick) |
Command Code | Note Explanation |
---|---|
find / -name file1 | Search files and directories in the root file system starting from '/'. |
find / -user user1 | Search files and directories belonging to user 'user1' |
find /home/user1 -name \*.bin | Search for files ending with '.bin' in the directory '/ home/user1'. |
find /usr/bin -type f -atime +100 | Search for executable files that have not been used in the last 100 days |
find /usr/bin -type f -mtime -10 | Search for files created or modified within 10 days |
find / -name \*.rpm -exec chmod 755 '{}' \; | Search for files ending in '.rpm' and define their permissions |
find / -xdev -name \*.rpm | Search for files ending in '.rpm', ignoring removable devices such as CD-ROMs, JDs, etc. |
locate \*.ps | Search for files ending in '.ps' - run 'updatedb' first |
whereis halt | Show location of a binary file, source code or man |
which halt | Show the full path to a binary or executable file. |
Command Code | Explanation |
---|---|
mount /dev/hda2 /mnt/hda2 | Mount a disk called hda2 - make sure the directory '/ mnt/hda2' already exists |
umount /dev/hda2 | Unmount a disc called hda2 - exit from mount point '/ mnt/hda2' first |
fuser -km /mnt/hda2 | Force uninstallation when device is busy |
umount -n /mnt/hda2 | Run the uninstall operation without writing to the /etc/mtab file - useful when the file is read-only or when the disc is written over |
mount /dev/fd0 /mnt/floppy | Mount a floppy disc |
mount /dev/cdrom /mnt/cdrom | mount a cdrom or dvdrom |
mount /dev/hdc /mnt/cdrecorder | Mount a cdrw or dvdrom |
mount /dev/hdb /mnt/cdrecorder | Mount a cdrw or dvdrom |
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 flash memory device |
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share | Mount a windows network share |
Command Code | Explanation |
---|---|
df -h | Show the list of mounted partitions |
ls -lSr |more | Sort files and directories by size |
du -sh dir1 | Estimates the amount of space already used by the directory 'dir1'. |
du -sk * | sort -rn | Display files and directories by size. |
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n | Show space used by installed rpm packages in order of size (fedora, redhat-like systems) |
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n | Shows the space used by installed deb packages in order of size (ubuntu, debian-like systems). |
Command Code | Comments |
---|---|
groupadd group_name | Creates a new user group |
groupdel group_name | Delete a usergroup |
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 | Creates a user belonging to the "admin" user group. |
useradd user1 | Create a new user |
userdel -r user1 | Delete a user ('-r' excludes home directories) |
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 | Modify user attributes |
passwd | Modify password |
passwd user1 | Modify a user's password (root only). |
chage -E 2020-12-31 user1 | Set the expiration date of a user's passphrase |
pwck | Check '/etc/passwd' for file format and syntax corrections, and existing users |
grpck | Check '/etc/passwd' for file formatting and syntax corrections and existing groups |
newgrp group_name | Log in to a new group to change the default group of the newly created file. |
Command Code | Explanation of comments |
---|---|
ls -lh | Display permissions |
ls /tmp | pr -T5 -W$COLUMNS | Divide the terminal into 5 columns for display |
chmod ugo+rwx directory1 | Sets read (r), write (w) and execute (x) permissions for the owner (u), group (g) and others (o) of a directory. |
chmod go-rwx directory1 | Remove read, write, and execute permissions for groups (g) and others (o) on a directory. |
chown user1 file1 | Change the owner attribute of a file |
chown -R user1 directory1 | Change the owner attributes of a directory and change the attributes of all files in the directory. |
chgrp group1 file1 | Changing the group of a file |
chown user1:group1 file1 | Change the owner and group attributes of a file |
find / -perm -u+s | List all files on a system that are SUID controlled. |
chmod u+s /bin/file1 | Set the SUID bit of a binary file - the user running the file is given the same privileges as the owner |
chmod u-s /bin/file1 | Disable the SUID bit for a binary file |
chmod g+s /home/public | Set the SGID bit for a directory - similar to SUID, but directory-specific |
chmod g-s /home/public | Disable the SGID bit for a directory |
chmod o+t /home/public | Set the STIKY bit for a file - allows only legal owners to delete the file |
chmod o-t /home/public | Disable the STIKY bit for a directory |
Command Code | Explanation of comments |
---|---|
chattr +a file1 | Allow reading and writing to files only in append mode |
chattr +c file1 | Allows the file to be automatically compressed/decompressed by the kernel. |
chattr +d file1 | This file will be ignored by the dump program when making file system backups. |
chattr +i file1 | Set the file as immutable and cannot be deleted, modified, renamed or linked. |
chattr +s file1 | Allow a file to be securely deleted |
chattr +S file1 | As soon as an application performs a write operation on the file, cause the system to immediately write the result of the modification to disk. |
chattr +u file1 | If a file is deleted, the system will allow you to recover the deleted file at a later time. |
lsattr | Displaying Special Attributes |
Command Code | Explanation |
---|---|
bunzip2 file1.bz2 | Unpacks a file called 'file1.bz2'. |
bzip2 file1 | Compress a file called 'file1 |
gunzip file1.gz | Decompresses a file called 'file1.gz'. |
gzip file1 | Compresses a file called 'file1'. |
gzip -9 file1 | Maximum compression |
rar a file1.rar test_file | Creates a package called 'file1.rar'. |
rar a file1.rar file1 file2 dir1 | Compress 'file1', 'file2' and the directory 'dir1' at the same time |
rar x file1.rar | Decompress the rar package |
unrar x file1.rar | Decompressing a rar package |
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 | Display the contents of a package |
tar -xvf archive.tar | Releasing a package |
tar -xvf archive.tar -C /tmp | Releases a tarball into the /tmp directory. |
tar -cvfj archive.tar.bz2 dir1 | Creates a bzip2 archive. |
tar -jxvf archive.tar.bz2 | Decompress a bzip2 archive |
tar -cvfz archive.tar.gz dir1 | Creates a gzip archive |
tar -zxvf archive.tar.gz | Decompress a gzip archive. |
zip file1.zip file1 | Create a zip archive |
zip -r file1.zip file1 file2 dir1 | Compresses several files and directories into a single zip archive. |
unzip file1.zip | Decompress a zip archive |
Command Code | Explanation |
---|---|
rpm -ivh package.rpm | Installing an rpm package |
rpm -ivh --nodeeps package.rpm | Installs an rpm package and ignores dependency warnings. |
rpm -U package.rpm | Update an rpm package without changing its configuration file. |
rpm -F package.rpm | Update an rpm package that is sure to be installed |
rpm -e package_name.rpm | Remove an rpm package |
rpm -qa | Show all installed rpm packages on the system |
rpm -qa | grep httpd | Show all rpm packages with the word "httpd" in their name. |
rpm -qi package_name | Get special information about an installed package |
rpm -qg "System Environment/Daemons" | Show rpm packages for a component |
rpm -ql package_name | Show the list of files provided by an installed rpm package |
rpm -qc package_name | Display a list of configuration files provided by an installed rpm package. |
rpm -q package_name --whatrequires | Display a list of dependencies on an rpm package. |
rpm -q package_name --whatprovides | Shows the size of an rpm package |
rpm -q package_name --scripts | Show 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 | Confirms which rpm package provided the given file. |
rpm -qp package.rpm -l | Display a list of files provided by an uninstalled rpm package. |
rpm --import /media/cdrom/RPM-GPG-KEY | Import public key digital certificates |
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 | Checks file size, licence, type, owner, group, MD5 check and last modification time. |
rpm -Va | Check all installed rpm packages on the system - use with care! |
rpm -Vp package.rpm | Verify that an rpm package is not installed |
rpm2cpio package.rpm | cpio --extract --make-directories *bin* | Run an executable from an rpm package |
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm | Installing a built package from an rpm source code |
rpmbuild --rebuild package_name.src.rpm | Building an rpm package from an rpm source code |
Command Code | Notes |
---|---|
yum install package_name | Download and install an rpm package |
yum localinstall package_name.rpm | Will install an rpm package, using your own repository to resolve all dependencies for you |
yum update package_name.rpm | Updates all installed rpm packages on the current system. |
yum update package_name | Update an rpm package |
yum remove package_name | Remove an rpm package |
yum list | List all packages installed on the system |
yum search package_name | Search for packages in the rpm repository |
yum clean packages | Clear rpm cache to remove downloaded packages |
yum clean headers | Remove all header files |
yum clean all | Remove all cached packages and headers |
Command Code | Notes |
---|---|
dpkg -i package.deb | Installs/updates a deb package |
dpkg -r package_name | Remove a deb package from the system |
dpkg -l | Show all installed deb packages on the system |
dpkg -l | grep httpd | Displays all deb packages whose names contain the word "httpd". |
dpkg -s package_name | Get information about a particular package already installed on the system |
dpkg -L package_name | Show the list of files provided by a deb package that is already installed on the system. |
dpkg --contents package.deb | Show the list of files provided by a package that has not yet been installed. |
dpkg -S /bin/ping | Confirms which deb package provides the given file. |
Command Code | Explanation of comments |
---|---|
apt-get install package_name | Install/update a deb package |
apt-cdrom install package_name | Install/update a deb package from a disc |
apt-get update | Upgrade packages in the list |
apt-get upgrade | Upgrade all installed software |
apt-get remove package_name | Remove a deb package from the system |
apt-get check | Confirm the correct repositories for dependencies |
apt-get clean | Clear cache from downloaded packages |
apt-cache search searched-package | Return the package name that contains the search string you want |
Command Code | Explanation |
---|---|
cat file1 | View the contents of a file in the forward direction starting from the first byte. |
tac file1 | View the contents of a file in reverse from the last line. |
more file1 | View the contents of a long file |
less file1 | Similar to the 'more' command, but it allows the same reverse operation as the forward operation in a file. |
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 the contents of a file as it is added in real time. |
Command Code | Annotate Description |
---|---|
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt | Merge the detailed description text of a file and write the description to a new file |
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt | Merges the text of a file's description and writes the description to an existing file. |
grep Aug /var/log/messages | Find the keyword "Aug" in the file '/var/log/messages'. |
grep ^Aug /var/log/messages | Look for words starting with "Aug" in the file '/var/log/messages'. |
grep [0-9] /var/log/messages | Select all lines in the file '/var/log/messages' that contain numbers |
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 example.txt file. |
sed '/^$/d' example.txt | Delete all blank lines from example.txt file |
sed '/ *#/d; /^$/d' example.txt Remove all comments and blank lines from example.txt | Remove all comments and blank lines from example.txt |
echo 'esempio' | tr '[:lower:]' '[:upper:]' | Merge top and bottom cells |
sed -e '1d' result.txt | Exclude the first line from the example.txt file |
sed -n '/stringa1/p' | View lines containing only the word "string1". |
sed -e 's/ *$//' example.txt | Remove blank characters at the end of each line |
sed -e 's/stringa1//g' example.txt | Remove only the word "string1" from the document and keep all the rest. |
sed -n '1,5p;5q' example.txt | View the content from line 1 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 | Mark the number of lines in the file |
cat example.txt | awk 'NR%2==1' | Delete all even lines in example.txt file |
echo a b c | awk '{print $1}' | View the first column of a row |
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 a "+". |
sort file1 file2 | Sort the contents of two files |
sort file1 file2 | uniq | Take out the union of the two files (keep only one copy of the duplicate rows). |
sort file1 file2 | uniq -u | Delete the intersection, leaving the other lines |
sort file1 file2 | uniq -d | Remove the intersection of the two files (leaving only the files that exist in both files). |
comm -1 file1 file2 | Compare the contents of two files removing only the contents of 'file1'. |
comm -2 file1 file2 | Compare the contents of two files and delete only the contents of 'file2'. |
comm -3 file1 file2 | Comparing two files removes only the parts that are common to both files. |
Command Code | Explanation |
---|---|
dos2unix filedos.txt fileunix.txt | Converts the format of a text file from MSDOS to UNIX. |
unix2dos fileunix.txt filedos.txt | Converts a text file from UNIX to MSDOS. |
recode ..HTML page.html | Convert a text file to html |
recode -l | more | Show all allowed conversion formats |
Command Code | Explanation of comments |
---|---|
badblocks -v /dev/hda1 | Check for bad blocks on disk hda1 |
fsck /dev/hda1 | Repair/check integrity of linux filesystem on disk hda1 |
fsck.ext2 /dev/hda1 | Repair/check integrity of ext2 file system on disk hda1 |
e2fsck /dev/hda1 | Repair/check integrity of ext2 file system on disk hda1 |
e2fsck -j /dev/hda1 | Repair/check the integrity of the ext3 file system on disk hda1 |
fsck.ext3 /dev/hda1 | Repair/check integrity of ext3 file system on hda1 disc |
fsck.vfat /dev/hda1 | Repair/check integrity of fat file system on hda1 disc |
fsck.msdos /dev/hda1 | Repair/check integrity of dos file system on hda1 disc |
dosfsck /dev/hda1 | Repair/check the integrity of the dos filesystem on disk hda1 |
Command Code | Notes |
---|---|
mkfs /dev/hda1 | Create a file system on hda1 partition |
mke2fs /dev/hda1 | Create a linux ext2 filesystem on hda1 partition |
mke2fs -j /dev/hda1 | Creates a linux ext3 (journaling) file system on partition hda1. |
mkfs -t vfat 32 -F /dev/hda1 | Create a FAT32 file system |
fdformat -n /dev/fd0 | Format a floppy disc |
mkswap /dev/hda3 | Creating a swap filesystem |
Command Code | Explanation |
---|---|
mkswap /dev/hda3 | Create a swap file system |
swapon /dev/hda3 | Enables a new swap file system |
swapon /dev/hda2 /dev/hdb3 | Enable two swap partitions |
Command Code | Notes |
---|---|
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 | Synchronise the two directories |
rsync -rogpav -e ssh --delete /home ip_address:/tmp | rsync over SSH channel |
rsync -az -e ssh --delete ip_addr:/home/public /home/local | Sync a remote directory to a local directory via ssh and compression |
rsync -az -e ssh --delete /home/local ip_addr:/home/public | Sync a local directory to a remote directory via ssh and compression |
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' | Perform a backup of a local disc on a remote host via ssh |
dd if=/dev/sda of=/tmp/file1 | Backing up the contents of a disc 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' | Copying the contents of a directory 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 - ) | Locally copy a directory to another location, preserving permissions and links |
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents | Find and copy all files ending in '.txt' from one directory to another directory |
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 | Find all files ending in '.log' and make a bzip package of them |
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 | Do a copy of the MBR (Master Boot Record) contents to a floppy disc |
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 | Restore the MBR contents from a backup that has been saved to a floppy. |
Command Code | Explanation |
---|---|
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force | Empties the contents of a rewritable disc |
mkisofs /dev/cdrom > cd.iso | Creates an iso image of the disc on the disk. |
mkisofs /dev/cdrom | gzip > cd_iso.gz | Creates a compressed iso image of a disc on a disk. |
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd | Creates 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 | Extract audio tracks from a CD disc to a wav file |
cd-paranoia -- "-3" | Extract tracks from a CD disc to a wav file (parameter -3) |
cdrecord --scanbus | Scan the bus to identify scsi channels |
dd if=/dev/hdc | md5sum | Verify the md5sum encoding of a device, e.g. a CD |
Command code | Note Explanation |
---|---|
dhclient eth0 | Enable 'eth0' network device in dhcp mode |
ethtool eth0 | Show traffic statistics for network card 'eth0' |
host www.example.com | Find hostnames to resolve names with IP addresses and mirrors |
hostname | Display hostnames |
ifconfig eth0 | Display the configuration of an Ethernet card |
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 | Controlling IP Addresses |
ifconfig eth0 promisc | Set 'eth0' to promiscuous mode for packet sniffing |
ifdown eth0 | Disable an 'eth0' network device |
ifup eth0 | Enable an 'eth0' network device |
ip link show | Display the connection status of all network devices |
iwconfig eth1 | Display the configuration of a wireless 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 on the system and their PIDs. |
netstat -rn | Display the routing table, similar to the "route -n" command. |
nslookup www.example.com | Finds hostnames to resolve names and IP addresses and mirrors them. |
route -n | Display the routing table |
route add -net 0/0 gw IP Gateway | Controlling Predefined Gateways |
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 | Control static routes to network '192.168.0.0/16'. |
route del 0/0 gw IP gateway | Delete static routes |
echo “1”> /proc/sys/net/ipv4/ip_foward | Activate IP Forwarding |
tcpdump tcp port 80 | Show all HTTP loops |
whois www.example.com | Lookup in Whois database |
Command Code | Note Explanation |
---|---|
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 | Show remote share of a windows host |
smbget -Rr smb://ip addr/share | Download files from a windows host via smb like wget. |
Command Code | Explanation |
---|---|
iptables -t filter -L | Displays all links in the filter table |
iptables -t nae -L | Displays all links in the nat table |
iptables -t filter -F | Clean up all rules based on the filter table |
iptables -t nat -F | Clears all rules based on the nat table |
iptables -t filter -X | Delete all links created by the user |
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 forwarding of POP3 connections on links |
iptables -t filter -A INPUT -j LOG --log-prefix | Log all packets blocked on the link |
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | Set up a PAT (Port Address Translation) to mask outgoing packets at eth0 |
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 | Divert packets destined for one host address to other hosts |
Command Code | Notes |
---|---|
free -m | List RAM status in megabytes |
kill -9 process id | Force a process to shut down and end it |
kill -1 process id | Force a process to reload its configuration |
last reboot | Show reboot history |
lsmod | List the status of kernel modules |
lsof -p process id | List a list of files opened by a process |
lsof /home/user1 | List opened files in the given system paths |
ps -eafw | List linux tasks |
ps -e -o pid,args --forest | List linux tasks in a hierarchical way. |
pstress | Display processes in a tree view |
smartctl -A /dev/hda | Monitor the reliability of a hard disc device by enabling SMART. |
smartctl -i /dev/hda | Checks whether SMART is enabled for a hard disc 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 | Display internal events during kernel boot |
tail /val/log/messages | Show system events |
top | List the linux tasks that use the most CPU resources |
watch -nl ‘cat /proc/interrupts’ | List real-time interrupts |
Command Code | Notes |
---|---|
alias hh='history' | Set an alias for the command history. |
apropos ...keyword | Make a list of commands with program keywords, especially useful if you only know what the program does and don't remember the commands |
chsh | Changing shell commands |
chsh --list-shells | A nice command for finding out if you have to 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. |