need to create script in KSH to mv files to other directory in same server older than 8 days they all .CSV
2 Answers
The command you tried was almost right, but use +8 as the -mtime argument rather than +2.
You say you're using AIX so I'm going to guess that you're also using some ancient shell that requires {} to be quoted or escaped as \{\}. See gnu find and masking the {} for some shells - which?
find /tmp/sappodb/ -type f -mtime +8 -exec mv -v `{}` /tmp/sappodb1/ \; If you want to limit it to mv-ing .csv files only:
find /tmp/sappodb/ -type f -name '*.csv' -mtime +8 -exec mv -v `{}` /tmp/sappodb1/ \; simply use -t (--target-directory) in the mv cmd like the folowing way :
find csvdir -type f -name '*.CSV' -mtime +8 -exec mv -t 'otherdir/' {} \; this was my suggestion before i install ksh & test.
while [ $(ls folder/ | wc -l) -ge 8 ];
do
mv "$(ls -1t folder/*.csv | tail -1)" /otherdir/ ;
done
test
- mmm I cant get it, lol seems legit that way, maybe I spell wrong my question, I just need to keep the last generated files and mv the others to other directory I dont wnat to delete themRafael Murray Campbell– Rafael Murray Campbell2015-10-27 21:20:39 +00:00Commented Oct 27, 2015 at 21:20
- then just change rm "$(ls -1t folder/* | tail -1)"; to mv "$(ls -1t folder/* | tail -1)" /otherdir/ ;Yunus– Yunus2015-10-27 21:25:43 +00:00Commented Oct 27, 2015 at 21:25
- 1That doesn't answer the question. It doesn't find the files older than 8 days, it finds (and deletes, or moves) all but the 7 most recent files. and it does it extremely inefficiently, rm-ing or mv-ing one file at a time.cas– cas2015-10-27 21:33:00 +00:00Commented Oct 27, 2015 at 21:33
-
- 1I have read the question and all the comments and can't see anywhere that he mentioned keeping the newest 7 files.cas– cas2015-10-27 21:44:45 +00:00Commented Oct 27, 2015 at 21:44

findcommand. You'll find many similar questions (with answers) here./tmp/sappodbthat hadn't been modified in the last two days to/tmp/sappodb1. All you were missing was the-name '*.CSV'bit.