Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
comparing current date to modified date

Reply  
Thread Tools
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
28-Sep-2005, 04:24 PM #16
could I do something like
if -mtime +10 <= current time ?

Last edited by cgjoker; 28-Sep-2005 at 04:38 PM..
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
28-Sep-2005, 04:58 PM #17
i did this but i get the following error...

for file in *
do
if [ -f $file ]
then
flag=$(echo $file | cut -c1-2)
#echo "${flag}"
for f in `find . -type f -mtime ${flag} -name "${flag}${file}"`
do
echo "${flag}"
mv "$f" /directory/"b$f""_$date".dat
done
fi
done

error:
find: 0652-086 Specify a decimal integer for -mtime
Usage: find Path-list [Expression-list]
find: 0652-086 Specify a decimal integer for -mtime
Usage: find Path-list [Expression-list]
find: 0652-086 Specify a decimal integer for -mtime
Usage: find Path-list [Expression-list]
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
28-Sep-2005, 05:03 PM #18
updated the flag value to make it an expression, now i dont get any errors but the files that are older than the flag and where the name is the same as the flag, are still not moving.

for file in *
do
if [ -f $file ]
then
flag=`expr $(echo $file | cut -c1-2)`
#echo "${flag}"
for f in `find . -type f -mtime ${flag} -name "${flag}${file}"`
do
echo "${flag}"
mv "$f" /directory/"b$f""_$date".dat
done
fi
done
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
28-Sep-2005, 05:32 PM #19
im at a total loss.... it looks like the `find... ` command doesn't recognize predetermined variables. if it did i think this code would work fine...


for file in *
do
if [ -f $file ]
then
flag=`expr $(echo $file | cut -c1-2)`
echo "${flag}"
for f in `find . -type f -mtime +${flag} -name "${flag}${file}"`
do
echo "${flag}"
mv "$f" /directory/"b$f""_$date".dat
done
fi
done
AGCurry's Avatar
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
28-Sep-2005, 06:08 PM #20
Quote:
Originally Posted by cgjoker
im at a total loss.... it looks like the `find... ` command doesn't recognize predetermined variables. if it did i think this code would work fine...


for file in *
do
if [ -f $file ]
then
flag=`expr $(echo $file | cut -c1-2)`
echo "${flag}"
for f in `find . -type f -mtime +${flag} -name "${flag}${file}"`
do
echo "${flag}"
mv "$f" /directory/"b$f""_$date".dat
done
fi
done
Well, your find can't find the file because it's looking for the wrong name.
${flag}${file} - for the file "10farkel.blah" - would be "1010farkel.blah".

find . -name "$file" -mtime +${flag} -exec mv {} /directory \;
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
29-Sep-2005, 10:55 AM #21
I didn't even catch that... thanks.

Its working great now.. after all that these few lines does just what I need....

for file in `ls *`
do
flag=`expr $(echo $file | cut -c1-2)`
find . -name "$file" -mtime +${flag} -exec mv {} /directory/"b""$file".dat \;
done

less the removing of the 10 flag but I can do that.

Thanks so much for your help, you guys are great !
c.
AGCurry's Avatar
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
29-Sep-2005, 11:37 AM #22
Congratulations.

A couple of suggestions:

1. All you need in the first line is "for file in *". No need to load and run ls.

2. The line: flag=`expr $(echo $file | cut -c1-2)` bothers me. One reason is that the expr command should not be needed. The other is that IF there is a file which does not begin with numeric digits, find will fail. A test that $flag is numeric should probably be incorporated, e.g.,

if let $flag=$flag+0
then
find ...

Good luck!
Andy
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
29-Sep-2005, 01:41 PM #23
I see your point about the test, however, if there is a file with non numeric values it would just be ignored and the others would still get processed would it not?

by the way, im trying to add something where if the file has a numeric value it does one thing, if it has a two numerics it does another.. im can't seem to get it.. can you help please?

if ( $file =~ /[^0-9][a-zA-Z]*/ )
then
newfile=`echo $file | cut -b2- | sed -e 's/.dat//g'`
else
newfile=`echo $file | cut -b3- | sed -e 's/.dat//g'`
fi
AGCurry's Avatar
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
29-Sep-2005, 04:33 PM #24
Quote:
Originally Posted by cgjoker
I see your point about the test, however, if there is a file with non numeric values it would just be ignored and the others would still get processed would it not?

by the way, im trying to add something where if the file has a numeric value it does one thing, if it has a two numerics it does another.. im can't seem to get it.. can you help please?

