Get the App
SLTechnology News&Howtos  ›  Development  › 

How to find the shell script code for a specified suffix file in a specified directory

Shulou Source: shulou.com Published: 2022-06-03 07:41:06 09月22日 Update

This article will explain in detail for you how to achieve in the specified directory to find the specified suffix file shell script code, the editor feels very practical, so share to you to do a reference, I hope you can get something after reading this article.

The code is as follows:

#! bin/sh

# find files with the specified suffix in the specified location, including subdirectories

# usage:

# findf $1 $2

# the first parameter is a suffix

# find the file with the specified suffix and print it

# link:www.yisu.com

# date:2013/2/26

F ()

{

List= `find $2 | grep "/ .$ 1 / >" `

For i in $list

Do

Echo $I

Done

}

# Printing usage

Print ()

{

Echo "usage:"

Echo "$1 / $1 / $2"

Echo "the first parameter is the specified suffix name, such as'h'"

Echo "the second parameter is the specified directory, if this parameter is omitted, it defaults to the current directory"

Exit-1

}

# find in the current directory

F1 ()

{

F "$1" * "

}

# find in the specified directory

F2 ()

{

Cd $2

F "$1" * "

}

If ["$#"-lt "1"]

Then

Echo "too few parameters are given, at least one parameter is required."

Print "$0"

Fi

If ["$#"-gt "2"]

Then

Echo "too many parameters are given, a maximum of two parameters are required."

Print "$0"

Fi

If ["$#"-eq "1"]

Then

F1 $1

Exit 0

Fi

If ["$#"-eq 2]

Then

F2 $1 $2

Exit 0

Fi

On "how to achieve in the specified directory to find the specified suffix file shell script code" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: Parameters suffixes directories files code articles scripts more good practical location content subdirectories articles knowledge references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Technology Shulou Information Redmi Apple