Common command usage for Linux Basics (i)

Source: Internet
Author: User

First, the Linux file directory structure

Before the narration, the first short talk about the Windows file structure, open ' computer ', see a drive (letter, example C, D, etc.), click on any of the characters, see a file or folder, continue to open ..., each disk has its own root directory. If the opening process to draw down, you can get the following trees and parallel to the graph: 650) this.width=650; "Src=" Https://s3.51cto.com/wyfs02/M01/07/50/wKiom1nHhRyDp_ Ysaabh6-y85by188.png-wh_500x0-wm_3-wmp_4-s_4205401710.png "alt=" for "title=" Windows Files Wkiom1nhhrydp_ Ysaabh6-y85by188.png-wh_50 "/>

And under Linux, see is the folder (directory), Ubuntu No disk selector said, only a root directory (/expression), the same draw down:

Some readers may wonder: Linux is a multi-user operating system, more secure, and there is only one root file, that is, all users under the root directory, that user A can arbitrarily modify one of the files, for User B may be affected, how can it be safe? Cause: When creating different users, Linux will default to generate groups with the same name (group), each group and each user within the group has the appropriate operation permissions, generally speaking, ordinary users do not have permission to modify other groups of users or system information (such as password Authentication, administrator rights, file directory permissions, etc.), Therefore, multiple users in the same root directory is generally not entitled to group cross-permission to change the system, its group information. For example: With the earth as the root directory, each family for the group, the family members for the group of users; Xiao Wang, Xiao Wu is a good neighbor, one day, Xiao Wang want to go to Xiao Wang's home to borrow salt, the premise is to enter the small Wu's home, will have Xiao Wu's permission, enter after, but also to get the salt Linux is the same, so Linux is still safe.

Ii. common file and directory commands

1). Terminal command Format: commands [-options] [parameters]

Command: corresponding function english word or abbreviation

-Options: Command selection control [Note: There is a front bar]

Parameters: Add range to command

The brackets indicate that they can be omitted, for example:

$ls

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/07/51/wKiom1nHkr3igievAAAGxhNH38s153.png-wh_500x0-wm_ 3-wmp_4-s_4125576302.png "title=" 3.png "alt=" Wkiom1nhkr3igievaaagxhnh38s153.png-wh_50 "/>

$ls-ll

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/07/51/wKiom1nHk3bS4gpLAAAQiaBjTTY370.png-wh_500x0-wm_ 3-wmp_4-s_2467133793.png "title=" 5.png "alt=" Wkiom1nhk3bs4gplaaaqiabjtty370.png-wh_50 "/>

$ls-L test.py

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/A6/01/wKioL1nHkqvBl5q_AAAT92QDiXQ113.png-wh_500x0-wm_ 3-wmp_4-s_639557021.png "title=" 4.png "alt=" Wkiol1nhkqvbl5q_aaat92qdixq113.png-wh_50 "/>


2). Help command

Command--help or the man command (note: This is a double-slash, man is a shorthand for manual, which contains most of the Linux commands as instructions for use)

Such as:

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/A6/02/wKioL1nHlNXi21GMAABNGWZ8EPw541.png-wh_500x0-wm_ 3-wmp_4-s_4166231461.png "title=" 6.png "width=" "height=" 242 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:400px; height:242px; "alt=" Wkiol1nhlnxi21gmaabngwz8epw541.png-wh_50 "/>

3). Check and Change Operation command

touch/mkdir/rm/ls/pwd/cat/find/grep/more/Redirect, etc.

Touch: Create a new file, if the file exists, the time of the last operation to change the cost of time, the content is unchanged mkdir: New folder (directory), note that there is no duplicate name phenomenon

$touch a path under xxx1 xxxx2 ....

$mkdir a path under yyy1 yyy2 ....

Note: Both support batch creation and can specify a path

rm:remove abbreviation for deleting files, plus option-R forcibly deletes the folder, including its child content

Change command not recoverable (cannot be undone)

Ls:list abbreviations, see the contents of the directory (examples above)

There are common options for-a,-l,-H,

- A: Displays all subdirectories and files in the specified directory, including hidden;

-L: Displays detailed information in a list;

- H: Match-L Displays the size of the file in a list

