- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Touch the files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 08:34 PM
тАО02-19-2007 08:34 PM
Touch the files
I need to change the timestamp of particular filetype to that of the oldest file ( actually 2min later than the oldest file)
for example:
if i hav 2 files: file1,file2
file1 is having time stamp of 12:00
file2 is having time stamp of 9:00
i need the time stamp of file1 to be changed to 9:02
pls help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 08:40 PM
тАО02-19-2007 08:40 PM
Re: Touch the files
see "man touch"
touch -t 200702190902 file1
- Tags:
- Touch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 10:27 PM
тАО02-19-2007 10:27 PM
Re: Touch the files
I need to touch the recent file in a path with a time stamp, 2 minutes newer than the older file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 11:49 PM
тАО02-19-2007 11:49 PM
Re: Touch the files
#!/usr/bin/sh
file=`ls -t1 $1| tail -1`
file2=`ls -t1 $1| tail -2 | head -1`
ar -r foo $1/$file
timer=`tail -1 foo | awk -F' ' '{print $2}'`
echo "Original file $file " `echo "0d$timer=Y" | adb | tr -d '\011'`
timer=`expr $timer + 120`
newdate=`echo "0d$timer=Y" | adb | tr -d '\011' `
year=`echo $newdate | awk '{print $1}'`
month=`echo $newdate | awk '{print $2}'`
day=`echo $newdate | awk '{print $3}'`
time=`echo $newdate | awk '{print $4}'`
hour=`echo $time | awk -F':' '{print $1}'`
min=`echo $time | awk -F':' '{print $2}'`
typeset -u mmm=`echo $month`
typeset -u months=`cal $year | grep "[A-Z][a-z][a-z]"`
i=1
for mon in $months
do
if [ "$mon" != "$mmm" ]
then
i=`expr $i + 1`
else
typeset -xZ2 i
month=$i
fi
done
echo "touch -t $year$month$day$hour$min $1/$file2"
Assuming your files are in ./test
$ ll ./test
total 0
-rw-rw-rw- 1 xxxxxxxx users 0 Feb 20 12:00 file1
-rw-rw-rw- 1 xxxxxxxx users 0 Feb 20 09:00 file2
$
Running:
./a.sh ./test
Original file file2 2007 Feb 20 09:00:00
touch -t 200702200902 ./test/file1
$
Have you thought about reversing the date listing with ls -lrt ?
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-19-2007 11:54 PM
тАО02-19-2007 11:54 PM
Re: Touch the files
# perl -wle '$f1=shift;$f2=shift;$t=(stat($f1))[9]-120;utime($t,$t,$f2)' file1 file2
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-20-2007 12:00 AM
тАО02-20-2007 12:00 AM
Re: Touch the files
Oops, you want 'file' to be timestamped 2-minutes *later* than 'file2', so:
# perl -wle '$f1=shift;$f2=shift;$t=(stat($f2))[9]+120;utime($t,$t,$f1)' file1 file2
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2007 11:48 PM
тАО02-21-2007 11:48 PM
Re: Touch the files
I assume this problem is now resolved ?
Could you please complete the thread by awarding points to helpful answers and summarising the solution for you.
This will help resolution of similar problems in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2007 03:50 PM
тАО02-25-2007 03:50 PM
Re: Touch the files
then if i give
touch -r FILE FILE1
the timestamp will be changed..
But i dont want this FILE as reference. i want its timestamp to be taken as reference since while touchin the file, the reference file may b moved by some other job..
pls help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-26-2007 02:33 PM
тАО02-26-2007 02:33 PM
Re: Touch the files
(Are you somehow the author too?)
If you want it 2 minutes later, you can't use touch -r.
>i want its timestamp to be taken as reference since while touching the file, the reference file may be moved by some other job
This can happen in any of the above scenarios. You will have to legislate that you can't have another job, or the window is so small it won't matter. With solutions by Peter and JRF, the window will be very small, after your reference file is found. Of course if you have to change the time on N files, you may have to create a dummy reference file to use for the N other files.