0

Suppose I want to rename a file several directories down. I do,

mv dirA/dirB/dirC/name.suf dirA/dirB/dirC/newname.suf

Is there any easier way to type this? One option would be

cd dirA/dirB/dirC
mv name.suf newname.suf
cd -

Anything better?

  • Both of these seem to work and achieve what you need. Option 2 is a bit safer - making sure you do not miss any directory and move the file elsewhere. You can create a shell script that will perform all 3 operations in one line - but how often would you really need it? – Traveling Tech Guy May 04 '14 at 19:47

1 Answers1

3

Depending on your shell, you could make use of the filename expansion features. In ZSH (and, I believe Bash, too), you could run

mv dirA/dirB/dirC/{name,newname}.suf

which expands to

mv dirA/dirB/dirC/name.suf dirA/dirB/dirC/newname.suf

bevore executing the mv command (see zshexpn(1)).

DMKE
  • 146
  • 2