Tree: Displays the hierarchical relationships under the current directory, option-D shows only the directory-level relationships, or you can specify a directory

$tree

$tree-D

$tree-D A directory under a specified path

PWD: Displays the absolute path to the current directory, print working directory

Echo: Display content to the screen, acting like a mirror

$echo Hello.

650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M01/07/52/wKiom1nHpHXzXkr9AAACBnERh10176.png-wh_500x0-wm_ 3-wmp_4-s_583180622.png "title=" 7.png "alt=" Wkiom1nhphxzxkr9aaacbnerh10176.png-wh_50 "/>

Cat: View the contents of a file, create a file , merge files, append file content, and so on (there is no first create, then merge append, there is a direct operation), often with the pipeline (next to tell) with the use. Options are n-and-B, respectively, to enter the line number of the travel and non-blank lines, for example

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/A6/03/wKioL1nHppXgQU_eAAAIfaJtVAU577.png "title=" 8.png "Width=" 262 "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:262px;height:100px; "alt=" wkiol1nhppxgqu_ Eaaaifajtvau577.png "/>650) this.width=650;" Src= "https://s5.51cto.com/wyfs02/M02/A6/03/ Wkiol1nhqrlzhmr3aabjts8vejy389.png "title=" 8.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:300px;height:220px; "alt=" Wkiol1nhqrlzhmr3aabjts8vejy389.png "/>

History: View this historical command entered in the terminal.

Cd:change directory, users switch directories;

CD ~ and CD switch to the current user's home directory (/home/user directory, root directory/home directory) location

CD.. Top level directory

CD. current directory

CD-Switch back and forth between the current and previous directories

Find: Powerful search command to search for eligible files or directories under a specific directory.

Find [path]-name "Regular expression"

To find files ending in py in the current directory: $find-name "*.py"

grep: Powerful text Search tool, often used in conjunction with piping.

There are often-N,-I options, which display line numbers that match the criteria [regular expression] row,-I ignores case,

Pipe: by | means the output of one command is piped as input to another command.

Example: $cat 1.txt 2.py | 4.txt: Input 1.txt and 2.py content to 4.txt

$cat 4.txt: Prints the same results as 3.txt

$cat 1.txt 2.py | grep ' ghd ': No file name is specified on the right side of the pipe, the system will temporarily put the left result in the buffer, then go to the buffer to find the line that matches the condition ' ghd ' string

Redirect: Redirects execution results to a file. There are > and >> two ways, the former represents the output, will overwrite the original content of the file, the latter means append, append the content to the end of the existing file. Such as

$1.txt 2.py > 4.txt: The result on the left will overwrite the contents of the right file

$1.txt 2.py >> 4.py: The left result is appended to the end of the right side of the content and does not overwrite

MORE: The function is similar to cat, but in the case of many file contents, more can be split screen control display, Cat relative visual experience is not good enough. Options: Space bar,-B,-F, enter key, p: The role is to display the next screen, roll back one screen, roll one screen, scroll the next line, exit.

$more Xxx.log: Split-screen display of log content

$more Ifconfig | grep inet: Temporarily puts the ifconfig NIC information into the buffer and uses grep to find the inet information (that is, the IP address), and note that you use Ipconfig to view the network card information in Windows.

Summary: A) If the Linux command ignores the path, the current path is used by default;

b) Some commands are available with multiple functions, such as cat, which does not exist then creates the file before performing the response operation

c) Redirect, more, grep, no file specified, default action buffer

D) Say 1000 10,000, important things say three times: hands-on practice, hands-on practice, hands-on practice, only repeated to practice, can be impressive, remember: practice out of the truth!

Note: This article is encoded in Ubuntu virtual machines by default, and will be done in Ubuntu if no special notes are made in the future.

(If you have not installed a Linux virtual machine friend can refer to: Install Ubuntu system in VMware virtual machine)

---in the next article: will continue to explain Linux common commands (ii)-----

If there are deficiencies or errors in the article, I sincerely hope that you put forward comments, suggestions, I will improve as soon as possible, thank you O (∩_∩) o Thank you

This article is from the "Getting Started with Python" blog, so be sure to keep this source http://1710161254.blog.51cto.com/10607212/1968256

Common command usage for Linux Basics (i)

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.