FIND returns different results in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FIND returns different results in script
# 1  
Old 04-25-2008
FIND returns different results in script

When I execute this line at the command prompt I get a different answer than when I run it in a script? Any ideas on how to resolve? I'm trying to find all files/dir in a directory except files that start with the word file.
Once I get this command to work, I will add the "delete" part to the command. Just trying to make sure I have all the right files listed first.

COMMAND LINE
svdw1234 : find . -mtime -1 ! -name file\*
.
./test_purge
svdw1234 :


SCRIPT

+ find . -mtime -1 ! -name file\*
.
./test_purge
./test_purge/file_test_purge_subdir.txt
./file_sqr_test.txt
./file.txt
+ return_code=0

Thanks,
Barbara
# 2  
Old 04-25-2008
The syntax is kind of oddball, and chances are your interactive script is executed by something like ksh or bash, whereas your script is presumably executed by /bin/sh.

In particular, I imagine the unquoted exclamation mark might have some unseen side effects.

Try fix the find command to adhere to the spec:

Code:
find . -mtime -1 -a \! -name file\*

Also investigate whether the PATH is somehow different inside the script, and/or you have functions or aliases which interfere in the interactive shell.
# 3  
Old 04-25-2008
This should work too:

Code:
find . -mtime -1 ! -name "*file*"

Regards
# 4  
Old 04-25-2008
login shell vs. shebang line

Is your shebang line different from your login shell. Maybe the ! is having unwanted side effects and since your are interested only in files add the -type switch too.

Code:
find . -mtime -1 -type f ! -name "file*"

# 5  
Old 04-25-2008
I have changed to the shell to match the script and still not good results?

svdw0088 : ksh
$ find . ! -name 'file*' -mtime -1
.
./test_purge
$

SCRIPT first line:

#!/bin/ksh

SCRIPT output:

+ find . ! -name 'file*' -mtime -1
.
./test_purge
./test_purge/file_test_purge_subdir.txt
./file_sqr_test.txt
./file.txt
+ return_code=0

It still shows the files which start with the word file. I do want to exclude directory structures also.
Thanks,
Barbara

Last edited by blt123; 04-25-2008 at 04:23 PM..
# 6  
Old 04-25-2008
Use double quotes:

Code:
find . -mtime -1 ! -name "*file*"

Regards
# 7  
Old 04-26-2008
Franklin52: That's not it, single quotes are stronger than double, so the result should be the same (you want to prevent the asterisk from being expanded by the shell).

blt123: can you run the interactive shell with -x too?

Code:
prompt$ ksh -x
$ find . ! -name 'file*' -mtime -1
+ find . ! -name file* -mtime -1
.
./test_purge
./test_purge/file_test_purge_subdir.txt
./file_sqr_test.txt
./file.txt
$ exit
+ exit

See the + lines there? You can get them from an interactive session just like from a script. (No need to start a subshell either, you can just say set -x to enable them; set +x to turn them back off.)

The crucial question is whether the find command gets expanded to something unexpected.

Also, can you try with a hard-coded path to your find binary (/usr/bin/find I would guess)?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Linux find command returns nothing

Under one of my directories on server I have more than 500 files with different type and name. When I run the find command to list the files with 'ABC_DEFGH' in the begining of its name and older than 20 days, nothing is return as result. Though I know there are more than 400 files which their name... (10 Replies)
Discussion started by: Home
10 Replies

2. Shell Programming and Scripting

ksh script find command not printing any results

Hello, Hitting a wall on this one. When at the command prompt it works fine: # find /home/testuser -name 'PAINT*canvasON.txt' /home/testuser/PAINT_canvasON.txt # pwd /home/testuser # ls -l PAINT*canvasON.txt -rw-r--r-- 1 root user 23 Feb 07 02:58 PAINT_canvasON.txt... (2 Replies)
Discussion started by: seekryts15
2 Replies

3. Shell Programming and Scripting

rm -rf ab returns find: `./ab': No such file or directory

Hi Gurus. This is driving me a bit batty. I now if must be a simple matter but I cant find anything that references it. I have a housekeeping script that searches for some huge dump directories then removes them using rm -rf. find ./ -name 'ab' -exec rm -rf {} \; This works but always... (7 Replies)
Discussion started by: rinser
7 Replies

4. Shell Programming and Scripting

sed returns different results while substitution on a pipe delimited file

Hi, Need help with a sed command that I am using to substitute 3 positions of a pipe delimited file. i am getting different results while substituting the same position of two different files with the same value. Please see details below: $ cat chk2 ... (3 Replies)
Discussion started by: vmenon
3 Replies

5. Shell Programming and Scripting

find/grep returns no matches

Hi all! I've faced with very unintelligible error using find/grep like this: root@v29221:~# find /var/www/igor/data/www/lestnitsa.ru | grep u28507I get nothing as a result, but: root@v29221:~# grep u28507 /var/www/igor/data/www/lestnitsa.ru/_var.inc $db_name = 'u28507';... (2 Replies)
Discussion started by: ulrith
2 Replies

6. 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

7. UNIX for Dummies Questions & Answers

find command returns files with spaces, mv won't work...

Hi guys. I am trying, to move files found with the find command... Script runs fine, until it reaches a file that contains spaces... Here is what i wrote up quickly. ROOTDIR=/apps/data SEARCH=$(find /data/HDTMPRestore/home/tmq/ -type f -print | grep Mods/Input/bck | cut -c19-) for i... (1 Reply)
Discussion started by: Stephan
1 Replies

8. UNIX for Dummies Questions & Answers

find results

Hi, how can I get only useful results from find / -size 10000000 without the "Permissions denied" files ? tks C (5 Replies)
Discussion started by: Carmen123
5 Replies

9. UNIX for Dummies Questions & Answers

cant find command that returns blank line

This is my list of sed commands: can anyone tell me where im going wrong. The script works on a file called data which contains 6 student id's and there answers for 6 questions. !/bin/sh sed -e 's/*//g' \ #replace * with nothing -e s/ /X/g' \ #replacing empty space with X -e... (2 Replies)
Discussion started by: jeffersno1
2 Replies
Login or Register to Ask a Question