2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
grammar:ls [options] [directory name or file name]
Function: For a directory, this command lists all subdirectories and files under the directory. For a file, it lists the file name and other information
Common options:
-a: List all files in the current directory, including hidden files
-l : List detailed information of the file
-d: Display directories as files instead of files under them
-R: recursively list files in all subdirectories
Example:
summary:
In Linux, files starting with . are called hidden files. In every file, there are . and . . These two files are special files. . is the current directory, and . . is the parent directory.
ls file*, which means to list the files containing file in their names, as shown in the following figure:
grammar:pwd
Function: Print the current directory
Example:
summary:
/ is a path separator in Linux. We can locate the location of the file through the path.
grammar:cd directory name
Function: Jump to the specified directory
Example:
grammar:tree directory name
Function: Print the specified directory in tree form
Installation Instructions: yum install -y tree
Example:
summary:
We can see that the path is composed of multiple nodes. Any parent node can have multiple child nodes, and any child node has only one parent node, so we can say that the path is unique.
grammar:touch [file name]
Function: Create a new file that does not exist
Example:
grammar:mkdir [options] [directory name]
Function: Create a new directory under the current directory
Common options:
-p: recursively create a series of directories, that is, you can create multiple directories at a time
Example:
grammar:rmdir [options] [directory name]
Function: Delete empty directories
Common options:
-p: When a subdirectory is deleted and the parent directory becomes an empty directory, the parent directory is deleted as well
Example:
grammar:rm [options] [filename or directory name]
Function: Delete files or directories. The rm command can delete files or directories at the same time.
Options:
-f: Delete the file even if it is read-only (i.e. write-protected).
-i : Ask for confirmation before deleting each
-r: Delete the directory and all files under it
Example:
grammar:man [options] command
Function: Check the online manual for the command
Common options:
Manual 1 for general instructions
Manual 2 to check system calls
Manual No. 3 to check the library functions of C language
Example:
grammar:cat (tac) [options] [filename]
Function:cat (tac) View the contents of the target file in order (reverse order)
Common options:
-b: Number non-empty output lines
-n: Number all output lines
-s: Do not output multiple blank lines
Example:
summary:
grammar:nano file name
Function: Write to the target file
Installation Instructions:yun install -y nano
Example:
grammar:cp [options] source file or directory target file or directory
Function: Copy a file or directory, and create the target file or directory if it does not exist
illustrate: The cp command is used to copy files or directories. If more than two files or directories are specified at the same time, and the final destination is an existing directory, it will copy all the previously specified files or directories to 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 be displayed.
Common options:
-f: Force copying of files or directories, regardless of whether the destination file or directory already exists
-i : Ask the user before overwriting files
-r: Recursive processing, processing the files and subdirectories under the specified directory together
Example:
grammar: mv [options] source file or directory target file or directory
Function: 1. Move files and directories 2. Rename
Common options:
-f : If the target file already exists, overwrite it without asking
-i: If the target file already exists, it will ask whether to overwrite it
Example:
grammar:more [options] [filename]
Function: Similar to cat, you can view long files, but you can only scroll down, not up.
Options:
-n: Number the output lines
q: quit
Example:
grammar: less [options] filename
Function: less is similar to more, but with less you can browse the file at will, while more can only move forward but not backward, and less will not load the entire file before viewing.
Options:
-N: Display line numbers for each line
-i : Ignore case when searching
n : Repeat the previous search
N: Repeat the previous search in reverse direction
q : quit
grammar: head [options] [filename]
Function: head is used to display the beginning of a file to standard output. The default head command prints the first 10 lines of its corresponding file.
Options:
-n: Display the first n lines of data
Example:
grammar: tail [options] [filename]
Function: Used to display the content at the end of the specified file. If no file is specified, it is processed as input information. Commonly used to view log files.
Options:
-n: Display the number of lines
Example:
summary:
So how do we intercept the data between rows 5000 and 5020?
We can intercept the first 5020 lines of data first, and then intercept the last 20 lines of data. Do we need to create a new file? We can use pipelines to cleverly solve this problem:
Date display
date specifies the format to display time: date +%Y:%m:%d
date Usage: date [OPTION]… [+FORMAT]
grammar: cal [year][month][year]
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.
-3: Display the system's calendar for the previous month, current month, and next month
-j: Display the day of the year (the year is calculated by day, starting from January 1st, and the default display is the number of days in the current month in the year)
-y: Display the calendar for the current year
Example:
grammar: find pathname -options filename
Function: Used to find files in the file tree and make corresponding processing (possibly accessing the disk)
Common options:
-name Search for files by file name
-o or
Example:
grammar: grep [common options] search string files
Function: Search for a string in a file and print out the found lines
Common options:
-n: Output line number by the way
-i : Ignore uppercase and lowercase differences, so uppercase and lowercase are considered the same
-v: reverse selection, that is, display the line without the 'search string' content
Example:
grammar:which command
Function: Used to find the location of instructions
Example:
summary:
We found that these instructions are executable programs, also files, and they are stored in the directory /user/bin
Instructions, executable programs, and commands are the same thing and are all files.
grammar:alias directive alias
Function: Used to give an alias to a command
Example:
grammar: zip [compressed file.zip] [directory or file]
Function: Compress a directory or file into zip format
Installation:yum install _y zip unzip
Common options:
-r: Recursive processing, processing all files and subdirectories under the specified directory together
-d: extract to the specified directory
Example:
summary:
The role of packaging: reduce the amount of data transmitted over the network and facilitate network transmission
grammar:
Compression: tar -czf [filename.tgz] [file]
Decompression: tar -xzf [filename.tgz]
Function: Compress a directory or file into a .tgz file
Common options:
-C: Unzip to the specified directory
-v: Visualize the suppression process
-c: Create a parameter command for a compressed file
-x: parameter command to decompress a compressed file
-z: Can it be compressed by gzip?
-f: followed by the file or directory name
Example:
grammar:bc
Function:Calculate numbers and output the results
Example:
grammar:uname [options]
Function: uname is used to obtain information about the computer and operating system.
Additional Notes: uname can display basic information such as the version of the operating system used by the Linux host and the name of the hardware.
Common options:
-a: Output all information in detail, including kernel name, host name, kernel version number, kernel version, hardware name, processor type, hardware platform type, operating system name
-r: Output kernel version number
Example:
grammar: shutdown command
Function: Shutdown
Common instructions:
-h: Shut down the system immediately after stopping the system services.
-r: Restart the system after stopping the service
-t sec: -t is followed by the number of seconds, which means "shut down after a few seconds"
summary:
The author uses a cloud server and does not shut down the computer, otherwise he would have to go to the website to open it.