How do I check if find had no output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I check if find had no output
# 1  
Old 05-24-2006
How do I check if find had no output

Below script complains about remove, because the find that pipes into it has no results. It's okay operationally, but a bad error message.

I would like to first check whether find had any output, and only if it had output do the rm with xargs.

How can I check whether find had output?

Thanks!

**********
$ ./clean-createTopTen-output-dir ~/output-testdir/
rm
rm: missing operand
Try `rm --help' for more information.

$ cat clean-createTopTen-output-dir
#!/bin/bash

if [ $# -ne 1 ]; then
echo "usage: clean-createTopTen-output-dir ~/outputdir"
echo "removes CreateTopTen-outputted files from ~/outputdir"
exit
fi

cleandir=$1

# for now, just delete every file that is not a gif
# but leave dir structure intact
find $cleandir -type f ! -name *gif | xargs -t rm

$ find ~/output-testdir -type f ! -name *gif

(no files found)
# 2  
Old 05-24-2006
Please put code in code tags.
Code:
#!/bin/bash

if [ $# -ne 1  ]; then
  echo "usage: clean-createTopTen-output-dir ~/outputdir"
  echo "removes CreateTopTen-outputted files from ~/outputdir"
  exit
fi

cleandir=$1

# for now, just delete every file that is not a gif
# but leave dir structure intact
find $cleandir -type f ! -name *gif | xargs -t rm

Change rm to rm -f and that error message will disappear.
Code:
$ rm
rm: too few arguments
Try `rm --help' for more information.

$ rm -f
$

Alternatively, you could do it in xargs.
Code:
$ xargs ls < /dev/null
( current directory contents)

$ xargs --no-run-if-empty ls < /dev/null
$


Last edited by Corona688; 05-24-2006 at 05:32 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Console output then comparison check help

Hi everyone, need some help if anyone can spare some of their knowledge. I have a script i use and the script outputs some information of an action it performs. It lists as text when it peforms this important step: 1 renew done 2 renew done 3 renew done 4 renew done 5 renew done I had... (8 Replies)
Discussion started by: mr5ingh
8 Replies

2. UNIX for Beginners Questions & Answers

Check output of command before outputing and keep exit code

so i have scripts that are piped and then run through one of the following mechanisms: cat myscript.sh | sh cat myscript.pl | perl what i want to do is, after either of the above commands are run, if the output from the command contains a certain string, i want it to avoid printing... (3 Replies)
Discussion started by: SkySmart
3 Replies

3. Shell Programming and Scripting

Check & use output of svcs command

Hello Dear Friends, I need to check output of svcs command and so the status of some instances. -bash-3.00$ svcs -a | grep rfe online Aug_04 svc:/application/rfe/rfe_master_3:default online Aug_04 svc:/application/rfe/rfe_master_4:default as you can see there are two... (1 Reply)
Discussion started by: EAGL€
1 Replies

4. Shell Programming and Scripting

Need help to check the copy % from following output

I have a scenario where I need to wait for the copy to be 100% in the following output There can be multiple devices in the copy session so I need to wait till everything becomes 100%, also we can look for the protected tracks t0 become 0 opey # symclone -sid 822 -v -f... (2 Replies)
Discussion started by: rajsan
2 Replies

5. Emergency UNIX and Linux Support

Script to check if user can bind, then output to file

Hi, I've been trying to find the answer with no luck. I'm hoping someone can help me. Here's what I need to do: Run a KSH script that will check: 1. Server (Client) Type (AIX 5.3, 6.1, SUSE, and HP-UX are the possibilities). 2. LDAP.cfg is configured correctly and the ldap client... (3 Replies)
Discussion started by: tekster2
3 Replies

6. UNIX for Dummies Questions & Answers

Check for difference in output of 2 commands?

Hello! I'm just learning the shell, and I would really like to know how to do this: Given these 2 commands: ls -l ls -le How can I, with a one-liner, ask the shell to show me visually in the shell, what the difference is between the output of the two commands? They look the same to me... (6 Replies)
Discussion started by: turbofayce
6 Replies

7. Shell Programming and Scripting

Find: return code check

Hi, I've a find command like, find /abcd/efgh -name "xxxx" 2> /dev/null > file1 what would be the condition to check if this returns none(means if the file "xxxx" is not present) ???? I tried checking with $? and it returns 72 to me but even the file is present also it returns... (6 Replies)
Discussion started by: skcvasanth
6 Replies

8. Shell Programming and Scripting

Check for Numeric output in Perl

Hi All, I would like to convert my below csh script to Perl. Can any expert help ? # To check for numeric input set tested1 = `echo "$tested"| awk '/^+$/'`; # To remove un-neccessary zeros set tested2 = `echo "$tested"|awk '{print $0+0}'`; (3 Replies)
Discussion started by: Raynon
3 Replies

9. Shell Programming and Scripting

check for the value of one particular field and give output in a different file

hi i need to check for the value of one particular field : in the output file. the file may contain many such records as below how to ???? *** Throttled with base name + key params! : : -518594328 : les.alarm.LBS12005 : les.alarm.LBS12005 : les : lessrv1 : les : 2328 : 0... (7 Replies)
Discussion started by: aemunathan
7 Replies

10. What is on Your Mind?

Check this out. Find out the errors as much as possible. thanks

Sorry guys, busy working on a new project these days so I am not able to keep this topic update frequently. Few days earlier I talked to some of my friends in China and understand more about the current situation of China's IT industry. From what they told me and considering my experience and... (6 Replies)
Discussion started by: CULM
6 Replies
Login or Register to Ask a Question