(Linuxshell) Chapter 2-joy of command (1)

Source: Internet
Author: User

(Linuxshell) Chapter 2-joy of command (1)

This article is from my personal blog: (linux shell) Chapter 2 -- joy of command (1)

In the previous chapter, we described some syntaxes that need to be paid attention to in linux shell. Next we will begin to understand Common commands of linux shell. Let's go...

    Cat command:

    Cat itself indicates concatenate ). The cat command has some common parameters, such as-n and-s. We will introduce them one by one:

    If you want to quickly view the content of a text file, you can use the cat command:

    Cat file

    If you want to view multiple files at a time, add the file path to the file.

    Cat file1 file2 file3

    To display the row number of a text file, use the-n parameter:

    Cat-n file or cat-n file1 file2 file3

    If you want to remove empty lines from the text, use the-s parameter:

    Cat-s file or cat-s file1 file2 file3, of course, here you can also use the tr command to benefit from the blank line: cat file | tr-s ''; this tr command means to treat multiple line breaks as one line break.

    Find command:

    The find command traverses down the File hierarchy, matches the files that meet the conditions, and performs corresponding operations.

    Basic Syntax:

    Find.-print # print all file paths in the current directory with paths

    The find command also has many parameters. Let's take a look at the usage of some common parameters:

    1). Search by file name or regular expression

    Find.-name "*. sh"-print # find all files matching the end of sh in the current directory and print them to the terminal.


    -Name also has a corresponding-iname to ignore the case sensitivity of keywords.

    Find.-iname "*. sh"-print <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + ICAgICAgICAyKS64 + b7dwre + tsalxeQ8L3A + partition/wry/qsq8o6yy6dXSwre + partition = "http://www.2cto.com/uploadfile/Collfiles/20140726/2014072609082097.png" title = "partition" alt = "\">

    3). Regular Expression-based matching-regex

    Find.-regex ". * \. py $"-print

    4). Negative parameter!

    If you want to find a file that does not contain conditions, add it before the type! You can:

    Find .! -Name "*. sh"-print

    5). Search the directory in depth-maxdepth and-mindepth.

    We can use this command to limit the depth of the find downward search.

    Find.-maxdepth 1-type f-print # find a file in the current directory, that is, it does not traverse down


    -Maxdepth and-mindepth should appear as the third parameter of find. If they appear as the fourth or later parameter, the efficiency of find may be affected, because it has to perform some unnecessary checks.

    ? ? 6). Search for-type based on the file type.

    ? ? ? Find.-type d-print # Only list all directories

    ? ? ?

    ? ? ? Find.-type f-print # Only list all objects

    ? ? ? Find.-type l-print # Only list all links

    ? ? 7). Search by file time-mtime (modification time)-atime (access time)-ctime (Change Time). Time +,-indicates the time before and after

    ? ? ? Find.-type f-atime-7-print # print all files accessed in the last 7 days

    ? ? ?

    ? ? -Amin (access time),-mmin (modification time),-cmin (Change Time)

    ? ? ? Find.-type f-amin + 7-print # print all files whose access time exceeds 7 minutes

    ? ? ? Find.-type f-newer file. sh-print # find all files that have been modified for a longer time than file. sh.

    ? ? 8), search-size Based on file size

    ? ? ? Find. -type f-size + 2 k # search for all files larger than 2 kb. In addition to k, you can also use B -- block, c -- byte, w -- word, M -- MB, G -- Kyrgyzstan

    ? ? ?

    ? ? ? Find.-type f-size 2 k # files larger than or equal to 2 kb

    ? ? ? Find.-type f-size-2 k # files smaller than 2 kb

    ? ? 9). Matching operation

    ? ? ? Find.-name "*. sh"-delete # delete all matched files (usage)

    ? 10). Matching of file permissions and ownership -- perm

    ? ? ? Find.-type f-perm 644-print # print the file with the permission of 644

    ? 11). execute commands or actions in combination with find

    ? ? ? The find command can be combined with other commands with the help of Option-exec.-exec is one of the most powerful features of find.

    ? ? ? Find.-type f-user root-exec chown test {}\; In this command, {} is a special string used in combination with the-exec option. For each matching file, {} is replaced with the corresponding file name. In the above command, first find all the files that belong to the root user, and then add permissions to the test user.

    ? ? ? Find. -type f-name "*. sh "-exec cat {}\;> all_sh_files.txt this command first finds all sh files, and then adds the contents of the files to the text files .?

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.