2

If we have a dir/file setup like the following

var
  |-->usr
  |    |-FileA
  |    |-FileB
  |    |-FileC
  |    |-FileD

How can I move FileA and FileD without specifying the path twice like in the following cmd?

mv /var/usr/FileA /var/usr/FileB /home
0

2 Answers 2

5

Try doing this :

mv /var/usr/{FileA,FileB} /home

or :

( cd /var/usr/ && mv FileA FileB /home )

The later one use a subshell to return to the previous PATH.

Check brace expansion

2

You could just do:

mv /va[r]/usr/File[AB] /home

And possibly even...

mv /va[r]/usr/File[AB] /home
2
  • What's the point of the brackets around [r]?
    – Noumenon
    Dec 23, 2016 at 14:49
  • 1
    @noumenon - they expand the known /var/ path first so the stderr is more easy to test. i did an answer on it somewhere here that made more sense before - especially where * is used - but its not especially useful without variables. basically, even if you insert variables somewhere in the path, a filename that exists will always evaluate to /var/... whereas any broken or inaccessible pathname will work out to /va[r]/...
    – mikeserv
    Dec 31, 2016 at 22:46

Not the answer you're looking for? Browse other questions tagged .