简体   繁体   中英

List copied files in bash

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?

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

像这样(未经测试)。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM