Linux Common Commands

Source: Internet
Author: User
Tags bz2 clear screen create directory rar

1

A real-time log tracking active refresh to ensure that you see the latest archive content.
Format: tail-f filename Full name By default it displays the last ten lines of the file.
Such as:
Cd/app/log/passage
Tail-f Passage.log Real-time log tracking
Tail-f-N Catalina.out starting from the last 100 lines

Two. VI File Editor
VI test.txt
Explanation: If the file is not there, create the file and enter the command mode
Go straight to command mode if you have one.
Press the I key to enter the edit input mode input content
Press the ESC key to return to command mode
Input: Wq file Save and exit, if not save: Q can

VI three operation states, namely command mode, insert mode and bottom line command mode

Three. File deletion
File deletion format: RM file name

Four. Delete the directory and all of its files, folders
RM-RF command
-R is recursive down, no matter how many levels of directory, delete
-F is directly forcibly deleted, without any hint of meaning

Example: rm-rf/var/log/httpd/access/will delete the access directory and all of its files, folders
such as: Rm-f/var/log/httpd/access.log will force the deletion of Access.log this file
RM-RF *

#删除当前目录下所有文件, exclude Delete.bat
RM-RF ' ls *.| Egrep-v Delete.bat '
RM-RF *.log
RM-RF session/fixco*

Five. To delete an empty directory
RmDir dir1 Delete a directory called ' Dir1 '

Six. Text File view and connect tool.
Cat
Cat is a text file viewing and linking tool. To view the contents of a file, it is easier to use cat
The file name is followed directly.
For example: Cat passage.properties

A different way
Format more
Example: More ' nollpointerexception ' Datashift.log > Temp.log
More will be a page-by-page display to facilitate users to read pages, and the most basic instruction is to press the blank key (space) on the next page,
Press the B key to go back one page, and there is also the function of the search string. The more command reads the file backwards from the front, so
Example input: 200 can scroll a certain number of pages or: 100
Loads the entire file when it starts.
Example: More config.ada.php | grep ' [email protected] '
View config.ada.php all content and show [email protected] where
grep ' data/000592.csv:2016-01-27 ' 1.txt
Or: Cat config.ada.php | grep ' [email protected] '

Seven. Directed output to File
Format >
> is directed output to a file, if the file does not exist, the file is created, if the file exists, it is emptied;
such as: Ping 192.168.120.204 > Test.log
Ping the remote host in the background. and output files to Test.log;
This practice also makes use of more than one file to monitor. Use CTRL + C to terminate.

The output is appended to the destination file
Format >>
such as: Echo ' Test pitfalls ' >> test.log
will be at the end of the Test.log file the best test hidden words

Eight. View process Status
Format PS
The PS command is used to list those processes that are currently running on the system. The PS command lists the current snapshots of those processes,
is the process of executing the PS command at that moment, if you want to display the process information dynamically, you can make
With the top command.
such as: Ps-ef|grep Passage
View the status of the passage package process

Nine. Kill a process kill XXX
Example: Kill-9 324

10. Upload local files to Linux
Format: rz-be
The dialog box opens and is automatically uploaded to your directory when you select it.

Download files from Linux to a local directory
Format: SZ filename

