Basic operation of Linux files
New file: Touch test does not replace duplicate files, and Linux is all files, folders and files cannot have duplicate names
New folder: MkDir test
Using the-p parameter to create the parent directory at the same time (if the parent directory does not exist), we create a multilevel directory at the same time (this is useful when installing the software, configuring the installation path):
Mkdir-p Father/son/grandson
Copy file CP Test Father/son/grandson
Copy folder: Cp-r Father family must add parameter-r
Delete File: RM Test If the file is read-only, there is a hint, add parameter-F to rm-f test
Delete directory: Rm-r family
Moving files: MV file1 docments
Mobile directory: MV Dir1 DIR2
If the directory Dir2 does not exist, rename the directory Dir1 to Dir2; otherwise, move Dir1 to Dir2.
Renaming: MV File1 newfilename
Linux modifies file owners and permissions
Modify file owner: sudo chown Shiyanlou fileName
Modify Permissions:
Method One: chmod the number of permissions for the FileName 421
Method Two: chmod go-rw fileName
G, O and U represent group, others, and user, respectively,
+ and-each means adding and removing the appropriate permissions
R W x read, write, execute permissions
Linux Viewing files
viewing files using the CAT,TAC and NL commands
The cat is a positive sequence display, and the TAC is displayed in reverse order.
NL command, add line number and print, this is a more professional line number than cat-n Print command.
Paging through files using the more and less commands
Inside the man manual is the less used to display the content. The more commands are simpler and can only scroll in one direction, and less is based on more and VI (a powerful editor, we have a separate course to let you learn) and more powerful.
More passwd passing next line, Sapce next screen h help Q quit
Less passwd in VI mode
Viewing files using the head and tail commands
View only the first few lines of the file (the default is 10 lines, less than 10 lines show all), and the tail lines.
tail/etc/passwd
Even more directly look at a line, plus the-n parameter, followed by the number of rows:
Tail-n 1/etc/passwd
About the tail command, have to mention that it is a very good parameter-F, this parameter can be implemented to read the contents of a file and display. This allows us to dynamically view the logs to achieve real-time monitoring purposes.
Linux Comparison file differences
$ env|sort>env.txt
$ export|sort>export.txt
$ set|sort>set.txt
This action outputs the command output through the pipeline | Use the sort command to sort and then redirect to the object text file.
$ Vimdiff env.txt export.txt set.txt
Linux viewing file types
The types of files in Linux are not judged by file suffixes, and we typically use the file command to view the type of the files:
File/bin/ls
Linux Search files
Whereis,which,find and locate
Whereis Simple and fast
$whereis who
Locate Fast and full
Through the "/var/lib/mlocate/mlocate.db" Database lookup, but this database is not updated in real-time, the system will use scheduled tasks to automatically perform the UpdateDB command update once a day, so sometimes you just add the file, it may not be found, The UpdateDB command needs to be executed manually once (the command must be executed first in our environment). It can be used to find different file types under the specified directory, such as finding all files that start with SH under/etc:
$ locate/etc/sh
Find all JPG files under/usr/share/:
$ locate/usr/share/\*.jpg
which small and fine
Which itself is a shell built-in command, and we typically use which to determine if a specified software is installed because it only searches for the command from the path specified by the PATH environment variable:
$ which man
Find fine and fine
Find should be the most powerful of these commands, not only can be found by file type, file name and can be based on the properties of the file (such as the file's timestamp, file permissions, etc.) to search. The Find command is powerful to understand that you need at least a few separate lessons, and we'll cover only a few of the things that are commonly used here.
This command means to go to the/etc/directory and search for a file or directory named interfaces. This is the most common format for the Find command, so remember that the first parameter of find is the place to search:
$ sudo find/etc/-name interfaces
Common operations for Linux files