2014-04-03 12:45:56 +0000 2014-04-03 12:45:56 +0000
166
166

Linuxでファイルの最終更新日を取得する

Linux初心者です。私はコマンドラインを使用しています。ファイルの最終更新日を表示しようとしています。Linuxでコマンドラインからそれを行うにはどうすればいいですか?

回答 (7)

147
147
147
2015-09-21 10:22:09 +0000

最初はModifyChangeと混同していましたが、はっきりさせるために、statの出力は以下のようなリストになっています。 - Modifyは最後のデータの修正の時間を示しています。 - Changeはファイルの状態が最後に変更された時間を示しています。

例えば:

~ $ touch foo
~ $ stat foo
File: ‘foo’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fc01h/64513d Inode: 410397 Links: 1
Access: (0644/-rw-r--r--) Uid: (80972/ etomort) Gid: (18429/ eem_tw)
Access: 2015-09-21 12:06:11.343616258 +0200
Modify: 2015-09-21 12:06:11.343616258 +0200
Change: 2015-09-21 12:06:11.343616258 +0200
Birth: -

~ $ echo "Added bar to foo file" >> foo
~ $ stat foo
File: ‘foo’
Size: 42 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 410654 Links: 1
Access: (0644/-rw-r--r--) Uid: (80972/ etomort) Gid: (18429/ eem_tw)
Access: 2015-09-21 12:09:31.298712951 +0200
Modify: 2015-09-21 12:09:31.298712951 +0200
Change: 2015-09-21 12:09:31.302713093 +0200
Birth: -

~ $ chmod 444 foo
~ $ stat foo
File: ‘foo’
Size: 42 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 410654 Links: 1
Access: (0444/-r--r--r--) Uid: (80972/ etomort) Gid: (18429/ eem_tw)
Access: 2015-09-21 12:09:31.298712951 +0200
Modify: 2015-09-21 12:09:31.298712951 +0200
Change: 2015-09-21 12:10:16.040310543 +0200
Birth: -
69
69
69
2014-04-03 12:47:41 +0000

そのためには stat コマンドを使用します:

$ stat file
40
40
40
2017-08-31 01:04:43 +0000

より柔軟性の高いもう一つの方法は、date -rを使用することです。007から:

-r, --reference=FILE
       display the last modification time of FILE

これは、出力形式を指定できるという利点があります。

17
17
17
2015-11-16 05:43:54 +0000

ls -lは仕事をするべきです。

例:

#> ls -l /home/TEST/
total 16

-rw-r--r-- 1 rfmas1 nms 949 Nov 16 12:21 create_nd_lists.py

-rw-r--r-- 1 rfmas1 nms 0 Nov 16 12:35 enb_list

-rw-r--r-- 1 rfmas1 nms 0 Nov 16 12:35 nb_list

-rw-r--r-- 1 rfmas1 nms 0 Nov 16 12:35 nodes_ip.txt

-rw-r--r-- 1 rfmas1 nms 0 Nov 16 12:35 rnc_list
3
3
3
2019-08-14 16:24:39 +0000

Building off of @Adam Taylor ‘s comment in @phoops ’s answer and @Sparhawk ’s answer.

具体的にjust get the date (それは私の最後の誕生日だったので、例として2019年10月3日を使用して、あなたが金銭的に私を祝福するために導かれたと感じた場合は、ここに私のvenmoがあります。@levi_uzodike)

  • stat -c %y file | cut -d' ' -f1 will give you 2019-10-03
  • date +%F -r file will also give you 2019-10-03
  • date +%D -r file will give you 10/03/19
  • date +%x -r file will give you 10/03/2019
  • 10/03/19 will probably give either 03/10/2019, or 03/10/19 if you’re in the U.S. and either date, or `%’: > > - (hyphen) do not pad the field
    > _ (underscore) pad with spaces
    > 0 (zero) pad with zeros
    > ^ use upper case if possible
    > # use opposite case if possible

N.B.: These flags don’t work on the “combo formats” like if you're in the U.K.。これらの, ` フォーマットオプションは、私の理解では、他のフォーマットオプションを組み合わせたものです。以下は man ページ の説明です:

%b ロケールの短縮形の月名 (例: Jan) %B ロケールの完全な月名 (例: January) … 1月) … %d day of month (例: 01) %D date; same as %m/%d/%y %e day of month, space padded; same as %%d %F full date; same as %Y-%m-%d … %m month (01…12) … %x locale’s date representation (例: 12/31/99) %x ロケールの日付表現 (例: 12/31/99) %x ロケールの日付表現 (例: 12/31/99) %x ロケールの日付表現 (例: 12/31/99) %x ロケールの日付表現 (例: 12/31/99) 12/31/99) … %y 年の下二桁 (00…99) %Y 年 … デフォルトでは、日付は数値フィールドにゼロを入れます。
以下のオプションフラグが続く可能性があります。+%#Panddate +%P`. They are for the “singular field formats”.

Apparently this last flag ( # ) does not work as I’d expect (e.g., if PM gives AM, PM gives AM as opposed to date +%P) I guess this would be useless, but I’d think a lower case option would be more useful. PMdoes turn AM which might give date +%^P or date +%#P into %P or %P, respectively. So I guess it’s not a ‘per-character’ case switch but sets the case of all the characters in the string to the opposite case of the majority of the characters? Also %#P gives date +%0-。 e or date +%-e, but neither 3 nor date +%-0e change its output. My guess for this case is that date +%0e is just an alias for 03, and it seems that whenever you add more than one flag, the behavior is undefined/unpredictable ( e.g., date +%#^p gives the same as date +%^#p: pm and am gives the same as `locale -k LCTIME | grep ^dfmt:dfmt=“%m/%d/%Y”, which makes you think that only the flag next to the letter works or that it goes left to right, but bothdate +%^b %-e %-e %\%Y -r fileandOCT 3 2019`.

2
2
2
2017-01-06 10:08:23 +0000

ファイルが別のウェブサーバにある場合、私は httpie docs ) が好きです。

インストール

pip install httpie --user

使用法

-h コマンドはヘッダのみを与えます。パターンは

http -h [url] | grep 'Last-Modified\|Date'

例:

$ http -h https://martin-thoma.com/author/martin-thoma/ | grep 'Last-Modified\|Date'
Date: Fri, 06 Jan 2017 10:06:43 GMT
Last-Modified: Fri, 06 Jan 2017 07:42:34 GMT

この Date は、ローカルタイムではなくサーバータイムを報告するために重要です。また、すべてのサーバが Last-Modified を送信するわけではありません (例: スーパーユーザは送信しないようです)。

2
2
2
2018-11-14 04:22:35 +0000

ファイルをリストアップし、最終更新日時を表示する

ファイルをリストアップし、最終更新日時をトップに表示するには、-ltのオプションを使って、lsコマンドを使用します。

関連する質問

6
10
7
5
13