LoginSignup
1
4

More than 5 years have passed since last update.

【シェル芸】最後のファイルを探して中身を表示する

Last updated at Posted at 2017-07-12

最後のファイルを探してcatで表示するのに、スペースがファイル名に入っていた場合に苦戦したのでメモ。

追記 7/13 スペースとパイプに対応したものがこちら(コメントから反映)

find . -type f -name "*議事録*" -not -name "trashed*" | tail -1 | xargs -I% cat '%'

スペースのみ対応したものがこちら

cat "`find . -type f -name "*議事録*" -not -name "trashed*" | tail -1`"

出来ればパイプでつないで、最後にcat に渡したいが、tailを使ったところでどうしても、ヌル文字が切れてしまう。

以下が、スペースに対応できなかった失敗作

find . -type f -name "*議事録*" -not -name "trashed*" | tail -1 | xargs cat

通常は、find -print0 とxargs -0 のコンビで解決できるのだけれども、tailが中につくと引き継げなかった。

1
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4