Linux terminal command pitting skills

What is a home directory?

Like Windows, Linux is a typical multi-user operating system.

A multi-user operating system means that multiple users can be allowed to access the system at the same time. In order to facilitate the management of each user's data, the system will create a user directory at the same time as the login user is created. This directory is the current user's home directory, which is stored in the / home directory.

How to view the current working directory?

 pwd

How to switch working directory?

cd 路径

How to view the files in the directory?

Use the ls command to view the contents of a directory, including files and folders.
If you run ls without any parameters, then the contents of the current directory are displayed by default.

To list the contents of the specified directory, add the path of the directory after the ls command

You will find a color difference in the displayed results. What does this mean?
These different colors represent content with different attributes, such as
blue: directory, white: text file, red: archive file

How to create a new text file?

Usually under windows, you can create a blank text document by right-clicking the folder and then creating a new text document.
In the Linux terminal, by using the touch command, you can create a file.
touch test.txtYou can create a document file named test.txt, the suffix of txt is not necessary, the file under Linux is usually not determined by the suffix. There is only a suffix for easy identification.

Using standard stream redirection can also create files and write data to them at the same time they are created.
For example ls > ls.txt, the result of the ls command is redirected to the ls.txt file through fd.

How to rename / copy / delete a file?

Use the mv command to rename a file:
to rename the file test.txt in the current directory to test_new.txt. Enter the following name

mv log.txt new_log.txt

If the file is not in the current directory, you can use cd to jump to the directory and execute the mv command.
You can also directly add the full path of the file name to the mv command.

Use the cp command to copy files:
The usage of the cp command and the mv are basically similar. The difference is that after the mv command is executed, the renaming is achieved by deleting the original file and retaining the new file.
The cp command keeps both files.

Use the rm command to delete files:
rm -rf /* what does it mean?
-r: Recursively delete all files and directories in subdirectories.
-f: indicates that no confirmation is required and the forced deletion is performed directly.
/ *: All files in the root directory.

How to find files?

To search for files in a specified directory, use the find command. This command requires the directory path and file name as parameters. For example, to search for a file named climate.py in the / home / lab1 / directory, enter the following command:

find /home/lab1 -name climate.py

If no directory path is specified, the find command will search in the current working directory.

Use wildcards and find commands to achieve fuzzy search. For example, if you want to search all the files with the py suffix in the / home / lab1 / directory, you can change the search name to * .py. This will match all files with py suffix.

The "*" character is a wildcard and can represent any number of characters.

How to search for text in a file?

To search for text in a file, you can use the grep command. This command requires keywords and file names as parameters, and then displays the line containing the keywords in the terminal. For example, to search all lines in the py file in the file / home / lab / that contain the keyword climatet, use the grep command:

grep climate lab/*.py

If you want grep to display line numbers in the output, add the -n command line option. At the same time, grep does not automatically search subdirectories like the find command. If you need to search all files and find them in all subdirectories recursively, you need to add the -R parameter.

Published 28 original articles · won praise 2 · Views 3259

Guess you like

Origin blog.csdn.net/Maestro_T/article/details/103604581