An article teaches you "common operating instructions" under Linux

Preface

This article only talks about the basic use , without too much expansion and introduction. If you understand too much in the early stage, it will be easy to mess up and you should go deeper slowly;

ls (view directory)

Syntax: ls [option] [directory or file]
Function: For a directory, this command lists all subdirectories and files under the directory. For files, the filename is listed along with other information.
Common options:
-a lists all files in the directory, including hidden files starting with .
-l Lists detailed information on files.
-t Sort by time.
-s Output the size of the file after the l filename. (Sort by size, how to find the largest file in the directory)
-R List the files in all subdirectories. (Recursive)
Generally, I only use: ll (ll is the abbreviation of ls -l, the function is to list the detailed information of the file, which is more convenient)

Brief graphic
insert image description here
video operation
Please add a picture description

pwds (display the user's current directory)

Syntax : Enter pwd and press Enter

Function : Display the current directory of the user ;

Note: After logging in for a long time without operating the page, you should first pwd to confirm whether it is in the corresponding position;
briefly illustrate
insert image description here
the video operation
Please add a picture description

cd (change working directory)

Syntax : cd directory name
Function : Change the working directory . Change the current working directory to the specified directory.

Usage :
cd … : Return to the parent directory
cd /home/litao/linux/ : Enter the absolute path
cd …/day02/ : Enter the relative path
cd ~ : Enter the user’s home directory
cd - : Return to the most recently accessed directory
Video operation
Please add a picture description

mkdir (create directory)

Syntax : mkdir [option] text3
function : the option can be a -p, which means recursively create a directory . Without options, only directories are created .

Such as: mkdir text means to create a text3 directory in the current directory.
Brief illustration
insert image description here
If it is mkdir -p text3/binbin, it means to create a text3 directory in the current directory and create a binbin directory in the text3 directory Video
operation
Please add a picture description

rmdir (delete directory)

Syntax: mkdir filename
Function: Delete empty directory
Note: When deleting a non-empty directory as shown in the figure, the deletion will fail
insert image description here

touch (new file or update file time)

Syntax: touch file name
Function: Create a new file, if the file name exists, update the latest change time of the file
For example: touch binbin.c means to create a binbin.c file in the current directory
insert image description here

rm (remove directory or file)

Syntax: rm [options] [file name]
Applicable objects: all users
Function: delete files or directories
Common options:
-f Delete directly even if the file attribute is read-only (that is, write-protected) ( please use this carefully )
-i Ask for confirmation one by one before deleting -r Delete the directory
and all the files under it

insert image description here

tree (display directories in a tree structure)

Syntax: Enter tree and press Enter
Function: Display directory in tree structure
insert image description here

nano (text editor)

Syntax: nano file name
Function: It is a terminal text editor
such as: nano test.txt means to edit test.tx
and exit
Use ^X to exit, remember to save before exiting ( select y ).
Please add a picture description
After the animation above is edited, I operate in sequence:
CTRL+x and then enter y and press Enter

cat (view file contents)

Syntax: cat [option] [file name]
Function: View the content of the target file
Common options:
-b Number the non-empty output lines
-n Number all the output lines
-s Do not output multiple blank lines
such as: cat -n main3. c means to view the content of main3.c and number all lines of output
insert image description here

stat (display file operation information)

Syntax: stat file name
Function: display file operation information
Among them: Access: the last read time (access)
Modify: the last data modification time (modification)
Change: the last metadata modification time (change)
insert image description here

cp (copy)

Syntax : cp [option] source file or directory target file or directory
Function: copy file or directory
Explanation : cp command is used to copy files or directories, such as specifying two or more files or directories at the same time, and the final destination is an already exists, it will copy all the files or directories previously specified into this directory. If multiple files or directories are specified at the same time, and the final destination is not an existing directory, an error message will appear

Commonly used options :
-f: or --force forcibly copy files or directories, regardless of whether the destination file or directory already exists
-i: or --interactive ask the user before overwriting the file
-r: recursive processing, the files in the specified directory and the Subdirectories are processed together. If the form of the source file or directory does not belong to a directory or a symbolic link, it will be treated as an ordinary file.
-R: or --recursive recursive processing, the files and subdirectories in the specified directory will be processed together
insert image description here

mv (move and change files)

The mv command is the abbreviation of move, which can be used to move files or rename files (move (rename) files). It is a commonly used command in Linux systems and is often used to back up files or directories .
Syntax : mv [option] source file or directory target file or directory
For example: mv -i test.o ... means to move the test.o file to the upper-level directory (... means the upper-level directory)
Function:
1. View the first in the mv command Depending on the type of the two arguments (target file or target directory), the mv command renames the file or moves it to a new
directory.
2. When the second parameter type is a file, the mv command completes the file renaming. At this time, there can only be one source file (it can also be the source directory name), and it will rename the given source file or directory to the given The specified target file name.
3. When the second parameter is the name of an existing directory, there can be more than one source file or directory parameter, and the mv command will move the source files specified by each parameter to the target directory. Commonly used
options:
-f : force means that if the target file already exists, it will not be asked but will be overwritten directly -i : if the target file (destination) already exists, it will ask whether to overwrite and move multiple files Syntax : mv source file or directory source file or directory -t target file or directory Function: move multiple source files or directories to the target file or directory;

Please add a picture description



As follows: move the main.cpp Makefile to the test1 directory
insert image description here

less (browse files)

The less tool is also a tool for displaying files or other output in pages. It should be said that it is an orthodox tool for viewing file content in Linux, and its functions are extremely powerful.
You can use the functions of [pageup][pagedown] and other keys to look back and forth between files , which is easier to use to view the content of a file! In addition, you can have more search functions in less, you can not only search downward, but also search upward.

Syntax : less [parameter] file
Function: less is similar to more, but you can use less to browse files at will, while more can only move forward, but not backward, and less will not load the entire file before viewing.
Options:
-i: Ignore case when searching
-N: Show line number for each line
/ :string: Function to search down for "string"
? :string: Function to search up for "string"
n: Repeat previous search (relative to / or ?)
N: reverse repeat previous search (relative to / or ?)
q: quit
Please add a picture description

head (print the first n lines)

head and tail are as easy to understand as their names. They are used to display a certain number of text blocks at the beginning or end . head is used to display the beginning of the file to the standard output, and tail is taken for granted to look at the file. end.

Syntax : head [parameter] [file]
Function: head is used to display the beginning of the file to the standard output, and the default head command prints the first 10 lines of the corresponding file.
Options :
-n<number of lines> number of lines to display
Please add a picture description

tail (print the last n lines)

The tail command writes the file to the standard output from the specified point. Use the -f option of the tail command to easily check the log file being changed. tail -f filename will display the last content of the filename on the screen and keep refreshing , so that you can see the latest file content.
Syntax : tail[required parameter][selection parameter][file]
Function: used to display the content at the end of the specified file , if no file is specified, it will be processed as input information. Commonly used to view log files.
Options :
-f read in a loop
-n <number of lines> display the number of lines
Please add a picture description

date (display time)

Usage: date directly press Enter
Note: In fact, there are quite a lot of functions, but it is enough to check the time at the beginning.
Function: Display current time information
insert image description here

cal (view calendar)

Command format : cal [options]

Function: used to view calendar and other time information , if there is only one parameter, it means the year (1-9999), if there are two parameters, it means the month and year

Commonly used options:
-3 : Display the calendar of the previous month, the current month, and the next month of the system
-j : Display the first day of the year (the date of a year is calculated by day, starting from January 1st, and the current month is displayed by default month in day of year)
-y : display calendar for current year
Please add a picture description

find (file search)

Syntax : find -name file name
Function: used to find files in the file tree and make corresponding processing (may access disk)

Find the test.c file as shown below
Please add a picture description

grep (search for a string in a file)

Syntax : grep search string file [option]
function: search string in the file , print out the found lines

Commonly used options:
-i : Ignore the difference in case , so the case is treated as the same
-n : Output the line number by the way
-v : Reverse selection, that is, display the action image demonstration without the content of the 'search string'

Please add a picture description

zip (compressed file)

Command : zip -r compressed package file name.zir packaged file name
Function: pack and compress the file
insert image description here

unzip (unzip file)

Command : unzip The name of the decompressed file
Function: Decompress the compressed file
as shown in the animation below
Please add a picture description
In order to simplify the operation complexity, there are many shortcomings, please bear with me.

//The following is added later in the post of the article

man (man manual)

Linux commands have many parameters, we can't remember all of them, we can get help by checking the online manual . The command to access the Linux man page is as follows

Syntax: man [option] command
common options
-k search online help
num according to keywords, only find chapter num
-a display all chapters, such as man printf, it defaults to search from the first chapter, stop when you know , use the a option, when you press q to exit, he will continue to search back until all chapters are searched

Guess you like

Origin blog.csdn.net/ZhuGeBin26/article/details/128540016