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] Lord ?
-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
-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 =
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
OBS = byte: Each time you write the specified
Of = file: Write data into
SEEK = Block Number: Skate the output data of the specified
SKIP = Block Number: First skip the input data of the specified
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
The above code description, use the RDEV command to guide the root device in the kernel VMLinuz to / dev / hda, please "HDA" in its own partition, next to write the kernel to the floppy disk. Find1. 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