

InterviewSolution
Saved Bookmarks
1. |
Solve : Script to Check File Ownership? |
Answer» I want to see who owns more files me or root? I do not want to include directories in my search. I want it to output two lines...root (# of files) myusername (# of Files). What command tells who owns a file? and where is a good place to start? What command tells who owns a file? and where is a good place to start?man find.I did that I found i have to do something like Code: [SELECT] find / -name -root I do not know how to count the entries and start from root I think find / does that. I am not sure?i meant find -user To determine how many files there are in the current directory, put in ls -1 | wc -l. To accomplish what I think you want, play around with this one line command which you can modify & turn into a script. ls -lR|grep -v ^d|grep YOURUSERNAME|wc -l NOTES: ls -lR (that's an "L") cap. R for recursive grep -v ^d will exclude directories grep YOURUSERNAME includes all files with your username wc -l (that's an "L") will count each line & DISPLAY the count.Quote from: BKDC on March 27, 2009, 03:22:15 PM ls -lR|grep -v ^d|grep YOURUSERNAME|wc -lthe above method may not be accurate as you might have owner as someone other than root, and the GROUP is root. Code: [Select]ls -lR|awk '/^d/&&$3=="root"{s+=1}END{print s}' |
|