Shell Scritping find the list of .txt files in particular directory

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Shell Scritping find the list of .txt files in particular directory

Lokesh
Hi Friends,

Using shell scripting i need to find the .txt files in particular directory.

Could you please guide on this topic.

Thanks & Regards
Lokesh Chandramohan
Hungary.
Reply | Threaded
Open this post in threaded view
|

Re: Shell Scritping find the list of .txt files in particular directory

Guru
Administrator
Its the same find command which works for you on the command prompt need to go the shell script.

find <your directory> -name "*.txt"

Reply | Threaded
Open this post in threaded view
|

Re: Shell Scritping find the list of .txt files in particular directory

Lokesh
Hi Guru,

PFB the script which i wrote,kindly review the script and share your comments.

I need generic code.

#!/bin/bash

for file in "${1-.}"; do
   [ -d "${file}" ] &&   ((directories++))
   [ -f  "${file}" ] &&   ((files++))
done

echo "Number of files : ${files-0}"
echo "Number of directories : ${directories-0}"

Thanks & Regards
Lokesh Chandramohan
Hungary.
Reply | Threaded
Open this post in threaded view
|

Re: Shell Scritping find the list of .txt files in particular directory

Lokesh
Hi Guru,

PFB the Updated Shell Scripting code.

#!/bin/bash
mailto="lokesh.chandramohan@affinioninternational.com"
totalfiles=`ls -lrt /cfes/user_deposits/* | wc -l`
echo "UserDepositsListOfFiles::=$totalfiles"
totalfiles1=`ls -lrt /cfes/user_collections/* | wc -l`
echo "UserCollectionsListofFiles::=$totalfiles1"
total=`expr $totalfiles + $totalfiles1`
echo "the total is =$total"
echo "Total number of files:: $total" | mailx -s "files_list" $mailto


Thanks &Regards
Lokesh Chandramohan