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:

-a: OR--time=atime or--time=access or--time=use change access time only; -c: or--no-create does not create any files; -d: < Time and date > Use the specified date time instead of the current time; -f: This parameter is ignored and is only responsible for solving the compatibility problem of BSD version touch instruction; -m: or--time=mtime or--time=modify only longer than the change time; -r: < Reference file or directory > Set the date and time of the specified file or directory to be the same as the date and time of the reference file or directory; -t: < Date time > Use the specified date time instead of the current time;

mkdir Command

Create Directory

Options:

-Z: Sets the security context that works when SELinux is used; -m < Target attribute > OR--mode < Target attribute > Set the permissions of the directory at the same time of establishing the directory; -p or--parents If the upper directory of the directory to be established has not been established at present, it will 1 and establish the upper directory;

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:

-a: This parameter has the same effect as specifying the "-dpR" parameter at the same time; -d: When copying a symbolic connection, establish the destination file or directory as a symbolic connection and point to the original file or directory connected to the source file or directory; -f: Forcibly copy files or directories, regardless of whether the destination file or directory already exists; -i: Ask the user before overwriting existing files; -l: Hard-link source files instead of copying files; -p: Preserve the attributes of the source file or directory; -R/r: Recursive processing, all files under the specified directory and subdirectory 1 and processing; -s: Make symbolic connections to source files instead of copying files; -u: Using this parameter will only copy files when the source file is changed more recently than the target file or when the target file with corresponding names does not exist; -S: When backing up a file, replace the default suffix of the file with the specified suffix "SUFFIX"; -b: Backup the target file before overwriting the existing file target; -v: Details what the command does.

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:

--backup= < Backup mode > : If you need to overwrite the file, back it up before overwriting; -b: When a file exists, create a backup of it before overwriting; -f: If the target file or directory duplicates the existing file or directory, overwrite the existing file or directory directly; -i: Interactive operation. Ask the user before overwriting. If the source file has the same name as the target file or the file in the target directory, ask the user whether to overwrite the target file. The user enters "y" to indicate that the target file will be overwritten, and "n" to indicate that the source file will be unmoved. This will avoid overwriting the file by mistake. --strip-trailing-slashes: Remove slash "/" from source file; -S < Suffix > Specify a suffix for the backup file instead of using the default suffix; --target-directory= < Directory > Specifies that the source files are to be moved to the destination directory; -u: Move only when the source file is newer than the destination file or the destination file does not exist.

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.


Related articles: