# Combine two bash find commands

I have two similar find commands that I basically have the same code for both once the while loop begins. I want to combine them so I only need one find to search through files and directories, instead of one to search directories and one to search files. Here are the two that I want to combine into one line:

find "$ORIG_DIR" -name "*" -type d | while read dname find "$ORIG_DIR" -name "*" -type f | while read fname
-

find "$ORIG_DIR" -name "*" -type d -o -name "*" -type f | while read file -o matches all parameters, so the -name is provided twice in the above command. - @patrix Rewritten, now it doesn't re-traverse, and works :) – grgarside Jan 20 '14 at 20:46 For the while at the end, will this work: while read dname; fname; do work? – Erick Jan 20 '14 at 21:19 while read fame; do ... done. Might be a good idea to google for "Shell Scripting Primer" – patrix Jan 20 '14 at 21:30 You can use the test command to see whether it is a file or a folder: find "$ORIG_DIR" | while read thing; do
if [[ -d "$thing" ]]; then # do whatever you want to do with the directory fi if [[ -f "$thing" ]]; then