velava
October 4, 2012, 6:44am
1
Hi All,
I want to move the files in to different folders based on the files month in the file timestamp.
For example
All the september files in the directory should moves into the folder "sep_bkp_files" , August files in to aug_bkp_files folder...
Please help me to achive the above issue. I am using solaris OS.
Thanks,
Velava
post the output of ls -lrt
or is the filename having the timestamp ?
velava
October 4, 2012, 7:08am
3
Yes, the fiename having the timestamp.
if u provide the example filename, then i can help u
velava
October 4, 2012, 7:21am
5
filenames will be,
-rw-rw-r-- 1 b2binta1 b2badmin 16515066 Sep 18 00:57 test1.txt
-rw-rw-r-- 1 b2binta1 b2badmin 22824 Sep 18 01:30 test2.txt
-rw-rw-r-- 1 b2binta1 b2badmin 41844 Sep 18 01:30 test3.txt
-rw-rw-r-- 1 b2binta1 b2badmin 22824 Sep 18 01:36 sample1.txt
-rw-rw-r-- 1 b2binta1 b2badmin 213024 Sep 18 01:36 sample2.txt
-rw-rw-r-- 1 b2binta1 b2badmin 60864 Sep 18 04:34 hello.csv
Thanks
dest=/path/to/september/
touch -t 201209010000 /tmp/d1
touch -t 201209305959 /tmp/d2
find /path/to/files -type f |
while read fname
do
mv $fname $dest
done
try that.
velava
October 4, 2012, 9:27am
7
based on the month present in the file time stamp i have to move its respective folders.
it is not working as expected and it is moving all other month files as well.
Thanks
May be Jim missed something...
dest=/path/to/september/
touch -t 201209010000 /tmp/d1
touch -t 201209302359 /tmp/d2
find /path/to/files -type f -newer /tmp/d1 \! -newer /tmp/d2 | while read fname
do
mv "$fname" "$dest"
done
velava
October 4, 2012, 10:03am
9
Thanks elixir!
It is working fine for the september files. I need to move the other month files also needs to be moved to the respective folders.
Please help me to do this.
---------- Post updated at 09:03 AM ---------- Previous update was at 08:59 AM ----------
elixir_sinari:
May be Jim missed something...
dest=/path/to/september/
touch -t 201209010000 /tmp/d1
touch -t 201209302359 /tmp/d2
find /path/to/files -type f -newer /tmp/d1 \! -newer /tmp/d2 | while read fname
do
mv "$fname" "$dest"
done
I have an idea like first we have to find the list of files from the directory. then we have to get the month of the file using awk {print $6} and based on the month we have to move our files.
pls help me such a way to resolve this issue. Thanks!
ls -lrt | awk -v '/^\-/{print $6,$NF}' | while read month filename
do
mkdirp -p /full/path/${month}_bkp_files
mv ${filename} /full/path/${month}_bkp_files
done
velava
October 5, 2012, 5:26am
11
Thanks!
mv: cannot stat 'test.edi': No such file or directory
getting the above error