Tuesday, August 12, 2008

Script to identify long ago accessed files

He asked me how can he identify long ago accessed files. I've written the following script.

bash-2.05b$ more laaf.sh
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
FNAME=$1
DAYS=$2
if test $# -lt 2
then
echo 'Usage: laaf.sh <+|-N>, where N - number of days'; exit
fi
find $FNAME -type f -atime $DAYS -exec ls -lt --full-time '{}' \; | awk '{print $6,$5,$9;}'
==
Usage: ./laaf.sh <+|-N> [> file.out]
where - is the path to the target directory
<+|-N> - accessed before|after N days

In the output of this script will be modified date, size and file name with full path by row

Monday, August 11, 2008

script for sorting files by modification date

If you want to see files sorted by modification date in the subdirectories, you can paste below into the file for example mytest.sh, do it executable and run it with desireable directory as the argument
For example,
bash-2.05b$ ./mytest.sh /usr/local/etc
---
# cat > mytest.sh << EOF
#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin
FNAME=$1
find $FNAME -type f -exec ls -lt --full-time '{}' \; | awk '{print $6,$5,$9;}'
EOF
--
As a result you'll recieve date, size and pathname of all files from directory