LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 09-21-2009, 07:42 PM   #1
nass
Member
 
Registered: Apr 2006
Location: Athens, Greece
Distribution: slack(64|32)_v(13.37|14.0), debian6, ubuntu
Posts: 630

Rep: Reputation: 36
bash and operation on multiple files using xargs and copy


Hello everyone,
I am curious about some functionality of bash...
I have a file (generated with diff) that contains only the filenames of files that do not exist in both folders (in fact it is easy since the folder with the most files contains all the files of the other folder)...

i want to back up all these files ... of course i could use any backup utility.. .but since im here to learn, i decided to do it manually...

so diff (with a suiting grep) outputs only the files that do not exist in both folders, and now i have a file that contains only the filenames of those files... no absolute path or anything.

what i tried to do to get them copied to the backup folder is the following...

cat diff_output.txt | xargs cp -vt <backup folder> <path/ to/ location/ of/ the/ extra/ files/>

and i was hoping that bash would append the filenames read in the txt file directly to the source files and proceed with the copying..
what am i doing wrong?

Thank you for your help,
Nass
 
Old 09-21-2009, 11:48 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
That should work as long as you are in the directory with the files and execute

Code:
cat diff_output.txt | xargs cp -vt /path/to/<backup directory>
or preprocess the diff output to include the full path.

xargs will just append its input. If you say

Code:
cat diff_output.txt | xargs cp -vt <backup folder> <path/ to/ location/ of/ the/ extra/ files/>
and diff_output.txt contains the files 'foo' and 'bar' then cp will get

Code:
cp -vt <backup folder> <path/ to/ location/ of/ the/ extra/ files/> foo bar
You can't copy a directory onto a directory that way and foo and bar still won't exist.

Last edited by slakmagik; 09-21-2009 at 11:51 PM. Reason: use more code tags and try to make my example clearer
 
Old 09-22-2009, 03:20 AM   #3
nass
Member
 
Registered: Apr 2006
Location: Athens, Greece
Distribution: slack(64|32)_v(13.37|14.0), debian6, ubuntu
Posts: 630

Original Poster
Rep: Reputation: 36
hm i see...
but then how does 'find' work and you can pipe its output to another command??
 
Old 09-22-2009, 07:45 AM   #4
escaflown
Member
 
Registered: Apr 2009
Location: Canada
Distribution: Slackware
Posts: 237

Rep: Reputation: 30
Quote:
Originally Posted by nass View Post
hm i see...
but then how does 'find' work and you can pipe its output to another command??
Check out the "-exec" option of find
 
  


Reply

Tags
backup, copy, diff, filename, xargs


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
-bash: ulimit: open files: cannot modify limit: Operation not permitted pjglinuxq Linux - Server 3 06-11-2010 06:19 AM
Creating a script to move or copy files into multiple directories below the files matthes138 Linux - Newbie 5 08-25-2009 04:57 PM
how do i use bash to perform an operation on multiple files Brynn Linux - Newbie 6 07-24-2006 06:02 AM
How do I copy multiple files Leary664 Linux - General 18 09-06-2005 02:58 AM
copy multiple files into one file HelpPlease Programming 2 12-09-2003 02:36 PM


All times are GMT -5. The time now is 03:40 PM.

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