Skip to content

Instantly share code, notes, and snippets.

@gfxhacks
Created July 4, 2020 04:31
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 gfxhacks/cf4d296528ddb03cbff427455842079a to your computer and use it in GitHub Desktop.
Save gfxhacks/cf4d296528ddb03cbff427455842079a to your computer and use it in GitHub Desktop.
Snippets to extract path, filename, and extension from a full path input in bash. More info: https://gfxhacks.com/renaming-files-by-date-from-metadata/#extracting-path-filename-and-extension
FILEPATH=`dirname path/to/file.ext`
# returns: path/to
FILENAME=`basename path/to/file.ext`
# returns: file.ext
FILENAME=`basename path/to/file.ext | rev | cut -d . -f 2- | rev`
# returns: file
FILEEXT=`rev <<< path/to/file.ext | cut -d . -f 1 | rev`
# returns: ext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment