echo 2>/dev/null with a find command help


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users echo 2>/dev/null with a find command help
# 1  
Old 03-18-2012
echo 2>/dev/null with a find command help

Why does this not work?
Code:
echo 'find / -iname \'*katt*\' -size +500M 2>/dev/null'

How does this work? I have 5 single quotes. I though you needed an even amount of single quotes.
Code:
echo 'find / -iname \'*katt*\' -size +500M 2>/dev/null''

What is the trick to make it work with an alias? This won't work.
Code:
alias findnamesize="echo 'find / -iname \'*katt*\' -size +500M 2>/dev/null''"

# 2  
Old 03-18-2012
Because the \ escape does not work within single quotes. Try:
Code:
echo "find / -iname '*katt*' -size +500M 2>/dev/null"

# 3  
Old 03-18-2012
Quote:
Originally Posted by cokedude
Why does this not work?
Code:
echo 'find / -iname \'*katt*\' -size +500M 2>/dev/null'

Should you want to stick with single quotes for the external ones, you can use that syntax:
Code:
echo 'find / -iname '"'"'*katt*'"'"' -size +500M 2>/dev/null'

# 4  
Old 03-18-2012
@cokedude
When you post code which does not work, please provide sample input and sample expected output making the process specification emphatically clear.
Please also post what Operating System and version you are running and what Shell you are using.

It is unlikely than an optimum solution to your problem would involve the alias command.

Ps. I do wonder sometimes why do you persist in trying to use alias for complex commands when you should be using proper Shell Scripts?
Imho. If the alias command was deleted from all Shells it would be no great loss.

Did you know? You can modify the ${PATH} environment variable to include your scripts directory:
e.g.
Code:
PATH="${PATH}:/home/myuser/myscripts";export PATH

Then you can use the name of your script as if it was a command and avoid using aliases.

Last edited by methyl; 03-23-2012 at 02:53 PM.. Reason: layout; trivial typo
# 5  
Old 03-18-2012
Or you can define functions instead of aliases...
Code:
findnamesize() { find / -iname '*katt*' -size +500M 2>/dev/null ;}

There is no reason to use aliases anymore..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with /dev/null Please

Hello All and a Happy New year to yous guys. I'm running the below command on my AIX box and it keeps giving me the message that the file doesn't exist. I know the file don't exist, but I don't want to see the error. 2>/dev/null doesn't work. bash-3.00$ ls -l C* | wc -l 2>/dev/null ls:... (2 Replies)
Discussion started by: bbbngowc
2 Replies

2. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

3. Shell Programming and Scripting

find error?? find / -name "something.txt" 2>/dev/null

why is this giving me errors? i type this in: find / -name "something.txt" 2>/dev/null i get the following error messages: find: bad option 2 find: path-list predicate-list :confused: (5 Replies)
Discussion started by: magiling
5 Replies

4. UNIX for Dummies Questions & Answers

/dev/null 2>&1 Versus /dev/null 2>1

How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&" echo "hello" > /dev/null 2>&1 echo "hello" > /dev/null 2>1 (3 Replies)
Discussion started by: glev2005
3 Replies

5. UNIX for Dummies Questions & Answers

echo statement when find returns null

Hi, How do you echo something once when a find statement returns null results? This is when using mutiple locations and mutiple arguments. The below find command the inner loop of a nested for loop where the outter loop holds the $args and the inner loop holds the locations. find... (2 Replies)
Discussion started by: tchoruma
2 Replies

6. UNIX for Dummies Questions & Answers

Using /dev/null with grep and find

Hi, I am trying to display the filename in which a string was found after using find and grep. For this after some googling I found that this works: find -name "*.java" -exec grep "searchStr" {} /dev/null \; I wanted to know the difference between the above and the following: find -name... (0 Replies)
Discussion started by: gaurav_s
0 Replies

7. Solaris

What is /dev/tty /dev/null and /dev/console

Hi, Anyone can help My solaris 8 system has the following /dev/null , /dev/tty and /dev/console All permission are lrwxrwxrwx Can this be change to a non-world write ?? any impact ?? (12 Replies)
Discussion started by: civic2005
12 Replies

8. UNIX for Dummies Questions & Answers

redirect stderr and/or stdout to /dev/null from command line

Is it possible to redirect errors at the command line when you run the script such as bash scriptname & 2>/dev/null? (1 Reply)
Discussion started by: knc9233
1 Replies

9. UNIX for Advanced & Expert Users

Q1 :/dev/null Q2 -A

Hi, Q1-What does nroff -ms > /dev/null Q2- What does mean -A under STAT column : ps aux |head -20 UTIL PID %CPU %MEM SZ RSS TTY STAT STIME TIME COMMAND root 516 93,0 0,0 12 12 - A 04 nov 3906:51 wait Thank you. (4 Replies)
Discussion started by: big123456
4 Replies

10. UNIX for Dummies Questions & Answers

/dev/null

Hi , I am importing some table from /dev/null i dont understand what is /dev/null Sorry i am new to UNIX sam71 (3 Replies)
Discussion started by: sam71
3 Replies
Login or Register to Ask a Question