Skip to content

Instantly share code, notes, and snippets.

@chibby0ne
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chibby0ne/81507a2821f4b772ff48 to your computer and use it in GitHub Desktop.
Save chibby0ne/81507a2821f4b772ff48 to your computer and use it in GitHub Desktop.
One-liner that adds a 0 to filename's ranging from 1 to 9, when there are more than 9 files with numbers appended in their filename, thus fixing the ordering when listed
#!/bin/bash
# Add this one-liner script to the PATH variable and have the power to count the files in a directory from anywhere in the command line
#NAME is the prefix that the files share in common
NAME=$1; ls -1 | grep -E ${NAME}[0-9]{1}\\. | sed -e 'p;s/\([0-9]\)/0\1/g' | xargs -n 2 mv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment