Re: [SLUG] recursive tree log grep ?
At Tue, 24 May 2005 09:36:56 +0800 (WST), jam wrote: I love vi, but do not use the vi-command-edit option of bash. My mate who does asked me how to do this with the standard (emacs) shell edit functions: /someword # look for a history event starting 'someword' up # previous history event starting 'someword' cr # execute THAT command The bash/readline function you're looking for is history-search-backward, which is not bound to any keys by default. I'd bind it to M-p (if I was using bash) to make it similar to the old tcsh behaviour (and its better than the default M-p function - non-incremental-reverse-search-history) Put this in ~/.inputrc to have it work for all readline-using programs: \M-p: history-search-backward or run this from your .bashrc if you only want to use it in bash: bind '\M-p: history-search-backward' For reference, zsh users would put this in .zshrc to get the same thing: bindkey -m # get a meta key bindkey '\M-p' history-beginning-search-backward -- - Gus -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
Glen Turner wrote: In a real-world script you might also say ${dir} rather than $dir to allow nasty filenames. Does ${dir} buy you any more safety than $dir ?? I thought not. Also, a side question: how come 'events' and exclamation marks cause havoc in bash, in seemingly innocent situations: $ echo This is fun! -bash: !: event not found cheers rickw -- _ Rick Welykochy || Praxis Services People who enjoy eating sausage and obey the law should not watch either being made. -- Otto von Bismarck -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
On Mon, 23 May 2005 18:56:56 +1000, Rick Welykochy uttered $ echo This is fun! -bash: !: event not found Bash uses ! as a shell short-cut character. For example: !! Execute previous command !n Execute nth previous command !string Execute previous command starting with string !?string? Execute previous command containing string Cheers, -- Steve C offers you enough rope to hang yourself. C++ offers a fully equipped firing squad, a last cigarette and a blindfold. - Erik de Castro Lopo -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
Steve Kowalik wrote: On Mon, 23 May 2005 18:56:56 +1000, Rick Welykochy uttered $ echo This is fun! -bash: !: event not found Bash uses ! as a shell short-cut character. For example: !! Execute previous command !n Execute nth previous command !string Execute previous command starting with string !?string? Execute previous command containing string I've always wondered how you get a list of .bash-history so that you know the value of n. Cheers, -- Howard. LANNet Computing Associates - Your Linux people http://lannet.com.au -- When you just want a system that works, you choose Linux; When you want a system that just works, you choose Microsoft. -- Flatter government, not fatter government; Get rid of the Australian states. begin:vcard fn:Howard Lowndes n:Lowndes;Howard org:LANNet Computing Associates adr:;;PO Box 1174;Lavington;NSW;2641;Australia email;internet:howard [AT] lowndes [DOT] name tel;work:02 6040 0222 tel;fax:02 6040 0222 tel;cell:0419 464 430 note:If you want to phone me, you will need to ensure that your phone presents Caller ID. x-mozilla-html:FALSE url:http://www.lannet.com.au version:2.1 end:vcard -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
Hi Howard, Run help for a list of shell internals to get help on... $ help history history: history [-c] [-d offset] [n] or history -awrn [filename] or history -ps arg [arg...] Display the history list with line numbers. Lines listed with with a `*' have been modified. Argument of N says to list only the last N lines. The `-c' option causes the history list to be cleared by deleting all of the entries. The `-d' option deletes the history entry at offset OFFSET. The `-w' option writes out the current history to the history file; `-r' means to read the file and append the contents to the history list instead. `-a' means to append history lines from this session to the history file. Argument `-n' means to read all history lines not already read from the history file and append them to the history list. If FILENAME is given, then that is used as the history file else if $HISTFILE has a value, that is used, else ~/.bash_history. If the -s option is supplied, the non-option ARGs are appended to the history list as a single entry. The -p option means to perform history expansion on each ARG and display the result, without storing anything in the history list. Cheers, - Simon On Tue, 24 May 2005, Howard Lowndes wrote: Steve Kowalik wrote: On Mon, 23 May 2005 18:56:56 +1000, Rick Welykochy uttered $ echo This is fun! -bash: !: event not found Bash uses ! as a shell short-cut character. For example: !! Execute previous command !n Execute nth previous command !string Execute previous command starting with string !?string? Execute previous command containing string I've always wondered how you get a list of .bash-history so that you know the value of n. Cheers, -- Howard. LANNet Computing Associates - Your Linux people http://lannet.com.au -- When you just want a system that works, you choose Linux; When you want a system that just works, you choose Microsoft. -- Flatter government, not fatter government; Get rid of the Australian states. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
How simple - tks. :) Simon Bowden wrote: Hi Howard, Run help for a list of shell internals to get help on... $ help history history: history [-c] [-d offset] [n] or history -awrn [filename] or history -ps arg [arg...] Display the history list with line numbers. Lines listed with with a `*' have been modified. Argument of N says to list only the last N lines. The `-c' option causes the history list to be cleared by deleting all of the entries. The `-d' option deletes the history entry at offset OFFSET. The `-w' option writes out the current history to the history file; `-r' means to read the file and append the contents to the history list instead. `-a' means to append history lines from this session to the history file. Argument `-n' means to read all history lines not already read from the history file and append them to the history list. If FILENAME is given, then that is used as the history file else if $HISTFILE has a value, that is used, else ~/.bash_history. If the -s option is supplied, the non-option ARGs are appended to the history list as a single entry. The -p option means to perform history expansion on each ARG and display the result, without storing anything in the history list. Cheers, - Simon On Tue, 24 May 2005, Howard Lowndes wrote: Steve Kowalik wrote: On Mon, 23 May 2005 18:56:56 +1000, Rick Welykochy uttered $ echo This is fun! -bash: !: event not found Bash uses ! as a shell short-cut character. For example: !! Execute previous command !n Execute nth previous command !string Execute previous command starting with string !?string? Execute previous command containing string I've always wondered how you get a list of .bash-history so that you know the value of n. Cheers, -- Howard. LANNet Computing Associates - Your Linux people http://lannet.com.au -- When you just want a system that works, you choose Linux; When you want a system that just works, you choose Microsoft. -- Flatter government, not fatter government; Get rid of the Australian states. -- Howard. LANNet Computing Associates - Your Linux people http://lannet.com.au -- When you just want a system that works, you choose Linux; When you want a system that just works, you choose Microsoft. -- Flatter government, not fatter government; Get rid of the Australian states. begin:vcard fn:Howard Lowndes n:Lowndes;Howard org:LANNet Computing Associates adr:;;PO Box 1174;Lavington;NSW;2641;Australia email;internet:howard [AT] lowndes [DOT] name tel;work:02 6040 0222 tel;fax:02 6040 0222 tel;cell:0419 464 430 note:If you want to phone me, you will need to ensure that your phone presents Caller ID. x-mozilla-html:FALSE url:http://www.lannet.com.au version:2.1 end:vcard -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
On Tue, 24 May 2005 09:19:42 +1000, Howard Lowndes uttered I've always wondered how you get a list of .bash-history so that you know the value of n. Run 'history'. Cheers, -- Steve If it (dieting) was like a real time strategy game, I'd have loaded a save game from ten years ago. - Greg, Columbia Internet -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
Hi Run help for a list of shell internals to get help on... $ help history history: history [-c] [-d offset] [n] or history -awrn [filename] or history -ps arg [arg...] Display the history list with line numbers. Lines listed with with a `*' have been modified. Argument of N says to list only the last N lines. The `-c' option causes the history list to be cleared by deleting all of the entries. The `-d' option deletes the history entry at offset OFFSET. The `-w' option writes out the current history to the history file; `-r' means to read the file and append the contents to the history list instead. `-a' means to append history lines from this session to the history file. Argument `-n' means to read all history lines not already read from the history file and append them to the history list. If FILENAME is given, then that is used as the history file else if $HISTFILE has a value, that is used, else ~/.bash_history. If the -s option is supplied, the non-option ARGs are appended to the history list as a single entry. The -p option means to perform history expansion on each ARG and display the result, without storing anything in the history list. I love vi, but do not use the vi-command-edit option of bash. My mate who does asked me how to do this with the standard (emacs) shell edit functions: /someword # look for a history event starting 'someword' up# previous history event starting 'someword' cr# execute THAT command $ history | grep someword !2-whatever # works, but is cumbersome Any suggestion on how to preview a qualified list of history, and execute one of them without using the vi options (+o vi). Yea, I RFM'd the 100 odd pages, and thank heavens for info2html, IMHO the whole info system is diabolical. James -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
Rick Welykochy wrote: Does ${dir} buy you any more safety than $dir ?? I thought not. Depends if you are going to follow it with other characters. I was obviously trying to forestall more questions. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
RE: [SLUG] recursive tree log grep ?
The default editor mode for bash is Emacs. Even though I am also a vi editor user, I tend to leave bash at default. (I think your /someword is actual the vi command) To search backwards through history in standard bash, type Ctrl-r and then the search string. Repeated ctrl-r looks further back. BTW http://www.faqs.org/docs/bashman/bashref_95.html references other search functions. But some of these are broken (at least in Cygwin running bash). I imagine some like Ctrl-s are swallowed by the tty (Ctrl-s in terminals is normally XOFF - stops scrolling). (I found this http://lists.naos.co.nz/pipermail/wellylug/2004-September.txt - search for forward-search-history - gives a similar conclusion re Ctrl-s) Martin Visser, CISSP Network and Security Consultant Consulting Integration Technology Solutions Group - HP Services 410 Concord Road Rhodes NSW 2138 Australia Mobile: +61-411-254-513 Fax: +61-2-9022-1800 E-mail: martin.visserAThp.com This email (including any attachments) is intended only for the use of the individual or entity named above and may contain information that is confidential, proprietary or privileged. If you are not the intended recipient, please notify HP immediately by return email and then delete the email, destroy any printed copy and do not disclose or use the information in it. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Tuesday, 24 May 2005 11:37 AM To: slug@slug.org.au Subject: Re: [SLUG] recursive tree log grep ? Hi Run help for a list of shell internals to get help on... $ help history history: history [-c] [-d offset] [n] or history -awrn [filename] or history -ps arg [arg...] Display the history list with line numbers. Lines listed with with a `*' have been modified. Argument of N says to list only the last N lines. The `-c' option causes the history list to be cleared by deleting all of the entries. The `-d' option deletes the history entry at offset OFFSET. The `-w' option writes out the current history to the history file; `-r' means to read the file and append the contents to the history list instead. `-a' means to append history lines from this session to the history file. Argument `-n' means to read all history lines not already read from the history file and append them to the history list. If FILENAME is given, then that is used as the history file else if $HISTFILE has a value, that is used, else ~/.bash_history. If the -s option is supplied, the non-option ARGs are appended to the history list as a single entry. The -p option means to perform history expansion on each ARG and display the result, without storing anything in the history list. I love vi, but do not use the vi-command-edit option of bash. My mate who does asked me how to do this with the standard (emacs) shell edit functions: /someword # look for a history event starting 'someword' up# previous history event starting 'someword' cr# execute THAT command $ history | grep someword !2-whatever # works, but is cumbersome Any suggestion on how to preview a qualified list of history, and execute one of them without using the vi options (+o vi). Yea, I RFM'd the 100 odd pages, and thank heavens for info2html, IMHO the whole info system is diabolical. James -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
for DIR in `ls -d /home/*` do grep -R a-string $DIR/logs/ done James Fyi, you can do this with the ls. for dir in /home/* do if [ -d $dir ] then ... fi done In a real-world script you might also say ${dir} rather than $dir to allow nasty filenames. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
[SLUG] recursive tree log grep ?
I have tree like: /home/domain.tld/logs/ /home/domain2.tld/logs/ ... how do i run a grep across all logs, as in 'grep a-string /home/*/logs/*' -- Voytek -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
On Sat, May 21, 2005 at 11:12:22PM +1000, Voytek Eymont wrote: I have tree like: /home/domain.tld/logs/ /home/domain2.tld/logs/ ... how do i run a grep across all logs, as in 'grep a-string /home/*/logs/*' If the logs are all immediately in the relevant logs directory, what you've typed in your question is a good start. If the logs appear at different directory depths, then maybe you need find and xargs. Say something like find /home/*.*/logs -type f | xargs grep a-string -- Christopher Vance -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
On Sat, 21 May 2005 11:12 pm, Voytek Eymont wrote: I have tree like: /home/domain.tld/logs/ /home/domain2.tld/logs/ ... how do i run a grep across all logs, as in 'grep a-string /home/*/logs/*' man grep -R, -r, --recursive Read all files under each directory, recursively; this is equivalent to the -d recurse option. Makes sense when you think that a lot of Gnu tools use either -r or -R for recursive modifiers :) eg, for DIR in `ls -d /home/*` do grep -R a-string $DIR done Note the use of a for ; do ; done loop - this is necessary because you've used two wild cards in your original example. Using the loops breaks the two while loops up. Read the man page for grep. James -- Writing software is more fun than working. pgpaiwHTOsrrO.pgp Description: PGP signature -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
On Sat, 21 May 2005 11:20 pm, James Gray wrote: On Sat, 21 May 2005 11:12 pm, Voytek Eymont wrote: I have tree like: /home/domain.tld/logs/ /home/domain2.tld/logs/ ... how do i run a grep across all logs, as in 'grep a-string /home/*/logs/*' man grep -R, -r, --recursive Read all files under each directory, recursively; this is equivalent to the -d recurse option. Makes sense when you think that a lot of Gnu tools use either -r or -R for recursive modifiers :) eg, for DIR in `ls -d /home/*` do grep -R a-string $DIR done Oops. That script should read: for DIR in `ls -d /home/*` do grep -R a-string $DIR/logs/ done James -- The chicken that clucks the loudest is the one most likely to show up at the steam fitters' picnic. -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
Re: [SLUG] recursive tree log grep ?
quote who=Christopher JS Vance On Sat, May 21, 2005 at 11:12:22PM +1000, Voytek Eymont wrote: how do i run a grep across all logs, as in 'grep a-string /home/*/logs/*' If the logs are all immediately in the relevant logs directory, what you've typed in your question is a good start. If the logs appear at different directory depths, then maybe you need find and xargs. Say something like find /home/*.*/logs -type f | xargs grep a-string thanks, Christopher yes, they are all same depth, but., my string failed with: # grep elite /home/*/logs/* bash: /bin/grep: Argument list too long yours seems to work, though, thanks -- Voytek -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html