[Original] Those years of the Linux common commands, simple and clear

Source: Internet
Author: User
Tags svn svn update

Reprinted from: Http://www.cnblogs.com/purediy/p/4288649.html Query related find

Find a file or folder, including subdirectories, by rule

    • find . -name ‘*.sh‘--Files ending with. sh
    • find . -name ‘*channel*‘--File containing the channel character
    • find . -name ‘build*‘--Files that begin with build
    • find . -name ‘abc??‘--a two-character file behind ABC
Grep

Find content that contains the specified template style file, Global Regular Expression Print

    • grep -n pattern files--The rule-n indicates that the line number is displayed
    • grep -n ‘PostsActivity‘ AndroidManifest.xml
    • grep -n ‘\d‘ AndroidManifest.xml
    • grep ‘aapt‘ build-channel.xml--all places where the file contains a string
    • grep -n ‘aapt‘ build-channel.xml--all places where the file contains a string and displays the line number
    • ps -e | grep java--All Java processes
    • ps -e | grep -i qq--All QQ processes, case insensitive
    • find . -name ‘*channel.xml‘ | xargs grep -n ‘aapt‘--Find the place containing the ' aapt ' keyword in a file ending in Channel.xml
    • ls | grep ‘channel‘--Files containing the Channel keyword
which

Searches for the location of a system command in the path specified by the path variable, and returns the first search result

    • which zip
    • which grep
View command Tail

tail [-f] [-c number |-N number |-M number |-B number |-K number] [File]

Writes the file to standard output, starting at the specified point. Using the-f option of the tail command makes it easy to see the log files that are being changed, TAIL-F filename will display the most up-to-date content on the screen, and constantly refresh to keep you updated on the contents of the file.

    • tail -f test.log, loop through the contents of the file, CTRL + C to terminate
    • tail -n 5 test.log, showing the last 5 lines of the file
    • tail -n +5 test.logTo display the file starting from line 5th
More

more [-DLFPCSU] [-num] [+/pattern] [+linenum] [File ...]

The more commands and the cat function are the same view of the contents of the file, but the difference is that more can be viewed by the page to view the contents of the file, but also support the function of direct jump.

    • more +3 test.logTo display the contents of the file from line 3rd
    • more -5 test.log, set the number of rows per screen displayed
    • ls -l | more -5, showing 5 file information per page
    • more +/day3 test.log, find the first line that appears with a "day3" string, and start displaying the output from the previous two lines
Less

less [options] [File ...]

As with the more command, the less command is also used to display the contents of a file on a split screen. But there is a difference: the less command allows the user to navigate forward or backward through the file, while the more command can only be browsed forward. When displaying a file with the less command, use the PageUp key to page up and PAGE down with the PageDown key. To exit the less program, you should press the Q key.

    • less test.log, view files
    • ps -ef | lessTo view process information and display it via less paging
    • history | less, view the command history usage record and display it through less paging
    • less test1.log test2.log, browse multiple files, n and p toggle files
Watch

Watch [Options] Command

Run a command repeatedly at intervals of 2 seconds at a time. The command to run is passed directly to the shell (note the reference and escape of special characters). The results will be shown in full screen mode, so you can easily observe the changes

    • watch -n 60 date, execute the date command once every minute, enter ^c exit
    • watch -d ls -lTo view directory changes
    • watch -d ’ls -l | fgrep joe’, you want to find the files for Joe's users
    • watch -d ‘ls -l|grep scf‘To monitor changes in SCF ' files in the current directory
    • watch -n 10 ‘cat /proc/loadavg‘, 10 seconds The average load of the output system
    • watch -n 1 -d netstat -ant, highlighting changes in the number of network links every second
    • watch -n 1 -d ‘pstree | grep http‘, highlighting changes in the number of HTTP links every second
File Related VI

VI File

    • Press the I key to enter edit mode
    • Press the ESC key to enter command mode

      :w   保存文件但不退出vi :w file 将修改另外保存到file中,不退出vi:w! 强制保存,不推出vi:wq 保存文件并退出vi:wq! 强制保存文件,并退出viq: 不保存文件,退出vi:q! 不保存文件,强制退出vi:e! 放弃所有修改,从上次保存文件开始再编辑
chmod

Change mode, changing the read, write, and run permissions for a file or directory

