LinuxQuestions.org
Review your favorite Linux distribution.
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 04-04-2004, 11:59 PM   #1
davidas
Member
 
Registered: Mar 2004
Distribution: Debian 'Sarge'
Posts: 168

Rep: Reputation: 30
Is this a valid command? find ./ -name bash.bashrc | cat


david:/etc# find ./ -name bash.bashrc
./bash.bashrc

However, when I do a

david:/etc# find ./ -name bash.bashrc | cat
./bash.bashrc

cat doesn't show the content of ./bash.bashrc

Is something wrong with my syntax?

Thanks!
 
Old 04-05-2004, 12:00 AM   #2
Kristijan
Member
 
Registered: Sep 2003
Location: Melbourne, Australia
Distribution: NetBSD 3.0.1, Slackware 10.1
Posts: 394

Rep: Reputation: 30
Replace | with &&
 
Old 04-05-2004, 12:07 AM   #3
phoenix
LQ Newbie
 
Registered: Jan 2003
Location: PA
Distribution: Gentoo
Posts: 27

Rep: Reputation: 15
You are basically telling it to do the same thing both times

find ./ -name bash.bashrc
says find all files in the current directory named bash.bashrc

find ./ -name bash.bashrc | cat
says find all files inthe current directory named bash.bashrc then output to the cat command instead of standard out

you need to use the -exec switch with find to execute a command with the output
something like this:

find ./ -name bash.bashrc -exec cat {} \ ;

hope this helps...
 
Old 04-05-2004, 06:04 AM   #4
davidas
Member
 
Registered: Mar 2004
Distribution: Debian 'Sarge'
Posts: 168

Original Poster
Rep: Reputation: 30
I think I have a misconception here. Doesn't commandA | commandB means the output from commandA will be used as input for commandB ?

aka rpm -qa | grep grub ?

Thanks guys, these are very constructive replies

Quote:
Originally posted by phoenix
You are basically telling it to do the same thing both times

find ./ -name bash.bashrc
says find all files in the current directory named bash.bashrc

find ./ -name bash.bashrc | cat
says find all files inthe current directory named bash.bashrc then output to the cat command instead of standard out

you need to use the -exec switch with find to execute a command with the output
something like this:

find ./ -name bash.bashrc -exec cat {} \ ;

hope this helps...
 
Old 04-05-2004, 09:11 AM   #5
ugge
Senior Member
 
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028

Rep: Reputation: 45
The cat command concatenates the File to standard out (stdout), or in your case it concatenates the standard input (stdin) to standard out. That why it doesn't really read the file but just prints to stdout what it get in on stdin.

That's why you will have to use the -exec action.
 
Old 04-05-2004, 09:30 AM   #6
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,675

Rep: Reputation: Disabled
If you want a laugh:

http://www.sektorn.mooo.com/era/unix/award.html

Else I don't understand. You are searching for bash.bashrc in your current directory (./), so it must be there to generate output anyhow?!?

Anyhow you can use ">" (I think) like

Code:
find ./ -name bash.bashrc > cat
 
Old 04-05-2004, 09:34 AM   #7
ugge
Senior Member
 
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028

Rep: Reputation: 45
That would only make you a file called cat in your current directory containing the output of the find command.
 
Old 04-06-2004, 01:36 AM   #8
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,675

Rep: Reputation: Disabled
Aha. Better?

Code:
cat < 'find ./ -name bash.bashrc'
 
Old 04-06-2004, 01:42 AM   #9
ugge
Senior Member
 
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028

Rep: Reputation: 45
If that is going to have any posability to work you will have to use back quotes (`)
Back quotes will be substituted with the output of the command. That would be exactly like the first posted command and we are back at square one.

Go with phoenix answer it works. Belive us or try.
 
Old 04-06-2004, 01:52 AM   #10
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,675

Rep: Reputation: Disabled
I think I used backticks on my keyboard (maybe the font shows them wrong). I don't dispute phoenix's way -- but mine has nine letters less (if I discerned the blank spaces correctly).

What I still don't understand is why he wants to do it that way. I mean since he is in ./ he could just have typed
Code:
cat bash.bashrc
and have done?!?
 
Old 04-06-2004, 02:07 AM   #11
ugge
Senior Member
 
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028

Rep: Reputation: 45
I stand corrected. Your solution works.
Question is Why? What makes the difference from piping the stdout to cat and redirecting the stdin???
 
Old 04-06-2004, 02:16 AM   #12
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 13.1 / 12.3_64-KDE, Ubuntu 14.04, Fedora 20, Mint 17, Chakra
Posts: 3,675

Rep: Reputation: Disabled
As I understand it it's just syntax . I mean the output from one program has to be kept in memory and handed to the next program in both instances. Perhaps one of the moderators / gurus can enlighten us further. Hello? Anybody listening?
 
  


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
trouble with find command in bash vrdhananjay Linux - Newbie 3 10-30-2004 11:37 PM
bash connot find the command Dunadan1821 Linux - Software 9 08-30-2004 08:04 AM
bash cant find format or mkfs command Dunadan1821 Linux - Software 3 08-12-2004 01:27 PM
same find command not working in bash script, quotes? QuakerOatz Linux - Software 1 07-14-2003 12:04 PM
linux command error message bash: /usr/bin/find: No such file or directory sundaram123 Linux - General 8 04-02-2002 07:18 AM


All times are GMT -5. The time now is 07:58 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration