find command with -exec


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find command with -exec
# 8  
Old 08-01-2012
Code:
find . -newer <file_name> -exec ls -1ad {} \+

works fine.

Thanks!

Last edited by Franklin52; 08-01-2012 at 04:53 PM.. Reason: Please use code tags for data and code samples, thank you
# 9  
Old 08-01-2012
Hi

By the way, you can't use -exec ls -lrt to sort the find output, because ls will be called for each file, so it will only sort the given file.

You should sort after the find process, maybe you could use something like find ... -printf "%T@ %p", and then use sort -n on the output.
# 10  
Old 08-01-2012
I'm not sure whether sun find supports -printf in that way. You need to not rely on extensions when using Solaris.
# 11  
Old 08-01-2012
Quote:
Originally Posted by Corona688
I'm not sure whether sun find supports -printf in that way. You need to not rely on extensions when using Solaris.
You are right i forgot about those Solaris limits.

Maybe this should work then :

Code:
find  . -newer filename -exec perl -e "\$fname=\"{}\";"'$mtime=(stat($fname))[9]; printf("%ld %s\n",$mtime,$fname);' \; |
  sort -n |
  awk '{print $2}'

# 12  
Old 08-01-2012
If perl is going to be used, there's really not much point in using find, sort, or awk. Perl can traverse directory trees, sort lists, extract fields, etc.

The following may be of interest:
http://perldoc.perl.org/File/Find.html
http://perldoc.perl.org/find2perl.html

A similar, more efficient approach to your suggestion would be to -exec stat .... GNU and solaris both provide a stat utility, but they require different options to accomplish the same task. Before calling find, the script can test the platform to choose between the two syntaxes.

Regards,
Alister

Last edited by alister; 08-01-2012 at 01:31 PM..
# 13  
Old 08-01-2012
Quote:
Originally Posted by jonnyd
find . -newer <file_name> -exec ls -1ad {} \+

works fine.

Thanks!
This works fine as long as you either have a small number of files OR don't care about a long list of files that isn't sorted.

Note also that you can just use "+" instead of "\+"; you need "\;" instead of just ";" because an unescaped <semicolon> is special to the shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

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

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

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

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

7. UNIX for Dummies Questions & Answers

Find command with prune and exec options

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... (2 Replies)
Discussion started by: Sebarry
2 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
Login or Register to Ask a Question