Bash: loop through files that DO NOT match extension

后端 未结 6 393
眼角桃花
眼角桃花 2021-01-13 17:32

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

6条回答
  •  终归单人心
    2021-01-13 18:04

    Do

    find /path/to/look -type f -not -name "*.txt" -print0 | while read -r -d '' file_name
    do
    echo "$file_name"
    done
    

    when your filenames may be nonstandard.

    Note:

    If you don't wish to recursively search for files in subfolders include -maxdepth 1
    just before -type f.

提交回复
热议问题