chmod [-CFVR] [--help] [--version] Mode file ...

    • mode:权限设定字串, the format is as follows: [Ugoa ...] [[+-=][RWXX] ...] [,...]
    • uRepresents the owner of the file, g indicating that it belongs to the same group (group) as the owner of the file, indicating that the o a three persons are
    • +Represents an increase in permissions, a - cancellation permission, and a = unique set of permissions.
    • rRepresents a readable, writable, executable that indicates that the w x X file is a subdirectory or that the file has been set to be executable.
    • chmod也可以用数字来表示权限, the syntax is: chmod ABC file, such as chmod 777 file
    • 其中a,b,c各为一个数字, which represents the permissions for user, Group, and other respectively. R=4,w=2,x=1
    • chmod 777 file, equivalent to chmod a=rwx file
    • chmod ug=rwx,o=x file, equivalent to chmod 771 file
    • chmod 4755 filename, which gives the program root privileges
    • ls -lTo view file permissions that list the current user
Zip

Zip-r Filename.zip Filesdir

    • zip -r test.zip ./*, compress all current files to Test.zip
    • zip -r test.zip testAll files and directories of the test file, if you go to Test.zip
    • zip -d test.zip test.txt, delete the Test.txt file in the compressed file
    • zip -m test.zip ./test.txt, add the Test.txt file to the Test.zip in the compressed file
    • zip -r test.zip file1 file2 file3 filesdir, processing multiple files and directories, separated by spaces
Unzip
    • unzip zip-file, unzip to the current directory
    • unzip -d dst-dir zip-file, unzip to the specified directory, and d to the specified directory
    • unzip -n zip-file, do not overwrite the existing file,-N to not overwrite the original file
    • unzip -n -d dst-dir zip-file, extract to the specified directory, do not overwrite the existing file
    • unzip -o -d dst-dir zip-file,-o don't have to ask the user to overwrite the original file
    • unzip -l zip-fileTo view only the files contained within the compressed file
Tar
    • tar cvf test.tar test, make all the files and directories under test备份
    • tar czvf test.tar.gz test, and make all the files and directories under test 备份压缩
    • tar xzvf test.tar.gz, put this backup file 还原 and解压缩
    • tar tvf test.tar | more, 查看 back up the contents of the file and display it on the monitor in a split-screen manner
    • tar czvf test.tar.gz test --exclude=test/svn, 备份压缩 and 排除 directory
Touch Memory Related PS

Shows the dynamics of the instantaneous stroke (process), PS [options] [--help]

    • ps -A, list all the processes
    • ps -w, display widening can show more information
    • ps -auTo display more detailed information
    • ps -auxTo display all processes (including other users)
    • PS Command Detailed
    • PS Command Introduction

There are 5 states of processes on Linux:

    1. Running (running or waiting in the running queue)
    2. Interrupt (dormant, blocked, waiting for a condition to form or receive a signal)
    3. Non-interruptible (Received signal does not wake up and cannot be run, process must wait until interrupt occurs)
    4. Zombie (The process has been terminated, but the process descriptor exists until the parent process calls WAIT4 () after the system call is released)
    5. Stop (process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop running)
Top

Changes in the dynamic observer program, top [-d] | Top [-BNP]

    • top -d 2, updated every two seconds
    • top -b -n 2 > /tmp/top.txt, make the top information 2 times, and then output the result to/tmp/top.txt
    • top -d 2 -pid 10604, observing only the PID=10604 program
    • Top Command Introduction
Free

free [options]

The free command displays the idle, used physical memory and swap memory in the Linux system, and the buffer used by the kernel. In Linux system monitoring tools, the free command is one of the most frequently used commands

    • free -m, showing memory usage in megabytes
    • free -g, showing memory usage in gigabytes
    • free -s 10, periodically querying memory usage information
Kill

Kill [-S signal_name] pid ...

Sends the specified signal to the corresponding process, the kill utility sends a signal to the processes specified by the PID operand (s)

    • kill -l, List all signal names
    • kill -l SIGKILL, the value of the specified signal is obtained, sigkill=9
    • kill -9 pid, a forced abort process, a powerful and dangerous command that forces the process to terminate abruptly at run time, and the process cannot clean itself up after the end. A hazard is a system resource that is not normally released, and is generally not recommended unless other methods are invalid.
    • kill -HUP PID, stop and restart the process, which shuts down the Linux gentle execution process and then restarts immediately. This command is handy when configuring the application, which can be executed when the configuration file is modified to restart the process.
    • kill -l PIDTo end the process gracefully, the-l option tells the kill command to end the process as if the user who started the process was logged off. When this option is used, the kill command also attempts to kill the left child process. But this command is not always successful--you may still need to manually kill the child process before killing the parent process.
    • ps -ef | grep vim, find process
Network-related pings

ping [parameters] [host name or IP address]

Determine the status of networks and external hosts, track and isolate hardware and software issues, and test, evaluate, and manage networks.

    • ping -b 192.168.1.1, Ping the Gateway
    • ping -c 10 192.168.1.2, ping specified number of times
    • ping -c 10 -i 0.5 192.168.1.2, interval and number of times limit the ping
    • ping -c 5 www.baidu.com, Ping the site through the domain name on the public website
Netstat

Netstat [-accefghilmnnoprstuvvwx][-a< network type >][--IP]

Used to display statistics related to IP, TCP, UDP, and ICMP protocols, and is typically used to verify the network connectivity of each port on the machine.

    • netstat -a, List all ports
    • netstat -nuTo display the current UDP connection status
    • netstat -apuThat shows the use of UDP port numbers
    • netstat -i, display the list of network cards
    • netstat -g, show the relationship of the multicast group
    • netstat -s, Display network statistics
    • netstat -l, display the listening socket
    • netstat -nTo show all valid connections that have been established
    • netstat -e, display statistics about Ethernet
    • netstat -rTo display information about the routing table
    • netstat -at, List all TCP ports
    • netstat -ap | grep sshTo find out which port the program is running on
    • netstat -ptTo display the PID and process name in the Netstat output
    • netstat -anpt | grep ‘:16064‘To find the process running on the specified port
Telnet

telnet[parameters [Host]

Perform the Telnet command to open the terminal stage job and log in to the remote host.

    • telnet 192.168.120.206
    • service xinetd restart, start the Telnet service
Ifconfig

ifconfig [Network Devices] [parameters]

The Ifconfig command is used to view and configure network devices. This command can be used to configure the network appropriately when the network environment changes.

    • ifconfig -aShow all interface information
    • ifconfig -sDisplay summary information (similar to netstat-i)
Tool Command SVN
    • svn co path --username name --password password
    • svn co -path -dirname
    • svn add file
    • svn update -r m path
    • svn update -r 200 test.php, update to a version
Cvs
    • cvs history -ca | grep username | grep 01-01
    • cvs history -ca | grep username | grep kp | grep 2012-10-‘[1 2][0-9]‘
Ant

ant-arguments [Target1,target2,target3,target4 ...]

Ant build files are able to compile, package, and test the project. If you do not specify any parameters, ant will retrieve the Build.xml file in the current directory, run the file if it is found, and if it does not, you will be prompted not to find the relevant Build.xml file.

    • ant -h, which indicates that the ant command parameter task is provided
    • ant -projecthelp | -pThat shows the main tasks of the current build.xml, such as show clean, release
    • ant -versionTo display the current ant version
    • ant -diagnosticsTo diagnose all of the current ant's configurations
    • ant -debug | -dTo retrieve the current build file configuration
    • ant -quiet | -q, showing no dependent tasks for the current build file
    • ant -emacs | -e, call Edit Current build file Editor
    • ant -lib [path], call the Jar,class file in the current project
    • ant -logfile |-lCalled to run the *.log file in the current project
    • ant -buildfile |- f | -file, call a file that runs like Build.xml
    • ant -propertyfile [name], the call runs the specified property file
    • ant -find | -s fileTo retrieve a run of the specified build file
    • ant -autoproxyTo build files using System Auto Proxy
    • ant-main class, set the main class in the System class library file
    • ant -nice number, set the number of threads allowed for the main class thread
Maven
    • mvn archetype:create, create a Maven project
    • mvn compile, compiling the source code
    • mvn test-compile, compile the test code
    • mvn test, run the unit tests in the application
    • mvn site, a Web site that generates information about the project
    • mvn cleanTo clear the build results from the target directory
    • mvn packageTo generate a jar file based on the project
    • mvn install, install the jar in the local Repository
    • mvn eclipse:eclipse, build the Eclipse project file
    • mvn -Dmaven.test.skip=true, ignoring the test document compilation
adb
    • adb kill-server
    • adb start-server
    • adb devices
    • adb uninstall file
    • adb uninstall -k file,-K parameter, for uninstalling software but preserving configuration and caching files
    • adb push <本地路径> <远程路径>, you can copy the files or folders on the computer to the device (mobile)
    • adb pull <远程路径> <本地路径>, you can copy the files or folders on the device (mobile phone) to the local computer
    • adb reboot, restart ADB

[Original] Those years of the Linux common commands, simple and clear

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.