LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-24-2006, 06:32 PM   #1
C-RAF.
Member
 
Registered: Oct 2005
Distribution: Debian@work / Ubuntu@home
Posts: 42

Rep: Reputation: 15
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.
 
Old 02-24-2006, 06:48 PM   #2
Ictus
Member
 
Registered: Jan 2005
Location: Germany
Distribution: Fedora Core 4
Posts: 32

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

$ cp `ls --ignore '<this folder/file>'` <dest>
 
Old 02-24-2006, 07:04 PM   #3
C-RAF.
Member
 
Registered: Oct 2005
Distribution: Debian@work / Ubuntu@home
Posts: 42

Original Poster
Rep: Reputation: 15
aiight, make sense... I didn't know we could copy a command output

Thx
 
Old 02-25-2006, 04:14 PM   #4
C-RAF.
Member
 
Registered: Oct 2005
Distribution: Debian@work / Ubuntu@home
Posts: 42

Original Poster
Rep: Reputation: 15
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...
 
Old 02-26-2006, 05:25 AM   #5
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
Try it this way:
cp -r $(ls /original/path/full/of/folders/) new/folder/for/backup/
 
Old 02-26-2006, 05:56 PM   #6
C-RAF.
Member
 
Registered: Oct 2005
Distribution: Debian@work / Ubuntu@home
Posts: 42

Original Poster
Rep: Reputation: 15
nah, it doesn't work in either case.
 
Old 02-27-2006, 04:34 AM   #7
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
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

Last edited by /bin/bash; 02-27-2006 at 04:36 AM.
 
Old 02-27-2006, 12:53 PM   #8
C-RAF.
Member
 
Registered: Oct 2005
Distribution: Debian@work / Ubuntu@home
Posts: 42

Original Poster
Rep: Reputation: 15
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'


...but one day,
 
Old 02-27-2006, 04:58 PM   #9
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
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.
 
Old 02-28-2006, 04:23 AM   #10
C-RAF.
Member
 
Registered: Oct 2005
Distribution: Debian@work / Ubuntu@home
Posts: 42

Original Poster
Rep: Reputation: 15
Nice! Thx for that!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Option to specify Sender's Address in Mail command crazy_girl Linux - Newbie 2 08-20-2007 11:36 AM
Any arguement that can be used with 'ls' command to ignore case? davidas Linux - Newbie 5 02-26-2006 05:46 AM
enabling command option completion s_deepblue Debian 4 12-02-2005 06:42 PM
Command line option -F means what? TSynergy Linux - Newbie 5 11-15-2005 09:01 PM
tar command include option? x5452 Linux - General 7 05-20-2004 11:18 PM


All times are GMT -5. The time now is 02:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration