Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all, Just getting into Linux after a job move and have been asked to produce a GREP string that will list all the files owned by the root user ...
  1. #1
    Just Joined!
    Join Date
    Nov 2010
    Posts
    1

    Question noob - grep help

    Hi all,

    Just getting into Linux after a job move and have been asked to produce a GREP string that will list all the files owned by the root user and for this list to be stored in a file called “root_owned_files”.

    I understand the basics of grep but have no idea how to answer this

    I would appreciate any help given

    Thanks for your time

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,100
    hmm,
    grep works *in* files or stdin.
    Not directly on files.

    My suggestion would be "find".
    Code:
    man find
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Sep 2010
    Location
    Dhaka, Bangladesh
    Posts
    29
    For example, if the file is /home/username/root_owned_files, then this could work

    ls -l LOCATION | grep root > /home/username/root_owned_files

    Right now, I couldn't figure out a way to locate all files in entire hard drive.

  4. #4
    Linux Enthusiast meton_magis's Avatar
    Join Date
    Oct 2006
    Location
    arizona
    Posts
    665
    many ways to do this, depending on situation. the suggestion by sarmed will work, but it's not exact. That method will return any line from ls -l output that has the string "root" in it. including if root is the group owner (not user owner) or if the filename contains root. also, if you have a user named Sroot (even if it is a funny name) it won't work.

    the suggestion of using find is probably your best bet. The -user switch will probably be the place to start, but -uid will work too (root's uid is 0 )
    New to the internet, technical forums, or the hacker / open source community??
    Read this to learn good posting habits http://www.catb.org/~esr/faqs/smart-questions.html

    RHCE for RHEL version 5
    RHCT for RHEL version 4

  5. #5
    Just Joined!
    Join Date
    Sep 2010
    Location
    Dhaka, Bangladesh
    Posts
    29
    ls -n could work too, but it not exact either

    #ls --help | grep user
    -n, --numeric-uid-gid like -l, but list numeric user and group IDs


    the command could be ls -n | grep 0 >> /username/root_owned_files

Posting Permissions

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