Skip to content

Instantly share code, notes, and snippets.

@devuri
Created October 17, 2017 17:02
Show Gist options
  • Select an option

  • Save devuri/a41496d1cf1fc14bdfc9b0b472d7d7d1 to your computer and use it in GitHub Desktop.

Select an option

Save devuri/a41496d1cf1fc14bdfc9b0b472d7d7d1 to your computer and use it in GitHub Desktop.
remove last 12 characters of a file name
You could use rename. From inside the directory:
rename -n 's/(.*).{12}/$1/' *
Remove -n after testing to actually rename the files. Replace {12} with {whatever number of characters you want to delete from the end of the name}
Explanation
s/old/new/' replaceoldwithnew`
(.*) save any number of any characters...
.{12} the last twelve characters whatever they are
$1 the characters saved with ()
// credit
//https://askubuntu.com/questions/873617/remove-last-n-characters-of-filenames-in-a-directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment