LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 05: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, 05: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, 06: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, 03: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, 04:25 AM   #5
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
Try it this way:
cp -r $(ls /original/path/full/of/folders/) new/folder/for/backup/
 
Old 02-26-2006, 04: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, 03:34 AM   #7
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
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 03:36 AM.
 
Old 02-27-2006, 11:53 AM   #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, 03:58 PM   #9
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 47
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, 03: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



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 10:36 AM
Any arguement that can be used with 'ls' command to ignore case? davidas Linux - Newbie 5 02-26-2006 04:46 AM
enabling command option completion s_deepblue Debian 4 12-02-2005 05:42 PM
Command line option -F means what? TSynergy Linux - Newbie 5 11-15-2005 08:01 PM
tar command include option? x5452 Linux - General 7 05-20-2004 10:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:21 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration