[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: mv and exlude list



2009/5/7 Guillaume CHARDIN <guillaume chardin gmail com>:
> Hi, maybe some scripting genius gonna help me :D
>
> I need to move some file from one directory to other with some exclusions.
> Ex: move files from "/data/product/" to "/data/archives/2005" while
> the "*.dat" file/dirs stay in the right place.
>
> $mv /data/product/* !(/data/product/*.dat) /data/archives/2005

find /data/product -maxdepth 1 -type f \! -path "*.dat" -exec mv \{\}
/data/product/2005 \;

Which translates as finding the following criteria of files:

-maxdepth 1 : don't recurse into subdirectories e.g. not into /data/product/2005
-type f : find only files, not directories
\! -path "*.dat" : filename/path should not end in .dat

And then moving them to /data/product/2005 like this:

$ ls -lR /data/product
/data/product:
total 4
drwxr-xr-x 2 sjs298 root  4096 2009-05-07 16:57 2005
-rw-r--r-- 1 sjs298 users    0 2009-05-07 16:57 adatfile.dat
-rw-r--r-- 1 sjs298 users    0 2009-05-07 16:57 afile
-rw-r--r-- 1 sjs298 users    0 2009-05-07 16:57 anotherfile

/data/product/2005:
total 0
$ find /data/product -maxdepth 1 -type f \! -path "*.dat" -exec mv
\{\} /data/product/2005 \;
$ ls -lR /data/product/data/product:
total 4
drwxr-xr-x 2 sjs298 root  4096 2009-05-07 16:58 2005
-rw-r--r-- 1 sjs298 users    0 2009-05-07 16:57 adatfile.dat

/data/product/2005:
total 0
-rw-r--r-- 1 sjs298 users 0 2009-05-07 16:57 afile
-rw-r--r-- 1 sjs298 users 0 2009-05-07 16:57 anotherfile

-- 
Sam


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]