LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Is this a valid command? find ./ -name bash.bashrc | cat (https://www.linuxquestions.org/questions/linux-newbie-8/is-this-a-valid-command-find-name-bash-bashrc-%7C-cat-166301/)

davidas 04-04-2004 11:59 PM

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!

Kristijan 04-05-2004 12:00 AM

Replace | with &&

phoenix 04-05-2004 12:07 AM

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...

davidas 04-05-2004 06:04 AM

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...


ugge 04-05-2004 09:11 AM

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.

JZL240I-U 04-05-2004 09:30 AM

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

ugge 04-05-2004 09:34 AM

That would only make you a file called cat in your current directory containing the output of the find command.

JZL240I-U 04-06-2004 01:36 AM

Aha. Better?

Code:

cat < 'find ./ -name bash.bashrc'
:)

ugge 04-06-2004 01:42 AM

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.

JZL240I-U 04-06-2004 01:52 AM

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 :D (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?!?

ugge 04-06-2004 02:07 AM

I stand corrected. Your solution works.
Question is Why? What makes the difference from piping the stdout to cat and redirecting the stdin???

JZL240I-U 04-06-2004 02:16 AM

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? :D


All times are GMT -5. The time now is 04:47 AM.