LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-15-2008, 01:35 AM   #1
jianelisj
LQ Newbie
 
Registered: Mar 2008
Posts: 18

Rep: Reputation: 0
Store into a file the list of executable files of a system directory


How can i store into a file the list of executable files of a system directory?

My solution is:

if test -f $1 and test -x $1 then
echo $1
else
echo "message"
fi

int a file e.g. test

it runs correctly if i write test filename (only for 1 file),
but i need a solution for all the files of a system directory.

How can i recognize a system directory?

i would appreciate any help
 
Old 03-15-2008, 02:38 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
When you post code, please do so using [code] tags. This inproves readability to preserving whitespace and using a fixed width font.

You can iterate over files like this:
Code:
for thisfile in *; do
    if test -f "$thisfile" -a -x "$thisfile"; then
        echo "executable file:            $thisfile"
    else
        echo "not executable or not file: $thisfile"
    fi
done
You can modify the pattern * to examine only some sub-set of files in the directory, e.g.
Code:
for thisfile in *.txt; do
   ...
...to examine only files with a name ending in ".txt".

Last edited by matthewg42; 03-15-2008 at 02:40 AM.
 
Old 03-15-2008, 04:41 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
you can also use find for that .. do 'man find' and take a look at the examples for 'find . -perm'

here's an example statement to list the executable files in a directory:
Code:
find $dir -type f -perm /111 -maxdepth 1

Last edited by konsolebox; 03-15-2008 at 04:43 AM.
 
Old 03-17-2008, 01:26 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Start reading your training material, do your own homework.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Show only executable files of a system folder jianelisj Linux - Newbie 7 08-08-2013 10:26 AM
C++ List Files In Directory bendeco13 Programming 8 11-02-2010 01:08 PM
How to list only executable files seran Linux - General 3 06-08-2006 05:59 AM
how to list how many files in a directory? malaka56 Linux - Software 8 09-02-2005 06:37 AM
file extensions ? types ? executable files ?? abbasakhtar Linux - Newbie 13 10-06-2003 06:12 PM


All times are GMT -5. The time now is 05:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration