Skip to content

Instantly share code, notes, and snippets.

@544
Created April 15, 2011 08:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 544/921359 to your computer and use it in GitHub Desktop.
Save 544/921359 to your computer and use it in GitHub Desktop.
findとxargsでファイル名変更
find ./ -type f -maxdepth 1 | xargs -i mv {} {}_YYYYMMDD
#1. findコマンドで現在のディレクトリ以下 ( ./ ) にあるファイル ( -type f ) の一覧を取得。(ただし、サブディレクトリは除く ( -maxdepth 1 )
#2. 上の結果をパイプでつないで、xargsコマンドで “mv {} {}_YYYYMMDD” に渡す。(xargs の-iオプションで{}の部分がファイル名に変換しつつ実行されます)
#上をちょっと応用するとこんなこともできます。
find ./ -type f -maxdepth 1 | grep _YYYYMMDD | sed 's/\.end//' | xargs -i mv {}.end {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment