![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to listout the files based on group by the date...? | psiva_arul | UNIX for Dummies Questions & Answers | 3 | 04-21-2008 06:03 AM |
| Traversing thru dirs and deleting files based on date | ravi2082 | Shell Programming and Scripting | 5 | 07-18-2007 01:28 PM |
| Count of files based on date? | sbasetty | Shell Programming and Scripting | 6 | 01-11-2007 12:02 PM |
| Remove files based on date | hshapiro | UNIX for Dummies Questions & Answers | 4 | 12-09-2005 09:21 AM |
| Moving files based on creation date | dgoyea | UNIX for Dummies Questions & Answers | 1 | 06-28-2001 02:43 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
script to view files based on date
I have a UNIX box where in files are created every 5 minutes. I need to write a shell script which will take in the date as parameter and return me all files created on that day. Also I will like it to show me only files which have a size greater than 0 i.e. non-empty files. how do I go abt this? I am new to UNIX
Thanks in advance, Rahul |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Here is a script for you.
Code:
#! /bin/sh # krah.sh [ -z $1 ] && echo "Defaulting to $(date +%F)" && DATE=$(date +%F) || DATE="$1" touch -d "$1" /tmp/OLD touch -r /tmp/OLD -F 86400 /tmp/NEW find . -name '*' -newer /tmp/OLD ! -newer /tmp/NEW ! -size 0 rm -f /tmp/OLD /tmp/NEW Code:
./krah.sh YYYY-MM-DD Vino Last edited by vino; 10-03-2005 at 05:44 AM. |
|
#3
|
|||
|
|||
|
Need explanation
hi,
i am a fresher to scripts, can u explain what these commands will do.. touch -d "$1" /tmp/OLD touch -r /tmp/OLD -F 86400 /tmp/NEW find . -name '*' -newer /tmp/OLD ! -newer /tmp/NEW ! -size 0 Thanks in advance cskumar |
|
#4
|
||||
|
||||
|
In short RTFM.
From man touch Code:
-d, --date=STRING
parse STRING and use it instead of current time
-F, --forward=SECONDS
Modify the time by going forward SECONDS seconds. For example,
touch -r foo -F 5 bar will make the file bar 5 seconds newer
than file foo.
-r, --reference=FILE
use this file's times instead of current time
And then create /tmp/NEW which is exactly 24 hours newer compared to /tmp/OLD And from man find, Code:
-newer file
File was modified more recently than file. -newer is affected
by -follow only if -follow comes before -newer on the command
line.
-size n[bckw]
File uses n units of space. The units are 512-byte blocks by
default or if `b' follows n, bytes if `c' follows n, kilobytes
if `k' follows n, or 2-byte words if `w' follows n. The size
does not count indirect blocks, but it does count blocks in
sparse files that are not actually allocated.
Vino |
|
#5
|
|||
|
|||
|
thanks a lot
hi vino,,
thanks a lot !!!!!! regards, cskumar |
|
#6
|
|||
|
|||
|
Help with the script of day before yesterday
Quote:
There is a problem with this.. I am getting an error like "./Script.sh: cannot execute".. I dont know why it is happening.. CAn u help or suggest something? This is the exact thing thats being shown (my file is called Script.sh): $ Script.sh ksh: Script.sh: not found $ ./Script.sh ksh: ./Script.sh: cannot execute $ ls -lt total 1 -rw-r----- 1 BTBDEV1 dba 227 Oct 5 13:46 Script.sh $ vi Script.sh "Script.sh" 5 lines, 227 characters 1 [ -z $1 ] && echo "Defaulting to $(date +%F)" && DATE=$(date +%F) || DAT E="$1" 2 touch -d "$1" /tmp/OLD 3 touch -r /tmp/OLD -F 86400 /tmp/NEW 4 find . -name '*' -newer /tmp/OLD ! -newer /tmp/NEW ! -size 0 5 rm -f /tmp/OLD /tmp/NEW ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ :q |
|
#7
|
|||
|
|||
|
You dont have execute permission for the file Script.sh
Just run the following command to grant execute permission chmod u+x Script.sh -Mons |
|||
| Google The UNIX and Linux Forums |