LinuxQuestions.org
Visit Jeremy's Blog.
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-08-2004, 10:15 AM   #1
teeno
Member
 
Registered: Jul 2001
Posts: 72

Rep: Reputation: 15
Filer out binaries


Hi All,

This is probably the easiest question every. But here goes...

If the I have a directory the contains .c .o and binaries how do I filter out the .c .o files so that I can see only the binaries (they have on extension)

I can do:
Code:
ls *.c
To see just the .c files and the same to get just the .o files or even .? to get both the .c and .o

I also need to copy just the binaries to a different directory. How can I do this using the cp command?

The DOS commands would be:
Code:
dir *.exe
copy *.exe c:\temp
Thank you,

Pete
 
Old 03-08-2004, 10:18 AM   #2
gregaryh
Member
 
Registered: Jan 2004
Location: Utah USA
Distribution: SuSE Pro 9.0
Posts: 43

Rep: Reputation: 15
Same goes for Linux:

cp *.c /new/dir
 
Old 03-08-2004, 10:34 AM   #3
teeno
Member
 
Registered: Jul 2001
Posts: 72

Original Poster
Rep: Reputation: 15
Yes but the binaries don't have an extension.

eg.

file.c
file.o
file (no extension)
 
Old 03-09-2004, 04:34 AM   #4
teeno
Member
 
Registered: Jul 2001
Posts: 72

Original Poster
Rep: Reputation: 15
Should I conclude that this can't be done?
 
Old 03-09-2004, 05:09 AM   #5
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
Code:
for file in *
do
	if [ -x "$file" ]
	then
		echo "$file is executable"
	fi
done
You could replace the echo with whatever you want - like a move command:
Code:
for file in *
do
	if [ -x "$file" ]
	then
		mv "$file" ~/tmp
	fi
done
To use this on the command line (without putting it in a script) you would have to use semicolons to break the lines: for file in *; do if [ -x "$file" ]; then echo "$file is executable"; fi; done

This requires the executables to be executable by the user the script runs as, since that's what the -x bash test relies on.


Håkan
 
Old 03-09-2004, 05:11 AM   #6
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Rather than trying to mess with the names, and going on the principle that they're executable and nothing else but directories are, this might work. No guarantees, but I tested it briefly and it seemed okay. Though once a couple of my files disappeared - think it was just a typo when I changed the destination.

Code:
for f in `ls .`; do if [ -x $f -a \! -d $f ]; then mv $f /target_dir/; fi; done
Gotta be an easier way that I'm just going braindead on. But there are strange limitations in 'ls' and the 'mv', 'cp', etc. commands.
 
Old 03-09-2004, 05:12 AM   #7
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
I beat ya to it but you beat me on the directories.
I really should have thought of that.


Håkan
 
Old 03-09-2004, 05:15 AM   #8
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
Yeah - I'm just relieved to see a similar approach. Seems like there ought to be a more direct way.
 
Old 03-09-2004, 05:15 AM   #9
teeno
Member
 
Registered: Jul 2001
Posts: 72

Original Poster
Rep: Reputation: 15
Ok. Thanks for your help.

I think I will just copy all the files and delete the .c and .o files using rm *.c


Thanks
Peter
 
  


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
Debian, ROX-filer and what else? BaptismOfFire Linux - Software 2 06-14-2005 03:18 PM
Rox-filer bug? iwen Slackware 5 04-15-2005 03:06 AM
Filer recomedations gianh Linux - General 1 02-21-2004 10:09 PM
Starting rox filer Abe_the_Man Linux - Software 1 12-28-2003 09:23 PM
rox filer m4rqs Linux - Software 1 08-27-2002 08:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:13 PM.

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
Open Source Consulting | Domain Registration