first, the Linux operating environment
~ location is under the/root/directory
- Root: User name currently logged in
- @ delimiter
- Chengliang: Host Name
- ~: Current path location
Linux directory structure:
To switch directories:
New directory:
LS View current directory contents
Ls-ld/data View/data Directory details
Absolute path: The path starting from the root
C:\Program Files (x86) \microsoft Office
The path starting from the root is the absolute path
Absolute path:/etc/sysconfig/network-scripts/ifcfg-eth0
Relative path: Instead of starting from the "/" root, the current path is treated as the root, and the target file or directory is "distance" from the current path.
Second, the file operation
To create a file:
Added "I am a student" for Zcl.txt
Cat represents viewing file contents; echo "XX" >> file for Append files content
Windows copy and paste:
Under Linux:
Copy ====>copy===>cp: Copy the Zcl.txt file under the/data directory to the tmp/directory. NOTE: If the TMP directory is not created, it needs to be created first. I have the original TMP directory has zcl.txt file, it will be prompted to say whether it is necessary to overwrite the original Zcl.txt file.
Summary:
CP Copy file or directory (default cannot copy directory)
-R: Recursive, copy directory, directory and future generations
-P: Copy files while keeping the file attributes intact,
-A ===-PDR
Move the/data to the/root directory:
Mv/data/root
Summary :
/data ===>/data and future generations under the/data
/data/===>/data The following descendants
Note : Here the directory moves, if you want to just move the directory below the file without moving the directory using mv/data/*/root can
Recursive deletion
RM-RF Data Delete directory must be-r,-f-free to delete everything in the data directory and directory
Note : This command is very dangerous , not recommended, to take the removal of mobile MV (in Linux and directory to create a trash folder, want to delete the MV come over)
Remember, OPS is responsible for: safe , stable , efficient
Summary:
RM suffix can only delete files
-F hands-free forced removal
-R Delete directory (recursively delete everything under directory)
#慎用
Workaround: MV Move files or directories
Improve deletion accuracy with the find command
Find Data-type f-name "Chensiqi.txt"
-type: Type of target to find
F: File type
-name + FileName: The name of the file
First step: Find the file first
Step Two: Delete the file again
Pipeline command: Xargs
The previous delete file operation can also handle this:
In the production environment, how to minimize the accidental deletion of files by operation and maintenance personnel
- Be sure to back up your data before you modify or delete it, preferably offsite, modify the configuration, and then submit the version management system to the online
- Op-ops Delete should use the MV command to replace the RM command, useless files do not worry about deleting, but moving to the Recycle Bin/tmp to observe a period of time can be set up by aliases and other means to block RM, so that once directly using the RM command is realized (of course, I would like to use a means to cross the alias).
- If you want to delete the data, you can also find a combination of RM instead of the simple RM, including set timed tasks such as actions to perform cleanup.
- If you do not want to use RM Delete, please try to switch the directory and then delete the data under the directory, without the wildcard character
- If you must use the RM-RF command to force and recursively delete the folder, the last way to avoid the error is to use the tab to the folder name, do not hit any characters, prevent accidental deletion
- If the deletion is not a directory, do not use RM-RF, the smallest method rm-f can be, even important a small number of files, may not use the-F, to obtain confirmation deletion prompt message
Summarize:
A, after deleting the data, most of the cases can be recovered, but will affect the business
B, for example: the need for downtime recovery, and data loss, longer time users can not access the corresponding data
C, recovery tools such as EXT3GREP, etc.
D. It's much better to be prepared before it happens
E, the formation of norms, professional scientific operations and maintenance habits, operation and maintenance process is to avoid the key to be the hero!
Enterprise Face Test
Q: Linux deletes all files under a directory, but retains a specified file
Method One: Find (most important must be)
! Remove all files with the file type F in the directory but exclude files-name to File9
Method Two:grep filter content: Through find all the contents of the target folder, through the pipeline | grep Filter-v excludes target content before | Xargs delivery of content to RM commands for deletion
Method Three: Command nesting commands
This method only applies to deleting the contents of the current directory
The symbol (the ~ symbol above the TAB key does not press shift) is the result of executing the command within the symbol. This method means the contents of the execution result of the command inside the RM delete ' symbol '
Linux basic commands