Skip to content

Instantly share code, notes, and snippets.

@kpprt
Last active August 8, 2017 16:46
Show Gist options
  • Save kpprt/4f0af25aea09edcd5e4bcb8751e7cd41 to your computer and use it in GitHub Desktop.
Save kpprt/4f0af25aea09edcd5e4bcb8751e7cd41 to your computer and use it in GitHub Desktop.
A collection of short one line bash snippets.
#!/bin/bash
# find hidden files recursively from the current folder which file names are not starting with a dot
find . -flags +hidden -name \[\!.\]\*
# unhide all files recursively from the current folder which file names are not starting with a dot
find . -flags +hidden -name \[\!.\]\* -exec chflags nohidden {} \;
# simple search and replace in all file names of current folder
# echo is there for preview, remove it to actually execute the command
for f in *.*; do echo mv "$f" "${f/SEARCHSTRING/REPLACESTRING}"; done
# substring replace, e.g.
# ${param:3} # third character to end
# ${param:-3} # third last character to end
# ${param:3:2} # third character to fourth character (length of 2)
# ${param:3:-2} # third character to second last character, excluding second last character
for f in *.*; do echo mv "$f" "${f:offset:length}"; done
# see also http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment