Common Basic Instructions of Linux Operating System

Function: Change the general directory of Gong, and change the current working directory to the specified directory

  • cd ...: Return to the parent directory

  • cd ~: enter the user's home (home) directory (you can also use cd directly)

  • cd - : return to the most recently visited directory

The cd directory name indicates that you can enter the current directory

touch command

Syntax: touch [Options] file

Function: touch means to create a new file (empty file), the command parameters of touch can change the date and time of the document or directory, including access time and change time

touch java.txt //Indicates to create a java.txt file in the current directory. If the java.txt file already exists before, no modification will be made to the file content, but the modification time of the file will be updated

cat command

Syntax: cat file

Function: view the content of the target file

cat java.txt means to view the contents of the java.txt file

echo command

Syntax: echo [content] > [file name] (">" means redirection)

Function: modify the content of the file

echo hehe > java.txt means modify the content in the java.txt file to "hehe"

mkdir command

Syntax: mkdir [options]

Function: Create a directory under the current directory

  • -p: At this time, if some directories in the path do not exist yet, after adding this option, the system will automatically create those directories that do not exist yet, that is, multi-level directories can be created at one time

mkdir java means that a java directory will be created

mkdir demo1/demo2/demo3 -p means that if you do not want to create demo3 directories under demo1 and demo2 at this time, if there are no demo1 and demo2 directories at this time, demo1 and demo2 directories will be created automatically

tree command

tree Use tree directly to display the structure of the current directory

yum install tree means to install the tree command

rm command

Syntax: rm [-f -i -r -v] [file name or file]

Function: delete file or directory

  • -f : Even if the file attribute is read-only (that is, write-protected), it can be deleted directly

  • -i: Ask for confirmation one by one before deleting (enter "y" for yes, enter "n" for no)

  • -r: delete the directory and all files under it

rm -r directory name means to delete this directory and the contents of the directory, here every time you will be asked whether to delete

rm -rf directory name also means to delete the directory and its subdirectories and content, but there is a function of whether to delete (applicable to the situation with many subdirectories)

Note: After deleting here, it is really deleted, and you cannot restore it by conventional means (unlike Windows has a recycle bin). When the operating system deletes files, it essentially marks the corresponding disk area as an "invalid area" and does not If you really erase the data, you can use some special tools to recover part of it (why only part of it can be recovered? Because "the invalid area may be allocated to other files")

Do note: do not use rm -rf /

Do note: do not use rm -rf /

Do note: do not use rm -rf /

Because it will delete all the files on your system. Simply put, even if your machine must hang, you can only reinstall the system. Of course, if it is your own computer, you can play with it, but you must not try it after you join the job.

mv command

Syntax: mv [option] source file or directory target file or directory

Function:

1. Depending on the type of the second parameter in the mv command (whether it is a target file or a target directory), the mv command will rename the file or move 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 target filename

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

  • -f: force (mandatory), if the target file already exists, it will be overwritten without asking

  • -i: If the target file already exists, it will ask whether to overwrite!

mv demo1/java.txt demo2 means to move the java.txt file in the demo1 directory to the demo2 directory

mv java.txt test.txt means to modify the file name, change java.txt to text.txt

Note: The operation of mv is very efficient (you only need to modify the path of the asking price). This operation time has nothing to do with the file size. Even if it is a large file, moving it is a snap.

cp command

Syntax: cp [option] source file or directory target file or directory function: copy file or directory

  • -f: Forcibly copy files or directories, regardless of whether the destination file or directory already exists

  • -i: ask user before overwriting files

  • -r: Recursive processing, processing files and subdirectories under the specified directory 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: Process the files and subdirectories in the specified directory together

cp demo1/java.txt demo2 means to copy the java.txt in the demo directory to the demo2 directory, and the content is exactly the same. The copy operation is closely related to the file size. The larger the file, the longer the copy time

cp -r demo1 demo2 means to copy the demo1 directory to the demo directory (copy of the directory)

Description: 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 last destination is an existing directory, it will copy all the previous files or directories to this directory. If multiple files or directories are specified at the same time, and the final destination does not exist, an error message will appear

man command

Linux commands have many parameters, we cannot remember all of them, we can get help by checking the online manual

Syntax: man [option] command

  • -k: search online help by keyword

  • num only search for chapter num

  • man man can see several chapters and their meanings in the man manual

man ls means to open the "ls" help manual, you can view the usage of ls, etc...

Notice:

1. When using keywords to view, press "/" to start the search function, and then enter the corresponding keywords you want to find

2. When opening the help manual for the corresponding command, use the up and down keys to browse, q to exit

3. The BUILTINS internal key command cd/echo cannot be directly viewed using man

4. Man can view the Linux system API and the functions of the C language standard library, but cannot view Java, because Linux is implemented by C, so it has special treatment, that is, languages ​​like Java cannot implement the operating system

less instruction

【Enhanced version of cat】

Syntax: less [parameter] file

Function: view the file content, it will not load all the file content into the memory immediately, and it can only be searched

  • -jk / : Arrow keys: scroll up and down the screen

  • -N: Display the line number of each line

  • /string: function to search down for "string"

  • n: repeat the previous search

  • q: quit

less service means that viewing the content of the service is similar to cat, but cat displays all of them in one go, and less will delay loading

Note: The advantages of using less, if the file is particularly large, the opening speed of less will be very fast (delayed loading), and you can load as much as you want (similar to the lazy mode)

head command

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.

head etc/services indicates that the first ten lines of data of the service will be displayed

head "Analysis of Java interview questions of first-line manufacturers + back-end development study notes + latest architecture explanation video + actual project source code handouts" free open source prestige search public account [programming advanced road] -n 100 etc/services means that the front of the service will be displayed 100 rows of data

tail command

おすすめ

転載: blog.csdn.net/AK774S/article/details/124685742