1847893 Members
3763 Online
104021 Solutions
New Discussion

Re: cp

 
SOLVED
Go to solution
j773303
Super Advisor

cp

Please view the below, I just want to cp files created by Jul 14 to another directory, but not Jul 15. How about the command? Thanks.


---------------------------------------------
/tmp/jeff#ll
total 48
-rw-rw-rw- 1 root sys 247 Jul 14 17:34 a
-rw-rw-rw- 1 root sys 247 Jul 15 09:57 c
-rw-rw-rw- 1 root sys 32 Jul 15 09:23 d
Hero
6 REPLIES 6
Michael Tully
Honored Contributor
Solution

Re: cp

If they are one day old you use the find command.

# find . -mtime +1 -print | xargs cp
or
# find . -mtime +1 -print -exec cp {} \;
Anyone for a Mutiny ?
j773303
Super Advisor

Re: cp

I use this,
ll | grep "Jul 15" | tr -s ' ' | cut -f9 -d ' '

it would shows
c
c

Can you tell me, then how the command to copy c and d to another directory ? Thanks.
Hero
Muthukumar_5
Honored Contributor

Re: cp

You can use awk instead of cut command. It is very effective to do this. To copy a set of files to a directory use as like,

cp `ll | grep "Jul 15" | tr -s ' ' | cut -f9 -d ' '`

or

cp `ll | grep "Jul 15" | awk '{ print $9 }'` /directory of destination/*

or
echo cp `ll | grep "Jul 15" | awk '{ print $9 }'` /directory/ | sh

But find command syntax from tulley is effective one for this.

Regards,
Muthukumar.
Easy to suggest when don't know about the problem!
Con O'Kelly
Honored Contributor

Re: cp

Hi

Try using:
# ll | grep " Jul 14 " | awk '{print $9 }' | cpio -pmdv

Cheers
Con
Michael Tully
Honored Contributor

Re: cp

or even
$ for i in `ll | grep "Jul 14" | awk '{print $9}'`
> do
> cp $i /newdir
> done
Anyone for a Mutiny ?
Muthukumar_5
Honored Contributor

Re: cp

Another way to do with awk is,

cp `ll | awk '{ if ( $6 == "Jul" && $7 == 14 ) print $9 }'` /directory/

If you are going to do from any directory,give the input directory in the ll command.

you can get the files with the permission too with $1 option in the awk checking.

Regards,
Muthukumar.
Easy to suggest when don't know about the problem!