3

I have got the directory called Test and a few directories inside it. Both Test and the directories inside it have executable files. I'd like to print them with ls. I'd use this command.

ls -l `find Test/ -perm /u=x,g=x,o=x -type f`

Is this a good/right/quick command or not?

My solution is:

find Test/ -executable -type f -exec ls -l {} \;

and got the same result as warl0ck and pradeepchhetri offered.

  • You might want to check my updates ... – daisy Mar 31 '13 at 10:19
  • 2
    try find ... -exec -ls -l {} \+ instead of \; - doing that will cause only one ls command to be generated with multiple filename args, similar to how xargs works. read the find man page and search for -exec for details. – cas Mar 31 '13 at 10:23
8

Not really, you can integrate the ls command with find,

find Test/ -type f -perm /u=x,g=x,o=x -exec ls -l {} \;

UPDATE

Actually -executable is not an equivalent of -perm /u=x,g=x,o=x. You might have files that is executable only by the group or others, which will not be displayed.

So, depends on your purpose, if you want files executable only by you, that's okay to use -executable.

  • thanks. After I have gotten over 15 reputation, I'll vote up. – Maksim Dmitriev Mar 31 '13 at 10:05
4

There is no need to use -exec, as find comes with a -ls flag.

$ find Test/ -perm /u=x,g=x,o=x -type f -ls

From the man page:

-ls True; list current file in ls -dils format on standard output. The block counts are of 1K blocks, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used. See the UNUSUAL FILENAMES section for information about how unusual characters in filenames are handled.

3

You should use -exec argument of find command.

$ find Test/ -perm /u=x,g=x,o=x -type f -exec ls -l {} \;
  • thanks. I'll vote up your answer later. Now I don't have 15 reputation. – Maksim Dmitriev Mar 31 '13 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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