l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
April 21: Google Glass
Next Installfest:
TBD
Latest News:
Mar. 18: Google Glass at LUGOD's April meeting
Page last updated:
2002 May 29 14:34

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] quick, stupid bash question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] quick, stupid bash question



On Wed, May 29, 2002 at 11:29:29AM -0700, Peter Jay Salzman wrote:
> begin nbs <nbs@sonic.net> 
> >      strace lsof 2>&1 1> /dev/null | grep
>  
> ok, haven't tried this, but this looks to me like:
> 
> put stderr into stdout
> redirect stdout (and therefore stderr) into /dev/null
> pipe stdout (which should be null) to grep.

  The order of operation of file operators is right to left.  

  So the first operation "| grep" spawns a copy of grep on the 
stdout of a future output of a new pipe.  The second "1> /dev/null" 
takes stdout and throws it away.  The third "2>&1" takes stderr and 
redirects it to stdout.


  The command line you are looking for if you want stderr grepped
and stdout to still be displayed is some variant of this:

 ( strace ls -R / 2>&1 1>&3 | grep open; ) 3>&1


(which will show you each open call and the output that ls prints
after each, alternating... sample output below, kinda cool).

  here is a breakdown of the command-line above in order of operation...
=========
"( ... ) 3>&1"

  open a file descriptor 3 and attach it to my current stdout.

"( ... )"

  run the following in a subshell

"... | ..."

  run the thing on the left and direct it's stdout into the thing on the
  right.

"grep open"

  look for the word "open" in my stdin.

"1>&3"

  redirect stdout to file descriptor 3.

"2>&1"

  redirect stderr to stdout.
  
"strace ls -R /"

  strace the output of "ls -R /"
=========


  Note that the sample command above is just a sample, if you really
wanted all the times strace detected an open call then give strace the 
option "-e open" ... which is much better.

sample output from the new command:
=========
msimons@star:~/debian$ ( strace ls -R / 2>&1 1>&3 | grep open; ) 3>&1
open("/etc/ld.so.preload", O_RDONLY)    = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 4
open("/lib/librt.so.1", O_RDONLY)       = 4
open("/lib/libc.so.6", O_RDONLY)        = 4
open("/lib/libpthread.so.0", O_RDONLY)  = 4
open("/dev/null", O_RDONLY|O_NONBLOCK|O_DIRECTORY) = -1 ENOTDIR (Not a directory)
open("/", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 4
open("/etc/mtab", O_RDONLY)             = 4
open("/proc/meminfo", O_RDONLY)         = 4
/:
bin    cdrom   etc     ibm2    lost+found  proc  share	tmp  vmlinuz
boot   cdrom0  floppy  initrd  mnt	   root  test	usr  vmlinuz.old
brick  dev     home    lib     opt	   sbin  thor	var

open("/bin", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 4
/bin:
arch   dd	      fuser	ls	netstat    sed	      true	  zforce
ash    df	      grep	lspci	pidof	   setserial  umount	  zgrep
bash   dir	      gunzip	mkdir	ping	   sh	      uname	  zless
cat    dmesg	      gzexe	mknod	ps	   sleep      uncompress  zmore
chgrp  dnsdomainname  gzip	mktemp	pwd	   stty       vdir	  znew
chmod  echo	      hostname	more	rbash	   su	      zcat
chown  ed	      kill	mount	readlink   sync       zcmp
cp     egrep	      ln	mt	rm	   tar	      zdiff
cpio   false	      loadkeys	mt-gnu	rmdir	   tempfile   zegrep
date   fgrep	      login	mv	run-parts  touch      zfgrep

open("/boot", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 4
/boot:
System.map-2.4.18	 boot-menu.b  boot.b		   map
System.map-2.4.18-bf2.4  boot-text.b  chain.b		   os2_d.b
boot-bmp.b		 boot.0200    config-2.4.18	   vmlinuz-2.4.18
boot-compat.b		 boot.0801    config-2.4.18-bf2.4  vmlinuz-2.4.18-bf2.4
=========
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.