• Welcome to Valhalla Legends Archive.
 

Finding within files in Linux...

Started by iago, January 05, 2004, 12:48 PM

Previous topic - Next topic

iago

Quote from: cipher on January 06, 2004, 08:59 PM
heh, grep for DOS, didn't know that existed. too bad you can't just do like a ls -lR <dir> | grep <file>. bet there's no piping like that }=)

btw, if you have a working slocate db you can try a 'locate <file>' if it gives you an error about not having generated a database try an updatedb, if that too fails then let me know; i know that there is a way to force it to generate a new db, just can't remember off the top of my head.
I don't know where you got DOS from, I'm using linux.  And you can't pipe into grep because grep doexn't read from stdin, it reads from a parameter.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Adron

Quote from: cipher on January 06, 2004, 08:59 PM
heh, grep for DOS, didn't know that existed. too bad you can't just do like a ls -lR <dir> | grep <file>. bet there's no piping like that }=)

That's not a very good solution as it won't tell you in *what* directory it found the file. If you're looking for a file, your answer probably won't enlighten you very much at all. I suppose it might give you the answer if you just wonder whether you have a file or not, but finding out where it is would be a logical next step.

Try find <dir> -name <file> instead...

Kp

Quote from: iago on January 07, 2004, 05:52 AMI don't know where you got DOS from, I'm using linux.  And you can't pipe into grep because grep doexn't read from stdin, it reads from a parameter.

Well, Adron's version probably runs in a console window (as does the Windows port of grep that I use), and lots of people seem to get confused and think that a console window is 'DOS'. :)  You can do what he suggested and it would have a meaningful effect, though not a useful one as Adron pointed out.  If you don't tell grep what files to search, it searches stdin.  How else would you chain together a series of greps?
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

cipher

#18
Quote from: iago on January 07, 2004, 05:52 AM
Quote from: cipher on January 06, 2004, 08:59 PM
heh, grep for DOS, didn't know that existed. too bad you can't just do like a ls -lR <dir> | grep <file>. bet there's no piping like that }=)

btw, if you have a working slocate db you can try a 'locate <file>' if it gives you an error about not having generated a database try an updatedb, if that too fails then let me know; i know that there is a way to force it to generate a new db, just can't remember off the top of my head.
I don't know where you got DOS from, I'm using linux.  And you can't pipe into grep because grep doexn't read from stdin, it reads from a parameter.
When I said grep in DOS i was referring to what Adron had shown, which looked like a port of grep for command line DOS under some Windows * (gotta watch my ass here and be specific, or someone might try to correct me). Now maybe that's just how he has his PS1 variable set - that's a bit weird if so - and it's just made to look like DOS... but from what Kp has said, and since Adron didn't say anything, i'll just assume it was a DOS prompt.
Also, since when does grep not read from STDIN? This is new to me.
And yes, i realize my answer may not have been quite as functional -- iago was not entirely specific as to what exactly he wanted to do. If in fact you want to know the location of the file, and aren't just looking to see if it exists, then the find <dir> -name <file> would work (as Adron said), or just to show you that piping too would work, you could do find <dir> | grep <file> and that would better work for finding a pattern as the former would only match a file specifically called <file> while the latter would catch 'fsdfs<file>fdfdsf' if you wanted it to. edit: the find <dir> | grep <file> would return directories too, so if what you want are only "files" (directories are files too, but special kind of file) then 'find -type f' (for files) would give you what you want. A quick man find would show you the other "types" you can search for.
-cipher

iago

As far as I know, the find command works like this:
find [pattern] [switches]
one switch is -name "file name" [I can't really give anymore information since I'm in windows right now]

But I'm not talking at all about DOS, so if you mean in dos, it's pretty useless here.  As I said in the title, and probably in my first post, I'm using Linux here, not Windows or Dos.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


cipher

I don't think you are correctly reading my replies, or are at all taking the time to read them. I _know_ you aren't talking about DOS, and everything that I've referenced, command-wise, has been for a computer running Linux - assuming for the most part running bash as your shell. If you read the friggen first paragraph I wrote that I was referring to Adron's DOS-like command-prompt and not at all referring to what you were using. I'm sorry if I have not been clear, but I don't think I can make it any clearer.

Adron

I'm using Windows 2000:

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corporation

C:\Documents and Settings\Adron>


And the -name switch for find actually takes wildcards, so if what you want is "*file*", just write that...