file enumeration tool
This commit is contained in:
46
files/file-enumerate
Executable file
46
files/file-enumerate
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
function _help() {
|
||||
echo '
|
||||
Usage: file-enumerate [-k] [-p #]
|
||||
|
||||
Creates a folder "enumerated" and hard links all files in the current folder
|
||||
renamed with a number
|
||||
|
||||
-k keep filename, and insert the number in the beginning
|
||||
-p pad nunbers, defaults to 4
|
||||
'
|
||||
exit
|
||||
}
|
||||
keep=false
|
||||
pad=4
|
||||
for (( i=1; i<=$#; i++ )); do
|
||||
j=$(( i + 1 ))
|
||||
[[ "${!i}" = "-h" ]] && _help
|
||||
[[ "${!i}" = "--help" ]] && _help
|
||||
[[ "${!i}" = "-k" ]] && keep=true
|
||||
[[ "${!i}" = "-p" ]] && { pad=${!j}; i=$(( i + 1 )); }
|
||||
done
|
||||
|
||||
printf -v padstr "%%0%dd" $pad
|
||||
|
||||
_drive() {
|
||||
ls -1prt | grep -v "/$" | cat -n | while read n f; do
|
||||
printf -v padded $padstr $n
|
||||
if [[ $keep = true ]]; then
|
||||
printf -v outname "%s.%s" "$padded" "$f"
|
||||
else
|
||||
ext=${f#*.}
|
||||
if [[ "$ext" = "$f" ]]; then
|
||||
printf -v outname "%s" "$padded"
|
||||
else
|
||||
printf -v outname "%s.%s" "$padded" "$ext"
|
||||
fi
|
||||
fi
|
||||
printf "%30s -> %s\n" "$f" "$outname"
|
||||
cp -l "${f}" enumerated/"$outname"
|
||||
done
|
||||
}
|
||||
|
||||
mkdir -p enumerated
|
||||
_drive
|
||||
Reference in New Issue
Block a user