60 commands required for Linux

Source: Internet
Author: User
Tags control characters printable characters egrep

60 commands required for Linux

Linux system information is stored in files, which are similar to common official files. Each file has its own name, content, storage address, and other management information, such as the user and size of the file. A file can be a letter, an address book, or the program's source statement, program data, or even executable programs and other non-body content. The Linux File System has a good structure, which provides many file processing programs. This section describes common file processing commands.
File 1. The function file determines the file type by detecting the file content. The permission is applied to all users.
2. Format file [options] file Name 3. [options] Main Parameter-v: displays the version information after the standard output and exits.
-Z: detects the compressed file type.
-L: the connection is allowed.
-F name: read the list of file names to be analyzed from the file namefile.
4. Use the file command to know whether a file is an executable file in binary (ELF format), a Shell Script file, or other formats. File can recognize the following file types: Directory, Shell script, English text, binary executable file, C language source file, text file, DOS executable file.
5. If you see a file grap without a Suffix in the application instance, run the following command:
$ File grap: English text the system displays this file as an English text file. It must be noted that the file command cannot detect multimedia file types, such as graphics, audio, and video.
Mkdir 1. The mkdir command is used to create a subdirectory named dirname. Similar to the md command in ms dos, mkdir has the permission to all users.
2. Format mkdir [options] Directory Name 3. [options] Main Parameter-m, -- mode = mode: Set the permission <mode>, similar to chmod.
-P, -- parents: Create the upper-level directory when necessary. If the directory already exists, it is not treated as an error.
-V, -- verbose: information is displayed every time a new directory is created.
-- Version: displays the version information and leaves.
4. You can set the directory permission when creating a directory for an application instance. The "-m" parameter is used ". Assume that the directory to be created is named "tsk", so that all users have the rwx (read, write, and execute permissions), you can use the following command:
$ Mkdir-m 777 tsk grep 1. The grep command can specify the file to search for specific content and generate row standard output containing the content. Grep stands for Global Regular Expression Print, which indicates the Global Regular Expression version. Its permission is granted to all users.
2. Format: grep [options] 3. Main Parameters: [options] main parameters:
-C: only counts matching rows are output.
-I: case-insensitive (only applicable to single characters ).
-H: When querying multiple files, the file name is not displayed.
-L: When querying multiple files, only names containing matching characters are output.
-N: displays matching rows and row numbers.
-S: the error message that does not exist or does not match the text is not displayed.
-V: displays all rows that do not contain matched text.
Main Parameters of the regular expression pattern:
: Ignore the original meaning of special characters in regular expressions.
^: Match the start line of the regular expression.
$: Matches the end row of the regular expression.
<: Starts from the row that matches the regular expression.
>: Ends with the row matching the regular expression.
[]: A single character. For example, [A] indicates that A meets the requirements.
[-]: Range, such as [A-Z], that is, A, B, C Until Z all meet the requirements.
. : All single characters.
*: It can contain 0 characters.
Regular Expressions are very important concepts in Linux/Unix systems. A regular expression (also known as "regex" or "regexp") is a Pattern that describes a type of strings ). If a string can be described using a regular expression, we can say that this character matches the regular expression ). In DOS, the wildcard "*" can be used to represent any character. In Linux, regular expressions are usually used to find the text mode and perform the "search-Replace" operation and other functions on the text.
4. Application Instance query DNS is one of the daily tasks, which means to maintain a large number of IP addresses covering different networks. Sometimes the number of IP addresses exceeds 2000. If you want to view the nnn. nnn network address, but forget the rest of the second part, you only know that there are two periods, such as nnn nn... To extract all the nnn. nnn IP addresses, use [0-9] {3}. [0-0 {3 }. It means that any number appears three times, followed by a sentence, followed by any number three times, followed by a sentence.
$ Grep '[0-9] {3}. [0-0 {3}' ipfile supplement. The grep family also includes fgrep and egrep. Fgrep is a fix grep that allows you to search for strings rather than a pattern. egrep is an extended grep that supports basic and extended regular expressions, however, it does not support the application of the q mode range and some more standardized models.
Dd 1. The dd command is used to copy files and convert and format data according to parameters.
2. Format dd [options] 3. [opitions] Main Parameter bs = byte: Forced ibs = <byte> and obs = <byte>.
Cbs = byte: Specifies <byte> for each conversion.
Conv = Keyword: convert a file by using a comma-separated keyword.
Count = number of blocks: only the specified number of blocks is copied.
Ibs = byte: Read the specified <byte> each time.
If = file: reads the content of <File>, rather than non-standard input data.
Obs = byte: Specify <byte> for each write.
Of = file: write data to the <File> file, which is not displayed in the standard output.
Seek = number of blocks: first, the output data of the specified <number of blocks> In obs is skipped.
Skip = number of blocks: First, it skips the specified <number of blocks> in ibs.
4. Application Instance
Dd commands are often used to create Linux boot disks. First find a bootable kernel, point its root device to the correct root partition, and then use the dd command to write it to the floppy disk:
$ Rdev vmlinuz/dev/hda $ dd if = vmlinuz of =/dev/fd0
The code above indicates that the rdev command directs the root device in the kernel vmlinuz to/dev/hda. Replace "hda" with your own root partition, run the dd command to write the kernel to a floppy disk.
Find 1. The function of the find command is to search for files in the directory, and its permission is for all users.
2. The format of find [path] [options] [expression] path specifies the directory path. From here, the System Searches down the directory tree to find the file. It is a path list separated by spaces. If path is not written, the current directory is used by default.
3. Main Parameter [options] parameters:
-Depth: uses the depth-level search process to prioritize file content in a specified directory at a layer.
-Maxdepth levels: the level-level subdirectory of the Start directory. Level is a non-negative number. If level is 0, it indicates that it is only searched in the current directory.
-Mindepth levels: indicates that at least the level subdirectory of the Start directory is found.
-Mount: it is not found in directories and files of other file systems (such as Msdos and Vfat.
-Version: print the version.
[Expression] is a matching expression accepted by the find command. All operations of the find command are for the expression. It has many parameters. Here we only introduce some common parameters.
-Name: The wildcard * And? are supported ?.
-Atime n: searches for files read in the past n days.
-Ctime n: searches for files modified in the past n days.
-Group grpoupname: searches for all grpoupname files in the group.
-User name: search for all files whose owner is the user name (ID or name.
-Size n: the size of the search file is n blocks.
-Print: outputs and prints the search results.
4. Application tips:
(1) Search by file name. For example, to find a file named lilo. conf, run the following command:
Find/-name lilo. conf find command "/" indicates searching the entire hard disk.
(2) It takes a long time to quickly search for a file based on the file name, especially when large Linux file systems and large-capacity hard drive files are stored in Deep Sub-directories. If we know that this file is stored in a directory, we can save a lot of time by searching in this directory. For example, in the smb. conf file, the file suffix ". conf" can be used to determine that this is a configuration file, so it should be in the/etc directory. In this case, you can use the following command:
Find/etc-name smb. conf. In this way, you can use the "quick file search" method to shorten the time.
(3) Search for some file names. Sometimes we know that only one file package contains the four words abvd. To find all the files in the system that contain the four characters, enter the following command:
Find/-name '* abvd *'
After entering this command, the Linux system will find all the files containing the four characters abvd in the/directory (where * is a wildcard ), for example, all files that meet the conditions, such as abvdrmyz, can be displayed.
(4) Searching for files using hybrid search
The find command can use a hybrid search method. For example, we want to search for a file larger than 500000 bytes in the/etc directory and modify it within 24 hours, you can use-and (and) to link two search parameters into a hybrid search method.
Find/etc-size + 500000c-and-mtime + 1
Mv 1. The mv command is used to rename a file or directory, or move the file from one directory to another. Its permission is for all users. This command is like a combination of ren and move in the doscommand.
2. The format is mv [options] source file or directory target file or directory 3. [options] Main Parameter-I: interactive operation. If the mv operation will overwrite the existing target file, the system will ask whether to rewrite the file and ask the user to answer "y" or "n" to avoid overwrite the file by mistake.
-F: Disable interactive operations. When an mv operation overwrites an existing target file, no indication is given. If this parameter is specified, the I parameter will no longer work.
4. Application Instance (1) Move all files in/usr/cbu to the current directory (represented:
$ Mv/usr/cbu/*. (2 rename the file cjh.txt as wjz.txt:
$ Mv cjh.txt wjz.txt ls 1. The ls command is used to display the directory content. Similar to the dir command in DOS, its permission is granted to all users.
2. Format: ls [options] [filename] 3. options Main Parameter-a, -- all: Do not hide any project that starts with the "." character.
-A, -- almost-all: list any projects except "." and.
-- Author: prints the author of each file.
-B, -- escape: an octal overflow sequence to indicate non-printable characters.
-- Block-size = size: the block is in the unit of specified <size> bytes. -B, -- ignore-backups: do not list any ~ The project whose character ends.
-F: No sorting is performed. The-aU parameter takes effect and the-lst parameter is invalid.
-F, -- classify: add the file type indicator (*/= @ | one of them ).
-G: like-l, but do not list owner.
-G, -- no-group: inhibit display of group information.
-I, -- inode: List inode numbers of each file.
-I, -- ignore = style: do not print any items that match the Shell universal character <style>.
-K: -- block-size = 1 K.
-L: Used to list information in a long format.
-L, -- dereference: when the file information of the symbolic link is displayed, the object indicated by the symbolic link is displayed, not the information of the symbolic link itself.
-M: All items are separated by commas (,) and the whole row width is filled.
-N, -- numeric-uid-gid: similar to-l, but list UID and GID.
-N, -- literal: List unprocessed project names, for example, not specially processed control characters.
-P, -- file-type: add the file type indicator (/= @ | one of them ).
-Q, -- quote-name: Enclose the project name in double quotation marks.
-R, -- reverse: in reverse order.
-R, -- recursive: Lists All Sub-directory layers at the same time.
-S, -- size: Order the block size.
Diff 1. the diff command is used to compare two files and indicate the differences between the two files. Its permission is granted to all users.
2. Format: diff [options] source file target file 3. [options] Main Parameter-a: process all files as text files.
-B: Ignore spaces.
-B: Ignore empty rows.
-C: Use the outline output format. -H: Use the test method to accelerate search for large files.
-I: Ignore case sensitivity changes.
-N -- rcs: the format of the output RCS.
Cmp 1. uses the cmp (abbreviation of "compare") command to briefly identify whether two files are different. Its permission is granted to all users.
2. Format: cmp [options] File Name 3. [options] Main Parameter-l: outputs the bytes in decimal format and outputs different octal values in two files.
Cat 1. The cat (abbreviation of "concatenate") command is used to connect to and display information about one or more specified files. Its permission is granted to all users.
2. Format: cat [options] File 1 file 2 ......
3. [options] Main Parameter-n: Number of all output rows starting from the first line.
-B: similar to-n, except that the blank row is not numbered.
-S: When there are two or more consecutive blank rows, it is replaced by a blank row.
4. Application Example (1) the simplest use of the cat command is to display the content of a text file. For example, you can run the following command to view the content of the README file:
$ Cat README (2) Sometimes it is necessary to process several files into one and save the processing results to a separate output file. The cat command accepts one or more files on the input and prints them as a separate file to its output. For example, add the row number to the content of the README and INSTALL files (without blank lines), and then append the content to the new text file File1:
$ Cat readme install File1 (3) Another important feature of cat is to number rows, as shown in figure 2. This function is convenient for the compilation of program documents and legal and scientific documents. printing the row number on the left makes it easy to compile a part of the reference document, these are important in programming, scientific research, business reports, and even legislation.
The row numbering function has two parameters:-B (only numbers can be performed on non-blank rows) and-n (numbers can be performed on all rows:
$ Cat-B/etc/named. conf
Ln 1. The ln command is used to create links between files. Its permission is for all users.
2. Format ln [options] source file [Link name] 3. Parameter-f: the source file is deleted first after the link is completed.
-D: allows system administrators to hard link their directories.
-S: Symbolic Link ).
-B: Back up the files that will be overwritten or deleted during the link.
There are two types of links: Hard Link and Symbolic Link ). By default, the ln command generates a hard link.
Hard connection refers to the connection through the index node. In a Linux File System, a file stored in a disk partition is assigned with an Index node number (Inode Index) No matter what type it is ). In Linux, multiple file names direct to the same index node. Generally, this type of connection is hard connection. A hard connection allows a file to have multiple valid path names. In this way, you can create a hard connection to an important file to prevent "accidental deletion. The reason is as described above, because there is more than one connection to the index node of the directory. Deleting only one connection does not affect the connection between the index node and other nodes. Only when the last connection is deleted will the connection of the data block and directory of the file be released. That is to say, the object will be deleted.
In contrast to hard connection, there is another connection in the Lnux system, called Symbilc Link. Soft-link files are similar to Windows shortcuts. It is actually a type of special file. In a symbolic connection, a file is actually a text file containing the location information of another file.
Hands-on exercises
We have introduced the Linux File Processing commands. The following describes several instances. You can practice the commands you just mentioned.
1. Use symbolic links to quickly access key Directories
Symbolic Links are a very useful feature. It is assumed that some directories or files need to be frequently used, but these files or directories are in deep subdirectories due to Linux Files and directory structures. For example, the Apache Web server document is located in/usr/local/httpd/htdocs of the system, and does not want to enter such a long path from the main directory every time (in fact, this path is also hard to remember ).
To solve this problem, you can create a symbolic link in the main directory, So that you only need to enter this link when you need to enter this directory.
To conveniently enter the directory of the Web server (/usr/local/httpd/htdocs) document, run the following command in the main directory: $ ln-s/usr/local/httpd/htdocs gg
In this way, you can access the Web server documents every time you enter the gg directory. If you no longer access the Web server documents, you can delete the gg files, but the real Web Server documents are not deleted.
2. run the dd command. rd format root. ram content imported into memory dd if =/dev/fd0 of = floppy. fd dd if = root. ram of =/dev/ram0 #3. grep Command System Call
Grep is one of the most widely used commands in Linux/Unix. It can be called in many Linux systems.
(1) to query the directories in the directory list, use the following method:
$ Ls-l | grep 'cmdd'
(2) If you query all files in a directory that does not contain the directory, the method is as follows:
$ Ls-l | grep 'partition [partition d]'
(3) Use the find command to call grep, such as "Chinput" in all C source code. The method is as follows:
$ Find/ZhXwin-name *. c-exec grep-q-s Chinput {};-print

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.