Find file size and date


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Find file size and date
# 1  
Old 04-08-2008
Find file size and date

Hi in my shell script I have to do this

1. there is a file called testing.txt in /home/report directory

If the file size is 0(zero) and date is today's date, then I have to print
"Successful" else "Failed".

2. There is a file called number.txt which will have text only one line like this

20080324|0000040768

the first 8 digits is date. I have to check if that date is today's date, if so print 40768.

I mean I have to trim 0000040768 to 40768.


Any help is appreciated.

Regards,

G.
# 2  
Old 04-08-2008
Why is this in the "Advanced" forum? Looks like homework anyway.
# 3  
Old 04-08-2008
What?

your perception is wrong

Any body who is expert in a different field and had to get some work done in unix can post such questions.


Could help you if you have any doubts in ORACLE.

Regards,

G.
# 4  
Old 04-08-2008
1.
Code:
#!/bin/ksh
touch -t `+%Y%m%d0000` ./dummy
count=0
find  /home/report -name testing.txt -newer ./dummy | \
while read file
do
    let count=$count+1
done
if [[ $count -eq 1 ]] ; then
   echo "Success"
else
   echo "Failure"
fi

2.
Code:
awk -F'|'  '{print $1}' number.txt  | read today number
if [[ $today = "`date +%Y%m%d`" ]] ; then 
    printf "%d\n" $number
fi

# 5  
Old 04-08-2008
I couldn't get the second script to work. (Didn't try the first.) How about this instead:

Code:
IFS='|' read date number <number.txt
case $date in `date +%Y%m%d`) printf "%d\n" "$number";; esac

Thanks for the printf idea; I would have used sed or something but this is neater (provided you have printf).
# 6  
Old 04-08-2008
How's this for the first.

Code:
if find /home/report -maxdepth 1 -mtime -1 -name testing.txt -size 0 | grep . >/dev/null 
then
  echo Success
else
  echo Failure
fi

The find is slightly inexact; if your find has the -daystart option then that will fix the date calculation.
# 7  
Old 04-08-2008
Input

Hi,

really appreciate the input but still throwing errors

first one error

find: 0652-017 -maxdepth is not a valid option.

secon one error

printf: 3016-002 00004268 is not completely converted.




Any Ideas plz.

Regards,

G.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

2. UNIX for Dummies Questions & Answers

Looking for command line to find dirs based on size and date

Hi, My first time on this site, please excuse me if I've come to the wrong forum. I'm fairly new to Unix/Linux and hoping you can help me out. I'm looking for a command line that will return a list of directories that are larger than 50M and older than 2 days. I thought it may be... (6 Replies)
Discussion started by: Wisconsingal
6 Replies

3. HP-UX

find command to display size and date of a file

Hi, The blow code does not yeild any output. find . -name "*.jar" -o -name "*.ksh" -o -name "*.properties" -name "*.war" -o -name "*.ear" -o -name "*.sh" -o -name "*.cfg" -exec ls -l {} \; I wish to print the filename filesize filedate in HP-UX. Can anyone help ? (9 Replies)
Discussion started by: mohtashims
9 Replies

4. HP-UX

How can I find the size of files added to a folder after a particular date

Hi, I want to find the size of the files added to a folder after a certain date(say 1st of october), I know we can list the files which were created after a certain date , but is there anyway to find the total size of those files ? (3 Replies)
Discussion started by: alookachaloo
3 Replies

5. Shell Programming and Scripting

find with file size and show the size

Hi All... is the below command be modified in sucha way that i can get the file size along with the name and path of the file the below command only gives me the file location which are more than 100000k...but I want the exact size of the file also.. find / -name "*.*" -size +100000k ... (3 Replies)
Discussion started by: rpraharaj84
3 Replies

6. Shell Programming and Scripting

get file size by date for a directory

Good day Probably a simple script though I am new to attempting to script. I have a directory that I would like to get the size of the files and number of files for each date ie 14 Sep 669 files 1.8g 12 Sep 221 files 500mb Any ideas? Thanks (1 Reply)
Discussion started by: ibaboomer
1 Replies

7. UNIX for Dummies Questions & Answers

how to find folder size with created date

hi, please give me adivse .how to find the folder size with created created date . eg: i have directore and in that sub directoties and so on.. /home/mud/abc/dcb/ for this i want output like this path size date -------------------------------------------... (3 Replies)
Discussion started by: muddasani
3 Replies

8. UNIX for Dummies Questions & Answers

How can I find files by date or size from stout?

Hello all I wander if I make for example " ls -l " And it gives me all the files in the directory with the additional info like data size and privileges But what if I like to filter the stout result for example by date When I try to do: echo "`ls -l`" | grep "Jan 12" it gives me the... (2 Replies)
Discussion started by: umen
2 Replies

9. UNIX for Dummies Questions & Answers

shell script to find files by date and size

Hi, I have a directory PRIVATE in which I have several directories and each of these have several files. Therefore, I need to find those files by size and date to back up those files in another directory. I don't know how to implement this shell script using ''find''. appreciate any... (1 Reply)
Discussion started by: dadadc
1 Replies

10. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies
Login or Register to Ask a Question