Linux common command list,
Tips: Ctrl+F to quickly find Linux commands (click the title to
collapse and expand)
Command code | Comment description |
---|---|
arch | Display the machine's processor architecture (1) |
uname -m | Display the machine's processor architecture (2) |
uname -r | Display the kernel version in use |
dmidecode -q | Display hardware system components - (SMBIOS / DMI) |
hdparm -i /dev/hda | List the architectural features of a disk |
hdparm -tT /dev/sda | Perform a test read operation on the disk |
cat /proc/cpuinfo | Display CPU info information |
cat /proc/interrupts | Display interrupts |
cat /proc/meminfo | Check memory usage |
cat /proc/swaps | Display which swap is used |
cat /proc/version | Display the kernel version |
cat /proc/net/dev | Display network adapters and statistics |
cat /proc/mounts | Display loaded file systems |
lspci -tv | List PCI devices |
lsusb -tv | Display USB devices |
date | Display system date |
cal 2007 | Display the calendar for 2007 |
date 041217002007.00 | Set date and time - month, day, hour, minute, year, second |
clock -w | Save time changes to BIOS |
Command code | Comment |
---|---|
shutdown -h now | Shut down the system |
init 0 | Shut down the system |
telinit 0 | Shut down the system |
shutdown -h hours:minutes & | Schedule shutdown |
shutdown -c | Cancel scheduled shutdown |
shutdown -r now | Reboot |
reboot | Reboot |
logout | Logout |
Command code | Comment |
---|---|
cd /home | Go to '/ home' directory |
cd .. | Go back one level to the previous directory |
cd ../.. | Go back two levels to the previous directory |
cd | Go to one's home directory |
cd ~user1 | Go to one's home directory |
cd - | Go back to the last directory you were in |
pwd | Show working directory |
ls | View files in a directory |
ls -F | View files in a directory |
ls -l | Show detailed information about files and directories |
ls -a | Show hidden files |
ls *[0-9]* | Show file names and directory names that contain numbers |
tree | Show a tree of files and directories starting from the root directory |
lstree | Show a tree of files and directories starting from the root directory |
mkdir dir1 | Create a directory called '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 called 'file1' |
rmdir dir1 | Delete a directory called 'dir1' |
rm -rf dir1 | Delete a directory called 'dir1' and delete its contents at the same time |
rm -rf dir1 dir2 | Delete two directories and their contents at the same time |
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 | Copy 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 (needs conversion from ImageMagick) |
Command Code | Comment Description |
---|---|
find / -name file1 | Search for files and directories in the root file system starting at '/' |
find / -user user1 | Search for files and directories belonging to user 'user1' |
find /home/user1 -name \*.bin | Search for files ending with '.bin' in directory '/ home/user1' |
find /usr/bin -type f -atime +100 | Search for executable files that have not been used in the past 100 days |
find /usr/bin -type f -mtime -10 | Search for files created or modified in the past 10 days |
find / -name \*.rpm -exec chmod 755 '{}' \; | Search for files ending with '.rpm' and define their permissions |
find / -xdev -name \*.rpm | Search for files ending with '.rpm', ignoring removable devices such as CD-ROMs and Jiepian |
locate \*.ps | Find files ending with '.ps' - run 'updatedb' first Commands |
whereis halt | Show the location of a binary, source or man |
which halt | Show the full path to a binary or executable |
Command code | Comments |
---|---|
mount /dev/hda2 /mnt/hda2 | Mount a disk called hda2 - make sure the directory '/ mnt/hda2' already exists |
umount /dev/hda2 | Unmount a disk called hda2 - exit from mount point '/ mnt/hda2' first |
fuser -km /mnt/hda2 | Force unmount when device is busy |
umount -n /mnt/hda2 | 运行卸载操作而不写入 /etc/mtab 文件- 当文件为只读或当磁盘写满时非常有用 |
mount /dev/fd0 /mnt/floppy | Mount a floppy disk |
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 file |
mount -t vfat /dev/hda5 /mnt/hda5 | Mount a Windows FAT32 file system |
mount /dev/sda1 /mnt/usbdisk | Mount a usb shortcut or flash device |
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share | Mount a windows network share |
Command code | Comments |
---|---|
df -h | Show a list of mounted partitions |
ls -lSr |more | Sort files and directories by size |
du -sh dir1 | Estimate directory 'dir1' Used disk space' |
du -sk * | sort -rn | Show the size of files and directories in order of capacity |
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n | 以大小为依据依次显示已安装的rpm包所使用的空间 (fedora, redhat类系统) |
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n | 以大小为依据显示已安装的deb包所使用的空间 (ubuntu, debian类系统) |
Command code | Comment |
---|---|
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 group belonging to the "admin" user grouphousehold |
useradd user1 | Create a new user |
userdel -r user1 | Remove a user ('-r' excludes home directory) |
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 | Modify user attributes |
passwd | Change password |
passwd user1 | Modify a user's password (only allowed to be executed by root) |
chage -E 2020-12-31 user1 | Set user password expiration date |
pwck | Check '/etc/passwd' for file format and syntax fixes and existing users |
grpck | Check '/etc/passwd' for file format and syntax fixes and existing groups |
newgrp group_name | Log into a new group to change the default group for newly created files |
command code | Notes |
---|---|
ls -lh | Show permissions |
ls /tmp | pr -T5 -W$COLUMNS | Divide the terminal into 5 columns for display |
chmod ugo+rwx directory1 | 设置目录的所有人(u)、群组(g)以及其他人(o)以读(r )、写(w)和执行(x)的权限 |
chmod go-rwx directory1 | Remove the read, write, and execute permissions of the group (g) and others (o) on the directory |
chown user1 file1 | Change the owner attribute of a file |
chown -R user1 directory1 | Change the owner attributes of a directory and simultaneously change the attributes of all files in the directory |
chgrp group1 file1 | Change 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 controlled by SUID in a system |
chmod u+s /bin/file1 | 设置一个二进制文件的 SUID 位 - 运行该文件的用户也被赋予和所有者同样的权限 |
chmod u-s /bin/file1 | Disable the SUID bit of a binary file |
chmod g+s /home/public | Sets the SGID bit of a directory - similar to SUID, but for directories |
chmod g-s /home/public | Disable the SGID bit for a directory |
chmod o+t /home/public | Set the STIKY bit on a file - only allows the legitimate owner to delete the file |
chmod o-t /home/public | Disable the STIKY bit for a directory |
command code | Notes |
---|---|
chattr +a file1 | Only allowed to read and write files in append mode |
chattr +c file1 | Allow this file to be automatically compressed/decompressed by the kernel |
chattr +d file1 | The dump program will ignore this file when doing a file system backup |
chattr +i file1 | Files set to be immutable cannot be deleted, modified, renamed or linked to |
chattr +s file1 | Allow a file to be safely deleted |
chattr +S file1 | Once the application performs a write operation on this file, the system immediately writes the modified results to the disk. |
chattr +u file1 | If a file is deleted, the system will allow you to recover the deleted file later |
lsattr | Show special properties |
command code | Notes |
---|---|
bunzip2 file1.bz2 | Unzip a file called 'file1.bz2' |
bzip2 file1 | Compress a file called 'file1' |
gunzip file1.gz | Unzip a file called 'file1.gz' |
gzip file1 | Compress a file called 'file1' |
gzip -9 file1 | maximum compression |
rar a file1.rar test_file | Create a package called 'file1.rar' |
rar a file1.rar file1 file2 dir1 | Compress 'file1', 'file2' and directory 'dir1' simultaneously |
rar x file1.rar | Unzip rar package |
unrar x file1.rar | Unzip rar package |
tar -cvf archive.tar file1 | Create an uncompressed tarball |
tar -cvf archive.tar file1 file2 dir1 | Create an archive file containing 'file1', 'file2' and 'dir1' |
tar -tf archive.tar | Display the contents of a package |
tar -xvf archive.tar | release a package |
tar -xvf archive.tar -C /tmp | Release the compressed package to the /tmp directory |
tar -cvfj archive.tar.bz2 dir1 | Create a compressed package in bzip2 format |
tar -jxvf archive.tar.bz2 | Decompress a compressed package in bzip2 format |
tar -cvfz archive.tar.gz dir1 | Create a compressed package in gzip format |
tar -zxvf archive.tar.gz | Decompress a compressed package in gzip format |
zip file1.zip file1 | Create a compressed package in zip format |
zip -r file1.zip file1 file2 dir1 | Compress several files and directories into a compressed package in zip format at the same time |
unzip file1.zip | Unzip a zip format compressed package |
command code | Notes |
---|---|
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 file |
rpm -F package.rpm | Update an rpm package that is already installed |
rpm -e package_name.rpm | Delete an rpm package |
rpm -qa | Display all installed rpm packages in the system |
rpm -qa | grep httpd | Display all rpm packages containing "httpd" in their name |
rpm -qi package_name | Get special information about an installed package |
rpm -qg "System Environment/Daemons" | Display the rpm package of a component |
rpm -ql package_name | Display a 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 | Display the volume occupied by an rpm package |
rpm -q package_name --scripts | Show scripts executed during installation/removal |
rpm -q package_name --changelog | Display the modification history of an rpm package |
rpm -qf /etc/httpd/conf/httpd.conf | Confirm which rpm package the given file is provided by |
rpm -qp package.rpm -l | Display a list of files provided by an rpm package that has not yet been installed |
rpm --import /media/cdrom/RPM-GPG-KEY | Import public key digital certificate |
rpm --checksig package.rpm | Confirm the integrity of an rpm package |
rpm -qa gpg-pubkey | Confirm the integrity of all installed rpm packages |
rpm -V package_name | 检查文件尺寸、 许可、类型、所有者、群组、MD5检查以及最后修改时间 |
rpm -Va | Check all installed rpm packages on the system - use with caution |
rpm -Vp package.rpm | Confirm that an rpm package has not been installed yet |
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 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 software repository to resolve all dependencies for you |
yum update package_name.rpm | Update all rpm packages installed in the current system |
yum update package_name | Update an rpm packageDelete an rpm package |
yum remove package_name | List all packages installed on the current system |
yum list | Search for packages in the rpm repository |
yum search package_name | Clean rpm cache and delete downloaded packages |
yum clean packages | Remove all header files |
yum clean headers | Remove all cached packages and header files |
yum clean all | Linux commands - DEB packages (Debian, Ubuntu and similar systems) |
Notes | Install/update a deb package |
---|---|
dpkg -i package.deb | Remove a deb package from the system |
dpkg -r package_name | Display all installed deb packages in the system |
dpkg -l | Display all deb packages containing "httpd" in their name |
dpkg -l | grep httpd | Get information about a particular package that has been installed on the system |
dpkg -s package_name | Display the file list provided by a deb package that has been installed on the system |
dpkg -L package_name | Displays a list of files provided by a package that is not yet installed |
dpkg --contents package.deb | Confirm which deb package the given file is provided by |
dpkg -S /bin/ping | Linux Commands — APT Software Tools (Debian, Ubuntu and similar systems) |
Notes | Install/update a deb package |
---|---|
apt-get install package_name | Install/update a deb package from CD |
apt-cdrom install package_name | Upgrade packages in list |
apt-get update | Upgrade all installed software |
apt-get upgrade | Delete a deb package from the system |
apt-get remove package_name | Confirm that the dependent software repository is correct |
apt-get check | Clean cache from downloaded packages |
apt-get clean | Returns the package name containing the search string |
apt-cache search searched-package | Linux command — view file contents |
Notes | View the contents of the file forward starting from the first byte |
---|---|
cat file1 | View the contents of a file in reverse order starting from the last line |
tac file1 | View the contents of a long file |
more file1 | Similar to the 'more' command, but it allows reverse operations on files as well as forward operations |
less file1 | 类似于 'more' 命令,但是它允许在文件中和正向操作一样的反向操作 |
head -2 file1 | View the last two lines of a file |
tail -2 file1 | View content being added to a file in real time |
tail -f /var/log/messages | Linux Commands — Text Processing |
Notes | Merge the detailed description text of one file and write the introduction to a new file |
---|---|
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt | Merge the detailed description text of a file and write the introduction to an existing file |
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt | Search for the keyword "Aug" in the file '/var/log/messages' |
grep Aug /var/log/messages | Search the file '/var/log/messages' for words starting with "Aug" |
grep ^Aug /var/log/messages | Select all lines containing numbers in the '/var/log/messages' file |
grep [0-9] /var/log/messages | Search the directory '/var/log' and subsequent directories for the string "Aug" |
grep Aug -R /var/log/* | Replace "string1" in the example.txt file with "string2" |
sed 's/stringa1/stringa2/g' example.txt | Remove all blank lines from example.txt file |
sed '/^$/d' example.txt | sed '/ *#/d; /^$/d' example.txt from example.txt |
Remove all comments and blank lines from the file | Merge the contents of upper and lower cells |
echo 'esempio' | tr '[:lower:]' '[:upper:]' | Exclude the first line from the file example.txt |
sed -e '1d' result.txt | View lines containing only the word "string1" |
sed -n '/stringa1/p' | Remove whitespace characters at the end of each line |
sed -e 's/ *$//' example.txt | Remove only the word "string1" from the document and keep everything else |
sed -e 's/stringa1//g' example.txt | View content from line 1 to line 5 |
sed -n '1,5p;5q' example.txt | Look at line 5 |
sed -n '5p;5q' example.txt | Replace multiple zeros with a single zero |
sed -e 's/00*/0/g' example.txt | Indicates the number of lines in the file |
cat -n file1 | Delete all even lines in example.txt file |
cat example.txt | awk 'NR%2==1' | View the first column of a row |
echo a b c | awk '{print $1}' | Look at the first and third columns of a row |
echo a b c | awk '{print $1,$3}' | Merge the contents of two files or columns |
paste file1 file2 | Merge the contents of two files or two columns, using "+" to distinguish them. |
paste -d '+' file1 file2 | Sort the contents of two files |
sort file1 file2 | Take the union of two files (only one copy of duplicate lines is kept) |
sort file1 file2 | uniq | Remove intersection, leaving other rows |
sort file1 file2 | uniq -u | Take out the intersection of two files (leaving only files that exist in both files) |
sort file1 file2 | uniq -d | Compare the contents of two files and delete only the contents contained in 'file1' |
comm -1 file1 file2 | Compare the contents of two files and delete only the contents contained in 'file2' |
comm -2 file1 file2 | Compare the contents of two files and delete only the parts common to both files |
comm -3 file1 file2 | Linux commands - character settings and file format conversion |
Notes | Convert the format of a text file from MSDOS to UNIX |
---|---|
dos2unix filedos.txt fileunix.txt | Convert the format of a text file from UNIX to MSDOS |
unix2dos fileunix.txt filedos.txt | Convert a text file to html |
recode ..HTML < page.txt> page.html | Show all allowed conversion formats |
recode -l | more | Linux Commands — File System Analysis |
Notes | Check for bad blocks on disk hda1 |
---|---|
badblocks -v /dev/hda1 | Repair/check integrity of linux file system on hda1 disk |
fsck /dev/hda1 | Repair/check integrity of ext2 file system on hda1 disk |
fsck.ext2 /dev/hda1 | Repair/check integrity of ext2 file system on hda1 disk |
e2fsck /dev/hda1 | Repair/check integrity of ext3 file system on hda1 disk |
e2fsck -j /dev/hda1 | Repair/check integrity of ext3 file system on hda1 disk |
fsck.ext3 /dev/hda1 | Repair/check integrity of fat file system on hda1 disk |
fsck.vfat /dev/hda1 | Repair/check integrity of dos file system on hda1 disk |
fsck.msdos /dev/hda1 | Repair/check integrity of dos file system on hda1 disk |
dosfsck /dev/hda1 | Linux command — initialize a file system |
Notes | Create a file system on the hda1 partition |
---|---|
mkfs /dev/hda1 | Create a linux ext2 file system on the hda1 partition |
mke2fs /dev/hda1 | Create a linux ext3 (journaled) file system in the hda1 partition |
mke2fs -j /dev/hda1 | Create a FAT32 file system |
mkfs -t vfat 32 -F /dev/hda1 | Format a floppy disk |
fdformat -n /dev/fd0 | Create a swap file system |
mkswap /dev/hda3 | Linux Commands — SWAP File System |
Notes | Create a swap file system |
---|---|
mkswap /dev/hda3 | Enable a new swap file system |
swapon /dev/hda3 | Enable two swap partitions |
swapon /dev/hda2 /dev/hdb3 | Linux Commands — Backup |
Notes | Make a '/home' directory full backup |
---|---|
dump -0aj -f /tmp/home0.bak /home | Make an interactive backup of the '/home' directory |
dump -1aj -f /tmp/home0.bak /home | Restoring an interactive backup |
restore -if /tmp/home0.bak | Synchronize directories on both sides |
rsync -rogpav --delete /home /tmp | rsync over SSH channel |
rsync -rogpav -e ssh --delete /home ip_address:/tmp | Sync a remote directory to a local directory via ssh and compression |
rsync -az -e ssh --delete ip_addr:/home/public /home/local | Sync local directory to remote directory via ssh and compression |
rsync -az -e ssh --delete /home/local ip_addr:/home/public | Perform a local disk backup operation on the remote host through ssh |
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' | Back up disk contents to a file |
dd if=/dev/sda of=/tmp/file1 | Perform an interactive backup of the '/home/user' directory |
tar -Puf backup.tar /home/user | Copy the contents of a directory to a remote directory via ssh |
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' | Copy a local directory in a remote directory via ssh |
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' | Copy a directory locally to another place, retaining original permissions and links |
tar cf - . | (cd /tmp/backup ; tar xf - ) | Find and copy all files ending with '.txt' from one directory to another |
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents | 从一个目录查找并复制所有以 '.txt' 结尾的文件到另一个目录 |
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 | Perform an action to copy the contents of MBR (Master Boot Record) to a floppy disk |
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 | Recover MBR contents from backup that has been saved to floppy disk |
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 | Linux Commands — CD |
Notes | Erase the contents of a rewritable disc |
---|---|
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force | Create an iso image file of the CD on the disk |
mkisofs /dev/cdrom > cd.iso | Create a compressed CD iso image file on the disk |
mkisofs /dev/cdrom | gzip > cd_iso.gz | Create an iso image file of a directory |
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd | Burn an ISO image file |
cdrecord -v dev=/dev/cdrom cd.iso | Burn a compressed ISO image file |
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - | Mount an ISO image file |
mount -o loop cd.iso /mnt/iso | Rip audio tracks from a CD to wav files |
cd-paranoia -B | Rip audio tracks from a CD to a wav file (parameter -3) |
cd-paranoia -- "-3" | Scan bus to identify scsi channel |
cdrecord --scanbus | Verify the md5sum encoding of a device, such as a CD |
dd if=/dev/hdc | md5sum | Linux Commands - Network - (Ethernet and WIFI Wireless) |
Notes | Enable 'eth0' network device in dhcp mode |
---|---|
dhclient eth0 | Display traffic statistics of network card ‘eth0’ |
ethtool eth0 | Find hostnames to resolve names and IP addresses and mirrors |
host www.example.com | show hostname |
hostname | Display the configuration of an Ethernet card |
ifconfig eth0 | Control IP address |
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 | Set 'eth0' to promiscuous mode to sniff packets (sniffing) |
ifconfig eth0 promisc | Disable an 'eth0' network device |
ifdown eth0 | Enable an 'eth0' network device |
ifup eth0 | Display the connection status of all network devices |
ip link show | Display the configuration of a wireless network card |
iwconfig eth1 | Show wireless networks |
iwlist scan | Display the connection status of 'eth0' |
mii-tool eth0 | Show all enabled network connections and their PIDs |
netstat -tup | Display all listening network services in the system and their PIDs |
netstat -tup1 | Display the routing table, similar to the "route -n" command |
netstat -rn | Find hostnames to resolve names and IP addresses and mirrors |
nslookup www.example.com | show routing table |
route -n | Control default gateway |
route add -net 0/0 gw IP Gateway | Control static route to network '192.168.0.0/16' |
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 | Delete static route |
route del 0/0 gw IP gateway | Activate IP forwarding |
echo “1”> /proc/sys/net/ipv4/ip_foward | Show all HTTP loopbacks |
tcpdump tcp port 80 | Search in Whois database |
whois www.example.com | Linux Commands — Microsoft Windows Networking |
Notes | Mount a windows network share |
---|---|
mount -t smbfs -o username=user,password=pass //WinClient/share/mnt/share | netbios name resolution |
nbtscan ip addr | netbios name resolution |
nmblookup -A ip addr | Display remote shares of a windows host |
smbclient -L ip addr/hostname | Like wget, you can download files from a windows host via smb |
smbget -Rr smb://ip addr/share | Linux command — IPTABLES(firewall) |
Notes | Show all links in the filter table |
---|---|
iptables -t filter -L | Display all links in the nat table |
iptables -t nae -L | Clean up all rules based on filter table |
iptables -t filter -F | Clean up all rules based on NAT table |
iptables -t nat -F | Delete all links created by user |
iptables -t filter -X | Allow telnet access |
iptables -t filter -A INPUT -p tcp --dport telnet -j ACCEPT | Block telnet access |
iptables -t filter -A OUTPUT -p tcp --dport telnet -j DROP | Allow POP3 connections on forwarding links |
iptables -t filter -A FORWARD -p tcp --dport pop3 -j ACCEPT | Record blocked packets on all links |
iptables -t filter -A INPUT -j LOG --log-prefix | Set up a PAT (Port Address Translation) on eth0 to mask outgoing packets |
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | Forward packets destined for one host address to other hosts |
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 | Linux commands — monitoring and debugging |
Notes | List RAM status in megabytes |
---|---|
free -m | Force close the process and end it |
kill -9 process id | Force a process to reload its configuration |
kill -1 process id | Show restart history |
last reboot | Kernel module that lists status |
lsmod | List a list of files opened by a process |
lsof -p process id | List of open files in the given system path |
lsof /home/user1 | List linux tasks |
ps -eafw | List linux tasks in a hierarchical manner |
ps -e -o pid,args --forest | Display program in tree view |
pstress | Monitor the reliability of hard drive devices by enabling SMART |
smartctl -A /dev/hda | Check whether SMART is enabled on a hard disk device |
smartctl -i /dev/hda | List system calls made and use a process to receive them |
strace -c ls >/dev/null | List library calls |
strace -f -e open ls >/dev/null | Display internal events during kernel boot process |
tail /var/log/dmesg | Show system events |
tail /val/log/messages | List the Linux tasks that use the most CPU resources |
top | List real-time interrupts |
watch -nl ‘cat /proc/interrupts’ | Linux commands — other commonly used commands |
Notes | Set an alias for the command history |
---|---|
alias hh='history' | Make a list of commands including program keywords. This is especially useful when you only know what the program does but don’t remember the commands. |
apropos ...keyword | Change shell command |
chsh | Nice command to know if you have to connect remotely to another machine |
chsh --list-shells | Encrypt a file with GNU Privacy Guard |
gpg -c filel | Decrypt a file with GNU Privacy Guard |
gpg filel.gpg | 用GNU Privacy Guard解密一个文件 |