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
Anthon
  • 79,293
Jackarter
  • 29
  • 1
  • 2

2 Answers2

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
mikeserv
  • 58,310
  • What's the point of the brackets around [r]? – Noumenon Dec 23 '16 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 '16 at 22:46