Created
April 15, 2011 08:08
-
-
Save 544/921359 to your computer and use it in GitHub Desktop.
findとxargsでファイル名変更
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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