悪意のあるファイル名の一覧があるファイルがあります。多くのファイル名に空白が含まれています。私はそれらを見つけて権限を変更する必要があります。xargsエラー:ファイル名が長すぎます
grep -E ". " suspicious.txt | xargs -0 chmod 000
をしかし、私はエラーになっています:私は、次のことを試してみました
:File name too long
アイデアを?
悪意のあるファイル名の一覧があるファイルがあります。多くのファイル名に空白が含まれています。私はそれらを見つけて権限を変更する必要があります。xargsエラー:ファイル名が長すぎます
grep -E ". " suspicious.txt | xargs -0 chmod 000
をしかし、私はエラーになっています:私は、次のことを試してみました
:File name too long
アイデアを?
OK、あなたはあなたのファイルで1行に1つのファイル名を持ち、かつ-0
とxargs
は、ファイル名がNUL
によって分離されることを想定している間に問題は、xargs
-0
せずにスペースやタブだけでなく、ファイルの区切りとして改行を扱うということです改行はまったく気にしません。
のでxargs -0
コマンドに結果を供給する前にNUL
秒に改行を回す:
grep -E ". " suspicious.txt | tr '\n' '\0' | xargs -0 chmod 000
更新:
Mark Reeds正しい答えを参照してください。 grep
によって生成されたファイル名ではなく、ファイルからのファイル名にNULLが必要だったため、これは間違っていました。
オリジナル:xargsのmanページから
grep -Z -E ". " suspicious.txt | xargs -0 chmod 000
:
あなたはより多くのこのようなものが必要
Because Unix filenames can contain blanks and newlines, this default behaviour is often problematic; filenames containing blanks and/or newlines are incorrectly processed by xargs. In these situations it is better to use the -0 option, which prevents such problems. When using this option you will need to ensure that the program which produces the input for xargs also uses a null character as a separator.
grepのmanページから:
-Z, --null
Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name. For example, grep -lZ outputs a zero byte after each file name instead of the usual newline. This option makes the output unambiguous, even in the presence of file names containing unusual characters like newlines. This option can be used with commands like find -print0, perl -0, sort -z, and xargs -0 to process arbitrary file names, even those that contain newline characters.
いいえ、それは正しくありません。ファイル名はテキストファイル内の行です。彼らはすでに改行で区切られています。 '-Z'は' grep'自身が出力するファイル名(例えば 'grep -l'など)に役立ちます。 –
悲しいことに、スティーブンの解決策は機能しませんでした – Zaheer
マークありがとう、それは働いた! – Zaheer