Suggestions on finding file sizes in user home folders.
I am looking for a smart way to run a script to find files in users home folders larger than a specific file size.
Should I do something like find /homes/users/ -size +100k >> /auditing/homefoldersize.txt or is there any easier way to seperate per user in the text file?
IE: username1
/home/username1/bigfile.pkg etc etc etc. Keep listing all the files for that user and then list the next user with a header...
IE:
Username1
/home/username1/files
/home/username1/filesagain
Username 2
/home/username2/files.pkg
/home/username2/filesagain.pkg
Etc Etc. You get the idea.
Thanks!
Should I do something like find /homes/users/ -size +100k >> /auditing/homefoldersize.txt or is there any easier way to seperate per user in the text file?
IE: username1
/home/username1/bigfile.pkg etc etc etc. Keep listing all the files for that user and then list the next user with a header...
IE:
Username1
/home/username1/files
/home/username1/filesagain
Username 2
/home/username2/files.pkg
/home/username2/filesagain.pkg
Etc Etc. You get the idea.
Thanks!
Comments
-
TechJunky Member Posts: 881Also, the problem with this method is the file never gets overwritten, the new information would be appended to this file if you ran the script again.
I am looking to put this in a weekly cronjob. -
dynamik Banned Posts: 12,312 ■■■■■■■■■□
#!/bin/bash #To TechJunky from Dynamik @ TE ;) echo "=====Large file list=====" > /auditing/homefoldersize.txt grep "/home" /etc/passwd | awk -F: '{ print $1 }' | while read user do echo "###$user###" >> /auditing/homefoldersize.txt find /home/$user -size +100k >> /auditing/homefoldersize.txt done
>> will append data to a file while > will overwrite the file. -
liven Member Posts: 918dynamik wrote:
#!/bin/bash #To TechJunky from Dynamik @ TE ;) echo "=====Large file list=====" > /auditing/homefoldersize.txt grep "/home" /etc/passwd | awk -F: '{ print $1 }' | while read user do echo "###$user###" >> /auditing/homefoldersize.txt find /home/$user -size +100k >> /auditing/homefoldersize.txt done
>> will append data to a file while > will overwrite the file.
Very nice.encrypt the encryption, never mind my brain hurts. -
Grynder Member Posts: 106Very nice dynamik. I've always been scared of awk so only learned the minimum
-
dynamik Banned Posts: 12,312 ■■■■■■■■■□I've confessed this to several others privately, I'm a real Linux noob. You'll get that awk line by simply entering:
awk --help
I stumbled across it while googling the best way to enumerate users on a Linux box. That tiny script sadly took me over an hour. I felt like my Linux knowledge was getting a bit rusty (since I never work with it), so I decided to screw around with this to see if I could come up with a solution. -
liven Member Posts: 918dynamik wrote:I've confessed this to several others privately, I'm a real Linux noob. You'll get that awk line by simply entering:
awk --help
I stumbled across it while googling the best way to enumerate users on a Linux box. That tiny script sadly took me over an hour. I felt like my Linux knowledge was getting a bit rusty (since I never work with it), so I decided to screw around with this to see if I could come up with a solution.
sed and awk are two of the coolest command line scripting tools you can get (IMO).
And for most of us that use *NIX everyday we still get rusty with these tools. The bottom line is once you understand what these tools can do you will always be able to use them, you will never forget. Plus even if it takes a day to write the script, but you use it for months or years even, you have saved LOTS of time.
I have written many scripts that are less than 100 lines that took a week or two to get working perfectly. But then they would run every day, or sometimes multiple times a day. The work they would accomplish would saves so much time, and is usually WAY more accurate than can be done by hand.
Finally, google is all of ours best friend. So often when I am coding/scripting i get stuck. I start googling for clues or answers and bingo I am back off and running. Sure I wish I could just puke out shell and perl scripts with out even having to think about it. But that just doesn't happen for me. And it probably never will!encrypt the encryption, never mind my brain hurts.