- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- scripting to move files to specific date
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
05-18-2006 08:37 PM
05-18-2006 08:37 PM
I am attempting to write a script that searches an archive directory - finds files over 3 months old and create another directory then move the files to the specific month.
ie.
files listed in the directory will have dates such as march 1-31 feb 1-28/29 Jan 1 etc etc
so I do a find /Inarchive -mtime + 90 -exec ls -l {} \;
gives me my list then I wan to move these files to a specific date directory which is one dir up the tree with the original dirname then date ../Inarchive.yymm but this directory will need to be create from the script.
I have some idea's by creating lots of variables but am open to suggestions.
Thanks for you help chaps.
Mr L.
Solved! Go to Solution.
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2006 08:52 PM
05-18-2006 08:52 PM
Re: scripting to move files to specific date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2006 09:02 PM
05-18-2006 09:02 PM
Re: scripting to move files to specific date
Use this way to get the month & date for the files that are being moved.
NDATE=$(find /tmp -mtime +20 -exec ls -l {} \; |awk '{print $6 $7}')
I assume that you run this script once every day.
The 1st time you may get old files too.
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2006 09:15 PM
05-18-2006 09:15 PM
Re: scripting to move files to specific date
#!/usr/bin/sh
cd lnarchive
for a in `find . -mtime + 90 -type f`
do
month=`ll $a | awk -F' ' '{print $6}'`
file=`ll $a | awk -F' ' '{print $9}'`
if [ ! -d $month ]
then
echo "mkdir ../lnarchive.$month"
echo "mv $file ../$month/$file"
else
echo "mv $file ../$month/$file"
fi
done
This script pulls out the filedate month and then check if the directoryy exists.
If you are happy with the test run, remove the echo parts of the mkdir and mv lines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2006 09:16 PM
05-18-2006 09:16 PM
Solution#!/usr/bin/sh
cd lnarchive
for a in `find . -mtime + 90 -type f`
do
month=`ll $a | awk -F' ' '{print $6}'`
file=`ll $a | awk -F' ' '{print $9}'`
if [ ! -d $month ]
then
echo "mkdir ../lnarchive.$month"
echo "mv $file ../lnarchive.$month/$file"
else
echo "mv $file ../lnarchive.$month/$file"
fi
done
This script pulls out the filedate month and then check if the directoryy exists.
If you are happy with the test run, remove the echo parts of the mkdir and mv lines.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2006 09:26 PM
05-18-2006 09:26 PM
Re: scripting to move files to specific date
Write the following into a file and keep it in /Inarchive , goto Inacrchive and execute this.
I have put the echo for mkdir and mv currently so that you can test if it works to your satisfaction and then you cabn remove the echo.
find . -mtime +90 -type f | xargs ls -ld | awk '{print $6,$8,$NF}' > files.dat
grep ":" files.dat | awk '{print $1}' | sort -u | while read month
do
year=$(date +%y)
if test ! -d ../inarchive.$year$month
then
echo mkdir ../inarchive.$year$month
fi
files=$(grep "$month ..:" files.dat | awk '{print $NF}')
echo mv $files ../inarchive.$year$month
done
grep -v ":" files.dat | awk '{print $1,$2}' | sort -u | while read month year
do
year=$(echo $year | cut -c 3-4)
if test ! -d ../inarchive.$year$month
then
echo mkdir ../inarchive.$year$month
fi
files=$(grep "$month ..$year" files.dat | awk '{print $NF}')
echo mv $files ../inarchive.$year$month
done
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2006 11:10 PM
05-18-2006 11:10 PM
Re: scripting to move files to specific date
Thanks a million!