GNU/Linux >> Linux の 問題 >  >> Linux

フォルダ内のすべてのファイルを印刷しますか?

lsとしましょう retunrs file1 file2 dir1 dire2 ...you have file1 file2 dir1 dire2 ... in currnent folderを印刷したい 。

どうすればそれができますか?
ls | xargs -i echo 'you have {} in current folder' プリント

you have file1 in current folder
you have file2 in current folder
you have dir1 in current folder
you have dir2 in current folder
you have xxx in current folder

また、
ls |xargs printf 'you have %s %s %s %s in current folder'
しかし、それを機能させることができませんでした。ファイルの数は不定です。 printfの正しい構文は何ですか この場合?

ls | xargs printf 'you have [email protected] in current folder' 私が得ることができる最も近いものですが、機能しません。

承認された回答:

以下は機能しますが、おそらくセキュリティにマイナスの影響があります:

echo "You have" * "in current folder"

IMOの方が良い方法ですが、2行が必要になるのは次のとおりです。

files=(*)
echo "You have ${files[@]} in curent folder"

printfを使用する場合:

files=(*)
printf '%s ' "You have ${files[@]} in current folder"

Linux
  1. 2つのファイルを2つの列に印刷しますか?

  2. フォルダ内の不足しているファイルの名前を印刷するにはどうすればよいですか?

  3. フォルダ内のすべてのファイルにテキストを追加しますか?

  1. レンジャーで特定のフォルダ内のファイルを並べ替えますか?

  2. フォルダとリストファイルをループしますか?

  3. 1 つを除くすべてのファイルを移動する

  1. Macのコマンドラインから現在のフォルダーとすべてのサブフォルダーの.DS_STOREファイルを削除します

  2. フォルダ内のすべてのシェル スクリプトを実行する

  3. すべてのファイルを現在のディレクトリから上位ディレクトリに移動する方法は?