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 02-03-2011, 12:05 PM   #1
Vryali
LQ Newbie
 
Registered: Oct 2010
Location: Columbia, SC
Distribution: Arch Linux
Posts: 11

Rep: Reputation: Disabled
Alias for find that has 2>/dev/null in it?


My current find alias is just a simple:

find='find / -iname'

So that I can just type: find somefile

If I run it as a non-root user, of course there's all kind of trash that comes back from STDERR, is there anyway I'm able to write an alias so that I can basically automatically pipe STDERR to null? So basically when I type: find somefile, it runs:

find / -iname somefile 2>/dev/null

Cheers, thanks for any advice/help, not sure if I can really do what I'm asking without writing a special script for it.
 
Old 02-03-2011, 12:26 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
An alias won't cut it, because it can't handle parameters; you
could write a function, though, and put that in your ~/.bashrc
instead of having a script.
Code:
ff(){
  find / -iname "$1" 2>/dev/null
}
Btw, I wouldn't recommend using find's original name for the
function, but something similar to what I chose (or completely
different, for that matter ;D).



Cheers,
Tink
 
Old 02-03-2011, 12:26 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

I'm not sure if this can be done with an alias, but you can make a function that can do this.

Code:
function find()
{
  /bin/find / -iname "$@" 2>/dev/null
}
Put the above code in your .bashrc file, after the next login you can now use: find somefile. This is translated to: /bin/find / -iname somefile 2>/dev/null

BTW: The find command is not too resource friendly. Are you aware of the locate command (and the accompanying updatedb)? Much more resource friendly and build for "simple" lookups.

Hope this helps.
 
Old 02-03-2011, 01:24 PM   #4
z1p
Member
 
Registered: Jan 2011
Location: the right coast of the US
Distribution: Ubuntu 10.04
Posts: 80

Rep: Reputation: 23
try
Code:
alias find='find / -iname $(history -p) 2>/dev/null'
Not sure how optimal, but since history is a built-in command it shouldn't be too bad.
 
Old 02-03-2011, 02:12 PM   #5
Vryali
LQ Newbie
 
Registered: Oct 2010
Location: Columbia, SC
Distribution: Arch Linux
Posts: 11

Original Poster
Rep: Reputation: Disabled
Wow, thanks for the snappy response, I appreciate it =] The AIX boxes I work with don't have the locate command, and I like to try to keep things as similar between Linux/AIX boxes as I can. I actually knew about the locate command, but just have never used it before, so thanks for the heads-up regardless, I'll play around with it =]
 
  


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
What would happen if I where to cat /dev/mem > /dev/null Joey.Dale Linux - General 11 07-26-2009 01:46 PM
LXer: /dev/null And /dev/zero On Linux And Unix: What's The Difference? LXer Syndicated Linux News 0 04-29-2009 11:50 AM
Startx Permission problems on /dev/null and /dev/mem on freshly compiled 2.6.22.1 Eric_Cartman Linux - Kernel 2 09-09-2007 02:42 AM
What is meant by " file > /dev/null 2>&1 </dev/null " attockonian Linux - Newbie 5 06-30-2006 11:51 PM
qmail: setting up alias to go to /dev/null? m3kgt Linux - Software 4 11-18-2003 04:50 PM


All times are GMT -5. The time now is 08:55 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration