Коснитесь файлов из списка файлов [дубликат]

Я часто подправляю файлы, чтобы они отображались в верхней части файлового менеджера.

Есть ли способ прикоснуться к списку файлов вместо того, чтобы касаться каждого по отдельности?

touch test1 test2 - это не то, что я ищу.

Конвейер ... Таким образом, вывод списка файлов будет отправлен сенсорной команде.

Текстовый список файлов, переданных по конвейеру или что-то еще, что нужно коснуться = файлы с обновленными отметками времени. Канал - это форма перенаправления (передача стандартного вывода в другое место назначения), которая используется в Linux и других Unix-подобных операционных системах для отправки вывода одной команды / программы / процесса другой команде / программе / процессу для дальнейшей обработки. . Таким образом, вывод списка файлов будет отправлен сенсорной команде.

0
задан 5 June 2020 в 10:27

1 ответ

Assuming your filenames are listed, one per line, in a text file, with no leading or trailing whitespace (unless the filenames themselves start or end with whitespace), and no filename contains a newline character (since if one did, the list would be ambiguous), this is a good use case for xargs.

The xargs command reads words from input and passes them as arguments to a command. By default it breaks up the words using arbitrary whitespace. Since it's common that filenames contain whitespace, this default behavior probably won't work for you, and could even end up operating on files that weren't in your list. However, GNU xargs (which provides xargs in Ubuntu) has a -d option that can be used to specify an arbitrary delimiter. From your description it sounds like you already have a list of files, one per line. In that case you can specify \n as the delimiter.

Suppose the filenames are listed in a file called files.txt. Then you can run:

<files.txt xargs -d'\n' touch
  • redirects from files.txt.
  • xargs -d\'n' touch reads arguments from its input, split at newlines, and passes them to touch.
  • -d'\n' causes the shell to pass the literal text -d\n to xargs. It is xargs that treats the sequence \n specially, knowing you mean a newline.

You can of course put the redirection, , anywhere in the command you like (though most people would put it at the very beginning or the very end). If, rather than a file, you have a command that produces the list, you can pipe from that command to xargs. For example, if you have a script in the current directory called make-list, you could run:

./make-list | xargs -d'\n' touch

xargs in Ubuntu does also have a -a option, if you're using an existing file as input and for some reason you prefer to pass it a filename as an operand rather than redirecting to it:

xargs -a files.txt -d'\n' touch
2
ответ дан 19 June 2020 в 21:30

Другие вопросы по тегам:

Похожие вопросы: