Showing posts from November, 2017

Renaming files with Find on Unix

A quick handy hint for Unix command line users today - I had a lot of files to rename, spread through a file system. Sort of like this: The files were all named the same thing, but were in a whole lot of directories - I needed to rename each site-data.json file to just be data.json. I also had a bunch of other files that I wanted to leave alone - I didn't want to rename everything. I have done this sort of thing before, but every time I do I have to search again. I found lots of StackOverflow posts that didn't quite do what I wanted - which is: Find is an incredibly useful tool, and can look for names matching a pattern or word (site-data.json here) then pass that full file name to another command via the -exec option. The full path of the file is kept in {} - so that rename command applies the Perl regular expression (s/site-//g) to the full file name, and this chops off the site- prefix. It only affects the files I wanted to remain (they were the only things foun…