Linux must learn 60 command file processing (transferred from: CU)

xiaoxiao2021-03-06  53

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 1. The role of the file is determined by the probe file content, using the right to use all users. 2. Format File [Options] file name 3. [options] Main parameters - V: Display version information after the standard output, and exit. -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 Use the file command to 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 with a suffix, you can use the following command: $ file grap grap: english text At this time, 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 1. The role of the mkdir command is to establish a subdirectory named DIRNAME, similar to the MD command under MS DOS, which 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 instances can set permissions for the directory when performing directory, and the parameters used at this time are "-m". Suppose you want to create 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 1. The role grep command can specify the file Search for specific content and output line standards containing these contents. 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. -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 the regular expression. ^: 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 instance query DNS service is one of the daily work, which means maintaining a large number of IP addresses overwriting 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 1. The action 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 instance DD commands are often used to make a Linux boot disk. First find a bootable kernel, to point its root device to the correct root partition, then use the DD command to write it in a floppy disk: $ rdev vmlinuz / dev / hda $ dd if = vmlinuz of = / dev / fd0 above code description, With the RDEV command to direct the root device in the kernel VMLinuz to / dev / hda, please "HDA" in its own partition, next to the DD command to write the kernel to the floppy disk.

Find 1. The role of the role of the Find command is to search for files in the directory, and its usage rights are all users. 2. Format Find [PATH] [Options] [Expression] Path Specifies the directory path, and the system starts along the directory tree down here. 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 can give priority to the file content in a specified directory. -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. Apply Skills Finding Documents: (1) Find, for example, file name, for example, we want to find a file name that is lilo.conf, you can use the following command: Find / -Name Lilo.conf Find Command The "/" indicates the search throughout the hard disk. (2) Quick Find Files Find files according to file names will encounter a practical problem, which is a long period of time, especially the large Linux file system and massive hard drive 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 in the / etc directory, you can use the following command: find / etc -name smb.conf, use "Quick Find File" mode can shorten the time. (3) Finding method according to some file name Sometimes we know that only files contain 4 words, then find all files containing these 4 characters in the system, you can enter the following command: Find / -Name '* Abvd * 'Enter this command, the Linux system will find all files containing 4 characters contained in the / directory (where * are wildcards), such as AbvDrmyz, etc., can be displayed.

(4) Use the mixed lookup method to find the file Find command to use a mixed lookup method, for example, we want to find more than 50,000 bytes in the / etc directory, and a file modified within 24 hours, you can use -and ( And) link two lookup parameters together into a mixed lookup method. Find / etc -Size 1 500000c -and -mtime 1 mv 1. The action mv command is used to change the file or directory, or transfer the file from a directory into another directory, its usage authority 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 target file or directory 3. [Options] Main parameters -i: interactive operation. 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 / usr / cbu to the current directory (use ": $ mv / usr / cbu / *. (2) Rename the file CJH.txt Rename WJZ .txt: $ mv cjh.txt wjz.txt ls 1. The role ls command is used to display the directory content, similar to the DIR command under DOS, and its use right is all users. 2. Format ls [options] [filename] 3.Options Main parameters -a, --all: Do 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