#下载一个文件
SZ filename
#下载多个文件
SZ filename1 filename2
#下载dir目录下的所有文件, does not contain a folder under Dir
SZ dir/*

The download file location needs to be set in SECURTCRT, the following steps are set:
Option--"answer option--" X/y/zmodem


Eleven. File move
Format: MV
such as: MV Test.log. /addr
such as: MV Mongodb-linux-i686-2.0.7/usr/local/mongodb
Move the Test.log to the parent directory addr

Twelve. Search for matching characters in a file
Format grep ' bytes ' *log
Format more ' bytes ' *log
In the current directory, look for bytes in all files ending in log


13. Zip compression and decompression
1. Such as: Unzip Mongodb-win32-i386-2.6.5.zip
Unzip the mongodb-win32-i386-2.6.5.zip into the current directory

2. Such as: Zip-r xiaoma.zip mongodb-win32-i386-2.6.5
Compress the mongodb-win32-i386-2.6.5 file into a xiaoma.zip
Or: Zip-r abc123.zip ABC 123.txt
The directory below the ABC folder and 123.txt compression to become abc123.zip

Tar decompression
1 such as: TAR-ZXVF server-user-service-1.0.0.0.dist.tar.gz
Unzip the server-user-service-1.0.0.0.dist.tar.gz to the current directory

14. Copy all files in the specified directory to another directory
Format: cp-r source file or directory destination file or directory

xv. Build sh file
Touch test.sh

Granting file permissions
chmod u+x test.sh

16. Telnet
Example: Telnet 192.168.1.108 3306

17. Handling of documents too large

Find VI Data_w.log
View logs (top and bottom keys)
Pressed/Down key
Enter a keyword to find
Ctrl+b return to the previous screen;
CTRL+F scroll down one screen;

The tail of the file
Less Data_w.log
View logs (top and bottom keys)
shift+g keys roll directly to the tail

18. Script Start and stop
Example script name deploy.sh
Start./deploy.sh or SH deploy.sh
Stop SH cloud.sh stop

19. The search process contains the Invest
PS aux | grep Invest

20. Check if the port is occupied
NETSTAT-ANOPTL | grep Port number

Demonstrate
See if Port 8120 is occupied
[Email protected] invest]# NETSTAT-ANOPTL | grep 8120
TCP 0 0 0.0.0.0:8120 0.0.0.0:* LISTEN 20430/java off (0.00/0/0)

View specific port 8120 is used by that application
PS aux | grep 20430

21. View all the files in the directory to occupy memory
Du-sh

"System administration Commands"
Who shows online login
Clear Clear Screen
Hostname Display host name
Top dynamic display currently consumes the most resources process information
DF View disk size df-h with unit display disk information
Ifconfig Viewing network conditions
Ping Test network connectivity
Netstat Displaying network status information
Kill kills the process, you can first view the process ID with the PS or Top command, and then kill the process with the kill command.
History view historical commands for input

VI FileName: Opens or creates a new file and places the cursor at the beginning of the first
VI filename....filename: Open multiple files, edit them sequentially

Linux View folder size

Du-sh viewing the current folder size
Du-sh * | Sort-n Statistics the current folder (directory) size and sort by file size

See how many files and folders are in the directory to be entered in the terminal
ls | Wc-w


Linux Common Command Daquan
Date Displays the system date
Cal 2007 Displays the 2007 calendar table
Date 041217002007.00 sets the day and time of day-the year of the month. seconds
Clock-w saving time changes to the BIOS

Shutdown (System shutdown, restart, and logout)
SHUTDOWN-H now shut down system (1)
Init 0 Shutdown System (2)
Telinit 0 Shutdown System (3)
Shutdown-h Hours:minutes & Shutdown system at scheduled times
Shutdown-c Cancel the system at a predetermined time
Shutdown-r now restart (1)
Reboot restart (2)
Logout logoff
Top View CPU consumption

"Files and Directories"
Cd/home into the '/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-Return 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 displaying details of files and directories
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 displaying files and directories starting with the root directory tree (2)
mkdir dir1 Create a directory called ' Dir1 '
mkdir dir1 DIR2 Create two directories at a time
Mkdir-p/tmp/dir1/dir2 Create a directory tree
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 Renaming/Moving 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 en Coded 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 from '/' to the root file system to search for files and directories
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 file or executable file

"Packaging and compressing files"
BUNZIP2 file1.bz2 Extract a file called ' file1.bz2 '
bzip2 file1 compress a file called ' File1 '
Gunzip file1.gz Extract 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 simultaneously compresses ' file1 ', ' file2 ' and directory ' Dir1 '
rar x File1.rar decompression rar Package
Unrar 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 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 releases the compressed package into the/tmp directory
TAR-CVFJ archive.tar.bz2 Dir1 Create a compressed package in BZIP2 format
TAR-XVFJ archive.tar.bz2 extract a compressed package in BZIP2 format
TAR-CVFZ archive.tar.gz Dir1 Create a zipped package in gzip format
TAR-XVFZ archive.tar.gz Unzip a compressed package in gzip format
Zip file1.zip file1 Create a zip-format compression Package
Zip-r file1.zip file1 file2 Dir1 compresses several files and directories into a zip-format package at the same time
Unzip File1.zip unzip a zip-format tarball


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 that is added to a file

Return Top Index ^

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 Find the keyword "/var/log/messages" in the file '
grep ^aug/var/log/messages in file '/var/log/messages ' to find words that begin with "."
grep [0-9]/var/log/messages selects all rows in the '/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 excluding the first line from the file Example.txt
Sed-n '/stringa1/p ' view lines that contain only the word "string1"
Sed-e ' s/*$//' example.txt remove the last white space character from each line
Sed-e ' s/stringa1//g ' example.txt only removes the word "string1" from the document and retains all remaining
Sed-n ' 1,5p;5q ' example.txt view the contents from the first line to the 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, in the middle with "+" distinction
Sort file1 file2 Sorting two contents of a file
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 that are common to each other

*********************************************************************************************************
Common directives

LS Display file or directory
-l list File details L (list)
-a lists all files and directories under the current directory, including Hidden A (all)
mkdir Creating a Directory
-P Create directory, if no parent directory, create p (parent)
CD Switch Directory
Touch creates an empty file
echo Print Content
Cat View File Contents
CP Copy
MV Move or rename
RM Delete File
-R Recursive Delete, can delete subdirectories and files
-F Force Delete
Find searches a file system for a file
Grep finds a string in a text file
RmDir Delete Empty Directory
Tree structure display directory, need to install tree package
PWD Displays the current directory
LN creates a linked file
More, less pagination displays text file contents
Head, tail display file header, tail content
CTRL+ALT+F1 command line full-screen mode

Shut down/Restart the machine

Shutdown
-R shutdown Restart
-H shutdown does not restart
Now turn the machine off.
Halt shut down the machine
Reboot restart

Vim use
Vim three modes: Command mode, insert mode, edit mode. Use ESC or I or: to toggle the mode.
Command mode:

: Q exit
: q! Force exit
: Wq Save and exit
: Set number Displays line numbers
: Set Nonumber hidden line number


File Rights Management
Three basic permissions
R read value represented as 4
The W write value is represented as 2
X executable value represented as 1

Http://blog.sina.com.cn/s/blog_64e166580100vwk2.html

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.