Archive for June, 2013

moves files in unix from a date range to a different directory

June 7, 2013 2 comments
you can achive your date-based move with the following commands. (But
beware, find reports also files in sub directories, which will cause possible
problems with the mv command)

touch -t 201204192359 limit_begin  [YYYYMMDDHHSS]
touch -t 06082359 limit_end        [MMDDHHSS] If not year is specified it take current year

find . -newer limit_begin -a ! -newer limit_end -a -type f -exec mv {}
/otherdir \;

if you have many subdirs you could use sed to handle your task. In this case
the strings limit_begin and limit_end must be unique in the output of
ll -tr.

for file in `ll -tr | sed -n '/limit_begin/,/limit_end/p' | sed -n '/^-/p' |
awk '{ print $9}'`
mv $file /otherdir

Find files that a 14 days old from the current time and tar the files up , do not descend into directories

find . -maxdepth 1 -type f -mtime -14   | xargs tar cvf EMGC_OMS1_logs.tar
Categories: Linux