current position:Home>Linux commands

Linux commands

2022-01-26 21:51:49 Bo childe

One 、 Basic instructions

1、ls Instructions

meaning :ls(list)

usage 1:#ls

meaning : Lists all files in the current working directory / Folder name

  usage 2:#ls route

meaning : List all files in the specified path / Folder name

About the path ( important ):

There are two paths : Relative paths 、 Absolute path .

  The relative path : It's often used in relative paths 2 Symbols “./”【 Indicates the current directory 】、“../”【 Upper level directory

Next 】.

Absolute path : Absolute paths don't need references , direct From the root “/” Start looking for the path ;

usage 3:#ls Options route

meaning : List the files in the specified path / Name of the folder , And display in the specified format .

Common grammar :

#ls -l  route

#ls -la  route

Explanation of options :

-l: Express list, Show in the form of a detailed list

-a: Show all the files / Folder ( Contains hidden files / Folder )

Common commands :ls -lah route

  The first column of characters in the above list represents the type of document , among “-” Indicates that the document type corresponding to the line change is file ,“d” Represents a document Folder type .

  stay Linux In general, documents are hidden by “.” start .

usage 4:#ls -lh route

meaning : List all files in the specified path / Name of the folder , In the form of a list and in the form of... When displaying the document size Display in a readable form

Parameter meaning :

 2、pwd Instructions

usage :#pwd         print working directory, Print current working directory )

 3、cd Instructions

command :#cd            (change directory, Change the directory )

effect : Used to switch the current working directory

grammar :#cd route

Case study : The current in “/” Next , You need to use the absolute path to switch to /usr/local.

  Case study : The current in /var/tmp/ Next , You need to use a relative path to switch to home In the catalog test Go to the user's home directory .

Add :

stay Linux There's a special symbol in it “~”, Represents the home directory of the current user .

The way to switch :#cd ~

 4、mkdir Instructions

Instructions :mkdir    (make directory, Create directory )

grammar 1:#mkdir  route  【 route , It can be a folder name or a full path containing the name 】

  Be careful :ls The color description of the results listed , The blue name indicates the folder , Black indicates that the file , The green one has all permissions .

Case study : Create a folder in the specified path “test”

  grammar 2:#mkdir -p  route ( Dolls )

meaning : When creating multi tier nonexistent directory at one time , add to -p Parameters , Otherwise, an error will be reported

  grammar 3:#mkdir  route route route 3 ….  【 Means to create multiple directories at one time 】

 5、touch Instructions

Instructions :touch

effect : create a file

grammar :#touch File path 【 The path can be a direct file name or a path 】

Case study : Use touch To create a file in the current path , Name it Linux.txt

Case study : Use touch To create multiple files at the same time

Case study : Use touch Come on “Linux123” The user creates files in the home directory ,Linux.txt

 6、cp Instructions

Instructions :cp  (copy, Copy )

effect : Copy file / Folder to the specified location

grammar :#cp  The path of the copied document   The path to which the document was copied

Case study : Use cp Command to copy a file

Be careful :Linux In the process of copying, you can rename the file in the new location , But if it's not necessary , It is recommended to keep the name consistent .

Case study : Use cp Command to copy a folder

Be careful : When using cp When the command is used to copy a folder, you need to add options “-r”-r Represents recursive replication 】, Otherwise the directory will be ignored

 7、mv Instructions

Instructions :mv   (move, Move , shear )

effect : Move the document to a new location

grammar :#mv  The document path that needs to be moved   Location path to be saved

confirm : After moving, the original file is still not in the original location ? The original file is not in the original location

Case study : Use mv Command to move a file

Case study : Use mv Command to move a folder

  Add : stay Linux The command to rename in is also mv, Grammar is the same as mobile grammar .

 8、rm Instructions

Instructions :rm  (remove, remove 、 Delete )

effect : remove / Delete the document

grammar :#rm  Options   The document path to be removed

