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?
2 Answers
find ~ -type f -executable
should work. Maybe add -exec ls -l {} \;
to get user and group.
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)
-
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
~/bin
folder?