Linux: remove file extensions for multiple files

rename is slightly dangerous, since according to its manual page: rename will rename the specified files by replacing the first occurrence of… It will happily do the wrong thing with filenames like c.txt.parser.y. Here’s a solution using find and bash: find -type f -name ‘*.txt’ | while read f; do mv “$f” “${f%.txt}”; done Keep … Read more

How to zero pad numbers in file names in Bash?

It’s not pure bash, but much easier with the Perl version of rename: rename ‘s/\d+/sprintf(“%05d”,$&)/e’ foo* Where ‘s/\d+/sprintf(“%05d”,$&)/e’ is the Perl replace regular expression. \d+ will match the first set of numbers (at least one number) sprintf(“%05d”,$&) will pass the matched numbers to Perl’s sprintf, and %05d will pad to five digits

Renaming a branch in GitHub

As mentioned, delete the old one on GitHub and re-push, though the commands used are a bit more verbose than necessary: git push origin :name_of_the_old_branch_on_github git push origin new_name_of_the_branch_that_is_local Dissecting the commands a bit, the git push command is essentially: git push <remote> <local_branch>:<remote_branch> So doing a push with no local_branch specified essentially means “take … Read more

Python: Rename duplicates in list with progressive numbers without sorting list

My solution with map and lambda: print map(lambda x: x[1] + str(mylist[:x[0]].count(x[1]) + 1) if mylist.count(x[1]) > 1 else x[1], enumerate(mylist)) More traditional form newlist = [] for i, v in enumerate(mylist): totalcount = mylist.count(v) count = mylist[:i].count(v) newlist.append(v + str(count + 1) if totalcount > 1 else v) And last one [v + str(mylist[:i].count(v) … Read more

How do you change the capitalization of filenames in Git?

Starting Git 2.0.1 (June 25th, 2014), a git mv will just work on a case-insensitive OS. See commit baa37bf by David Turner (dturner-tw). mv: allow renaming to fix case on case-insensitive filesystems “git mv hello.txt Hello.txt” on a case-insensitive filesystem always triggers “destination already exists” error, because these two names refer to the same path … Read more