Options :

  •  -f:force, Mandatory deletion , Do not prompt to delete
  • -r: Represent recursion
  • rm -rf ./*

Case study : Delete a file

  If you delete without options , You will be prompted to delete , If you need to confirm, enter “y/yes”, Otherwise input “n/no” Press enter .

Be careful : If you don't want to confirm frequently when deleting , You can add options to the instruction “-f”, Express force( mandatory ).

  Case study : Delete a folder

  Be careful : When you delete a directory, you need to do recursive deletion , And generally there is no need to ask for deletion confirmation , So when you remove a directory, you usually need to use -rf Options .

Case study : Delete multiple documents

  Case study : To delete a document with public features in a directory , For example, they all take Linux start

  among * Call it a wildcard , Any character indicating meaning ,Linux*, It means as long as the file is marked with Linux start , The following characters are ignored .

9、vim Instructions

Instructions :vim  (vim It's a text editor )

grammar :#vim  Path to file

effect : Use vim To open the file

Case study : Use vim To open the file

go in vim Post press (a、i、o) Enter insertion mode , Press... After editing esc after , Press again shift+ English colon (:),q! Do not save and exit ,wq Save and exit

:q!( Do not save and exit )  :wq( Save and exit ) 

 10、 Output redirection

Normally the output of a command is displayed in the terminal , Sometimes you need to save the execution results of some commands to a file for subsequent analysis / Statistics , This is where the output redirection technique is needed .

>: Cover Output , Overwrite the contents of the original file

>>: Additional Output , The original file contents are not overwritten , It continues at the end of the original content

grammar :# Normal execution of instructions  > / >>  Path to file

Be careful : The file can not exist , If it doesn't exist, create a new one

Case study : Use overlay redirection , preservation ls -la The results of the implementation of , Save to... In the current directory test.txt

  Case study : Use append redirection , preservation ls -la The results of the implementation of the 1.txt in

11、cat Instructions

effect 1cat It has the function of opening a file directly .

grammar 1#cat  Path to file

effect 2cat You can also merge files

grammar 2#cat  File path to be merged File path to be merged 2 ….  File path n >  File path after merging

  Two 、 Advanced instructions ( a key )

1、df Instructions

grammar :#df -h         -h Show size in a more readable form

 2、free Instructions

effect : View memory usage

grammar :#free -m   -m Said to mb View for units

 3、head Instructions

effect : Look at the front of a file n That's ok , If you don't specify n, Before the default display 10 That's ok .

grammar :#head -n  File path    【n Representation number 】

 4、tail Instructions

effect 1: View the unsettled contents of a file n That's ok , If n After not specifying the default display 10 That's ok

grammar :#tail -n  Path to file     n It also means numbers

effect 2: Can pass tail Command to view the dynamic content of a file 【 The changed content cannot be added manually by the user

grammar :#tail -f  File path

This command is generally used to view the log of the system .

5、less Instructions

effect : see file , Output with less content , Press the auxiliary function key ( Numbers + enter 、 Space bar + Up and down direction key ) To view more

grammar :#less  File path to view

  In the exit button, just press q Press the key .

6、wc Instructions

effect : Statistics file content information ( Contains the number of rows 、 Number of words 、 Number of bytes )

grammar :#wc -lwc  File paths to be counted

       -l: Express lines, Row number

       -w: Express words, Number of words     Judge the number of words according to the space

       -c: Express bytes, Number of bytes

7、date Instructions ( a key )

effect : Represents the operation time and date ( Read 、 Set up )

grammar 1:#date          Form of output :2018 year  3 month  24 Japan   Saturday  15:54:28

 8、cal Instructions

effect : Used to operate the calendar

grammar 1:#cal     Equivalent to  #cal  -1         Output calendar of current month directly

grammar 2:#cal  -3                  Represents the output last month + This month, + Next month's calendar

grammar 3:#cal  -y  year                Represents the output of a calendar for a year

 9、clear/ctal+L Instructions

effect : Clear the existing commands and results in the terminal ( Information ).

grammar :clear           Or shortcut key :ctrl + L

It should be noted that , This command doesn't really clear the previous information , It's hiding the previous information at the top , Continue to view previous information through the scroll bar .

10、 The Conduit ( important )

Pipe, :|

effect : Pipes can generally be used for “ Filter ”,“ special ”,“ Extended processing ”.

grammar : Pipes cannot be used alone , It must be used together with some of the instructions mentioned above , Its role Mainly auxiliary function .

#ls / | grep y

For the above command description :

Take the pipeline as the dividing line , The previous command has an output , You need to input , And then filter , And finally output , Generally speaking, the output in front of the pipeline is the input of the following instructions ;

②grep Instructions : It is mainly used for filtering

3、 ... and 、 Advanced instruction

1、hostname Instructions

effect : Operation server Host name Read 、 Set up )

grammar 1:#hostname                     meaning : Represents the output full host name

grammar 2:#hostname  -f                meaning : Indicates to output... In the current host name FQDN( Full limit domain name

 2、id Instructions

effect : View some basic information about a user ( Include users id, User group id, Additional group id…), If the instruction does not specify a user, the current user will be default .

grammar 1:#id           By default, the basic information of the user currently executing the command is displayed

grammar 2:#id   user name            Display the basic information of the specified user

 3、whoami Instructions

effect :“ Who am I ?” Display the current login user name , Commonly used in shell Script , It is used to obtain the user name of the current operation for logging .

grammar :#whoami

 4、ps -ef Instructions ( a key )

Instructions :ps

effect : Mainly to view the process information of the server

Meaning of options :

  •        -e: Equivalent to “-A”, Indicates that all processes are listed
  •        -f: Show all columns ( Show all fields )

  The meaning of the column :

  • UID: The user who executed the process id;
  • PID: process id;
  • PPID: The parent process of the process id, If the parent process of a program cannot be found , The process of the program is called a zombie process (parent process ID);
  • CCpu The occupancy rate of , It's in the form of a percentage ;
  • STIME: Starting time of the process ;
  • TTY: Terminal equipment , The device identifier that initiated the process , If it shows “?” Indicates that the process is not initiated by the terminal device ;
  • TIME: The execution time of the process ;
  • CMD: The name of the process or the corresponding path ;

5、top Instructions ( a key )

effect : View the resources occupied by the process of the server (100% Use )

grammar :

Enter the command :#top   ( Dynamic display )

Exit command : Press down q key

Output result :

  The meaning of the header :

  • PID: process id;
  • USER: The corresponding user of the process ;
  • PR: priority ;
  • VIRT: Virtual memory ;
  • RES: memory-resident ;
  • SHR: Shared memory ;
  •          Calculate the memory actually used by a process  =  memory-resident (RES Shared memory (SHR
  • S: Indicates the state of the process statussleeping, among S It means sleep ,R Said to run );
  • %CPU: Express CPU Percent occupancy of ;
  • %MEM: Represents the percentage of memory used ;
  • TIME+: Execution time ;
  • COMMAND: The name or path of the process ;

Running top When , You can press the convenient shortcut key :

  • M: Indicates that the results are stored in memory (MEM) Descending from high to low ;
  • P: According to the result of CPU The utilization rate is in descending order from high to low ;
  • 1: When the server has multiple cpu It can be used when “1” Shortcut key to switch whether to display each cpu Details of ;

6、du -sh Instructions

effect : Look at the actual size of the directory

grammar :#du -sh  Directory path

Meaning of options :

  •        -s:summaries, Show only the size of the summary
  •        -h: Means to display in a highly readable form

Case study : Statistics “/etc” The actual size of the directory

 7、find Instructions

effect : Used to find files ( The parameters are 55 There are so many )

grammar :#find  Path range   Options   The value of the option

Options :

  •        -name: Search by document name ( Support fuzzy search )
  •        -type: Search by document type

The document type :“-” Said file ( In the use of find It needs to be used f To replace ),“d” Presentation folder

Case study : Search for etc All the conf Suffix file (#find /etc -name *.conf)

Case study : Use find To search for /etc/java/ All the file

#find /etc/java/ -type f

Case study : Use find To search for /etc/ All the Folder

 #find /etc -type d

 8、service Instructions ( a key )

effect : It is used to control the service startup of some software / stop it / restart

grammar :#service  service name  start/stop/restart

9、kill Instructions ( a key )

effect : It means kill process           ( When a zombie process is encountered or a process needs to be shut down for some reason )

grammar :#kill   process PID         ( Grammar needs to match ps Use it together )

10、ifconfig Instructions ( a key )

effect : It is used to operate instructions related to network card .

Simple grammar :#ifconfig            ( Get network card information )

11、reboot Instructions

effect : Restart the computer              

grammar 1#reboot           restart

grammar 2:#reboot  -w    Simulated restart , But don't restart ( Only write the log information of shutdown and startup )

12、shutdown Instructions

effect : To turn it off                  ( Use with caution )

grammar 1#shutdown -h now  “ Shutdown prompt ”   perhaps   #shutdown  -h 15:25  “ Shutdown prompt

Case study : Set up Linux The system shutdown time is 12:00

copyright notice
author[Bo childe],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262151467698.html

Random recommended