Linux must learn 60 command file processing (2)

xiaoxiao2021-03-06  43

Find

Role

The role of the Find command is to search for files in the directory, which is all users.

2. Format

Find [PATH] [options] [Expression]

Path Specifies the directory path, and the system starts to find files down along the directory tree. It is a path list, separated by spaces, if you don't write PATH, then default is the current directory.

3. Main parameters

[OPTIONS] parameters:

-Depth: Use the depth level lookup process, you specify the file content in a specified directory in a certain layer.

-MaxDepth levels: Represents the last directory of the start directory. Level is a non-negative number, if Level is 0, it means to find only in the current directory.

-Mindepth levels: indicates at least the colordeling of the first directory.

-Mount: Find in directory and files in other file systems such as MSDOS, VFAT, etc.).

-Version: Print version.

[Expression] is a matching expression, which is an expression acceptable, and all operations of the Find command are for expressions. Its parameters are very many, and only some common parameters are introduced here.

-Name: Support unmanagers * and?

-Time N: Search for files read in the past N days.

-Ctime N: Search for files modified in the past N days.

-Group GrPoupName: Search all groups of files for GrPoupName.

-User Username: Search all file owners for the user name (ID or name).

-Size N: Searching the file size is the file of n block.

-Print: Output search results, and print.

4. Application skills

Several methods of finding files:

(1) Find according to the file name

For example, we want to find a file name that lilo.conf, you can use the following command:

Find / -name lilo.conf

"/" after the Find command represents the entire hard drive.

(2) Quick lookup file

Depending on the file name finding files will encounter an actual problem, it is a long period of time, especially the large Linux file system and massive hard disk files are placed in a deep subdirectory. If we know that this file is stored in a certain directory, you can save a lot of time as long as you find it under this directory. For example, the SMB.conf file, from its file suffix ".conf" can determine that this is a configuration file, then it should be within the / etc directory, you can use the following command:

Find / etc -name smb.conf

In this way, the use of "quick lookup file" can shorten the time.

(3) Find a method according to some file names

Sometimes we know that only a file contains 4 words of ABVD, then you want to find all files containing these 4 characters in the system to enter the following command:

Find / -name '* abvd *'

After entering this command, the Linux system will find all files containing 4 characters containing ABVD (where * are wildcards), such as AbvDrmYz, such as AbvDrmYz, such as AbvDrmYz, such as AbvDrmyz, such as AbvDrmYz.

(4) Find files using a mixed lookup method

The Find command can use a mixed lookup method, for example, we want to find a file greater than 500,000 bytes in the / etc directory, and a file modified within 24 hours, you can use -and (and) link two lookup parameters linkage Combine into a mixed look. Find / etc -size 500000c -and -mtime 1

MV

Role

Use the mv command to be renamed for a file or directory, or transfer the file from a directory into another directory, which is all users. This command is like a combination of REN and MOVE in the DOS command.

2. Format

MV [options] source file or directory destination file or directory

3. [Options] Main parameters

-I: interactively operate. If the MV operation will result in overwrite the existing target file, the system is inquiry to override, requiring the user to answer "Y" or "n", which avoids erroneous overwriting files.

-F: interactive operation is prohibited. The MV operation does not give any indication when an existing target file is covered, and the i parameter will no longer work after specifying this parameter.

4. Application example

(1) Move all files in the / usr / CBU to the current directory (use "."):

$ mv / usr / cbu / *.

(2) Rename the file CJH.txt: WJZ.txt:

$ MV CJH.TXT WJZ.TXT

LS

Role

The ls command is used to display directory content, similar to DIR commands under DOS, which is all users.

2. Format

LS [options] [filename]

3.Options Main parameters

-A, --all: Does not hide any items starting with "." Characters.

-A, - Almost-all: Any item other than "." And ".." is listed.

--Author: Prints each document authority.

-B, -, --escape: The unprintable character is represented by an octa binary overflow sequence.

- Block-size = Size: Blocks in bytes specified .

-B, --ignore-backups: Does not list any items ending to characters.

-F: Do not sort, -au parameters take effect, the -lst parameter is invalid.

-F, --classify: Plus an indicator symbol of file type (* / = @ | one).

-G: like -l, but do not list Owner.

-G, --NO-group: inhibit Display of group information.

-I, --inode: Lists the Inode number of each file.

-I, --ignore = style: No items that match the Shell Wan Character