Linux command learning (1)

Disclaimer: Since it has not been sorted out, it will continue to be released in the future!

Linux command line

Chapter One:

Ubuntu terminal uses bash by default

Tab key: Autocomplete command

Open Terminal:  Ctrl + Alt + T

Close the terminal:  Ctrl + D

 

1Forcibly close the currently running program: Ctrl + C

2 Pause the current program, press any key to resume running after pause : Ctrl + S

3 Put the current program into the background to run, and restore to the foreground as the command fg : Ctrl + Z

4 Move the cursor to the beginning of the input line , equivalent to the Home key : Ctrl + A

5 Move the cursor to the end of the input line , equivalent to the End key : Ctrl + E

6 Delete from the cursor position to the end of the line : Ctrl + K

7 Delete one word forward : Alt + Backspace

8 Scroll the terminal display up : Shift + PgUp (progressive forward and backward)

9 Scroll the terminal display down : Shift + PgDn

 

Chapter two:

1 History input:  up and down keys

2 wildcards :

character

meaning

*

matches zero or more characters

?

matches any character

[list]

matches any single character in list

[!list]

matches any character other than any single character in list

[c1-c2]

Match any single character in c1-c2 such as: [0-9] [az]

{string1,string2,...}

matches one of string1 or string2 (or more)

{c1..c2}

Match all characters in c1-c2 such as {1..10}

 

3 Get help at the command line : man <command_name>

segment

illustrate

1

general order

2

system call

3

Library functions, covering the C standard library

4

Special files (usually devices in /dev) and drivers

5

File formats and conventions

6

Games and Screensavers

7

Miscellaneous

8

System Administration Commands and Daemons

 

To view the content of the corresponding section, just add the number of the corresponding section after man :

man 1 ls

Usually there is a lot of content in the man manual, and it may not be easy for you to find the results you want, but fortunately you can use search /<keyword you want to search for> in man, and you can use the n key to switch after searching To the location of the next keyword, shift+n is the location of the previous keyword. Use Space to turn pages, Enter to scroll down a line, or j,k ( the vim editor's movement keys) to scroll forward and backward. Press the h key to display the help (because man uses less as the reader, which is actually the help of the less tool), and press q to exit.

 

4 If you know what a command does and just want to quickly see what some of its specific parameters do, you can use the --help parameter :

ls --help

 

5 Command banner to output graphic characters : sudo apt-get install sysvbanner

 

 

third chapter:

1 View user: who

parameter

illustrate

-a

print everything that can be printed

-d

print dead processes

-m

同am i,mom likes

-q

Print the number of currently logged in users and their usernames

-u

Print the login information of the currently logged in user

-r

print runlevel

Who -m =whoami

 

2 Create users --> View users --> Delete users (basically useless):

su <user>  can switch to the user user, and you need to enter the password of the target user when executing. sudo <cmd>  can run the cmd command at the privilege level, the current user needs to belong to the sudo group, and the password of the current user needs to be entered. The su - <user>  command also switches users, and the environment variables will also be changed to the environment variables of the target user. [It is not used in general, it is just one user on one computer, you can skip it]

 

3 file permissions

Ls -l long format output

 

 

 

4 Read permission : cat <file name>

A directory must have both read and execute permissions to open and view internal files, and a directory must have write permissions to allow other files to be created in it .

5 ls other commands:

. (current directory) and .. (upper directory) ; ls -Al ; ls -dl <directory name> ;

ls -AsSh : ( displays all file sizes and presents them in a way that normal humans can understand )

The small s is to display the file size, and the large S is to sort by file size. If you need to know how to sort by other ways, please use the "man" command to query.

6 Change the owner of the file : ( shiyanlou , iphone6 ​​are both a file)

sudo chown shiyanlou iphone6

7 Modify file permissions:

 

Chapter Four:

1 FHS ( File System Hierarchy Standard ) defines two layers of specifications. The first layer is, what file data should be placed in each directory under /, for example, / etc should be placed in setting files, /bin and /sbin should be placed in executable files. documents, etc.

The second level is defined for the subdirectories of the two directories /usr and /var . For example , /var/log holds system log files, /usr/share holds shared data, and so on.

 

 

2 cd . Current directory      cd .. Return to the previous directory

indicates the last directory, ~  usually indicates the home  directory of the current user. Use the pwd  command to get the current path (absolute path)

3 The touch command creates a blank file

4 mkdir (make directories) command can create an empty directory ; -p parameter  multi-level directory to create mkdir -p father/son/grandson

5 Use the cp (copy) command to copy a file to the specified directory ; cp -r (-R) command to copy a directory

6 Delete files or file directories :  rm -rf family  ( -f ignores the prompt , -r deletes the directory)

7 Move files: mv source directory file destination directory ;

rename  mv old filename new filename

8 Batch  rename rename

 

9 View files

View files with cat, tac and nl commands

cat -n filename ( -n displays line numbers)

 

Use the more and less commands to page through files

View files with head and tail commands

tail -n 1 filename (-n to see how many lines)

tail -f dynamic real-time display of content

Edit file: vim; vim tutorial (vimtutor: terminal run)

exit closes the terminal similar to crtl + D

 

 

chapter Five:

1 Environment variables

There are usually three types of variables we will involve:

The current shell process private user-defined variable .

variables built into the shell itself.

Environment variables derived from custom variables.

There are also three commands related to the above three environment variables: set, env, export. These three commands are very similar, all of which are used to print environment variable information, the difference is that the scope of the variables involved is different. See the table below for details:

Order

illustrate

set

Displays all variables of the current Shell, including its built-in environment variables (related to Shell appearance, etc.), user-defined variables and exported environment variables.

env

Displays environment variables related to the current user, and also allows commands to run in a specified environment.

export

Displays variables exported as environment variables from the shell, and can also export custom variables as environment variables through it.

 

 

 

Note: In order to distinguish it from ordinary variables, we usually make environment variable names uppercase .

According to the life cycle of variables, Linux variables can be divided into two categories:

Permanent: The configuration file needs to be modified, and the variable takes effect permanently;

Temporary: use the export command line declaration, the variable will be invalid when the shell is closed.

Here are two important files /etc/bashrc (some Linux do not have this file) and /etc/profile, which store shell variables and environment variables respectively.

 

Ubuntu user variables : Personally prefer to use

/home/users/".bashrc " ctrl +H display, open for writing

export PATH=”....path...”$PATH

source ~/.bashrc (effective immediately)

 

2 Search files: commonly used whereis , which , find  and locate


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324705828&siteId=291194637