0

I need to copy files from one directory to another (pretty obvious :) ) but I want to store list of files that were copied with destination path. So let's say I have: /mnt/a/f1 /mnt/a/f2

and I want to copy all files from 'a' to root so I do: cp -rv /mnt/a/* /

output from cp I will have will look like:

`/mnt/a/f1` -> `/f1`

`/mnt/a/f2` -> `/f2`

and now I want to store in some file list that will looks like:

/f1

/f2

Does somebody know how can I achieve such output?

tomekK
  • 748
  • 8
  • 19

2 Answers2

4
cp -rv /mnt/a/* / 2>&1 | cut -d\` -f4 | tee thefile.txt

Something like this (untested).

Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
  • Great! Thanks! Works almost fine, I put wrong output format (for cp) so here is slightly corrected solution: cp -rv mnt/a/ / 2>&1 | cut -d\` -f3 | cut -d\' -f1 | tee thefile.txt – tomekK Oct 01 '12 at 08:45
  • Ah, I see. Yes, my `cut` was based on your output, but glad you figured it. – Michael Krelin - hacker Oct 01 '12 at 08:47
0

You can simply use something like

cp -rv files dest > output_file 

and redirect all the output to a file, but if you absolutely need to split it so you only have the ending I would recommend writing something quickly in Ruby, Python, or Perl and just symlink it as something like "verbose_cp". If you really want to you can do the splitting in Bash, though in my opinion doing it in languages with stronger string handling would be much easier.

Community
  • 1
  • 1
jroesch
  • 1,170
  • 7
  • 16