if ( $file =~ /[^0-9][a-zA-Z]*/ )
then
newfile=`echo $file | cut -b2- | sed -e 's/.dat//g'`
else
newfile=`echo $file | cut -b3- | sed -e 's/.dat//g'`
fi
I often find it easiest to use "case" for this kind of thing:

case "$file" in
[0-9][0-9]*) do one thing ;;
[0-9]*) do another thing ;;
*) do something else ;;
esac
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
29-Sep-2005, 05:04 PM #25
thanks again... c.
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
30-Sep-2005, 12:40 PM #26
So im trying to figure out how I can use the case loop for this? So the idea again was that I want to be able to get either files that have 2 digits or 1 digit in the file name.
In the code below, it is only going after 2 digits.

cd /olddirectory

for file in `find . -name "00*.*"`
do
if [ $file ]
then
fnow=`echo $file | cut -b4- | sed -e 's/.dat//g'`
mv "$file" /directory/"$fnow""_$date".dat
done

for ffile in *
do
if [ $ffile ]
then
fflag=`echo $ffile | cut -c2`
newffile=`echo $ffile | cut -b3- | sed -e 's/.dat//g'`
find . -name "$ffile" -mtime +${fflag} -exec mv {} /directory/"$newffile""_$date".dat \;

fi
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
30-Sep-2005, 01:03 PM #27
i have an idea ill try and let you know.
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
30-Sep-2005, 02:46 PM #28
my idea didn't work... ill have to rethink this approach...

for fnow in `find . -name "0*.*"`
do
if [ $fnow ]
then
case "$fnow" in
[0-9][aA-zZ]*) now=`echo $fnow | cut -b3- | sed -e 's/.dat//g'`;;
[0-9][0-9]*) now=`echo $fnow | cut -b4- | sed -e 's/.dat//g'`;;
*) echo "$dt: no files found, continuing processing" ;;
esac
mv "$fnow" /directory/"b$fnow""_$date".dat

done

for ffile in *
do
if [ $ffile ]
then
fflag=`echo $ffile | cut -c1-2`
case "$ffile" in
[0-9][aA-zZ]*) newffile=`echo $ffile | cut -b3- | sed -e 's/.dat//g'`;;
[0-9][0-9]*) newffile=`echo $ffile | cut -b4- | sed -e 's/.dat//g'`;;
*) echo "$dt: no files found, continuing processing"
;;
esac
find . -name "$fblfile" -mtime +${fflag} -exec mv {} /directory/"b$newfile""_$date".dat \;
echo "$dt: ${ffile} file found equal to 1
done
AGCurry's Avatar
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
30-Sep-2005, 04:16 PM #29
Quote:
Originally Posted by cgjoker
my idea didn't work... ill have to rethink this approach...

for fnow in `find . -name "0*.*"`
do
if [ $fnow ]
then
case "$fnow" in
[0-9][aA-zZ]*) now=`echo $fnow | cut -b3- | sed -e 's/.dat//g'`;;
[0-9][0-9]*) now=`echo $fnow | cut -b4- | sed -e 's/.dat//g'`;;
*) echo "$dt: no files found, continuing processing" ;;
esac
mv "$fnow" /directory/"b$fnow""_$date".dat

done
problems:
find command will find files beginning with 0 only.
if [ $fnow ] should be if [ -f $fnow ] ( you want only normal files ).
case is built to recognize file names that find will never find.
cut -b3 - why do you want the 3rd byte? aren't you looking for the first and/or second bytes?
Quote:
for ffile in *
do
if [ $ffile ]
then
fflag=`echo $ffile | cut -c1-2`
case "$ffile" in
[0-9][aA-zZ]*) newffile=`echo $ffile | cut -b3- | sed -e 's/.dat//g'`;;
[0-9][0-9]*) newffile=`echo $ffile | cut -b4- | sed -e 's/.dat//g'`;;
*) echo "$dt: no files found, continuing processing"
;;
esac
find . -name "$fblfile" -mtime +${fflag} -exec mv {} /directory/"b$newfile""_$date".dat \;
echo "$dt: ${ffile} file found equal to 1
done
Better. But...
if [ $ffile ] doesn't make sense (same reason as above).
fflag=`echo $ffile | cur -c1-2` gets the first two characters. Your case, again, isn't really set up to match the possibilities correctly.

Here's a shot:

for file in *
do
if [ -f $file ]
then
case "$file" in
[0-9][A-z]*) agedays=$(echo $file | cut -c1) ;; # one digit
[0-9][0-9]*) agedays=$(echo $file | cut -c1-2) ;; # two digits
*) agedays=999 ;;
esac

if [ $agedays -ne 999 -a $agedays -gt 0 ]
then
do whatever you need to do
fi
fi
done


case "$file"
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:49 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.