Common commands, Common commands in linux

Source: Internet
Author: User

Common commands, Common commands in linux
Search string/search down? Search n up and repeat the above operations
Delete x, which is equivalent to cutting the entire line of backspacedydd and copying the entire line of yy
In the editing status, press the back button. Although the body is still in progress, you can rewrite it.
P paste backward P paste forward
J
1G at the beginning of the document
$ Cursor to the end of a row 0 cursor to the beginning of a row: 16 move to 16 rows
Head-nTail-n
U undo
Set nu/nonu
Ctrl insert copy Shift insert Paste
Find wu *
> Wu. log: delete file content
Mv rename cp copy file Create File


FTP
Switch LCD to local directory
Bin
Put/getMget/mput supports getPrompt of tab * To disable interaction.
Bye


Create a file
Touch creates an empty file, echo
Create directory
Mkdir
Delete an object
Rm
Delete empty directory
Rmdir


The ls-a command lists all contents in the folder, including hidden files starting.
The ls-l command lists the contents of a folder in detail mode (long listing fashion.


Uname-

Linux tecmint 3.8.0-19-generic # 30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686 GNU/Linux


Note: uname indicates the kernel category, and uname-a indicates the details. The above output details the uname-
"Linux": the kernel name of the machine
"Tecmint": the node name of the machine
"3.8.0-19-generic": kernel version released
"# 30-Ubuntu SMP": kernel version
"I686": Processor Architecture
"GNU/Linux": Operating System name
The history command is a historical record. It shows the history of all commands executed in the terminal.



Root @ tecmint :~ # History

1 sudo add-apt-repository ppa: tualatrix/ppa
2 sudo apt-get update
3 sudo apt-get install ubuntu-tweak
4 sudo add-apt-repository ppa: diesch/testing
5 sudo apt-get update
6 sudo apt-get install indicator-privacy
7 sudo add-apt-repository ppa: atareao/atareao
8 sudo apt-get update
9 sudo apt-get install my-weather-indicator
10 pwd
11 cd & sudo cp-r unity/6/usr/share/unity/
12 cd/usr/share/unity/icons/
13 cd/usr/share/unity
Note: press CTRL + R to search for executed commands, which can be automatically completed when you write commands.
1
(Reverse-I-search) 'if': ifconfig


The touch command updates the file access and modification time to the current time. The touch command creates a file only when the file does not exist. If the file already exists, it updates the timestamp but does not change the file content.


Xdecompress tarccreate tarzuse gzip .gz file unzip v show detailed information of decompression process f specify document name t View

Example 1: package all the files in the/etc directory into/tmp/etc.tar
[Root @ linux ~] # Tar-cvf/tmp/etc.tar/etc <= package only, do not compress!
[Root @ linux ~] # Tar-zcvf/tmp/etc.tar.gz/etc <= compressed with gzip
[Root @ linux ~] # Tar-jcvf/tmp/etc.tar.bz2/etc <= compressed with bzip2
# Note that the file name after parameter f is obtained by ourselves. We use. tar for identification.
# If the z parameter is added, .tar.gz or. tgz is used to represent the tar file ~ compressed by gzip ~
# If you add the j parameter, use .tar.bz2 as the file name ~
# A warning message is displayed when the preceding command is executed:
# "Tar: Removing leading '/" from member names "is a special setting for absolute paths.


Example 2: Check the files in the above/tmp/etc.tar.gz file?
[Root @ linux ~] # Tar-ztvf/tmp/etc.tar.gz
# When we use gzip to compress the files in the tar file,
# Add the z parameter! This is important!


Example 3: Decompress the/tmp/etc.tar.gz file under/usr/local/src.
[Root @ linux ~] # Cd/usr/local/src
[Root @ linux src] # tar-zxvf/tmp/etc.tar.gz
# By default, We Can uncompress files anywhere! In this example,
# First, I will transform the working directory to the/usr/local/src directory, and unlock/tmp/etc.tar.gz,
# The unlocked directory will be in/usr/local/src/etc! In addition, if you enter/usr/local/src/etc
# The file attributes in this directory may be different from those in/etc!


Example 4: Under/tmp, I only want to unbind the etc/passwd in/tmp/etc.tar.gz.
[Root @ linux ~] # Cd/tmp
[Root @ linux tmp] # tar-zxvf/tmp/etc.tar.gz etc/passwd
# I can use tar-ztvf to check the file name in the tarfile. If you only need one file,
# You can issue it in this way! Notice! The root directory in etc.tar.gz/is removed!


Example 5: Back up all the files in/etc/and save their permissions!
[Root @ linux ~] # Tar-zxvpf/tmp/etc.tar.gz/etc
# This-p attribute is very important, especially when you want to keep the attributes of the original file!


Example 6: only new files in/home are backed up.
[Root @ linux ~] # Tar-N '2014/1/01 '-zcvf home.tar.gz/home


Example 7: I want to back up/home,/etc, but not/home/dmtsai
[Root @ linux ~] # Tar-exclude/home/dmtsai-zcvf myfile.tar.gz/home/*/etc


Example 8: package/etc/and unpack it under/tmp without generating a file!
[Root @ linux ~] # Cd/tmp
[Root @ linux tmp] # tar-cvf-/etc | tar-xvf-
# This action is a bit like cp-r/etc/tmp ~ It is still useful!
# Note that the output file is changed to-and the input file is changed to-, and there is another file | Yes ~
# This represents standard output, standard input, and pipeline commands respectively!




Example 1: ps aux is the most commonly used
[Root @ localhost ~] # Ps-aux | more
You can use | the MPs queue is connected to more to view it by page;
[Root @ localhost ~] # Ps-aux> ps001.txt
[Root @ localhost ~] # More ps001.txt
This shows all the processes and outputs them to the ps001.txt file. Then, you can view them by page through more;
Example 2: Combine with grep to extract the process of the specified program;
[Root @ localhost ~] # Ps aux | grep httpd
Ps-ef | grep java
Weblogic 282746 254140 1 22:15:35 pts/0/usr/java6/bin/java-Xms256m-Xmx512m-da-Dplatform. home =/home/weblogic/bea103/wlserver_10.3-Dwls. home =/home/weblogic/bea103/wlserver_10.3/server-Dweblogic. home =/home/weblogic/bea103/wlserver_10.3/server-Dweblogic. management. discover = true-Dwlw. iterativeDev = false-Dwlw. testConsole = false-Dwlw. logErrorsToConsole =-Dweblogic. ext. dirs =/home/weblogic/bea103/patch_wls1030/profiles/default/sysext_manifest_classpath:/home/weblogic/bea103/patch_cie660/profiles/default/login-Dweblogic. name = AdminServer-Djava. security. policy =/home/weblogic/bea103/wlserver_10.3/server/lib/weblogic. policy weblogic. server
Weblogic 389290 409808 0 22:28:01 pts/1 grep java


11111111 indicates the current process ID and 22222222 indicates the parent process ID.
# Kill-9 pid // kill-9 11111111, kill the process whose process number is 11111111.
This can be done in a lazy way. In a production environment, we recommend that you do not perform this operation. Use the specified script or command to shut down the process to exit the process safely.


Print working directory: displays the full path of the current working directory on the terminal.
?
1
2
3
Root @ tecmint :~ # Pwd

/Home/user/Desktop
Note: This command is not often used in scripts, but for beginners, it is absolutely a life-saving tool to lose the path in the terminal after a long time from being connected to nux.

Parameter/B matches the pattern if it is at the beginning of the row. /E matches the pattern if it is at the end of the row. /L searches for strings by word. /R uses a search string as a regular expression. Findstr interprets all metacharacters as regular expressions unless/l is used. /S searches for matched files in the current directory and all subdirectories. The/I specified search is case insensitive. /X print the exact matched rows. /V only prints rows that do not contain a match. /N print the row number before each matching row. /M if the file contains a match, only the file name is printed. /O print the search offset before each matching row. /P skips files that contain non-printable characters. /Offline uses offline attribute settings to process files. /F: The File reads the File list from the specified File. /C: String uses the specified text as the text search String. /G: File obtains the search string from the specified File. /D: DirList: List of directories separated by commas. /A: ColorAttribute uses two hexadecimal numbers to specify the color attribute. Strings specifies the text to be searched in FileName. [Drive:] [Path] FileName [...] specifies the file to be searched. /? Display help at a command prompt. Note

Use spaces to separate multiple search strings, unless the parameter is prefixed with/c. To search for "hello" or "there" in file x. y, type:

Findstr "hello there" x. y

To search for "hello there" in file x. y, type:

Findstr/c: "hello there" x. y

To find all the words "Windows" (W uppercase letters) in the file Proposal.txt, type:

Findstr Windows proposal.txt

To search for the current directory containing the word Windows and each file in all subdirectories (case-insensitive), type:

Findstr/s/I Windows *.*

To search FOR all rows that contain the word "FOR" (there can be any space in front, such as loops in computer programs) and include the row numbers that appear each time, type:

Findstr/B/n/c: "* FOR" *. bas

If you want to search for several different projects in the same group of files, create a text file containing each search standard on the new line. You can also list the exact files to be searched in text files. To use the search criteria in the Finddata.txt file to search for the files listed in Filelist.txt and save the Results to the file Results. out, type:

Findstr/g: finddata.txt/f: filelist.txt> results. out

Suppose you want to find every file in the current directory and all subdirectories that contains the word "computer", regardless of the case of letters. To list all files containing the word "computer", type:

Findstr/s/I/m "/<computer/> "*.*

It is assumed that not only the word "computer" needs to be searched, but also all other words starting with the letter "comp", such as "compliment" and "compete ". Enter:

Findstr/s/I/m "/<comp .*"*.*



[Tree Command example]

[Example 1] 
Tree d:> d: \ dTree.txt
Or
Tree d: \> d: \ dTree.txt

Purpose: export all directory structures under the d drive in a tree structure, and save the contents in the d: \ folder as the "dtree.txt" file.

[Example 2] 
Tree d:/f> d: \ dF.txt
Or
Tree d: \/f> d: \ dF.txt

Purpose: export all directories and file structures under the d drive in a tree structure, and save the df.txt file to the d: \ folder.

[Example 3]
Tree C: \ WINDOWS \ system32/f> C: \ s32f.txt

Purpose: export all directories and file structures under C: \ WINDOWS \ system32/f> C: \ s32f.txt in a tree structure, and store the s32f.txt file in the c: \ folder.

[Example 4] 
Tree E: \ BitComet \ Downloads/f> f: \ download \ tree \ dl.txt

Purpose: export all directories and files under E: \ BitComet \ downloads in a tree structure, and save the directory dl.txt in the folder f: \ download \ tree.

[Tree Command considerations]
[NOTE 1] The folder names involved in the TREE Command must not contain spaces
 
For example, commands similar to the following cannot play a role:
Tree C: \ Documents ents and Settings \ Administrator/f> c: \ administrator.txt

To extract the file structure, such as the file structure in the My doc folder of the edisk, You can first enter this directory (e: Press enter first, then cd My doc press Enter), and then use the tree Command to extract:
Tree/f> mydoc.txt

[NOTE 2] understand some default DOS statements for the current prompt
For example, at the prompt E: \ My doc>, you can use the following simple command:
Tree/f> mydoc.txt
Export all directories and file structures under E: \ My doc> in a tree structure, and save mydoc.txt in the folder E: \ My doc.

Note that there is no drive letter or path after the TREE Command. The default value is the path of the current prompt. The exported character ">" is also the same as the default one.

[NOTE 3] The backslash following the path 
(1) At the prompt C: \ Documents ents and Settings \ Administrator>, if you want to export all the file structures of drive C, you must use a command similar to the following:
Tree c: \> c: \ ct.txt

Instead of such commands:
Tree c:> c: \ ct.txt

This command does not export the content of the entire drive C, but the content of the prompt in the path C: \ Documents ents and Settings \ Administrator>.

(2) but in general, the path cannot be followed by a backslash.
For example, if you want to export the structure under D: \ ghost, you cannot use such commands:
Tree D: \ ghost \/f> d: \ ghost.txt
But it can only be:
Tree D: \ ghost/f> d: \ ghost.txt

[NOTE 4] spaces before and after the export operator can be omitted, but spaces before the \ F parameter cannot.
This command is valid: tree D: \ ghost/F> d: \ ghost.txt

This command is invalid: tree D: \ ghost/F> d: \ ghost.txt


Windows:

Dir/s/B | find "str": find the files in the current directory and subdirectory whose names contain str. B only displays the file names.


Tree/f> 1.txt: current file structure; f: list file names


Findstr/s/I/m "str" *. * s recursively queries sub-directories. I is case insensitive and m only displays file names.


Linux


In linux system management, you often need to find files that contain a specific string. This requires the use of the find, xargs, and grep commands in combination to achieve the goal.

The following describes how to use the find, xargs, and grep commands in Linux to find a file containing a specific string and print the file name and path.
It also extends the specific usage of the find command to find files containing a specific string in a specific directory depth.

First, basic usage.

You can use the following command combination to find all the files that contain the "VPSeek" string in the current directory and Its subdirectories.
Example:
 

Find. | xargs grep "VPSeek"

Second, extended usage.

Run the following command to find all the files that contain the "VPSeek" string in the current directory and its first-level subdirectory.
Example:
 

Find.-maxdepth 2 | xargs grep "VPSeek"

Then, you can use the following command combination to find all the files whose names end with "cmd.txt" and contain the string "VPSeek" in the current directory and its first-level sub-directories.
Example:
 

Find.-maxdepth 2-name "*. txt" | xargs grep "VPSeek"


Find.-regex '. * \. txt \ |. * \. doc \ |. * \. mp3'







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.