Operating System - HP-UX
1831600 Members
2525 Online
110027 Solutions
New Discussion

Re: supressing error messages

 
SOLVED
Go to solution
Party
Occasional Contributor

supressing error messages

Hi,
Can somebody help me in solving this small problem ...I want to avoid displaying the error messages on the screen (Eg:Given)while
searching for a particular file
find / -name test -print |grep -sv test
find: cannot search /etc/ftpd (Errors)
find: cannot open /etc/opt/resmon/persistence
find: cannot open /etc/opt/resmon/pipe
find: cannot open /etc/sam/custom
find: cannot search /etc/Tivoli/tec
find: cannot open /tmp/.AgentSockets
find: cannot search /tmp/mail.old/maillog.31104
find: cannot open /home/jhazen

Thanks
Bins
4 REPLIES 4
Robert-Jan Goossens
Honored Contributor

Re: supressing error messages

Hi,

Try this.

# find / -name test -type f | xargs grep -l "test"

Robert-Jan
Party
Occasional Contributor

Re: supressing error messages

Hi

It is not working

Thanks
Binu
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: supressing error messages

find / -name 'test' -type f 2>/dev/null | grep -sv 'test'
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor

Re: supressing error messages

The error messages are written to stderr rather than stdout. Since your screen is (by default) configured to show both, just redirect the errors (stderr) to /dev/null by using file descriptor 2:

find / -name test 2>/dev/null

I'm not sure why your grep -v is there. The combination of -name test with grep -v test will produce nothing. Note also that grep is non-selective. That means that it will match /var/tmp/testing. Now in your example, find will locate *ANYTHING* with test as a name (ie, directory, socket, symbolic link, named pipe, file, etc). If you are looking for a file, add -type f to your search.

And lastly, if this is a single user workstation, find / is probably OK. But on a large server, the search will interfere with every program that also uses the disks. It will search mounted CDROMs, NFS mounpoints on other computers, all the database files, etc. When you are looking for a particulat file, it is less invasive (and much faster) to limit the search to a specific set of directories.


Bill Hassell, sysadmin