Linux must learn 60 command file processing (1)

xiaoxiao2021-03-06  43

The Linux system information is stored in the file, and the file is similar to the ordinary official document. Each file has its own name, content, storage address, and some other management information, such as the user, the size of the file, etc. The file can be a letter, a address book, or a source statement of the program, the data of the program, can even include executable programs and other non-text content. The Linux file system has a good structure, and the system provides a lot of file handler. Here mainly introduces the commonly used file processing commands.

File

Role

FILE uses the probe content to determine the file type, the use of rights is all users.

2. Format

File [Options] file name

3. [Options] Main parameters

-v: Displays version information after the standard output, and exits.

-z: Detect the compressed file type.

-L: Allows connection.

-f name: Read the list of files to be analyzed from the file namefile.

4. Brief Description

Using the file command, you can know that a file is the executable of binary (ELF format), or the shell script file, or other format. FILE can identify file types with directory, shell scripts, English text, binary executables, C language source files, text files, DOS executables.

5. Application example

If we see a file GRAP without suffix, you can use the following command:

$ FILE GRAP

Grap: english text

At this point, the system displays this is an English text file. It should be noted that the file command cannot detect multimedia file types such as graphics, audio, and video.

Mkdir

Role

The role of the mkdir command is to establish a subdirectory named DIRNAME. Similar to the MD command under MS DOS, its use right is all users.

2. Format

MKDIR [OPTIONS] directory name

3. [Options] Main parameters

-M, --mode = mode: Set permissions Similar to ChMod.

-P, --parents: Create a top directory when needed; if the directory already exists, it is wrong.

-V, --verbose: Information is displayed each time you create a new directory.

--Version: Displays the version information to leave.

4. Application example

Permissions for the directory can be set when the directory is created, and the parameters used at this time are "-m". Suppose you want to create a directory name is "TSK", so that all users have RWX (ie read, write, execute permissions), then you can use the following command:

$ mkdir -m 777 TSK

GREP

Role

The grep command can specify the specific content in the file and output the line standard containing these content. The GREP is full of global regular expression, representation of global regular expression versions, which is all users.

2. Format

Grep [options]

3. Main parameters

[Options] Main parameters:

-C: Only the count of matched rows is output.

-I: Does not vary in cases (only for single characters).

-H: The file name is not displayed when querying multi-files.

-L: You only output file names that contain match characters when querying multi-files.

-N: Display matching row and line number.

-S: Do not display error messages that do not exist or have no text.

-V: Displays all rows that do not contain matching text.

Pattern regular expression Main parameters:

/: Ignore the original meaning of special characters in regular expressions. ^: Match the start of the regular expression.

$: Match the end line of the regular expression.

/ <: From the row of matching regular expressions.

/>: The row of the matching regular expression is over.

[]: Single character, such as [a], is a conformity.

[-]: Range, such as [A-Z], that is, A, B, and C, until Z is compliant.

. : All single characters.

*: There is a character, the length can be 0.

Regular expressions are very important concepts in the Linux / UNIX system. Regular expression (also known as "regex" or "regexp") is a pattern that can describe a class of strings (Pattern). If a string can be described in a regular expression, we say this character and the regular expression match (Match). This and DOS users can use wildcard "*" to represent any character. On Linux systems, regular expressions are often used to find text mode, and the text execute "Search-Replace" operation and other functions.

4. Application example

Query DNS services is one of the daily work, which means maintaining a large number of IP addresses overriding different networks. Sometimes IP address will exceed 2,000. If you want to view the Nnn.nnn network address, but I forgot the rest of the second part, I only know that there are two periods, such as NNN NN ... To extract all NNN.NNN IP addresses, use [0-9] / {3 / }/ .[0-0/ }/. The meaning is that any number appears 3 times, then follow the sentence, then the arbitrary number appears 3 times, then follow the sentence.

$ GREP '[0-9] / {3 / }/.[0-0/ {3/On }/' ipfile

Supplementary description, the GREP family also includes FGREP and EGREP. FGREP is FIX GREP, allowing a string instead of a mode; EGREP is extended GREP, supports basic and extended regular expressions, but does not support / Q mode scope and some more specifications corresponding to it.

DD

Role

The DD command is used to copy the file and convert the data and format data according to the parameters.

2. Format

DD [Options]

3. [opitions] Main parameters

BS = byte: Forced IBS = and OBS = .

CBS = byte: Each conversion specified .

CONV = Keyword: Convert files based on a comma-separated keyword represented.

Count = Block Number: Only the input data specified .

IBS = byte: Each time you read the specified .

If = file: Read content, not standard input data.

OBS = byte: Each time you write the specified .

Of = file: Write data into instead of the standard output display.

SEEK = Block Number: Skate the output data of the specified in OBS.

SKIP = Block Number: First skip the input data of the specified in IBS.

4. Application example

DD commands are often used to make a Linux boot disk. First find a bootable kernel, point the root device to the correct root partition, then write it to the floppy disk using the DD command:

$ RDEV VMLINUZ / DEV / HDA

$ dd if = vmlinuz of = / dev / fd0

转载请注明原文地址:https://www.9cbs.com/read-71417.html

New Post(0)