|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | 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 and shell scripting languages here. |
|
|
|
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 |
| Sponsored Links | ||
|
|
#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 You should run it in the following format Code:
./krah.sh YYYY-MM-DD If you dont provide anything, then the current date will be picked up. Vino Last edited by vino; 10-03-2005 at 08:44 AM.. |
| Sponsored Links | ||
|
|
#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 timeThat means create /tmp/OLD which has a timestamp provided by the user. 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.The find script says -- find all files which are newer than /tmp/OLD but not /tmp/NEW and whose size is not zero. Vino |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
thanks a lot
hi vino,,
thanks a lot !!!!!! regards, cskumar |
| Sponsored Links | |
|
|
#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 |
| Sponsored Links | |
|
|
#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 |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to view files from a specific date/day | mady135 | Shell Programming and Scripting | 1 | 05-03-2011 07:11 AM |
| view gzipped files with name file.gz.$DATE on a Solaris box (without unzipping first) | slashdotweenie | UNIX for Dummies Questions & Answers | 4 | 04-12-2011 03:37 PM |
| Need script to select multiple files from archive directory based on the date range | bbc17484 | Shell Programming and Scripting | 3 | 01-22-2010 12:45 AM |
| script to search context from 2 files based on date and name | ezmethod | Shell Programming and Scripting | 1 | 08-24-2009 06:15 PM |
| Count of files based on date? | sbasetty | Shell Programming and Scripting | 6 | 01-11-2007 02:02 PM |
|
|