Last active
November 15, 2017 13:36
-
-
Save davidfoerster/6b845f84054f8cad28f3f82edb99535b to your computer and use it in GitHub Desktop.
find test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
declare -r TMP="${1:-"${TMP:-/tmp}/find-test"}" | |
declare -ri file_count="${2:-1000000}" pad="${3:-255}" | |
declare -ar find=( find "$TMP" -mount -mindepth 1 ) | |
# Preparation | |
mkdir -p -- "$TMP" | |
declare -i free_inodes="$(stat -f -c %d -- "$TMP")" | |
if [ "$free_inodes" -gt 0 ]; then | |
free_percentage="$(bc -l <<< "$file_count * 100 / $free_inodes")" | |
/usr/bin/printf \ | |
"This action requires %'.1f %% of free inodes on the device.\n" \ | |
"$free_percentage" >&2 | |
[ "${free_percentage#.*}" -lt 50 ] || | |
read -p "If you don't want to proceed, press CTRL+C to abort; otherwise press ENTER." | |
fi | |
# Create files | |
declare -i char_count="$( | |
seq 1 "$file_count" | | |
xargs -rd '\n' -- printf "$(sed -e 's/[%\\]/&&/g' <<< "$TMP")/%0${pad}u\0" | | |
tee >(exec xargs -r0 -- touch --) | | |
wc -c)" | |
printf "%'u created files, %'u total path name length\n" \ | |
"$("${find[@]}" -printf . | wc -c)" "$char_count" >&2 | |
# Touch files through `find` | |
"${find[@]}" -exec touch -c -t 197012250000 -- {} + | |
# Find any files that weren't changed in the last year | |
"${find[@]}" -ctime +365 -printf '%f\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment