[Linux Advanced Road] Basic Instructions (Part 1)

* —— wildcard

Use with ls

Insert image description here

  • 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

Insert image description here

  • 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

Insert image description here

  • 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
Insert image description here

  • 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 quote

  • Here is the printf instruction found in Manual No. 1

  • Simple use of printf instruction

Here is the quote


  • 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

Insert image description here
Insert image description here

  • This is the result found under Manual No. 3 - the upper left corner shows 3

man + pwd

Insert image description here

  • Therefore, we can know from the content of NAME that pwd prints the current file directory.

echo - output the specified content

echo + string

Insert image description here
Insert image description here

  • 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.
    Insert image description here
  • 2.> - Output redirection overwrites the content into the file, which means that if the original file has content, it will be overwritten here .

Insert image description here
3. >>—— Append redirection is to append the content to the file, that is, append the content after the original file.

Insert image description here

cat - print the contents of a file

cat + file name

  • Print file contents
    Insert image description here

  • illustrate:

    1. <——Input redirection, input the contents of the specified file and display it on the screen.

Insert image description here
When no file is added after cat, the data will be read from the keyboard by default and displayed on the monitor.

Insert image description here
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

Insert image description here

  • -n numbers all lines of output

Insert image description here

  • -s does not output multiple blank lines

Insert image description here

  • 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.Insert image description here
  • Print out the contents:

Insert image description here

  • How to view the contents of a specified line?
    Let’s take a look directly using more + file name

Insert image description here
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

Insert image description here
This will jump directly to line 500. What if we want to continue looking at line 9999?
Insert image description here
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

Insert image description here

Press enter
Insert image description here

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.

Insert image description here

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.

Insert image description here

| ——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.

Insert image description here

  • Is there an easier way?
  • The pipeline is here - equivalent to the products on the assembly line
    Insert image description here
  • 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

Insert image description here

  • 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!
Insert image description here
This will not prompt you
Insert image description here

  • -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.

Here is the quote
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 .
Insert image description here

Move directory

  • The principle is the same as moving files, and no -r option is required.

Insert image description here

Overwrite directory

Insert image description here

  • This is the coverage directory

Insert image description here

  • This is to copy the directory to the specified directory, rather than overwriting the specified directory!

alias - alias a command

Basic understanding of instructions

Insert image description here

  • 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?

Insert image description here

  • 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?

Insert image description here

  • Therefore: instructions are essentially no different from executable programs .

Basic usage of alias

Insert image description here

  • 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!

Guess you like

Origin blog.csdn.net/Shun_Hua/article/details/130503963