File Renaming Trick

Posted

For a lot of you it may be pretty obvious but I want to share a quick trick I thought of just now. Often I find myself renaming a file in a sub-directory and find it a pain to type the whole path twice.

mv my/long/path/file.txt my/long/path/newname.txt

However you can use shell expansion to make this easier.

mv my/long/path/{file,newname}.txt

I never thought of it earlier because I think of expansions like when creating multiple arguments of they same type (source files, packages to install…), but since the order is predictable it works well for specifying the from and to arguments for the mv and cp commands.

Discuss this Article

Find Posts on Reddit - Share on Reddit

Find Tweets on Twitter - Share on Twitter