Skip to content

Instantly share code, notes, and snippets.

@phette23
Created July 16, 2024 19:20
Show Gist options
  • Save phette23/35b51af01865b92f07314843d3a0fe6c to your computer and use it in GitHub Desktop.
Save phette23/35b51af01865b92f07314843d3a0fe6c to your computer and use it in GitHub Desktop.
create CSV of file paths, size, and last accessed times for Moodle filedir
#!/usr/bin/env bash
# create a csv of path, file size, last access time for all files in a directory tree
# usage: file-tree-csv.sh /path/to/directory > output.csv
FILEDIR=/opt/moodledata/filedir
cd $FILEDIR || (echo "Moodle filedir not found, exiting" && exit 1)
echo "path,size,atime"
# shellcheck disable=SC2044
# all Moodle file names & paths only contain hexadecimal chars
for file in $(find . -type f); do
size=$(stat -c %s $file)
atime=$(stat -c %x $file)
echo "$file,$size,$atime"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment