SoFunction
Updated on 2025-03-10

Find shell script code for the specified suffix file in the specified directory


#!bin/sh 
# Find files with specified suffixes at the specified location, including subdirectories
# Usage:
# findf $1 $2 
# The first parameter is the suffix
# Find the file with the specified suffix and print it out
# link:
# date:2013/2/26

f() 

  list=`find $2|grep "/.$1/>"` 
  for i in $list 
    do 
    echo $i 
  done 


# Print 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 will default to the current directory"
 exit -1 


# Find in the current directory
f1() 

  f "$1" "*" 


# Search in the specified directory
f2() 

  cd $2 
  f "$1" "*" 


if [ "$#" -lt "1" ] 
then 
echo "The given parameters are too few, at least one parameter is needed."
   print "$0" 
fi 

if [ "$#" -gt "2" ] 
then 
echo "There are too many parameters given, and at most two parameters are needed."
  print "$0" 
fi 

if [ "$#" -eq "1" ] 
then 
  f1 $1 
  exit 0 
fi 

if [ "$#" -eq 2 ] 
then 
  f2 $1 $2 
  exit 0 
fi