I\'m writing a bash script that needs to loop files inside a directory that do not match a specific extension. So far, I\'ve found that the following code loops all files th
If you are ok for a GNU
solution, give a try to this:
for f in $(find . -maxdepth 1 -type f \! -name \*.txt) ; do
printf "%s\n" "${f}"
done
This is going to break if special chars are contained in the filenames, such as (space).
For something safe, still GNU
, try:
find . -maxdepth 1 -type f \! -name \*.txt -printf "%p\0" | xargs -0 sh -c '
for f ; do
printf "%s\n" "${f}"
done' arg0