Using the grep command display, all files not owned by you in your home directory?

  • 1
    Probably you rather want to use find. I suggest you have a look at the man page. – Philippos Aug 5 '17 at 4:08
  • is that possible with grep? i am not that good , i tried but didn't get any! – Pavan Kumar Munnam Aug 5 '17 at 4:09
  • stat --format="%n:%F:%U" ~/* ~/.??* | grep -v ':username$' where username is your login id. Play with the stat options and possibly pipe through sed and/or awk for cleaner/fancier output. – Deathgrip Aug 5 '17 at 4:19

grep is not the best tool for this job. Use find instead. For example, find combined with the id -u command (which outputs your numeric uid):

find ~/ ! -uid "$(id -u)"

That displays all files in your home directory (and all subdirectories) which are not owned by you.

If you want to restrict it to just your home directory (no subdirectories):

find ~/ -maxdepth 1 ! -uid "$(id -u)"

if you want more details on the files:

find ~/ -maxdepth 1 ! -uid "$(id -u)" -ls


find ~/ -maxdepth 1 ! -uid "$(id -u)" -exec ls -ld {} +

(the -d option is used here with ls to prevent it from displaying the contents of any subdirectories that aren't owned by you)

| improve this answer | |

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