Linux Command Summary

Source: Internet
Author: User
Tags chmod gpg rar recode nslookup rsync

$ System Information
# Arch Display Machine Processor Architecture (1)
# UNAME-M Display the processor architecture of the machine (2)
# UNAME-R shows the kernel version being used
# DMIDECODE-Q Display hardware system components-(SMBIOS/DMI)
# hdparm-i/dev/hda A list of the architecture features of a disk
# HDPARM-TT/DEV/SDA performing a test read operation on disk
# CAT/PROC/CPUINFO Displays information about CPU info
# cat/proc/interrupts Display Interrupt
# Cat/proc/meminfo Checking Memory usage
# Cat/proc/swaps shows which swap is used
# Cat/proc/version Displays the kernel version
# Cat/proc/net/dev Display network adapter and statistics
# cat/proc/mounts display of loaded file systems
# LSPCI-TV List of PCI devices
# LSUSB-TV Display USB device
# Date Display system date
# Cal 2007 Displays the 2007 calendar table
# date 041217002007.00 sets the day and time-the year of the month. seconds
# Clock-w Save time changes to BIOS

Shutdown (System shutdown,
# shutdown-
# init 0 off system
# Telinit 0
# shutdown-
# shutdown-
# shutdown-
# Reboot Restart (
# Logout Logout

$ files and directories
# cd/home into '/home ' directory '
# CD: Return to the top level directory
# CD: /.. Return to the top level two directory
# CD into the personal home directory
# CD ~user1 into the personal home directory
# CD-Back to the last directory
# PWD Display work path
# ls To view the files in the directory
# ls-f viewing files in a directory
# ls-l Show file and directory details
# ls-a Show hidden files
# ls *[0-9]* displays filenames and directory names that contain numbers
# tree displays files and directories starting with the root directory (1)
# Lstree display files and directories starting with the root directory tree (2)
# mkdir Dir1 Create a directory called ' Dir1 '
# mkdir Dir1 Dir2 Simultaneous creation of two directories
# 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 under 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)
# file File1 outputs the MIME type of the file as text
# iconv-l List of known encodings
# iconv-f fromencoding-t toencoding inputfile > OutputFile creates a new from the given input file by assuming it is # encoded in fromencoding and converting it to toencoding.
# Find. -maxdepth 1-name *.jpg-print-exec Convert "{}"-resize 80x60 "thumbs/{}" \; Batch resize files in the current # directory and send them to a thumbnails directory (requires convert from Imagemagick)

$ File Search
# Find/-name file1 Enter the root file system to search for files and directories from '/'
# Find/-user User1 search for files and directories belonging to user ' User1 '
# find/home/user1-name \*.bin in directory '/home/user1 ' search for files with '. Bin '
# find/usr/bin-type f-atime +100 Search execution 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 with '. RPM ' and define their permissions
# Find/-xdev-name \*.rpm search for files ending with '. RPM ', ignoring removable devices such as optical drives, Czech disks, etc.
# Locate \*.ps looking for files ending with '. ps '-run the ' updatedb ' command first
# Whereis Halt shows the location of a binary file, source code, or man
# which halt displays the full path of a binary or executable file

$ mount a file system
# MOUNT/DEV/HDA2/MNT/HDA2 mount a disk called hda2-ok directory '/mnt/hda2 ' already exists
# umount/dev/hda2 Uninstall a disk called Hda2-first from Mount point '/mnt/hda2 ' exit
# FUSER-KM/MNT/HDA2 force unload when device is busy
# umount-n/mnt/hda2 Run unload operation without writing/etc/mtab file-useful when file is read-only or when disk is full
# 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 drive or flash device
# mount-t Smbfs-o username=user,password=pass//winclient/share/mnt/share mount a Windows network share

$ disk space
# DF-H Displays a list of the partitions that are already mounted
# LS-LSR |more arrange files and directories in size
# du-sh dir1 estimate directory ' Dir1 ' already used disk space '
# Du-sk * | SORT-RN display the size of files and directories in terms of capacity size
# rpm-q-a--qf '%10{size}t%{name}n ' | SORT-K1,1N the space used by the installed RPM package, based on size (Fedora, Redhat class System)
# dpkg-query-w-f= ' ${installed-size;10}t${package}n ' | SORT-K1,1N Displays the space used by the installed Deb package based on size (Ubuntu, # Debian system)

$ users and Groups
# Groupadd Group_name Create a new user group
# Groupdel Group_name Delete a user group
# groupmod-n New_group_name old_group_name renaming a user group
# useradd-c "Name Surname"-G admin-d/home/user1-s/bin/bash user1 Create a user belonging to the "admin" user group
# Useradd User1 Create a new user
# Userdel-r User1 Delete a user ('-R ' exclude home directory)
# usermod-c "User FTP"-G system-d/ftp/user1-s/bin/nologin user1 Modify the properties of users
# passwd Change Password
# passwd User1 Modify a user's password (root only allowed)
# chage-e 2005-12-31 user1 set the expiration period of the user password
# PWCK Check the '/etc/passwd ' file format and syntax corrections as well as the presence of the user
# GRPCK Check file format and syntax corrections for '/etc/passwd ' and existing groups
# newgrp Group_name Login into a new group to change the preset group of newly created files

$ file Permissions-use "+" to set permissions, use "-" to cancel
# LS-LH display Permissions
# Ls/tmp | Pr-t5-w$columns divide the terminal into 5 columns
# chmod ugo+rwx di Rectory1 Set the directory owner (U), Group (g), and others (O) to read (R), write (w), and execute (x) Permissions
# chmod go-rwx directory1 Delete Group (g) Read and write execution permissions to the directory with other People (O)
# Chown user1 File1 Change the Owner property of a file
# chown-r user1 directory1 Change the owner property of a directory and change the properties of all files in the directory at the same time
# chgrp group1 file1 Change file Group
# chown User1:group1 file1 Change the owner and group properties of a file
# Find/-perm-u+s list all files in a system that use Suid control
# chmod U+s/bin/file1 Set the SUID bit of a binary file-the user who is running the file is also given the same permissions as the owner
# chmod u-s/bin/file1 Disable the SUID bit of a binary
# chmod g+s/home/public set a directory SGID bit-similar to suid, but this is the
# chmod g-s/home/public for the directory disable the SGID bit of a directory
# chmod o+t/home/public set the STIKY bit of a file-only allowed Legal owner Delete File
# chmod o-t/home/public disable STIKY bit of a directory

$ file Special Properties-use "+" to set permissions, use "-" to cancel
# chattr +a file1 only allowed to read and write files in append mode
# chattr +c File1 allows this file to be automatically compressed/decompressed by the kernel
# chattr +d file1 The DUMP program ignores this file when a file system backup is in progress
# chattr +i File1 is set to an immutable file and cannot be deleted, modified, renamed, or linked
# chattr +s File1 allows a file to be safely deleted
# chattr +s File1 Once the application writes to this file, the system immediately writes the result of the modification to the disk
# chattr +u file1 If the file is deleted, the system will allow you to recover the deleted file later.
# lsattr display of special properties

$ package and compress files
# bunzip2 file1.bz2 extract 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 call ' fil E1.rar ' Package
# rar a file1.rar file1 file2 dir1 simultaneously compress ' file1 ', ' file2 ' and directory ' Dir1 '
# rar x file1.rar extract rar package
# UNR AR x file1.rar decompression rar Package
# TAR-CVF Archive.tar file1 Create a non-compressed tarball
# TAR-CVF Archive.tar file1 file2 dir1 Create a containing The ' file1 ', ' file2 ', and ' Dir1 ' files
# TAR-TF Archive.tar Display the contents of a package
# TAR-XVF Archive.tar free a package
# TAR-XVF Arch IVE.TAR-C/TMP Release the compressed package to the/tmp directory
# TAR-CVFJ archive.tar.bz2 dir1 Create a BZIP2-formatted compressed package
# TAR-XVFJ archive.tar.bz2 Unzip a B ZIP2 Format Compressed Package
# TAR-CVFZ archive.tar.gz dir1 Create a zipped package in gzip format
# TAR-XVFZ archive.tar.gz Extract an gzip-formatted compressed Package
# ZIP file 1.zip file1 Create a zip-format compression Package
# zip-r file1.zip file1 file2 dir1 compress several files and directories into a zip-format Package
# Unzip File1.zip unzip a zip format Compress package

$ RPM Package-(Fedora, Redhat and similar systems)
# RPM-IVH package.rpm Install a RPM package
# RPM-IVH--nodeeps package.rpm Install an RPM package and ignore dependency warnings
# rpm-u package.rpm update a RPM package without changing its configuration file
# rpm-f package.rpm update one to determine which RPM package is installed
# rpm-e package_name.rpm Delete an RPM package
# RPM-QA displays all installed RPM packages in the system
# Rpm-qa | grep httpd shows all RPM packages with the words "httpd" in their names
# Rpm-qi Package_name Get special information for an installed package
# RPM-QG "System environment/daemons" shows the RPM package for a component
# rpm-ql Package_name Displays a list of files provided by an already installed RPM package
# RPM-QC Package_name Displays a list of configuration files provided by an already installed RPM package
# rpm-q Package_name--whatrequires shows a list of dependencies that exist with a RPM package
# rpm-q Package_name--whatprovides shows the volume of a RPM package
# rpm-q package_name--scripts Show scripts executed during installation/removal L
# rpm-q Package_name--changelog shows the revision history of a RPM package
# rpm-qf/etc/httpd/conf/httpd.conf confirm which RPM package is provided for the given file
# RPM-QP Package.rpm-l Displays a list of files provided by a RPM package that has not been installed
# RPM--import/media/cdrom/rpm-gpg-key Import public key digital certificate
# RPM--checksig package.rpm confirm the integrity of a RPM package
# RPM-QA Gpg-pubkey Verify the integrity of all RPM packages installed
# rpm-v package_name Check file size, license, type, owner, group, MD5 check, and last modified time
# Rpm-va Check all installed RPM packages in the system-use with care
# RPM-VP package.rpm confirm that an RPM package is not installed
# Rpm2cpio package.rpm | Cpio--extract--make-directories *bin* Run executable from an RPM package
# rpm-ivh/usr/src/redhat/rpms/' arch '/package.rpm install a built-in package from a RPM source
# rpmbuild--rebuild package_name.src.rpm Build a RPM package from one RPM source


$ JVM Command
# Jstack-l 3310 (Process ID) >1.txt Store the current thread information to a file
# Jstack-l 3310 (Process ID) >2.txt Store the current thread information to a file
# Vimdiff 1.txt 2.txt Comparison


$ YUM Package Upgrade-(Fedora, Redhat and similar systems)
# yum Install package_name download and install a RPM package
# yum Localinstall package_name.rpm will install a RPM package and use your own repositories to resolve all dependencies for you
# Yum Update package_name.rpm updates all installed RPM packages in the current system
# Yum Update package_name updates an RPM package
# yum Remove package_name Delete an RPM package
# Yum list lists all packages installed in the current system
# Yum Search package_name searching for packages in RPM repositories
# Yum Clean Packages cleanup rpm cache to delete downloaded packages
# Yum Clean headers Delete all header files
# yum Clean all deletes all cached packages and header files

DEB packages (Debian, Ubuntu and similar systems)
# dpkg-i Package.deb Install/update a deb Package
# dpkg-r Package_name Remove a deb package from the system
# DPKG-L Displays all installed Deb packages in the system
# Dpkg-l | grep httpd Displays all the Deb packages with the words "httpd" in their names
# dpkg-s Package_name Get information on a special package already installed in the system
# dpkg-l Package_name Displays a list of files provided by a Deb package that is already installed in the system
# dpkg--contents Package.deb shows a list of files provided by a package that has not yet been installed
# dpkg-s/bin/ping confirm which Deb package the given file is provided by

APT software tools (Debian, Ubuntu and similar systems)
# Apt-get Install package_name installing/updating a deb package
# Apt-cdrom Install package_name installing/updating a Deb package from CD
# Apt-get update packages in the upgrade list
# Apt-get Upgrade upgrade all installed software
# apt-get Remove Package_name a deb package from the system
# Apt-get check confirms that the dependent repositories are correct
# Apt-get Clean the cache from the downloaded package
# Apt-cache Search Searched-package Returns the package name that contains the string you want to search

View File Contents
# cat File1 Viewing the contents of a file starting from the first byte
# TAC File1 To reverse view the contents of a file from the last line
# more File1 View the contents of a long file
# less file1 is similar to the ' more ' command, but it allows a reverse operation in the same way as a 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 Real-time view of content added to a file

Text Processing
# cat File1 file2 ... | Command <> File1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT
# cat File1 | Command (SED, grep, awk, grep, etc ...) > Result.txt Merge the detailed description text of a 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
# grep aug/var/log/messages in the file '/var/log/messages ' to find the keyword "the"
# grep ^aug/var/log/messages in file '/var/log/messages ' to find words that begin with "the word"
# grep [0-9]/var/log/messages Select all rows in '/var/log/messages ' file that contain numbers
# grep aug-r/var/log/* searches the directory '/var/log ' and subsequent directories for the string "the"
# sed ' s/stringa1/stringa2/g ' example.txt replace "string1" in Example.txt file with "string2"
# sed '/^$/d ' example.txt remove all blank lines from the Example.txt file
# sed '/*#/d; /^$/d ' Example.txt Remove all comments and blank lines from the Example.txt file
# echo ' Esempio ' | TR ' [: Lower:] ' [: Upper:] ' merging upper and lower cell contents
# sed-e ' 1d ' result.txt exclude first line from file Example.txt
# sed-n '/stringa1/p ' view lines that contain only the word "string1"
# sed-e ' s/*$//' example.txt delete the last white space character of each line
# sed-e ' s/stringa1//g ' example.txt only delete the word "string1" from the document and keep all remaining
# sed-n ' 1,5p;5q ' example.txt view contents from first line to 5th line
# sed-n ' 5p;5q ' example.txt view line 5th
# sed-e ' s/00*/0/g ' Example.txt replaces multiple zeros with a single 0
# cat-n File1 number of lines to mark a file
# Cat Example.txt | awk ' nr%2==1 ' deletes all even lines in the Example.txt file
# echo a b C | awk ' {print '} ' view one row of the first column
# echo a b C | awk ' {print $1,$3} ' view the first and third columns of a row
# paste File1 file2 merge two files or two columns of content
# paste-d ' + ' file1 file2 merge two files or two columns of content, middle with "+" distinction
# sort File1 file2 contents of two files sorted
# Sort File1 File2 | Uniq Remove the set of two files (duplicate lines are retained only one copy)
# Sort File1 File2 | Uniq-u Delete the intersection, leaving the other rows
# Sort File1 File2 | Uniq-d Remove the intersection of two files (leaving only files that exist in two files)
# comm-1 File1 file2 Compare the contents of two files delete only what ' file1 ' contains
# comm-2 File1 file2 Compare the contents of two files delete only what ' file2 ' contains
# comm-3 File1 file2 Compare the contents of two files delete only two files in common


Character settings and file format conversions
# Dos2unix Filedos.txt fileunix.txt Convert the format of a text file from Msdos to Unix
# Unix2dos Fileunix.txt filedos.txt Convert the format of a text file from UNIX to Msdos
# Recode. HTML < page.txt > page.html Convert a text file to HTML
# Recode-l | More Show all allowable conversion formats

File System Analysis
# badblocks-v/dev/hda1 Check for bad magnetic blocks on disk hda1
# FSCK/DEV/HDA1 Repair/Check the integrity of the Linux file system on the HDA1 disk
# FSCK.EXT2/DEV/HDA1 Repair/Check the integrity of the Ext2 file system on the HDA1 disk
# E2FSCK/DEV/HDA1 Repair/Check the integrity of the Ext2 file system on the HDA1 disk
# e2fsck-j/DEV/HDA1 Repair/Check integrity of ext3 file system on HDA1 disk
# FSCK.EXT3/DEV/HDA1 Repair/Check the integrity of the Ext3 file system on the HDA1 disk
# FSCK.VFAT/DEV/HDA1 Repair/Check the integrity of the FAT file system on the HDA1 disk
# FSCK.MSDOS/DEV/HDA1 Repair/Check the integrity of the DOS file system on the HDA1 disk
# DOSFSCK/DEV/HDA1 Repair/Check the integrity of the DOS file system on the HDA1 disk

Initializing a file system
# MKFS/DEV/HDA1 Create a file system in the HDA1 partition
# mke2fs/dev/hda1 Create a Linux ext2 file system in the HDA1 partition
# mke2fs-j/DEV/HDA1 Create a Linux ext3 (journaled) file system in 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

Swap file system
# 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

Backup
# 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 sync on both sides of the directory
# rsync-rogpav-e ssh--delete/home ip_address:/tmp via SSH channel rsync
# rsync-az-e SSH--delete ip_addr:/home/public/home/local synchronizes a remote directory to a local directory via SSH and compression
# rsync-az-e SSH--delete/home/local ip_addr:/home/public synchronizing the local directory to the remote directory via SSH and compression
# dd bs=1m If=/dev/hda | gzip | SSH [email protected]_addr ' dd of=hda.gz ' to perform a backup of the local disk on the remote host via SSH
# DD IF=/DEV/SDA of=/tmp/file1 Backup disk contents to a file
# TAR-PUF Backup.tar/home/user performs an interactive backup operation on the '/home/user ' directory
(cd/tmp/local/&& tar C.) | ssh-c [email protected]_addr ' cd/home/share/&& tar x-p ' copy a directory content from the remote directory via SSH
(Tar c/home) | ssh-c [email protected]_addr ' cd/home/backup-home && tar x-p ' copy a local directory from the remote directory via SSH
# Tar CF-. | (cd/tmp/backup; tar xf-) copy a directory locally to another location, preserving the 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 a directory to another directory
Find/var/log-name ' *.log ' | Tar CV--files-from=-| bzip2 > log.tar.bz2 Find all files that end with '. Log ' and make a bzip package
DD If=/dev/hda of=/dev/fd0 bs=512 count=1 do an action to copy the contents of the MBR (Master Boot Record) to a floppy disk
DD if=/dev/fd0 of=/dev/hda bs=512 count=1 recover MBR content from a backup that has been saved to a floppy disk

Disc
# cdrecord-v gracetime=2 Dev=/dev/cdrom-eject Blank=fast-force to clear a rewritable disc content
# Mkisofs/dev/cdrom > Cd.iso Create a CD-ROM ISO image file on disk
# Mkisofs/dev/cdrom | Gzip > Cd_iso.gz Create a compressed disc ISO image file on disk
# mkisofs-j-allow-leading-dots-r-V "Label CD"-iso-level 4-o./cd.iso data_cd Create an ISO image file for a directory
# cdrecord-v Dev=/dev/cdrom cd.iso burning 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 from a CD to the audio track to the WAV file
# Cd-paranoia--"-3" from a CD to the audio track to the WAV file (parameter-3)
# Cdrecord--scanbus Scan bus to identify SCSI channels
# DD IF=/DEV/HDC | md5sum Verifying the md5sum encoding of a device, such as a CD

Network-(Ethernet and WiFi wireless)
Ifconfig eth0 shows the configuration of an Ethernet card
Ifup eth0 enable a ' eth0 ' network device
Ifdown eth0 Disable a ' eth0 ' network device
Ifconfig eth0 192.168.1.1 netmask 255.255.255.0 control IP Address
Ifconfig eth0 promisc set ' eth0 ' into promiscuous mode to sniff packets (sniffing)
Dhclient eth0 enable ' eth0 ' in DHCP mode
Route-n Show routing Table
Route add-net 0/0 GW ip_gateway Configura default Gateway
Route add-net 192.168.0.0 netmask 255.255.0.0 GW 192.168.1.1 Configure static route to reach network ' 192.168.0.0/16 '
Route del 0/0 GW ip_gateway remove static route
echo "1" >/proc/sys/net/ipv4/ip_forward activate IP routing
Hostname show hostname of system
Host www.example.com lookup hostname to resolve name to IP address and viceversa (1)
nslookup www.example.com lookup hostname To resolve name to IP address and viceversa (2)
IP link Show Show link status of all interfaces
Mii-tool eth0 Show link status of ' eth0 '
Ethtool eth0 Show statistics of the network card ' eth0 '
Netstat-tup Show all active network connections and their PID
NETSTAT-TUPL Show all network services listening on the system and their PID
Tcpdump TCP port Show all HTTP traffic
Iwlist Scan Show Wireless networks
Iwconfig eth1 Show configuration of a wireless network card
Hostname show hostname
Host www.example.com lookup hostname to resolve name to IP address and viceversa
nslookup www.example.com lookup hostname To resolve name to IP address and viceversa
Whois www.example.com lookup on Whois database

Linux Command Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.