- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2017-02-07T12:50:19+09:00","","")
#navi(../)
* findやgrepで検索した結果をファイル日付でソートする方法 [#x3f7997b]
findやgrepで該当するファイルを検索し出力された内容をファイルのタイムスタンプでソートしたい場合の例を以下に記します。
#contents
#htmlinsertpcsp(linux_ads_top.html,linux-sp.html)
* 関連記事 [#p08fb9cf]
-[[指定サイズより大きいファイルを探す・findコマンド>逆引きUNIXコマンド/指定サイズより大きいファイルを探す・findコマンド]]
* findの場合 [#m6195432]
findで検索した内容をファイルのタイムスタンプでソートしたい場合は、xargsとlsを使えば簡単に実現できます。~
以下に実行例を記します。
フィアルサイズが4M以上のファイルをfindで検索し、lsコマンドでソートした例です。
** ls -lt [#q427ac16]
tオプションでタイムスタンプでソートしています。
sakura@hpmini:~$ find /usr/bin/ -size +4M | xargs ls -lt
-rwxr-xr-x 1 root root 9612924 12月 14 22:33 /usr/bin/php5
-rwxr-xr-x 1 root root 6575456 7月 2 2016 /usr/bin/gimp-2.8
-rwxr-xr-x 1 root root 4340528 11月 8 2014 /usr/bin/aptitude-curses
-rwxr-xr-x 2 root root 4595016 10月 8 2014 /usr/bin/python3.4
-rwxr-xr-x 2 root root 4595016 10月 8 2014 /usr/bin/python3.4m
** ls -ltr [#y644ad64]
rオプションを追加しリバース(r)で表示した例です。
sakura@hpmini:~$ find /usr/bin/ -size +4M | xargs ls -ltr
-rwxr-xr-x 2 root root 4595016 10月 8 2014 /usr/bin/python3.4m
-rwxr-xr-x 2 root root 4595016 10月 8 2014 /usr/bin/python3.4
-rwxr-xr-x 1 root root 4340528 11月 8 2014 /usr/bin/aptitude-curses
-rwxr-xr-x 1 root root 6575456 7月 2 2016 /usr/bin/gimp-2.8
-rwxr-xr-x 1 root root 9612924 12月 14 22:33 /usr/bin/php5
* grepで検索したファイル一覧をタイムスタンプでソートする [#dfc0c80e]
grepも同様の方法で実現できます。
以下、grepでdebianが含まれるファイル一覧を取得しています。
sakura@hpmini:~$ grep -ilr debian /etc/X11/
/etc/X11/Xsession.d/70im-config_launch
/etc/X11/app-defaults/KOI8RXTerm-color
/etc/X11/app-defaults/XTerm-color
/etc/X11/app-defaults/UXTerm-color
/etc/X11/app-defaults/XTerm
/etc/X11/Xsession
/etc/X11/Xwrapper.config
/etc/X11/rgb.txt
xargsとlsを使いタイムスタンプでソートしてみます。
** ls -lt [#befc566a]
tオプションでタイムスタンプでソートしています。
sakura@hpmini:~$ grep -ilr debian /etc/X11/ | xargs ls -lt
-rw-r--r-- 1 root root 601 11月 25 20:59 /etc/X11/Xwrapper.config
-rw-r--r-- 1 root root 6217 3月 1 2015 /etc/X11/app-defaults/KOI8RXTerm-color
-rw-r--r-- 1 root root 6209 3月 1 2015 /etc/X11/app-defaults/UXTerm-color
-rw-r--r-- 1 root root 10201 3月 1 2015 /etc/X11/app-defaults/XTerm
-rw-r--r-- 1 root root 6207 3月 1 2015 /etc/X11/app-defaults/XTerm-color
-rw-r--r-- 1 root root 1497 3月 30 2014 /etc/X11/Xsession.d/70im-config_launch
-rwxr-xr-x 1 root root 3517 9月 26 2013 /etc/X11/Xsession
-rw-r--r-- 1 root root 17394 9月 26 2013 /etc/X11/rgb.txt
** ls -ltr [#t3055508]
rオプションを追加しリバース(r)で表示した例です。
sakura@hpmini:~$ grep -ilr debian /etc/X11/ | xargs ls -ltr
-rw-r--r-- 1 root root 17394 9月 26 2013 /etc/X11/rgb.txt
-rwxr-xr-x 1 root root 3517 9月 26 2013 /etc/X11/Xsession
-rw-r--r-- 1 root root 1497 3月 30 2014 /etc/X11/Xsession.d/70im-config_launch
-rw-r--r-- 1 root root 6207 3月 1 2015 /etc/X11/app-defaults/XTerm-color
-rw-r--r-- 1 root root 10201 3月 1 2015 /etc/X11/app-defaults/XTerm
-rw-r--r-- 1 root root 6209 3月 1 2015 /etc/X11/app-defaults/UXTerm-color
-rw-r--r-- 1 root root 6217 3月 1 2015 /etc/X11/app-defaults/KOI8RXTerm-color
-rw-r--r-- 1 root root 601 11月 25 20:59 /etc/X11/Xwrapper.config
以上、findとgrepのファイル一覧をファイルのタイムスタンプでソートして表示する方法でした。
#htmlinsertpcsp(linux_ads_btm.html,linux-sp.html)