Summary of linux File Directory Management Command
- 2021-07-06 12:24:03
- OfStack
touch Command
It has two functions: 1. It is used to update the time label of existing files to the current time of the system (default mode), and their data will be kept intact; 2 is used to create a new empty file.
Options:
mkdir Command
Create Directory
Options:
Parameters:
Directory: Specifies a list of directories to create, separated by spaces.
cp Command
Used to copy one or more source files or directories to the specified destination file or directory.
Options:
Parameters:
Source files: Make a list of source files. By default, the cp command cannot copy directories, and if you want to copy directories, you must use the-R option;
Target file: Specifies the target file. When the "source file" is multiple files, the "destination file" is required to be the specified directory.
Note: All target files must specify directories that already exist. The cp command cannot create directories.
Example:
When we use cp command to copy files under Linux, sometimes we need to overwrite 1 file with the same name. When overwriting files, there will be a prompt: we need to press Y constantly to determine the execution of overwriting. It's good that the number of files is not large, but if hundreds of them are estimated to vomit blood according to Y, they have tossed and summarized a method for half a day:
cp aaa/* /bbb
Copy all files under aaa to the/bbb directory. If there are files with the same name as aaa in the/bbb directory, press Y to confirm and skip the subdirectories under aaa directory.
cp -r aaa/* /bbb
You still need to press this time Y To confirm the operation, but the subdirectories are not ignored.
cp -r -a aaa/* /bbb
Still need to press Y To confirm the operation and put aaa Directory and subdirectory and file attributes are also passed to the /bbb .
\cp -r -a aaa/* /bbb
Success, no prompt press Y The directory property is passed, and the directory is not skipped.
mv Command
Used to rename files or directories, or to move files from one directory to another.
Options:
Example:
Move all files in direction/usr/men to the current directory (denoted by.):
mv /usr/men/* .
rm Command
Delete one or more files or directories in one directory, or delete all files and subdirectories of a directory and its subordinates. For linked files, just delete the whole linked file, while the original file remains unchanged.
Options:
-d: directly delete the hard-connected data of the directory to be deleted into 0, and delete the directory; -f: Forced deletion of files or directories; -i: Ask the user before deleting an existing file or directory; -r or-R: Recursive processing, all files in the specified directory are processed with subdirectory 1; --preserve-root: No recursive operation on the root directory; -v: Displays detailed execution of instructions
dd Command
Copy the file and transform and format the contents of the original file. It is recommended to use dd for physical disk operations when necessary, and block device files are best used when using dd for disk operations.
Options:
bs= < Number of bytes > Sets ibs (input) and obs (output) to the specified number of bytes; cbs= < Number of bytes > When converting, only the specified number of bytes is converted at a time; conv= < Keyword > Specify the method of file conversion; count= < Number of blocks > Read only the specified number of blocks; ibs= < Number of bytes > Number of bytes read per time; obs= < Number of bytes > Number of bytes per output; of= < Documents > Output to file; seek= < Number of blocks > : 1 When starting output, skip the specified number of blocks; skip= < Number of blocks > : 1 Skips the specified number of blocks when starting reading;
Example:
dd if=/dev/zero of=sun.txt bs=1M count=1
This command creates a file sun. txt with the size of 1M, where the parameters interpret:
if stands for the input file. If if is not specified, input is read from stdin by default. of stands for the output file. If of is not specified, stdout is used as the default output by default. bs represents the block size in bytes. count represents the number of blocks copied. /dev/zero are 1-character devices that continually return 0-value bytes (\ 0).
file Command
Used to probe the type of a given file. file command to check the file is divided into three processes: file system, magic number check and language check.
Options:
-f < Name file > When a name file is specified and its contents have one or more file names, let file identify these files in sequence, and the format is one file name per column; -b: When listing identification results, the file name is not displayed; -c: Detailed display of instruction execution process to facilitate troubleshooting or analysis of program execution; -L: Displays directly the file category to which the symbolic connection points; -m < Magic digital file > : Specify magic digital files; -z: Try to interpret the contents of the compressed file.
Parameters:
Files: To determine the type of file list, multiple files are separated by spaces, and shell wildcards can be used to match multiple files.
Example:
Display file type
[root@localhost ~]# file install.log
install.log: UTF-8 Unicode text
[root@localhost ~]# file -b install.log <== Do not display file names
UTF-8 Unicode text
[root@localhost ~]# file -i install.log <== Display MIME Category.
install.log: text/plain; charset=utf-8
[root@localhost ~]# file -b -i install.log
text/plain; charset=utf-8
Displays the file type of symbolic link
[root@localhost ~]# ls -l /var/mail
lrwxrwxrwx 1 root root 10 08-13 00:11 /var/mail -> spool/mail
[root@localhost ~]# file /var/mail
/var/mail: symbolic link to `spool/mail'
[root@localhost ~]# file -L /var/mail
/var/mail: directory
[root@localhost ~]# file /var/spool/mail
/var/spool/mail: directory
[root@localhost ~]# file -L /var/spool/mail
/var/spool/mail: directory
The above is all the knowledge points introduced this time. Thank you for your study and support for this site.