Differences between revisions 5 and 6
Revision 5 as of 2016-04-05 04:11:57
Size: 1358
Editor: SamatJain
Comment: Fix whitespace issues in source code
Revision 6 as of 2016-04-05 22:03:18
Size: 1343
Editor: SamatJain
Comment: Remove echo's
Deletions are marked like this. Additions are marked like this.
Line 33: Line 33:
  find . -type f -name "*${EXTENSION}" -exec echo sed -i "s/[[:blank:]]*$//" {} \;   find . -type f -name "*${EXTENSION}" -exec sed -i "s/[[:blank:]]*$//" {} \;
Line 35: Line 35:
  find . -type f -name "*${EXTENSION}" -exec echo sed -i -e '$a\' {} \;   find . -type f -name "*${EXTENSION}" -exec sed -i -e '$a\' {} \;
Line 37: Line 37:
  find . -type f -name "*${EXTENSION}" -exec echo sed -i 's/\t/ /g' {} \;   find . -type f -name "*${EXTENSION}" -exec sed -i 's/\t/ /g' {} \;

Delete files not modified in n days

Useful for clearing out caches that aren't properly cleaned out otherwise.

# Delete files not modified in 30 days
find . -type f -mtime +30 -exec rm {} \;
# Same, but faster
find . -type f -mtime +30 -print0 | xargs -0 -n256 rm

Replace text in all files in & under the current directory

find . -type f -exec sed -i 's/old/new/g' {} \;

Find files NOT named something

# Find files matching a pattern that are NOT already compressed, then compress them
# (This particular example compresses Maildirs for use w/ dovecot's transparent decompression)
find . -type f -name '*S=*' -not -name '*.gz' -print0 | xargs -0 -P4 -n 16 zopfli -l100

Fix whitespace issues

for EXTENSION in php css html js; do
  # Remove whitespace (incl. tabs) at the end of lines
  find . -type f -name "*${EXTENSION}" -exec sed -i "s/[[:blank:]]*$//" {} \;
  # Add trailing newlines to the end of a file
  find . -type f -name "*${EXTENSION}" -exec sed -i -e '$a\' {} \;
  # Replace tabs w/ spaces
  find . -type f -name "*${EXTENSION}" -exec sed -i 's/\t/    /g' {} \;
done


CategoryCheatSheet

SamatsWiki: CheatSheet/GNUFind (last edited 2019-01-13 22:01:38 by SamatJain)