Linux Common commands

Source: Internet
Author: User
Tags bz2 diff gz file log log rar cpu usage disk usage

Linux commands

1. Ls-a,–all lists all files in the directory, including the. The implied file at the beginning
-L The file's permissions, owner, file size, and other information, in addition to file names
2. CD CD/system root directory
3.PWD pwd–p Show actual path view current working directory
4.mkdir mkdir [Options] directory ... Directory
Mkdir-p test2/test22 Create multiple directories recursively
MKDIR-M 777 Test3 Create a directory with permissions of 777
5. RM RM File Name
Rm-f Log1.log forcibly Delete file
Rm-i *.log Delete any. log files; Ask for confirmation before deleting
Rm-r test1 Delete all files in the Test1 subdirectory and subdirectories
RM-RF Test2 Delete all files in Test2 subdirectory and subdirectories without one by one confirmation
RM---F Delete files starting with-F
6. RmDir is a common command, the function of the command is to delete the empty directory, a directory is deleted before it must be empty
RmDir cannot delete a non-empty directory
Rmdir-p logs rmdir-p When a subdirectory is deleted and makes it an empty directory, it is deleted by the way
7. MV [option] source file or directory destination file or directory
File Rename command: MV Test.log test1.txt
Move File command: MV Test1.txt test3
MV Log1.txt Log2.txt Log3.txt test3
Move command for directory: MV Dir1 DIR2
Files in one subdirectory are moved to another subdirectory command: MV Test3/*.txt TEST5
8. Basic permissions control of file directory in Linux system
stat+ file name, where we see 644 is the permission of the file
Ls-l + file name, this displayed information will include the permissions of the files
chmod 777
Use the LS-LD directory name to view permissions for the directory
9. CP command to copy files or directories
CP [Options] ... Source... Directory
CP [Options] ...-t directory source ...
CP log.log TEST5 Copy a single file to the target directory
Cp-a test3 test5 Copy Entire Directory
Touch is used to modify the file timestamp, or to create a new file that does not exist.
touch [Options] ... File...
Touch Log2012.log Log2013.log Create files that do not exist
Touch-t 201211142234.50 Log.log Setting the timestamp of the file
The purpose of the cat command is to connect files or standard input and print
Cat [Options] [file] ...
Show entire file at once: Cat filename
Create a file from the keyboard: cat > FileName can only create new files and cannot edit existing files.
Merge several files into one file: Cat file1 file2 > file
Cat-n Log2012.log log2013.log Add the Log2012.log file content and enter the line number after the Log2013.log
Append the contents of the Log2012.log and Log2013.log files to the log.log after adding the line number (blank line not added)
Cat-b Log2012.log Log2013.log Log.log
The cat is continuously displayed on the screen from the first line to the last row, while the TAC is displayed on the screen in reverse from the last line to the first line
The NL command is used in a Linux system to calculate the number of lines in a file NL can automatically add the output file content to the line number
NL [Options] ... [File] ...
NL Log2012.log Listing Log2012.log with NL empty Line no line number
Nl-b a Log2012.log the contents of the Log2012.log with NL, the line number is also added to the empty bank
More will be a page-by-page reading, and the most basic instruction is to press the blank key next page, press the B key will go to the previous page
+n starting from joys N rows
-N defines the screen size as n rows
-S displays a contiguous number of empty rows as a row
-U Remove the line from the contents of the file
More +3 Log2012.log Displays the contents of the file from line 3rd
More +/day3 Log2012.log finds the first line that appears with the "Day3" string and starts at the top two lines
More-5 Log2012.log Set the number of rows per screen
Ls-l | More-5 column A directory of files, because the content is too much, we use more to pagination
The less tool is also a tool for pagination display of files or other outputs less [parameter] files
Less log2013.log viewing files
Ps-ef | Less PS view process information and display with less paging
History | Less view command history usage record and show by less paging
The head and tail are as easy to understand as their names, which are used to display a number of words at the beginning or end of a block.
The head is used to display the beginning of the file to the standard output, and the default head command prints the first 10 lines of its corresponding file
Head-n 5 Log2014.log Display the first 5 lines of a file
Head-c Log2014.log Display the first 20 bytes of the file
Head-n-6 log2014.log output file except the last n rows of the entire content
The. Tail command writes the file to standard output starting at the specified point
tail[necessary parameters [selection parameters] [file]
Tail-n 5 Log2014.log Display the end of the file 5 lines of content
Tail-f test.log Loop View file contents
Tail-n +5 log2014.log Show file starting from line 5th
Which view the location of the executable file Whereis view the location of the file locate view the file location with the database
Find actual search hard disk query file name
With the which command, you can see whether a system command exists, and which command is executed at which location.
Which pwd/bin/pwd
The. Whereis command can only be used for program name searches
Whereis Tomcat Whereis-b SVN
Locate allows users to quickly search the file system for specific files
Locate [Select parameters] [style]
Locate pwd Find all the files associated with PWD
Locate/etc/sh Search all files starting with SH in etc directory
The Find command under Linux provides quite a few search criteria
Find Pathname-options [-print-exec-ok ...]
Find-atime-2 to find files that have been modified within a specified time
Find. -name "*.log" finds files that end with. Log in the current directory. ". " Represents the current directory
find/opt/soft/test/-perm 777 Find a file with permission 777 in the/opt/soft/test/directory
Find. -type f-name "*.log" finds the normal file when the directory ends with. log. -type D | Sort find normal file when directory ends with. log
Find. -size +1000c-print find files larger than 1K in the current directory
Ind. -name "[a-z]*[4-9].log"-print current directory Find file names start with a lowercase letter, and finally 4 to 9 plus. Log End files
Find. -perm 755-print
Follow the file permission mode with the-perm option to find files by file permission mode
Find/-mtime-5-print look up files with a change of time within 5th
Find/etc-type D-print Find all directories in/etc directory
Find. -size +1000000c-print Find files with file lengths greater than 1 m in the current directory
./etc: Configuration file
/bin: Important Execution file
/dev: Required device files
/lib: Function libraries required for execution of files and modules required by the core
/sbin: Important System Execution files
The data placed within/USR is shareable and non-volatile
/var is the directory that will take up the hard drive capacity after the system is running
The. chmod command is used to change access rights for Linux system files or directories
U: The current user of the directory or file
G: The current group of directories or files
O: Users or groups other than the current user or group of directories or files
A: All Users and Groups
R: Read permission, denoted by the number 4
W: Write permission, denoted by the number 2
X: Execute permission, denoted by the number 1
-: Delete permission, denoted by the number 0
S: Special Permissions
chmod a+x log2012.log Add file All user groups executable permissions
chmod ug+w,o-x log2012.log Simultaneous modification of different user rights
chmod a-x log2012.log Delete file permissions
chmod u=x log2012.log Use "=" To set permissions chmod u=rwx,g=rx,o=x file
Chmod-r u+x test4 Add permissions to all files in a directory and its subdirectories
. Tar compress, unzip, package, unpack
tar[necessary parameters [selection parameters] [file]
Unpacking: Tar xvf Filename.tar
Package: Tar cvf filename.tar DirName
gzip[parameters [file or directory]
Decompression 1:gunzip filename.gz
Decompression 2:gzip-d filename.gz
GZIP-DR Test6 to extract the directory recursively
Compression: gzip FileName
Decompression: Tar zxvf FileName.tar.gz
Compression: Tar zcvf FileName.tar.gz DirName
gzip * Compress each file in the Test6 directory into a. gz file
GZIP-DV * Unzip each compressed file in the previous step
Gzip-l * Displays information for each compressed file in the previous step, and does not understand the pressure
Gzip-r Log.tar compresses a tar backup file, at which time the compressed file has an extension of. tar.gz
GZIP-RV test6 Recursive compression directory
All of the files under test have become *.gz, directories still exist, but the files in the directory become *.gz.

Decompression 1:bzip2-d filename.bz2
Decompression 2:BUNZIP2 filename.bz2
Compression: Bzip2-z FileName
Decompression: Tar jxvf FileName.tar.bz2
Compression: Tar jcvf FileName.tar.bz2 DirName

Decompression 1:bzip2-d filename.bz
Decompression 2:BUNZIP2 filename.bz
Decompression: Tar jxvf FileName.tar.bz

Decompression: Unzip Filename.zip
Compression: Zip Filename.zip DirName

Decompression: rar x filename.rar
Compression: rar a filename.rar DirName
24. Control of the permissions of a file or directory to manage CHGRP [options] [group] [file]
Chgrp -V Othergroup log2012.log change the group properties of the file
Chgrp--reference=log2012.log log2013.log
Group properties that make the file Log2013.log group properties and reference files Log2012.log
Chgrp-r othergroup test changes the group properties of all files in the specified directory and its subdirectories
25. Chown change the owner of the file to the specified user or group, which can be either a user name or a user ID, a group name, or a group ID
chown [options] ... Owner [: [Group]] file ...
Chown tom:toms Log2012.log change owners and groups
Chown:mail log2012.log Change the file group by default is root
Chown-r-v root:toms test6 change the specified target The owner of all files under its subdirectory,
26. The Linux/etc/group file and the/etc/passwd and/etc/shadow
files are files that are related to the management of users and user groups by the system administrator
Cat/etc/group
27. The function of the DF command in Linux is to check the disk space usage of the Linux server's file system
DF Display disk usage
df-i display disk usage in inode mode
df-t ext3 display specified type of disk
Df-ia list I node usage for each file system
Df-t list file system types
Df-h display current disk space and usage in a more readable manner

The du command also looks at the space used, but unlike the DF command, the Linux du command is the space used for files and directory disks
Du displays the space occupied by a directory or file
Du Log2012.log Displays the space occupied by the specified file
Du SCF View the space occupied by the specified directory
Du log30.tar.gz log31.tar.gz shows the space occupied by multiple files
Du-s Show only the sum size
Du-h test easy to read format display
Du-ah test files and directories are displayed
Du-c log30.tar.gz log31.tar.gz shows how many files or directories each occupy the size of disk space
Du|sort-nr|more Sort by Space size
LN is another very important command in Linux, and its function is to create a synchronized link for a file in another location.
ln [parameter] [source file or directory] [destination file or directory]
Ln-s log2013.log link2013 Create soft links to files if Log2013.log is lost, link2013 will expire
ln Log2013.log ln2013 To create a hard link to a file
The diff command is a very important tool on Linux to compare the contents of a file
diff[parameter [file 1 or directory 1][file 2 or directory 2]
Diff Log2014.log Log2013.log Comparison of two files
Diff log2014.log Log2013.log-u Unified format output
Diff test3 Test6 Compare folders different
Date can be used to display or set the system's dates and times
Date
Date ' +%c '
Date ' +%d '
Date ' +%x '
Date ' +%t '
Date ' +%x '

Cal commands can be used to display the Gregorian calendar
Cal Displays the current month calendar
Cal 9 2012 Displays the calendar for the specified month
Cal-y 2013 Show 2013 calendar
Cal-j shows the number of days since January 1
The grep command in a Linux system is a powerful text-search tool that can search for text using regular expressions
grep [option] Pattern file
^ #锚定行的开始 such as: ' ^grep ' matches all lines that begin with grep.
$ #锚定行的结束 such as: ' grep$ ' matches all lines that end with grep.
. #匹配一个非换行符的字符 such as: ' GR.P ' matches gr followed by an arbitrary character followed by P.
* #匹配零个或多个先前字符 such as: ' *grep ' matches all one or more spaces followed by the line of grep.
. * #一起用代表任意字符.
[] #匹配一个指定范围内的字符, such as ' [Gg]rep ' matches grep and grep.
[^] #匹配一个不在指定范围内的字符, such as: ' [^a-fh-z]rep ' matches the beginning of a letter that does not contain a-r and t-z, immediately following the line of the Rep.
\(.. \) #标记匹配字符, such as ' \ (love\) ', Love is marked as 1.
\< #锚定单词的开始, such as: ' \<grep ' matches lines that contain words that begin with grep.
\> #锚定单词的结束, such as ' grep\> ', matches lines that contain words ending with grep.
X\{m\} #重复字符x, M times, such as: ' 0\{5\} ' matches rows containing 5 O.
X\{m,\} #重复字符x, at least m times, such as: ' O\{5,\} ' matches rows with at least 5 O.
X\{m,n\} #重复字符x, at least m times, not more than n times, such as: ' O\{5,10\} ' matches rows of 5--10 O.
\w #匹配文字和数字字符, that is, [a-za-z0-9], such as: ' G\w*p ' is matched with a G followed by 0 or more literal or numeric characters, followed by P.
\w #\w The reverse form, matching one or more non-word characters, such as the dot period, and so on.
\b #单词锁定符, such as: ' \bgrep\b ' only matches grep.
Ps-ef|grep SVN to find the specified process
Cat Test.txt | Grep-f Test2.txt
The output Test.txt file contains the content lines of the keywords read out from the Test2.txt file
Cat Test.txt | GREP-NF Test2.txt
The output Test.txt file contains the line of contents of the keyword read from the test2.txt file and displays the line number of each line
grep ' Linux ' test.txt find keywords from files
grep ' Linux ' test.txt test2.txt find keywords from multiple files
Cat Test.txt |grep ^u Find the line contents that have u start
Cat test.txt |grep ^[^u] Output line contents not beginning with u
Cat test.txt |grep hat$ output line content ending in hat
Cat Test.txt |grep-e "ed|at" displays content lines containing ed or at characters
grep ' [a-z]\{7\} ' *.txt the current directory, ending with. txt
The functionality of the WC (Word Count) command in a Linux system counts the number of bytes in a specified file
WC [Options] File ...
-C Count bytes.
-L counts the number of rows.
-M counts the number of characters. This flag cannot be used with the-C flag.
-W count words. A word is defined as a string separated by a blank, a jump, or a newline character.
-L Prints the length of the longest line.
WC Test.txt View the number of bytes, words, and lines of a file
PS command in Linux is the abbreviation for process status
1. Running (running or waiting in the running queue) R
2. Interrupt (dormant, blocked, waiting for a condition to form or receive a signal) S
3. Non-interruptible (the signal does not wake up and is not operational, the process must wait until there is an interruption) D non-interruptible
4. Zombie (The process has terminated, but the process descriptor exists until the parent process calls WAIT4 () after the system call is released) Z
5. Stop (process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop running) T
Ps-a Show All process information
Ps-u root displays specified user information
PS-EF Displays all process information, along with the command line
Ps-ef|grep ssh PS and grep common use combinations to find specific processes
Ps-l will now belong to your own this log in the PID and related information listed
PS aux lists all currently in-memory programs
The top command is a common performance analysis tool under Linux that shows the resource usage of each process in the system in real time.
The Killall command in a Linux system is used to kill a process with a named name
Killall VI kills all processes of the same name
Kill VI Process: Killall-term VI or Killall-kill VI
The. Free command can display the idle, used physical memory and swap memory in the Linux system, and the buffer used by the kernel
FREE-G displays memory usage in gigabytes.
FREE-M displays memory usage in megabytes.
Iostat in the Linux system is the I/O statistics Iostat tool will monitor the disk operation activity of the system
-C Display of CPU usage
-D Display disk usage
-N Display of disk array (LVM) information
-N Display of NFS usage
-p[disk] Displays disk and partition conditions
-t display terminal and CPU information
Watch can help you monitor the results of a command.
40. In the Linux system you may have found out why the system often does some tasks automatically at the command
The Ifconfig command is used to view and configure network devices
Ifconfig eth0 up ifconfig eth0 down start shutdown specified NIC
Ifconfig eth0 192.168.120.56 to eth0 network card configuration IP ground: 192.168.120.56
Ifconfig eth0 ARP ifconfig eth0-arp enabling and shutting down the ARP protocol
The route command for the Linux system is used to display and manipulate the IP routing table route
The ping command for Linux systems is a common network command
ping [parameters] [host name or IP address]
Ping-c 192.168.120.206 Ping specified number of times
Ping-c 5 www.58.com
The. Telnet command is usually used to Telnet
telnet[parameters [Host]
Service xinetd restart Start Telnet service
The. rcp command used to copy files or directories at the remote end

Linux 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.