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 09-15-2009, 11:13 AM   #16
dwives
LQ Newbie
 
Registered: Sep 2009
Posts: 10

Rep: Reputation: 0

Yessir, saw the reply. Was just wanting to learn the why of the reason not to use ls. I used to be semi-proficient in linux, so I'm probably a dangerous mix of knowing too much and not having enough experience.

Also, tasteless bump of the USB boot post I put up this morning.
 
Old 09-15-2009, 11:29 AM   #17
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
@all: If I understand what you mean, how about my above command?
 
Old 09-15-2009, 11:38 AM   #18
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555
Quote:
Originally Posted by quanta View Post
@all: If I understand what you mean, how about my above command?
Basically: it's definitely quick, and if one doesn't mind all the errors/warnings produced, then I guess it would do. But IMHO it's not optimal:

Quote:
sh-4.0# grep -lir "Volkerding" /
grep: warning: /opt/kde3/lib64/qt3/mkspecs/default/linux-g++: recursive directory loop

grep: warning: /opt/kde3/lib64/qt3/mkspecs/linux-g++/linux-g++: recursive directory loop

grep: warning: /opt/kde3/lib64/qt3-3.3.8b/mkspecs/default/linux-g++: recursive directory loop

grep: warning: /opt/kde3/lib64/qt3-3.3.8b/mkspecs/linux-g++/linux-g++: recursive directory loop
grep: /drivers/Quatech-PCI-Serial/K96serqtpci: No such file or directory
grep: /lib/udev/devices/ppp: No such device or address
^C
sh-4.0#
Though I should mention: when you try to do things on files in /proc and /sys and sometimes /dev, weird results can occur whatever method is being used. I just re-tested my own method, and got an I/O Error from a file in /proc/

Luckily we have MANY ways to choose from, when doing stuff like this in Linux, but it looks wise to skip over /proc in this case.

Sasha

Last edited by GrapefruiTgirl; 09-15-2009 at 11:56 AM.
 
Old 09-15-2009, 03:04 PM   #19
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by pwc101 View Post
This will be quite slow for a large number of hits as you're launching a new instance of grep for every file you find; you can just put the grep into the find command using the + instead of \; termination, then grep will be given a large number of files instead of only a single file:
Code:
find /path/of/interest -type f -exec grep "my string" "{}" +
Just a thought.
Look at the newsgroup title. My method takes longer to execute, but it is easier for a newbie to understand and to modify.

Methods using "xargs" are often the source of endless threads in this discussion forum because its syntax is beyond the comprehension of Linux newcomers. To me, the point is not to overwhelm newbies with breathtakingly incomprehensible syntax, but to provide accessible, modifiable methods.

It's the "one-liner" disease, and it is a disease. One-liners are by definition a bad way to explain something. Should we make the computer happy, or should we try making the newbies happy?
 
Old 09-15-2009, 03:06 PM   #20
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by thomas2004ch View Post
I find your solution is a little bit too complicated.
That's because you haven't tried the alternatives yet, and discovered all the ingenious ways they have of failing.
 
Old 09-15-2009, 04:09 PM   #21
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by lutusp View Post
Look at the newsgroup title. My method takes longer to execute, but it is easier for a newbie to understand and to modify.
I would argue that having to learn the syntax of a loop is as difficult as learning to read a single command; both have a learning curve associated with them.
Quote:
Originally Posted by lutusp View Post
Methods using "xargs" are often the source of endless threads in this discussion forum because its syntax is beyond the comprehension of Linux newcomers.
This is partly why I didn't use xargs. Keeping it all in find makes it easier to understand, from my perspective, because there's no need to learn about pipes.
Quote:
Originally Posted by lutusp View Post
To me, the point is not to overwhelm newbies with breathtakingly incomprehensible syntax, but to provide accessible, modifiable methods.
Whilst that's obviously a laudable aim, there's also some mileage in showing them different approaches, and where some of the limitations of certain methods occur, and why.
Quote:
Originally Posted by lutusp View Post
It's the "one-liner" disease, and it is a disease. One-liners are by definition a bad way to explain something. Should we make the computer happy, or should we try making the newbies happy?
I find that when the computer's happy, I'm happy. There's nothing more frustrating than waiting for the computer to finish doing something.
 
Old 09-15-2009, 08:24 PM   #22
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555Reputation: 555
Originally Posted by lutusp:
To me, the point is not to overwhelm newbies with breathtakingly incomprehensible syntax, but to provide accessible, modifiable methods.

Indeed, that's a good thing to keep in mind; laudable. Luckily, at least as far as this particular thread goes, there's nothing "breathtakingly incomprehensible" about any of the methods suggested.

Cheers,
Sasha
 
Old 09-16-2009, 04:38 AM   #23
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by lutusp View Post
It's the "one-liner" disease, and it is a disease. One-liners are by definition a bad way to explain something. Should we make the computer happy, or should we try making the newbies happy?
And they are hard to debug whereas step-by-step code allows easy inspection of intermediate results.
 
Old 09-16-2009, 08:16 PM   #24
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,349

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Absolutely; this obsession with one-liners is a PITA if it ever makes it into production code.
 
  


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
grep string with space (2 word string) casperdaghost Linux - Newbie 7 08-24-2009 02:11 AM
read files from a folder and grep a string bhagirathi Programming 6 07-06-2009 06:27 AM
How to grep for a string in a file kaprasanna Linux - Newbie 3 01-06-2009 06:29 AM
grep the exact string only ZAMO Linux - General 11 08-28-2008 05:08 AM
how to grep only one string pr match gummimann Linux - General 3 11-06-2003 09:40 AM

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

All times are GMT -5. The time now is 11:30 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
Open Source Consulting | Domain Registration