LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   cp command: except or ignore option? (https://www.linuxquestions.org/questions/programming-9/cp-command-except-or-ignore-option-419240/)

C-RAF. 02-24-2006 05:32 PM

cp command: except or ignore option?
 
Hi there,

I was looking in the man page of the basic "cp" command and I didn't find any command allowing the user to copy a bunch of file EXCEPT some of them. Kinda like when u're doing "ls --ignore '<this folder/file>' "....
somebody help me!!!

A long way to go... before being a Guru.

Ictus 02-24-2006 05:48 PM

Since cp doesnt have such a function, why dont just use ls's?

$ cp `ls --ignore '<this folder/file>'` <dest>

C-RAF. 02-24-2006 06:04 PM

aiight, make sense... I didn't know we could copy a command output

Thx

C-RAF. 02-25-2006 03:14 PM

It's not working for me :(

For this command:

cp -r `ls /original/path/full/of/folders/` new/folder/for/backup/

I get this:

cp: cannot stat `<files2copy>': No such file or directory
cp: cannot stat `<files2copy>': No such file or directory
cp: cannot stat `<files2copy>': No such file or directory
cp: cannot stat `<files2copy>': No such file or directory
cp: cannot stat `<files2copy>': No such file or directory
cp: cannot stat `<files2copy>': No such file or directory

But all this files are present in the system, it's like cp couldn't handle ls output... I don't get it... :confused:

/bin/bash 02-26-2006 04:25 AM

Try it this way:
cp -r $(ls /original/path/full/of/folders/) new/folder/for/backup/

C-RAF. 02-26-2006 04:56 PM

nah, it doesn't work in either case. :scratch:

/bin/bash 02-27-2006 03:34 AM

cpio is good at copying directories. From the Advanced Bash Scripting Guide I found and modified this:

find /original/path/full/of/folders/ | cpio -admvp new/folder/for/backup/

NOTE: Use ! -name [IGNORE] to ignore files matching IGNORE. For example:

find /original/path/full/of/folders/ ! -name "*.bak" | cpio -admvp new/folder/for/backup/
Will copy all files except .bak files

C-RAF. 02-27-2006 11:53 AM

:D Damn that's sleek!!! it works!!! Thanx a lot!!!

The sad thing is that I can't find this kind of stuff by myself 'yet' :cry:


...but one day, :jawa:

/bin/bash 02-27-2006 03:58 PM

The important thing is that you do at least try.

The Advanced Bash-Scripting Guide is an invaluable guide. I look through it on a regular basis. Download it to your computer and make a Bookmark for it.

C-RAF. 02-28-2006 03:23 AM

Nice! Thx for that! :study:


All times are GMT -5. The time now is 01:37 AM.