[Solved] weird in find -exec command


 
Thread Tools Search this Thread
# 8  
Quote:
Originally Posted by alister
Notice that the -exec ls ... output shows duplicate filenames.
There, not here. Not with my GNU find, which works as expected.

Please, again, try yourself:
Code:
lem@biggy:/tmp$ touch {file,test}{1,2,3}
lem@biggy:/tmp$ find /tmp/*test* -ls
197009    0 -rw-rw-r--   1 lem      lem             0 set  2 20:03 /tmp/test1
197010    0 -rw-rw-r--   1 lem      lem             0 set  2 20:03 /tmp/test2
197011    0 -rw-rw-r--   1 lem      lem             0 set  2 20:03 /tmp/test3
lem@biggy:/tmp$ find /tmp/*test* -exec ls -l '{}' \;
-rw-rw-r-- 1 lem lem 0 2012-09-02 20:03 /tmp/test1
-rw-rw-r-- 1 lem lem 0 2012-09-02 20:03 /tmp/test2
-rw-rw-r-- 1 lem lem 0 2012-09-02 20:03 /tmp/test3
lem@biggy:/tmp$ find /tmp/*test* -exec ls -lr '{}' +
-rw-rw-r-- 1 lem lem 0 2012-09-02 20:03 /tmp/test3
-rw-rw-r-- 1 lem lem 0 2012-09-02 20:03 /tmp/test2
-rw-rw-r-- 1 lem lem 0 2012-09-02 20:03 /tmp/test1

Quote:
There is nothing in that find command that prints a matching file name twice (and non-consecutively), and since a directory cannot contain two identically-named files, the shell must be matching one or more directories with that pattern (in addition to *test* files in tmp, if any).
Strange. He run an -exec -ls -l, not an -execdir. And he didn't notice that the files were in different subdirectories!?

Quote:
With a directory path, the -exec predicates of those find commands will list or attempt to delete every regular file in that directory and its subdirectories, regardless of a file's name.
Of course.
So you're saying that his find is working as expected, too. Nice. Smilie
--
Bye

Last edited by Lem; 09-02-2012 at 03:36 PM..
# 9  
Quote:
Originally Posted by Lem
There, not here. Not with my GNU find, which works as expected.

Please, again, try yourself:
I don't need to try anything. Looking at your output, your test results are exactly what I would expect. However, your test is not relevant. Your file layout does not match the OP's (if it does, the sample data in post #3 is wrong).

It seems you have totally missed my point.

Regards,
Alister
# 10  
Quote:
Originally Posted by alister
Your file layout does not match the OP's (if it does, the sample data in post #3 is wrong).
Since
Quote:
file1
file2
file3
test1
test2
test3
file1
file2
file3
test1
test2
test3
can never ever be the output of an
Code:
ls -l

command, we cannot know what the OP has really done and what has been the real output.

In his first post, the OP stated:
Code:
second command it listed all the files inside the directory which including those filename that not *test*

Quote:
It seems you have totally missed my point.
We both have made assumption about what has happened. You seem to be sure that the last output in post3 has been something with the names of the files repeated two times... and that the OP missed the different subdirs despite not using -execdir, which is a bit strange.

I assumed that that output has been duplicated by the OP in posting, and that he wrote the truth in his first post. So I just assured him that my find works as expected, not knowing what's going on there.

Re-reading all the thread, you can surely be right.
--
Bye
# 11  
Quote:
Originally Posted by Lem
Since ... can never ever be the output of an ls -l command, we cannot know what the OP has really done and what has been the real output.
... <snip> ....

We both have made assumption about what has happened. You seem to be sure that the last output in post3 has been something with the names of the files repeated two times... and that the OP missed the different subdirs despite not using -execdir, which is a bit strange.

I assumed that that output has been duplicated by the OP in posting, and that he wrote the truth in his first post. So I just assured him that my find works as expected, not knowing what's going on there.
Very good points.

Add to them that none of the find commands in posts #1 and #3 are syntactically valid: the ; that terminates an -exec ... must be the only character in its argument.

Regards,
Alister
# 12  
thanks, it works when i change to -name '*test*'
# 13  
Told you...
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Computers
Difficulty: Medium
MacOS is based on Linux.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Find and move command with exec

Hi all, I am trying to find files newer than a given file and them mv them to a new location. So I far I have: find . ! -newer <file_name> -exec ls -l {} \; and find . ! -newer <file_name> -exec mv /TEMP_LOCATION {} \; find is not liking this. Anyone know how to modify the last... (2 Replies)
Discussion started by: jonnyd
2 Replies

3. UNIX for Dummies Questions & Answers

What does the '\' in find -exec command

Hi, I have two scripts that remove files. One works fine and is coded find -name "syst*" -mtime +1 -exec rm {} \; The other is almost the same - only thing missing is the '\'. On that script though I keep getting: rm syst1202.file ? etc Does the \ make that difference or is it a... (3 Replies)
Discussion started by: Grueben
3 Replies

4. Shell Programming and Scripting

find command with -exec

Hi all, Please could someone help with the following command requirement. I basically need to find files NEWER than a given file and order the result on time. My attempt so far is as follows: find . -newer <file_name> -exec ls -lrt {} ;\ But I dont seem to get the right result... (12 Replies)
Discussion started by: jonnyd
12 Replies

5. Shell Programming and Scripting

How to get the exit code of -exec in the find command

Hi I have a little problem with the find command in a script that I'm writing. The script should check if there are some files younger than 100 seconds and then syncronise them with rsync. My find command: find -type f -cmin -100 -exec rsync -a --delete directory1/ directory2/ When I... (8 Replies)
Discussion started by: oku
8 Replies

6. Shell Programming and Scripting

find command with -exec

Hi People, I have a directory full of compressed files (.Z extention) In many of these files there is a string pattern (3800078163033) I want to find all file names which contain this string in their text. Regards, Abhishek (2 Replies)
Discussion started by: max29583
2 Replies

7. Shell Programming and Scripting

find command with exec doesnt work

Hi There, I have a script which finds for log files and removes them if the file has changed in the last day. The script runs fine without errors. The log file is still there. So, I decided to print the find command and run the command outside the script. Getting "Incomplete statement" Can you... (6 Replies)
Discussion started by: funtochat2002
6 Replies

8. UNIX for Advanced & Expert Users

Find command with prune and exec

Hi, I'm using the following command to get a list of files on the system. find /releases -type f -exec ls -l > /home/sebarry/list.txt '{}' \; however, its searching a directory I don't want it to search so I know I have to use prune but I don't seem to be able to get prune and exec to work... (1 Reply)
Discussion started by: Sebarry
1 Replies

9. UNIX for Dummies Questions & Answers

find command exec error

Hi All, i am writing a shell script in korn shell which deletes all the files in a directory once in every 10DAYS. the directory has different format files. the script has something like this; cd /home/data/pavi echo "Please Enter the Number of Days to search for" read DAYS... (2 Replies)
Discussion started by: pavan_test
2 Replies

Featured Tech Videos