Article directory
- * —— wildcard
- ctrl +C——terminate current operation
- man - guide to instructions
- echo - output the specified content
- cat - print the contents of a file
- more
- less
- head——View the first N lines of the file
- tail
- | ——Pipeline
- cp - copy files and directories
- mv – move files and directories
- alias - alias a command
* —— wildcard
Use with ls
- ls + * displays all files - excluding hidden files
- ls + *+suffix name - displays files with the same suffix name
- ls + prefix name + * - displays files with the same prefix name
- Note: The * here cannot be separated from the name!
Use with rm
-
Note: The general way to use commands is: command + option + file name . This is because command + file name + option may not be available under some LInux versions!
-
Summarize:
-
Wildcard is a powerful search character that can help us delete and display some files in batches, which improves the efficiency of finding and deleting related files .
ctrl +C——terminate current operation
- When the instructions I input or the situation I face are out of control, I can just use ctrl + C without thinking.
man - guide to instructions
-
Note: Since the Linux operating system is implemented in C language, there are a large number of C instruction interfaces .
-
man + command - get detailed information about the command
man + man
Basic information about man
- man has seven chapters of manual content, each chapter corresponding to a type of information.
- The search order is from Manual No. 1 to Manual No. 7
man + printf
- Here is the printf instruction found in Manual No. 1
- Simple use of printf instruction
- So how do we find the printf function in the library function?
- Because the functions in the library are in Manual No. 3, we need to search under Manual No. 3.
- Command: man + manual number + function to be checked
- This is the result found under Manual No. 3 - the upper left corner shows 3
man + pwd
- Therefore, we can know from the content of NAME that pwd prints the current file directory.
echo - output the specified content
echo + string
-
Note: A string in Linux can be "content", or it can be 'content', or even directly content.
-
Here is the string output to the display
Under LInux, everything is a file. For example, the monitor is a file that can only output, that is, it can only print content on the monitor, but cannot read content from the monitor. The keyboard is a file that can only be input, that is, it can only Read content on the keyboard, but cannot output content to the keyboard.
- Supplement: > (greater than symbol) - refers to redirecting content to the specified file
- Therefore: echo + content +> + file means outputting the specified content to the file.
- illustrate:
- 1. If the file does not exist, a file will be created to store the specified content.
- 2.> - Output redirection overwrites the content into the file, which means that if the original file has content, it will be overwritten here .
3. >>—— Append redirection is to append the content to the file, that is, append the content after the original file.
cat - print the contents of a file
cat + file name
-
Print file contents
-
illustrate:
-
- <——Input redirection, input the contents of the specified file and display it on the screen.
When no file is added after cat, the data will be read from the keyboard by default and displayed on the monitor.
When we change the input location - under the test.txt file, cat will read the data from test.txt and output it to the monitor.
Common options
- -b output line numbers for non-empty lines
- -n numbers all lines of output
- -s does not output multiple blank lines
- Summary: cat is suitable for reading small texts, but not suitable for reading large texts (such as tens of thousands of lines of text).
more
- How to construct a large text under Linux?
- cnt=1;while [ $cnt -le 10000 ]; do echo “Hello world $cnt”; let cnt++; done > test.txt
- This command outputs 10,000 lines of hello word to the test.txt file.
- Print out the contents:
- How to view the contents of a specified line?
Let’s take a look directly using more + file name
A screen of content will be displayed here, and you can only use the Enter key to scroll down. To exit, press q.
- more + line number + file name
This will jump directly to line 500. What if we want to continue looking at line 9999?
Just enter /9999 to jump to the vicinity of line 9999.
less
- The function of less is similar to that of more, but one of the more powerful functions is that it can turn data up and down.
- Note: less + line number + file name will not jump to the specified line.
Commonly used
- / + line number is used the same as more
- ? + line number
Press enter
head——View the first N lines of the file
- head + - line number + file
- Note: If you do not enter a line number, the content of the first 10 lines will be viewed by default.
tail
- tail + - line number + file
- Note: If you do not enter a line number, the content of the last 10 lines will be viewed by default.
| ——Pipeline
- What should we do when we want to take out a specified range of text from a large text?
- For example:
- Take out lines 5000-6000 of test.txt
- We can first take out the first 6000 lines and put them into a temporary file, and then take out the last 1000 lines of the temporary file.
- Is there an easier way?
- The pipeline is here - equivalent to the products on the assembly line
- This command can directly extract the lines of the file we want.
- Description: Pipes are memory-level files .
cp - copy files and directories
Copy files
Basic usage: cp + files in directory + directory + renamed files
- Note: When the copied file is in the current file, our first directory can be omitted . When we do not need to rename it when copying, the second renamed file can be omitted .
copy directory
- cp + r + directory under the specified directory + copy to the directory at the target (rename the directory copied to the target)
Common options
- -f or --force forcefully copies a file or directory, regardless of whether the destination file or directory already exists.
- -i or --interactive ask the user before overwriting the file
here it isIt will only prompt if the file is overwritten, but not in other cases!
This will not prompt you
- -r recursively processes files and subdirectories in the specified directory together . If the form of the source file or directory does not belong to a directory or symbolic link, it will be treated as an ordinary file.
- -R or --recursive recursive processing, processing files and subdirectories in the specified directory together
mv – move files and directories
Move files
- mv + file/directory in the specified directory + target directory + rename
- Note: The target directory is the same as the specified directory and must be changed to a different name from the original, which is equivalent to changing the name of the original file or directory.
When moving files in the current directory, the specified directory can be omitted. When moving to the current directory, the target directory can be omitted. When renaming is not required, renaming can be omitted .
Move directory
- The principle is the same as moving files, and no -r option is required.
Overwrite directory
- This is the coverage directory
- This is to copy the directory to the specified directory, rather than overwriting the specified directory!
alias - alias a command
Basic understanding of instructions
- After writing a piece of code, compilation will generate an executable program. ./a.out runs the executable program, and the content we compiled will be printed here. This is similar to the execution of instructions.
So can we guess that the instructions are executable programs one by one?
- Take a look at where are some basic instructions?
- Therefore: the basic instructions are in the /usr/bin directory
Then we write the executable program we wrote and put it in this directory. Can it be run as a command?
- Therefore: instructions are essentially no different from executable programs .
Basic usage of alias
- Note: We use alias to alias a certain command, which will be automatically deleted when we log in again, so alias is temporary .
- Suggestion: We try to use system commands as the basis, and we do not recommend using aliased commands!