
私は学校の課題をしていてパテを使ってそれを完了しました。課題の形式が大きな変更を許可していないため、1つの回答だけで次の質問に進むことができました。また、彼らは答えを得るために可能な限り短いパス名とコマンドを使用したいと思います。
現在のディレクトリはSample_dirです。 cars2では、「ford」という文字列を含むレコードを探し、結果に文字数を表示します。サンプルディレクトリ2
-- sample_dir
|-- admin
|-- cambridge
| `-- security
| |-- annex
| `-- parking
|-- history.exe
|-- markham
| |-- annex
| |-- building1
| `-- parking
`-- stenton
|-- f1
|-- f12
|-- f2
|-- gen_ed
| |-- Holidays
| `-- cars2
|-- lib_arts
| `-- english.txt
`-- phone_directory
| |-- Holidays
| `-- cars2
|-- lib_arts
| `-- english.txt
`-- phone_directory
私は
grep -c ford stenton/gen_ed/cars2
別のオプションを試してみましたgrep
。この道が合っているのか、それとも私が道を離れたのか?
答え1
cars2ファイルにfordを含む行を表示するには、次のものを使用できます。
find . -name cars2 -exec grep ford {} \;
レコードのグローバル文字数を計算します。
find . -name cars2 -exec grep -h ford {} \; | wc -c
答え2
正解は:
grep "ford" stenton/gen_ed/cars2 | wc -c
答え3
努力する:
grep ford stenton/gen_ed/cars2 -r
答え4
する方法は簡単です。
grep ford stenton/gen_ed/cars2 | wc -m