Home > Linux > moves files in unix from a date range to a different directory

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

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}'`
do
mv $file /otherdir
done

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
Advertisements
Categories: Linux
  1. Chris Broll
    June 7, 2013 at 6:50 pm

    Some versions of find also have a maxdepth option that comes in handy.

    • mikey
      June 10, 2013 at 9:38 am

      chris

      guess i dont get that with HP-UX 🙂

      Thanks
      mike

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: