Skip to content

Latest commit

 

History

History
33 lines (27 loc) · 955 Bytes

mv-tips-and-tricks.md

File metadata and controls

33 lines (27 loc) · 955 Bytes

mv Tips and Tricks

There are a couple tricks that can be used to make working with mv a little quicker and less painless. The first one is uses brace expansion to rename a file without having to type the full path twice[1]:

$ mv -v README.{md,org}
README.md -> README.org

Globbing and brace expansion don't play together however, so if you want to move multiple files according to a pattern, you can use a simple for loop[2]:

$ touch {1,2,3,4,5}.txt
$ for file in *.txt; do
for> mv -v "$file" "${file%.txt}.md"
for> done
1.txt -> 1.md
2.txt -> 2.md
3.txt -> 3.md
4.txt -> 4.md
5.txt -> 5.md

There are other useful shortcuts for basic string manipulation in shell.

[1] Cyberciti.biz
[2] StackExchange