Find the answer to your Linux question:
Results 1 to 6 of 6
I'm writing a script that searches user's files for IP addresses, and I'm trying to find a way to display the owner of the file....
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2011
    Posts
    4

    Command that displays owner of a file?


    I'm writing a script that searches user's files for IP addresses, and I'm trying to find a way to display the owner of the file.

  2. #2
    Administrator jayd512's Avatar
    Join Date
    Feb 2008
    Location
    Kentucky
    Posts
    5,023
    Hello and Welcome!

    What about just using ls?
    Using either the -l or -o options will display the owner.
    Jay

    New users, read this first.
    New Member FAQ
    Registered Linux User #463940
    I do not respond to private messages asking for Linux help. Please keep it on the public boards.

  3. #3
    Just Joined!
    Join Date
    Sep 2011
    Posts
    4
    I was kind of hoping for a way to display
    Code:
     Owner of File: "owner"
    Without all of the other stuff that ls -l displays. Also, if I'm looking at a particular file with IP addresses, will ls still work, or will it just display everything in that particular directory?

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,380
    Something like this?
    Code:
    cd <DIRECTORY_WITH_THE_FILES>
    egrep -Hr '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}' * | cut -d ":" -f1 | sort | uniq | xargs -L 10 stat -c "%U %n"
    Note: %U needs a valid name in /etc/passwd. In doubt, use %u

    Note2: Yes, I know that the regex is not exact. Sue me
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    Sep 2011
    Posts
    4
    thanks for that. It looks a lot like the cut that I was working on, but just couldn't get right.

  6. #6
    Just Joined!
    Join Date
    Sep 2011
    Posts
    4
    here's the part of the script I need help on
    Code:
    hammer=/home
    dirs=$(ls $crank)
    oof=`echo ls -o | cut -c 14-`
    for user in "$crank"/*; do
             echo Username: "$oof"
             echo -e "\nPath: $user"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •