Skip to content

Instantly share code, notes, and snippets.

@Lucent
Last active July 5, 2023 00:35
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 Lucent/86567af89db57ed45a7c01190f78fd27 to your computer and use it in GitHub Desktop.
Save Lucent/86567af89db57ed45a7c01190f78fd27 to your computer and use it in GitHub Desktop.
Useful bash one-liners
# Remove all empty folders
find . -maxdepth 1 -type d -empty -print0 > empty.txt; xargs -0 rmdir < empty.txt
# Remove empty folders 2 levels deep, and their parent
find . -maxdepth 2 -type d -empty > empty.txt; rmdir $(<empty.txt)
find . -maxdepth 1 -type d -empty > empty.txt; rmdir $(<empty.txt)
# Move all folders with certain name into their own named folder
find -maxdepth 2 -name 'lavajava' -printf '%h\n' > lavajava.txt; mkdir lavajava; mv $(<lavajava.txt) lavajava/
# Move root dir files in subdirs into a root folder
find -maxdepth 2 -type f -printf '%h\n' > files.txt; mv $(<files.txt) root/
# Sort Trillian XML chat log by time
sed -r 's/^.*time="([^"]+)".*$/\1 &/' newfile.xml|sort -n|sed 's/[^ ]* //'
# Rename Samsung Voice recorder files to prefix their Media Create date
exiftool '-FileName<CreateDate' -d "%Y%m%d_%H%M%S %%f.%%e" -api QuickTimeUTC=1 *.m4a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment