Find in Linux Shell

Source: Internet
Author: User
Tags uppercase letter

Post address: cy158358.cublog.cn

 

 

#! /Bin/shcheck_patch ()
{
Test-d $1
Return
} # Check whether the path exists
Check_patch $2
If [$? -Ne 0]
Then
Echo "No such path $2"
Exit 1
Fiif ["$1" = "name"]
Then
# Searching for TXT files
Echo "-------------------------- *. txt"
Find $2-name "*. txt"
 
# Search for files starting with an uppercase letter
Echo "-------------------------- [A-Z] * [A-Z] *. *"
Find $2-name "[A-Z] *" # Find a file starting with two lower-case letters followed by one digit followed by another upper-case letter
Echo "-------------------------- [A-Z] [A-Z] [0-9] [A-Z] *"
Find $2-name "[A-Z] [A-Z] [0-9] [A-Z] *" Elif ["$1" = "perm"]
Then
# Search for readable, writable, and executable TXT files
Find $2-name "*. txt"-Perm 777 Elif ["$1" = "type"]
Then
# Searching all directories
Echo "------------------- all dir"
Find $2-type D # Find all files except Directories
Echo "------------------- all files"
Find $2! -Type D # search for all symbolic link files
Echo "------------------- all link"
Ln-S $2/B $2/ln-B
Find $2-type lelif ["$1" = "size"]
Then
# Search for all 0-byte files
Echo "------------------- size = 0"
Find $2-name "*. *"-size 0C # search for all files smaller than 1 KB
Echo "------------------- size <1 K"
Find $2-name "*. *"-size-1024c # search for all files larger than 2 K bytes
Echo "------------------- size> 2 K"
Find $2-name "*. *"-size + 2048c # search for all files larger than 2 K bytes (including directories)
Echo "------------------- size> 2 K"
Find $2-size + 2048 celif ["$1" = "depth"]
Then
# Search for test. c In the root directory before searching in the subdirectory
Echo "------------------- find test. c"
Find $2-name "test. c"-depth # search for test. c
Echo "------------------- find test. c"
Find $2-name "test. c" Elif ["$1" = "EXEC"]
Then
# Check the file test. C in the directory and display its attributes.
Echo "------------------- find test. c LS-l"
Find $2-name "test. c"-exec LS-l {}/; # Check the file DDD. C in the directory and delete it
Echo "------------------- find DDD. c RM"
Touch $2/DDD. c
Find $2-name "DDD. c"-exec RM {}/; # Check the file DDD. C in the directory and delete it (confirm)
Echo "------------------- find DDD. c RM"
Touch $2/DDD. c
Find $2-name "DDD. c"-OK RM {}/; # Check the file AAA. C in the directory and copy it to the back directory.
Echo "------------------- find AAA. c copy"
Touch $2/AAA. c
Test-d $2/../back
If [$? -Ne 0]
Then
Mkdir $2/../back
Fi
Find $2-name "AAA. C "-exec CP {}$ 2 /.. /back/; FI saves the above content as the script file find, and then you can test the functions of the find command .. /Find name path: displays all TXT files in the path directory. All files starting with an uppercase letter in the path directory. All files in the path directory are displayed with two lower-case letters, 1 digit, and 1 Capital. A file starting with a letter. /find perm path: displays all readable, writable, and executable files under the path directory. /find type path display directory path all folder directory names show all file names under directory path show all link file names under directory path. /find size path: All 0-byte files in the path directory. All <1 K files in the path directory. All> 2 k files in the path directory. All> 2 k files in the path directory. directory. /find exec path: Find test under the directory path. c file and display its detailed properties to find the DDD under the directory path. c file and delete it to find the DDD under path. c file and delete it (you need to confirm) to find AAA under path. copy the c file to the back folder in the upper directory.

 

 

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.