TransWikia.com

Piping tar archive via mv on macOS

Unix & Linux Asked on November 14, 2021

I ran:

tar -cjvf ~/Dict_$(date +%Y-%m_%d-%H_%M_%S).tar.bz2 ~/Dictionaries | xargs mv ~/Documents

but it leaves the resulting file in ~/ and does not move it.

How do I move the resulting file (after it was archived) to another folder?

One Answer

Did you look at the output?  Did it say something like

mv: target ‘some filename’ is not a directory
?

In general, if cmd outputs a, b and c, and you run

cmd | xargs d e f
then xargs will run
d e f a b c
So your command caused xargs to run
mv ~/Documents file1 file2 file3
That’s not how mv works.

Try

(your tar command)  |  xargs mv -t ~/Documents

Note: you should probably first verify that the version of mv on your system supports the -t option.  If you were on Linux, it would be pretty much guaranteed, but I’m not sure about macOS.

Answered by G-Man Says 'Reinstate Monica' on November 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP