How can I read a list of filenames from a file in bash?

前端 未结 7 1186
青春惊慌失措
青春惊慌失措 2021-01-30 10:59

I\'m trying to write a bash script that will process a list of files whose names are stored one per line in an input file, something the likes of

find . -type f          


        
7条回答
  •  一生所求
    2021-01-30 11:25

    I believe you can skip the temporary file entirely and just directly iterate over the results of find, i.e.:

    for F in $(find . -type f -mtime +15) ; do
      ...
    done;
    

    No guarantees that my syntax is correct but I'm pretty sure the concept works.

    Edit: If you really do have to process the file with a list of filenames and can't simply combine the commands as I did above, then you can change the value of the IFS variable--it stands for Internal Field Separator--to change how bash determines fields. By default it is set to whitespace, so a newline, space, or tab will begin a new field. If you set it to contain only a newline, then you can iterate over the file just as you did before.

提交回复
热议问题