15

How would I go about discovering all of the files created by a particular user and display them to the screen?

I've started a script that prompts the current user to enter the username of whom they wish to view all the files of. I've thought about using an if statement considering I'd like to include error checking.

echo -e "Option 11: Display all the Files a Particular User Has Created\n\n"
echo -e "Enter Username below\n"
read username
  • 6
    find has a -user option for searching for files owned by a particular user. Not sure how you would be able to determine who created a file beyond that, though. Ownership can change so I don't know if that's what you're really wanting. – Bratchley May 6 '15 at 3:27
  • 2
    The only way I see to perform that is by having filesystem audit in place. – BitsOfNix May 6 '15 at 10:09
21

You cannot do that on the usual Linux filesystems, as it doesn't keep track of the creator of the file, only of the owner of the file. The creator and owner are usually, but not necessarily the same.

If you want to find the owner of the file, you can, as Bratchley indicated, use

find / -type f -user user_name

to find those files and display the names.

To display the the files you would need some program that can show the content for any file type you might find that way. If you have such a show_file utility that takes a single file_name as argument, you can do:

find / -type f -user user_name -exec show_file {} \;
0

Use find:

find / -type f -user “<SHORTUSERNAME>" -print 2>/dev/null

So, in your script:

echo “Enter Username:”;  
while read -e;do find / -type f -user $REPLY -print 2>/dev/null;done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.