The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 08-24-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Quote:
Originally Posted by bztian View Post
oh btw - When you send in the -exec command with the ls -(options) command, why do you need to add the "{} \;"?
The {} gets replaced with the found file's name, and the \; shows where the -exec command line ends, so you can continue to specify other options to find.
You could even have multiple -exec actions:


Code:
find . -type f -exec ls -l {} \; -exec touch {} \;

Without the \; how would you know where the first -exec command ends and we are back in find's command line proper again? The command you -exec could even be another find so looking for familiar options is not a good way to disambiguate; and besides, other programs than find have options like -type and -name too.

Having said that, -exec is usually the last thing you do, and the file name of the found file is usually the last thing in that command line, so it does seem a bit redundant in those cases. A common exception would be the mv command where the found file is usually the thing you want to move.