[Ilugc] cp command

  • From: steve@xxxxxxxxxxxx (steve)
  • Date: Fri Nov 27 11:08:07 2009

Hello Sagayaraj,

On 11/26/2009 09:16 PM, Sagayaraj wrote:

Dear ALL,

   How to copy the specific files only in cp command in RHEL 5 or all linux
flavor?
Ex i've 1000 files in a folder, i want to copy only 715 files olny in that
folder to paste other place. what command using for that..waiting for your
prompt reply.


You weren't very descriptive about what critera you would use to select the 715 
files out of the 1000 to copy. There are multiple ways to do this depending on 
your selection criteria.

For example if the criteria is based on the name of the files which follow a 
certain pattern and all the files are in the same directory, you would use 
something like

$ cp /path/to/1000/file/<pattern> /destination/folder

where <pattern> is a file 'glob' as describe in bash info pages ...
$ info bash --index-search='Pattern Matching'

If the files are in multiple sub-directories, you still can use:

$ cp /path/to/top/level/dir/<dir glob>/<file glob> /destination/folder

or two commands, one to do the matching (like 'find') and another to do the 
copying:

$ find /path/to/top/level/dir/ -name "<file glob>" \
        -exec cp {} /destination/folder ';'

now, with find you can also use other the selection criteria besides the name. 
Read more in the find info pages:
$ pinfo find --node='Finding Files'

...and lastly of course you can also write a script to match and copy the files.

HTH,
cheers,
- steve
-- 
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/

Other related posts: