When working on DNS zone files, a lot of the time I get them emailed to me as text files (e.g., db.towerstream.com.txt) and our naming convention is db.[domain].[tld] (e.g., db.towerstream.com) so I need to rename the files. No big deal if I only have a couple, but recently I got over a dozen emailed to me and I was thinking there must be an easier way….
A little web surfing and I came across the basename command and saw that it would natively strip all path information from a file and if you pass a suffix as an argument it will strip that as well. Now, all I need to do is put the files and a directory and one quick loop later all is done. It is good to be lazy 😉
Here is what a quick loop to go through the current directory and strip off the .txt from the files:
for i in `ls`; do mv $i $(basename “$i” .txt); done;