Linux Operations Common commands

Source: Internet
Author: User
Tags bz2 gpg hex to decimal locale mirror website recode rsync

propos Word displays commands related to Word

Which command displays the full path name of the commands
Time command to calculate when commands run
Time Cat starts timing. ctrl-d stop.
Nice info runs a low-priority command (here is info)
Renice 19-p $$ The script to run at a low priority level. For non-interactive tasks.
Look prefix Quick Find in (ordered) dictionary
grep--color expr...ion/usr/share/dict/words to highlight matching regular expressions in the dictionary
Gpg-c file encryption
GPG file.gpg File Decryption
Alias hd= ' od-ax-tx1z-v ' convenient hex output. (Example of usage:? hd/proc/self/cmdline | less)
Alias Realpath= ' Readlink-f ' shows the true path that the symbolic link points to (use example:? Realpath ~/. /$USER)
Set | grep $USER Find $ USER in the current environment
Ls/usr/bin | Pr-t9-w$columns Print 9 columns of output on the current terminal width
Touch-c-T 0304050607 file change time label (YYMMDDHHMM)

Directory Operations

CD-Back to previous directory
CD Back to User directory
(cd dir && command) go to directory dir, execute command commands and return to current directory
pushd. Press the current directory into the stack and later you can use POPD to return to this directory

CD

Gzip </dev/cdrom > cdrom.iso.gz save disc Copy
Mkisofs-v Name-r dir | gzip > Cdrom.iso.gz Set up the directory Dir's disc image
Mount-o Loop Cdrom.iso/mnt/dir mount the disc image to/mnt/dir (read only)
Cdrecord-v dev=/dev/cdrom blank=fast Empty a piece of CDRW
GZIP-DC cdrom.iso.gz | Cdrecord-v Dev=/dev/cdrom-Burn disc image (use Dev=atapi-scanbus to confirm the use of Dev)
Cdparanoia-b the disc tracks into WAV files in the current directory
Cdrecord-v Dev=/dev/cdrom-audio *.wav to burn a WAV file in the current directory to a music disc (see CDRDAO)
Oggenc--tracknum= ' track ' track.cdda.wav-o ' track.ogg ' convert WAV files to OGG format

Archive

Tar C dir/| bzip2 > dir.tar.bz2 to package the directory dir/compression  
BZIP2-DC dir.tar.bz2 | Tar x Expand the package (use gzip for tar.gz files instead of bzip2) & nbsp
Tar C dir/| gzip | gpg-c | ssh [email protected] ' dd of=dir.tar.gz.gpg ' directory dir/compress package and place on remote machine  
Find dir/- Name ' *.txt ' | Tar C--files-from=-| bzip2 > DIR_TXT.TAR.BZ2 Packaging all. txt files in the directory dir/and its subdirectories  
Find dir/-name ' *.txt ' | xargs cp-a--target-directory=dir_ txt/--parents copies all the. txt in the directory dir/and its subdirectories to dir_txt/  according to the directory structure;
(tar c/dir/to/copy) | (cd/where/to/&& tar x-p) copy directory copy/to directory/where/to/and keep file attributes  
(cd/dir/to/copy && tar c.) | (cd/where/to/&& tar x-p) copy all files under directory copy/to the directory/where/to/and keep the file attributes  
(tar c/dir/to/copy) | ssh-c [email& Nbsp;protected] ' cd/where/to/&& tar x-p ' copy directory copy/to remote directory/where/to/and keep file attributes  
DD bs=1m If=/dev/hda | gzip | SSH [email protected] ' dd of=hda.gz ' backs up the entire hard drive to the remote machine  

= = Rsync = = (test with the--dry-run option)
Rsync-p rsync://rsync.server.com/path/to/file file only gets diffs. You can do it multiple times when you have a problem.
Rsync--bwlimit=1000 FromFile ToFile has a speed-limited local copy, which is advantageous for I/O
Rsync-az-e ssh--delete ~/public_html/remote.com: ' ~/public_html ' mirror website (using compression and encryption)
Rsync-auz-e ssh remote:/dir/. && rsync-auz-e ssh. remote:/dir/synchronizing the current directory and remote directory

File Search

Alias l= ' Ls-l--color=auto ' single character file List command
LS-LRT displays files by date.
Find-name ' *. [CH] ' | Xargs grep-e ' expr ' finds ' expr ' in all. C and. h files in the current directory and its subdirectories. See Findrepo
Find-type f-print0 | Xargs-r0 grep-f ' string ' finds string ' strings ' in regular files in the current directory and its subdirectories
Find-maxdepth 1-type F | Xargs grep-f ' string ' in the current directory to find string ' ' string '
Find-maxdepth 1-type D | While read dir; do Echo $dir; Echo cmd2; Done multiple commands for each found file (using the while loop)
Find-type f! -perm-444 looking for all unreadable files (useful for the site)
Find-type d! -perm-111 Search for inaccessible directories (useful for Web sites)
Locate-r ' file[^/]*\.txt ' use locate to find all files that match *file*.txt

