Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2005
    Location
    Maputo, Mozambique, Africa
    Posts
    19

    Copy many files excluding a few of them using terminal


    Hi all,

    Let's say a have 20 files in a directory. I want to copy 19 of them to another location.

    How can I easily do this? Is there any option to exclude files on the CP command?

  2. #2
    You can do it if you pattern-match the names to exclude the unwanted one. Or try
    Code:
    cp $(ls | grep -v unwantedfilename) dest_dir
    which looks suitably cunning and obscure.

  3. #3
    Just Joined!
    Join Date
    Apr 2005
    Location
    Maputo, Mozambique, Africa
    Posts
    19
    Hi,

    It worked, but only for files without space char at the file name. When I try to escape the space chars, it give me an error.

    Code:
    [amussa@cust29-10 rock]$ cp $(ls -b | grep -v METALLICA) ../testdir
    cp: invalid option -- \
    Try `cp --help' for more information.
    [amussa@cust29-10 rock]$

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •