Linux Beginner-File Management Chapter
Everything in the Linux system is stored as files in the computer, so the management of the files in the Linux system is very important. The following are some common approaches to file management.
1, the establishment of documents
The creation of a file or the timestamp of a modified file typically uses the "touch" command, such as creating a file named "file" in the current directory, which can be entered directly into the command "Touch file". If you need to create n files, enter "Touch FILE{1..N}", for example, if you need to create 10 file File1-file10, enter "Touch file{1..10}".
2, the establishment of the directory
The establishment of a directory usually uses the "mkdir" command, such as creating a directory named Test, you need to enter "mkdir test", if you need to set up n directories, such as the establishment of 3 directories, then enter "MkDir test{1..3}".
Note: If the parent directory to be established does not exist, you need to add the parameter "-P", for example, to create a folder named Q in the desktop, there is a W directory, enter "Mkdir-p q/w" can be.
3. Editing of files
General text editing using "vim" command, such as edit "file" to enter the command "Vim file", at this time the command mode is not able to edit the file, you need to press "I" into the insert mode can be edited, after the completion of editing press "ESC" key and enter ": Wq" save. More use of the "vim" command will be summarized later on.
4, the file content of the view
You can use "cat", "less", "Head-n X", "Tail-n X" to view the contents of the file. "Cat" can view the contents of the file directly, "Less" can be paged and can search keywords, suitable for more than the content of the file. "Head" and "tail" can view the first few lines of a file and the last few lines.
5. Deletion of directories and files
The deletion of directories and files is usually implemented with the "RM" command, which was previously created with a file "files", which can now be deleted with the command "RM file", but if a hint of deletion is determined, the input y can be deleted. If you enter "Rm-f file" You can forcibly delete files without prompting. If you want to delete the directory you need to use the parameter "-R", if you need to delete the previously established directory "test", then enter "RM-FR test" to delete the directory.
6. Copying of directories and files
Replication of directories and files typically uses the "CP" command, which is essentially a new process. When copying files, using the CP file directory to copy files to the directory, such as copying "file1" files to the directory "Test1", you need to enter the command "CP file1 test1".
Using "CP file 1 File 2" can be file 1 for the template to establish a file 2, such as the "file1" file is copied as "File" files, enter the command "CP file1 file".
When copying a directory, you need to add the parameter "-R", for example, copy the "test1" directory to the "test2" directory and enter the command "Cp-r test1 test2".
Note that when you use the "CP" command to copy a file or directory to another directory, you can include n files or directories before the target directory, but only one destination directory. For example, the file "File1" "File2" and the Directory "Test1" are copied to the "Test3" directory.
7. Movement of directories or files
The move command for directories and files is "MV", and moving under the same disk is the process of renaming, and the movement of different disks is the process of copying and deleting.
Use the "MV File or directory directory" to copy files to the directory, such as copying "file3" files to the "test2" directory.
You can rename a file or directory that exists by using the file or directory that does not exist in the MV file or directory command. For example, rename the "Test1" directory to the "test" directory.
These are the basic commands that are commonly used by file management in Linux systems.
Linux Beginner-File Management Chapter