0

I understand that it is a bad practice to keep files owned by oneself in one's home area which are executable, so I am in need of a script/tool which checks recursively through a given directory (in this case my home directory) and all of its sub-directories etc (should check hidden files and folders obviously too) and outputs the name and location of any files which are executable, it should also indicate the owner of the file. I am running Ubuntu GNOME 15.10 with GNOME 3.18, is something like this possible?

10
  • Why is it bad practice to keep executables you own in $HOME ? Should I get rid of my ~/bin folder?
    – wjandrea
    May 2, 2016 at 4:15
  • 1
    It's not a bad practice, really. Most power users do exactly the same thing: keep a ~/bin folder. Panda has his own reasons for it :) May 2, 2016 at 5:45
  • @wjandrea: I guess because people can execute them when they get access to your machine. But if you want to know more and the exact reason I suggest you ask Pilot6 as he's the one who originally said it.
    – user364819
    May 2, 2016 at 10:53
  • 1
    Ok, the general idea is that developers expect you to have their software installed in particular places, like /usr/bin . But it's not a bad practice, even from security point of view. If i get to your computer, I'm more concerned with system binaries and installing my own malware than whatever you have in your home. As for scripts, they're typically not expected to be in any specific folder, so ~/bin is OK. In fact , that's a better place for it, or in /opt, as i suggest on my answers that have link to GitHub May 2, 2016 at 13:15
  • 1
    @ParanoidPanda if they have access to root or your sudo account, they can do these things anyway to system binaries or scripts not in your home folder. In fact, that's a common practice May 2, 2016 at 13:40

2 Answers 2

3

find ~ -type f -executable should work. Maybe add -exec ls -l {} \; to get user and group.

1

find command is the most appropriate for this task, in combination with stat , you can see the owner of the file

find $HOME -type f -executable -printf "FILE:%p OWNER: "   -exec stat -c "%U" {} \;

Or purely with find printf:

find $HOME -executable -printf "FILE:%p OWNER:%u\n " 

And if you're adventurous enough, here's a pythonic solution:

import os

for root, dirs, files in os.walk( os.getcwd()  ):
    for name in files:
        file=os.path.join(root,name)
        owner_uid=os.stat(file).st_uid
        if os.access(file,os.X_OK):
           print(file,owner_uid)
1
  • What needed is -type f , because directories also have executable permissions set, otherwise - the system won't let you read directories May 1, 2016 at 21:20

You must log in to answer this question.