Skip to content

Commit

Permalink
Use POSIX syntax for maximum length argument lists in find's -exec
Browse files Browse the repository at this point in the history
  • Loading branch information
l0b0 committed Jun 26, 2013
1 parent 1e01ad9 commit a5dab2e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .bash_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ zsed() {
while IFS= read -r -d '' -u 9
do
sed -i -e "$replacement" "$REPLY"
done 9< <( find . -type f -exec printf '%s\0' {} \; )
done 9< <( find . -type f -exec printf '%s\0' {} + )
tar -czf "$full_path" .
cd - >/dev/null
done
Expand Down
12 changes: 6 additions & 6 deletions .bash_history
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ find_date_sorted . -mindepth 1 # files
find_date_sorted . -mindepth 1 | sort --reverse --zero-terminated | while IFS= read -r -d ''; do stat -- "$REPLY"; done # files loop reverse
find . -empty
find . -empty -delete # remove files
find . -exec printf '%s\0' {} \; | while read -r -d ''; do printf %q "$REPLY"; printf '\n'; done
find . -group 1000 -exec chgrp $(id --group) {} \; # update files permissions
find . -exec printf '%s\0' {} + | while read -r -d ''; do printf %q "$REPLY"; printf '\n'; done
find . -group 1000 -exec chgrp $(id --group) {} + # update files permissions
find -L . -type l # broken symlinks
find . -mindepth 1 -exec printf '%s\0' {} \; | shuf --head-count 10 --zero-terminated # random shuffle files
find . -mindepth 1 -exec printf '%s\0' {} + | shuf --head-count 10 --zero-terminated # random shuffle files
find . -mindepth 1 -exec printf x \; | wc -c # count files posix safe
find . -name '*.marks' -delete # remove jedit temp files
find . \( -path ./.git -o -path ./.svn \) -prune -o \( -type f -exec grep --files-with-matches $'\t' {} + \) # exclude vcs directories tab files
Expand Down Expand Up @@ -1667,7 +1667,7 @@ sudo sh -c 'apt-get update && apt-get upgrade --yes && if [[ -f /var/run/reboot-
sudo sh -c 'dhclient -r wlan0 && dhclient wlan0' # request refresh dhcp ip
sudo sh -c 'ip addr add 192.168.0.99/16 wlan0 && dhclient wlan0' # set ip address network
sudo sh -c "mkdir -p /var/lib/rrdcached/db /var/lib/rrdcached/journal && chown $(printf %q "$USER"):$(printf %q "$(groups | awk '{print $1}')") /var/lib/rrdcached/db /var/lib/rrdcached/journal && apt-get install rrdcached" # fix ubuntu rrdcached install bug 985341
sudo sh -c 'tail --follow name --retry --lines 0 $(find /var/log/ -type f -exec file -- {} \; | grep ":.*\(ASCII\|UTF\)" | cut --delimiter : --field 1)' # text
sudo sh -c 'tail --follow name --retry --lines 0 $(find /var/log/ -type f -exec file -- {} + | grep ":.*\(ASCII\|UTF\)" | cut --delimiter : --field 1)' # text
sudo showkey # keyboard
sudo strace -p 123 # process
sudo tail --follow=name --retry --lines 0 /var/log/syslog
Expand Down Expand Up @@ -1847,9 +1847,9 @@ wget --output-document - http://user:password@host/function?id=foo 2>service.log
wget --server-response --output-document=/dev/null http://example.org/ # web header
whatis mv # exact help man
which make
while IFS= read -r -d '' -u 9; do if [[ "$(file --brief --special-files --mime-type -- "$REPLY")" = text/* ]]; then sed --in-place --expression 's/[ \t]\+\(\r\?\)$/\1/;$a\' -- "$REPLY"; else echo "Skipping $REPLY" >&2; fi; done 9< <(find . \( -type d -regex '^.*/\.\(git\|svn\)$' -prune -false \) -o -type f -exec printf '%s\0' {} \;) # whitespace eol eof
while IFS= read -r -d '' -u 9; do if [[ "$(file --brief --special-files --mime-type -- "$REPLY")" = text/* ]]; then sed --in-place --expression 's/[ \t]\+\(\r\?\)$/\1/;$a\' -- "$REPLY"; else echo "Skipping $REPLY" >&2; fi; done 9< <(find . \( -type d -regex '^.*/\.\(git\|svn\)$' -prune -false \) -o -type f -exec printf '%s\0' {} +) # whitespace eol eof
while IFS= read -r -d '' -u 9; do jedit -reuseview "$REPLY"; done 9< <(grep --null --files-with-matches --recursive --exclude-dir .git --exclude-dir .svn --exclude-dir CVS --regexp 'pattern' .) # search open files
while IFS= read -r -d '' -u 9; do printf '%q\n' "${REPLY#* }"; done 9< <(find . -printf '%T@' -exec printf ' %s\0' {} \; | sort --general-numeric-sort --zero-terminated) # sort file list modification date
while IFS= read -r -d '' -u 9; do printf '%q\n' "${REPLY#* }"; done 9< <(find . -printf '%T@' -exec printf ' %s\0' {} + | sort --general-numeric-sort --zero-terminated) # sort file list modification date
while IFS= read -r -u 9; do if [[ "$REPLY" =~ .*\.dot$ ]]; then dot -O -Tsvg "$REPLY"; fi; done 9< <(inotifywait --event close_write --format %f --monitor .)
while IFS= read -r -u 9; do if [[ "$REPLY" =~ .*\.markdown$ ]]; then markdown_page "$REPLY" > "${REPLY%.markdown}.xhtml"; fi; done 9< <(inotifywait --event close_write --format %f --monitor .)
while IFS= read -r -u 9; do if [[ "$REPLY" =~ .*_test\.rb$ ]]; then rake test; fi; done 9< <(inotifywait --event close_write --format %f --monitor test/*)
Expand Down
2 changes: 1 addition & 1 deletion examples/safe-find.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ do
printf %q "$file_name"
printf '\n'
fi
done 9< <( find "$test_dir_path" -type f -exec printf '%s\0' {} \; )
done 9< <( find "$test_dir_path" -type f -exec printf '%s\0' {} + )

rm -- "$test_file_path"
rmdir -- "$test_dir_path"
4 changes: 2 additions & 2 deletions scripts/duplicates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ while IFS= read -r -d '' -u 9
do
file_path="$(readlink -fn -- "$REPLY"; echo x)"
file_path="${file_path%x}"
exec 8< <( find "$start_dir" -type f \( -path "$file_path" -o -exec printf '%s\0' {} \; \) )
exec 8< <( find "$start_dir" -type f \( -path "$file_path" -o -exec printf '%s\0' {} + \) )
while IFS= read -r -d '' -u 8 OTHER
do
cmp --quiet -- "$REPLY" "$OTHER"
Expand All @@ -71,4 +71,4 @@ do
;;
esac
done
done 9< <( find "$start_dir" -type f -exec printf '%s\0' {} \; )
done 9< <( find "$start_dir" -type f -exec printf '%s\0' {} + )

0 comments on commit a5dab2e

Please sign in to comment.