- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: script to move 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
07-14-2006 12:48 AM
07-14-2006 12:48 AM
set -x
for i in `ls -l |awk '{print $6,$7}' |uniq`
do
if [ $i != $TODAY ] ; then
DIR=$($i |sed s/' '//)
mkdir $DIR
fi
done
+ ls -l
+ uniq
+ awk {print $6,$7}
+ [ 06 != 20 Jul ]
+ + sed s/ //
+ 06
how can i parse "06 Jun" into [ $i != $TODAY ]as one string?
Manyb Thanks
Solved! Go to Solution.
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2006 01:35 AM
07-14-2006 01:35 AM
Re: script to move files
TODAY=$(date +"%d %b")
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2006 02:15 AM
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2006 02:24 AM
07-14-2006 02:24 AM
Re: script to move files
ls -l |grep -v ^d|awk '{print $6,$7}' |uniq|while read i
do
if [ $i != $TODAY ] ; then
DIR=$($i |sed s/' '//)
mkdir $DIR
fi
done
Enrico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2006 02:36 AM
07-14-2006 02:36 AM
Re: script to move files
if [ "$i" != "$TODAY" ]
Sorry
Enrico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2006 03:52 AM
07-14-2006 03:52 AM
Re: script to move files
If I understand you correctly, you need something like that:
#!/bin/sh
TODAY=$(date +%d%b)
/bin/ls -lt |grep -v ^d |while read FN; do
DATE=$(echo $FN|awk '{printf("%02d%s\n",$7,$6)}')
if [ "$DATE" != $TODAY ]; then
if [ ! -d $DATE ] ; then
mkdir $DATE
fi
fi
done
This works if all files in the current directory have been created on this year, otherwise you have to lok at $8, which is either year or HH:MM, but these are details.
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2006 05:10 AM
07-14-2006 05:10 AM
Re: script to move files
Change the awk statement on the for-loop line so that it outputs a string w/o any embedded spaces. This also helps in compacting code since you don't need the sed statement anymore, which basically removes embedded spaces in $i, and make sure $TODAY contains the same date format as $i. Here's your code with the suggested modifications.
change -> awk '{print $6,$7}'
to -> awk '{print $6$7}'
remove -> DIR=$($i |sed s/' '//)
set -x
TODAY=$(date +"%b%d")
for i in `ls -l |awk '{print $6$7}' |uniq`
do
if [ $i != $TODAY ]; then
mkdir $i
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2006 11:58 PM
07-16-2006 11:58 PM
Re: script to move files
I want to list all files in the directory - if the directory doesn't exist create it, then move the relevant date files to the directory
if the directory does exist just move the files there.
TY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2006 12:17 AM
07-17-2006 12:17 AM
Re: script to move files
I'd archive this way:
# touch -amt 07170000 /tmp/myref #...today
# mkdir /tmp/myarchive
# cd /tmp/myarchive
# find /path ! -newer /tmp/me|cpio -padmxv .
...This will find all files (and directories) that have been modified *before* today and copy then to your archive directory. A listing of the files copied is automatically generated. Modification and access times of the files are preserved.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2006 03:34 AM
07-17-2006 03:34 AM
Re: script to move files
#!/bin/ksh
DIR=/usr/dump/JDE/data/out/ARCHIVE
LOGFILE=/sysadmin/logs/mvdata_JDE.log
REMOVE=/usr/dump/JDE/toberemoved
TODAY=$(date +"%d %b")
for a in `find $DIR -ctime 1 -type f`
do
month=`ls -l $a | awk -F' ' '{print $6$7}'`
file=`ls -l $a | awk -F' ' '{print $9}'`
if [ ! -d $month ] ; then
mkdir /usr/dump/JDE/data/out/ARCHIVE/$month
mv $file /usr/dump/JDE/data/out/ARCHIVE/$month
else
mv $file /usr/dump/JDE/data/out/ARCHIVE/$month
fi
done
this will create the directory and move the file.
The issue I have now is when the script runs the second day it still attempts to move all files that where moved the previous day.
how can i get find just to search the directory /usr/dump/JDE/data/out/ARCHIVE and not /usr/dump/JDE/data/out/ARCHIVE/day.mnth
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2006 04:19 AM
07-17-2006 04:19 AM
Re: script to move files
the easiest thing would be to keep the monthly archive outside the find tree:
...
M_ARCHIVE=${DIR}-bymonth
[ -d $M_ARCHIVE ] || mkdir $M_ARCHIVE
for a in `find $DIR -ctime 1 -type f`
do
...
[ -d $M_ARCHIVE/$month ] || mkdir $M_ARCHIVE/$month
mv $file $M_ARCHIVE/$month
...
done
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2006 04:47 AM
07-17-2006 04:47 AM
Re: script to move files
You are using the 'ctime' or last change time for a file's inode. The 'ctime' changes whenever ownership, permissions are changed or whenever a file is renamed.
Using 'ctime' tracks metadata changes. If you truly want to find files based on *modification* of their data, you need to use 'mtime'.
The manpages for 'stat(2)' will clarify things for you.
BTW, I still suggest the 'cpio' method I posted above for your archiving needs.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2006 04:57 AM
07-17-2006 04:57 AM
Re: script to move files
find $DIR ! -path "/usr/dump/JDE/data/out/ARCHIVE/day.mnth/*" -ctime 1 -type f
~hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2006 07:54 PM
07-17-2006 07:54 PM
Re: script to move files
James thanks for the suggestion however the business have request the archive directories this was.
I like your idea however it wouldn't work for what is required as there are over 3000 files daily that sometimes require a search etc etc.
Chris.