Pages tagged with find

  • How to find files not owned by a particular user or group - To find files below the current directory not owned by particular user, use the following command (in this example the user is called steph): find . \! -user steph -print You can do the same with groups: find . \! -group steph -print References ...
  • Change extension of multiple files - To change the extension of multiple files, e.g. rename .html.bak to .html: find . -type f -name "*.html.bak" -exec sh -c 'mv {} `basename "{}" .bak`' \;
  • Dealing with spaces when using find with exec - To prevent problems with spaces in filenames when running the ‘find’ command with -exec, use double quotes: find . -type f -name "*.html" -exec grep ls "{}" \;
  • Find with nested commands - If you want to run nested commands on the results of a ‘find’, then you’ll have to stop bash expansion running before the find command. E.g. This won’t work because the shell expansion will happen before the find has set the {}...
  • Find and replace text in multiple files - As always, back up all files before doing this. In the regexp, remember to escape the necessary characters, e.g. slashes. Use the find command to list all files matching the criteria and pipe through xargs to perl to find and replace the text with a ...
  • Find and replace - Find ignoring a file In this example excluding todo.txt prevents an infinate loop that would otherwise result in todo.txt growing to fill all space on the hard disk. find . -type f \( -name "*.txt" ! -name "todo.txt" \) -exec grep "TODO" -iHn {} \; &...
Go to top

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top