- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- commands (or script) to capture specific 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
Forums
Discussions
Discussions
Discussions
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
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
08-01-2002 04:36 AM
08-01-2002 04:36 AM
commands (or script) to capture specific files.
As scripting is not a strong point for me, I need some help from you learned people. I want to use a series of commands (or need a script)
to capture files/directories that were creatred in the year 2001 for archival. I want to move them to a directory called: 2001_files
I was going to use the following at the command line from within the appropriate directory (for this eg the dir is /data/abcdef):
grep '2001' | mv -i * /data/abcedf/2001_files
Can anyone tell me if this is the best way to do it, if not can you suggest a way?
Best regards,
To
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 04:46 AM
08-01-2002 04:46 AM
Re: commands (or script) to capture specific files.
First, the grep statement you use would not work, as it expects a stdin or file arguement.
A find would be a good start:
find /
But then to get the 2001 bit you'd need to add:
find / -exec ls -ld {} \; | grep 2001
Better performance would be:
find / | xargs ls -ld | grep 2001
Then you want to trim off the file names
find / | xargs ls -ld | grep 2001 | awk '{print $9}'
Then to move enclose the above in grav quotes:
mv `above command` /your/destination/dir
HOWEVER - DO NOT do this from /, as a lot of system files are 2001 dated. Start it off with
find /your/file/directory
Cheers!
James
If it's hard, you're doing it wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 05:06 AM
08-01-2002 05:06 AM
Re: commands (or script) to capture specific files.
Try this:
DIR=/data/abcdef
DESTDIR=/data/abcedf/2001_files
ll $DIR | while read LINE
do
date=`echo $LINE|awk '{print $8}'`
file=`echo $LINE|awk '{print $9}'`
if [ $date = "2001" ]
then
mv "$DIR/$file" $DESTDIR
fi
done
One way of many and probably more eleagant solutions, bu it works
Good luck
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 05:18 AM
08-01-2002 05:18 AM
Re: commands (or script) to capture specific files.
# find . \( -newer filename -a -atime +210 \) -exec ll {} \;
This will list the files whiche were created after 'filename' and which were not accessed for last 210 days (approx. 2002 Jan). if you find the list is correct, then replace ll with 'mv' command.
you can also check a simple command:
# cd dir
# ls -la | grep 2001 | mv ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 05:28 AM
08-01-2002 05:28 AM
Re: commands (or script) to capture specific files.
This should work as well.
----- script starts ------
#!/bin/sh
find /data/abcedf -type f | xargs ll | while read $LINE
do
if [ `echo $LINE | awk '{print $8}'` = 2001 ]; then
mv `echo $LINE | awk '{print $9}'` /data/abcedf/2001_files
fi
done
------ script ends ------
Hai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2002 05:52 AM
08-01-2002 05:52 AM
Re: commands (or script) to capture specific files.
for FILE in $(ll |grep " 2001 "|tr -s " "|cut -d" " -f9)
do
mv $FILE /data/abcdef/2001_files
done
Or to ensure that the file is not actually a directory -
for FILE in $(ll |grep " 2001 "|tr -s " "|cut -d" " -f9)
do
if [ -f $FILE ]
then
mv $FILE /data/abcdef/2001_files
fi
done
Then again as already mentioned find may be better and theres an option to find called -mtime which would locate files more than a specified number of days ago - eg
find /data/abcdef -mtime +365
You could do something like this then -
DAY=$(date +%j)
for FILE in $(find /data/abcdef -mtime +$DAY)
do
mv $FILE /data/abcdef/2001_files
done
This would find all files older than the current year.