File listing ditties

Here are some simple bash scripts to list files into a text files that can be used to catalog stuff. Most of the time I use the last one. 
[cce_bash]

filer=$(find . -mtime -1)
sizer=$(ls -lah $filer | awk ‘{ print $5″\t” $6″\t” $7″\t” $8″\t” $9″\t\n” }’)
echo $sizer

[/cce_bash]

or this one

[cce_bash]
ls -ghG –full-time | awk ‘{ print $1″\t” $3 “\t” $4 “\t” $7 $8 $9 $10 $11 $12 “\n” }’ > files.txt
cat files.txt
[/cce_bash]
The script above makes output as follows. The extra lines just made it easier for me to read. This one will output files with spaces in the name by removing the spaces (lumping the words together). If you don’t like that, just put the ” ” between $7 $8 $9 etc. above.

1
2
[john.zastrow@appsrv ~]$ cat files.txt
total
[john.zastrow@appsrv ~]$ cat files.txt
total
1
drwxr-xr-x.     4.0K    2011-03-24      Desktop
drwxr-xr-x.     4.0K    2011-03-24      Desktop
1
drwxr-xr-x.     4.0K    2011-03-24      Documents
drwxr-xr-x.     4.0K    2011-03-24      Documents
1
drwxr-xr-x.     4.0K    2011-03-24      Downloads
drwxr-xr-x.     4.0K    2011-03-24      Downloads
1
-rwxrwxrwx      126     2011-04-29      filer1.sh
-rwxrwxrwx      126     2011-04-29      filer1.sh
1
-rwxrwxrwx      158     2011-04-29      filer2.sh
-rwxrwxrwx      158     2011-04-29      filer2.sh
1
-rwxrwxrwx      123     2011-04-29      filer3.sh
-rwxrwxrwx      123     2011-04-29      filer3.sh
1
-rw-rw-r--      0       2011-04-29      files.txt
-rw-rw-r--      0       2011-04-29      files.txt
1
-rwxrwxrwx      73      2011-04-29      inter.sh
-rwxrwxrwx      73      2011-04-29      inter.sh

Then this script

 

?

[cce_bash]
#!/bin/sh
date > statfile.txt
echo -e “File_type \t Modified_date \t Change_date \t File_bytes \t File_name” >> statfile.txt
stat –printf “%F \t %y \t %z \t %s \t %N\n” * >> statfile.txt
cat statfile.txt

[/cce_bash]

 is just a little different and produces the following output. Notice that in both script I’m using tabs so these text files should come into a spreadsheet program nicely as below. Also notice the use of –printf so that I can embed the tabs right into stat’s output thereby more gracefully handling filenames with spaces in them (plus I quote them for good measure). A good use of this would be to combine find with it.