Network (ifconfig, route, Mii-tool, nslookup commands are obsolete)

IP link Show shows interface list
Ethtool interface Display Interface status
IP link set dev eth0 name Wan rename eth0 to Wan
IP addr Add 1.2.3.4/24 brd + dev eth0 adding IP and Masks (255.255.255.0)
IP link Set dev interface up start interface (or off)
IP route add default via 1.2.3.254 to set the defaults gateway 1.2.3.254
TC Qdisc Add dev lo root handle 1:0 netem delay 20msec increase 20ms transfer time to loopback device (for commissioning)
TC Qdisc del Dev lo root Remove the transfer time added above
Host pixelbeat.org Find the IP address of the given name and vice versa
Hostname-i Find local IP address (equivalent to host ' hostname ')
NETSTAT-TUPL List Internet services in the system
Netstat-tup List of active connections

wget (Multi-purpose download tool)

(CD cmdline && wget-nd-phekk http://www.pixelbeat.org/cmdline.html) Download the specified Web page and its associated files in the current directory to make it fully browsable
Wget-c http://www.example.com/large.file continue the last download
Wget-r-nd-np-l1-a ' *.jpg ' http://www.example.com/bulk download files into the current directory
wget ftp://remote/file[1-9].iso/Download the entire directory on the FTP station
Wget-q-o-http://www.pixelbeat.org/timeline.html | grep ' a href ' | Head Direct processing output
echo ' wget url ' | At 01:00 one o'clock in the afternoon to download the specified file to the current directory
wget--limit-rate=20k URL limit download speed (limited to 20kb/s here)
WGET-NV--spider--force-html-i bookmarks.html Check the existence of links in the file
wget--mirror http://www.example.com/Update the local copy of the website (can be conveniently used for cron)

Windows (Samba provides all Windows-related network support)

Smbtree looking for a Windows host. See FINDSMB
Nmblookup-a 1.2.3.4 looking for a specified IP for Windows (NetBIOS) name
Smbclient-l Windows_box display all shares on a Windows host or Samba server
Mount-t Smbfs-o fmask=666,guest//windows_box/share/mnt/share to mount a Windows share
echo ' Message ' | Smbclient-m Windows_box send a pop-up message to the Windows host (XP SP2 default off this feature)

Calculate related

? Echo ' (1 + sqrt (5))/2 ' | Bc-l Convenient calculator (calculate φ)
? Echo ' obase=16; ibase=10; 123 ' | BC Binary conversion (decimal to hexadecimal)
? echo $ ((0X2DEC)) binary conversion (Hex to decimal) ((Shell Math extension))
? Echo ' pad=20; min=64; (100*10^6)/((pad+min) *8) ' | BC more complex calculation, here calculate the maximum faste packet rate
? Echo ' pad=20; min=64; Print (100E6)/((pad+min) *8) ' | A scientific representation of the value of Python python processing
? Echo ' pad=20; Plot [64:1518] (100*10**6)/((pad+x) *8) ' | Gnuplot-persist shows the faste packet rate relative to the package size of the graphic

Text Manipulation

(SED uses standard input and standard output, if you want to edit the file, you need to add <oldfile >newfile)
Sed ' s/string1/string2/g ' replaces string1 with string2
Sed ' s/. ?1/\12/g ' replaces any string ending with 1 with a string ending with 2
Sed '/*#/d; /^ *$/d ' Delete comments and Blank lines
Sed ': A; /\\$/n; s/\\\n//; Ta ' connection ends with \ Line and its next line
Sed ' s/[\t]*$//' removes whitespace after each line
Sed ' s/['"$] /\\\1/g ' adds all escape characters before the \
Sed-n ' 1000p;1000q ' output line 1000th
Sed-n ' 10,20p;20q ' output 第10-20 line
Sed-n ' s/.*<[tt][ii][tt][ll][ee]>. ? <\/[tT][iI][tT][lL][eE]>.*/\1/p; T;q ' The contents of the <title></title> field in the output HTML file
Sort-t.-k1,1n-k2,2n-k3,3n-k4,4n Sort IPV4 Address
echo ' Test ' | TR ' [: Lower:] ' [: Upper:] ' converted to uppercase
TR-DC ' [:p rint:] ' </dev/urandom filter out characters that cannot be printed
grep ' Processor '/proc/cpuinfo | Wc-l calculates the number of occurrences of a specified word

set operation (Lang=c can increase speed if English text is used)

Lang=c Sort File1 File2 | Uniq two unsorted files in a set
Lang=c Sort File1 File2 | Uniq-d the intersection of two unsorted files
Lang=c sort file1 file1 file2 | Uniq-u the difference between two unsorted files
Lang=c Sort File1 File2 | Uniq-u symmetric difference set of two unsorted files
Lang=c Comm File1 File2 | Sed ' s/^\t*//' two sequential files of the set
Lang=c comm-12 file1 file2 The intersection of two ordered files
Lang=c comm-13 file1 file2 Two ordered file difference set
Lang=c comm-3 file1 file2 | A symmetric difference set of two ordered files of sed ' s/^\t*//'

Calendar

cal-3 Display a calendar
Cal 9 1752 Displays the calendar for the specified month, year
date-d Fri This Friday is the date. See Day
Date--date= ' Dec ' +%a this year's Christmas is the day of the week
Date--date ' 1970-01-01 UTC 1234567890 seconds ' converts a number of seconds relative to 1970-01-01 00:00 to time
tz= ': America/los_angeles ' date shows current U.S. West Coast time (use Tzselect to find time zone)
echo "Mail-s ' Get the train ' [email protected] </dev/null" | At 17:45 send a message at a specified time
echo "display= $DISPLAY xmessage Cooker" | At "Now + minutes" pop-up dialog at a given time

locales

? printf "% ' d\n" 1234 output the correct number separated by locale
? echo "I live in ' locale territory '" expands information from the locale database
? Locale | cut-d=-F1 | Xargs LOCALE-KC | Less displays all fields in the locale database
? Lang=en_ie.utf8 locale Int_prefix Find locale information for the specified region. See Ccodes

disk space (see FSLINT)

? LS-LSR displaying files in descending order of file size
? Du-s * | Sort-k1,1rn | Head displays the largest number of files in the current directory that occupy space. See Dutop
? Df-h Display of free disk space
? Df-i shows the free inode
? Fdisk-l Show disk partition size and type (performed under root)
? Rpm-q-a--qf '%10{size}\t%{name}\n ' | SORT-K1,1N displays all packages installed on the RPM release, in order of packet byte size
? Dpkg-query-w-f= ' ${installed-size;10}\t${package}\n ' | SORT-K1,1N displays all packages installed on the Deb release and is in KB package size
? DD Bs=1 SEEK=2TB if=/dev/null of=ext3.test Build a large test file (no space). See truncate

Monitoring/Debugging

? Strace-c LS >/dev/null summary/parse command made system call
? Strace-f-e open ls >/dev/null display command made system call
? Ltrace-f-e getenv LS >/dev/null displays the library function called by the command
? Lsof-p $$ Displays the files that are open by the current process
? Lsof ~ Show the process of opening user directory
? Tcpdump not port 22 shows network traffic in addition to SSH. See Tcpdump_not_me
? PS-E-O Pid,args--forest displays the process in a tree-like structure
? PS-E-o Pcpu,cpu,nice,state,cputime,args--sort pcpu | Sed '/^ 0.0/d ' displays processes in the order of CPU utilization
? PS-E-orss=,args= | Sort-b-k1,1n | Pr-tw$columns Displays the process in the order of memory usage. See ps_mem.py
? Ps-c firefox-bin-l-o pid,tid,pcpu,state Displays all thread information for the specified process
? PS-P display process information for the specified process ID
? Last reboot display system restart record
? Free-m Display (remaining) total memory (-m shown in MB)
? Watch-n1 ' cat/proc/interrupts ' monitoring file/proc/interrupts changes

System Information (see SYSINFO)

Hdparm-i/dev/hda Displays information about the disk HDA
Hdparm-tt/dev/hda detecting the Read speed of the disk HDA
Badblocks-s/dev/hda detects all bad sectors on the disk HDA
? Mount | COLUMN-T displays all mounted file systems and aligns the outputs
? Cat/proc/partitions Show all partitions registered in the system
? grep Memtotal/proc/meminfo Displays the total amount of memory visible to the system
? grep "model name"/proc/cpuinfo Display CPU information
? Lspci-tv displaying PCI information
? Lsusb-tv displaying USB information

Recode

Iconv, Dos2unix, Unix2dos is out of date)
Recode-l | Less displays all valid character sets and their aliases
Recode windows-1252. File_to_change.txt convert an ANSI file under Windows to the current character set (automatic conversion of carriage return newline characters)
Recode Utf-8/crlf. File_to_change.txt convert an ANSI file under Windows to the current character set
Recode iso-8859-15. UTF8 file_to_change.txt convert Latin9 (Western European) character set file to UTF8
Recode. /b64 < file.txt > file.b64 Base64 encoding
Recode/qp. < file.txt > FILE.QP quoted-printable format decoding
Recode. HTML < file.txt > file.html convert text files to HTML
? RECODE-LF windows-1252 | grep euro looks for the euro symbol in the character table
? Echo-n 0x80 | Recode latin-9/x1. Dump displays character mappings for characters in latin-9
? Echo-n 0x20ac | Recode ucs-2/x2. latin-9/x Display LATIN-9 encoding
? Echo-n 0x20ac | Recode ucs-2/x2. utf-8/x Display UTF-8 encoding

Interactive

? MC Powerful File Manager, can browse rpm, tar, FTP, SSH, ...
? Screen Multi-window virtual terminal, ...
? Links Web Browser
? Gnuplot Interactive and scripted drawing tools
? Octave a tool similar to MATLAB

Linux Operations Common commands

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.