可能的重复:
如何执行 ls 然后按创建日期对结果进行排序?
Linux 中是否有显示文件创建时间的命令?我看到ls -l
给出了上次修改时间,但是我可以获得创建的时间/日期吗?
日期按什么顺序排列?当然不是字母数字顺序。
ls -lt
按修改时间排序。但我需要创作时间。
我想找出特定文件的创建日期,而不是修改日期或访问日期。
我已经尝试过ls -ltrh
和stat filename
。
我刚刚阅读了 的Birth
部分,stat
似乎 ext4 应该支持它,但即使是我刚刚创建的文件也将其留空。
~ % touch test slave-iv
~ % stat test.pl slave-iv
File: ‘test.pl’
Size: 173 Blocks: 8 IO Block: 4096 regular file
Device: 903h/2307d Inode: 41943086 Links: 1
Access: (0600/-rw-------) Uid: ( 1000/xenoterracide) Gid: ( 100/ users)
Access: 2012-09-22 18:22:16.924634497 -0500
Modify: 2012-09-22 18:22:16.924634497 -0500
Change: 2012-09-22 18:22:16.947967935 -0500
Birth: -
~ % sudo tune2fs -l /dev/md3 | psp4 slave-iv
tune2fs 1.42.5 (29-Jul-2012)
Filesystem volume name: home
Last mounted on: /home
Filesystem UUID: …
Run Code Online (Sandbox Code Playgroud) 如何编写一个脚本来将 20 个最旧的文件从一个文件夹移动到另一个文件夹?有没有办法抓取文件夹中最旧的文件?
有什么历史原因吗?Stat
存储上次访问时间、上次修改时间和上次更改时间,但不存储创建时间!是不是很重要的信息。
我不明白为什么开发人员会遗漏这么重要的信息。一些文件系统确实存储了数据,正如这个问题中所指出的。但显然,这些信息的重要性被淡化了。为什么会这样?
笔记:
stat -c %W <filename>
Run Code Online (Sandbox Code Playgroud)
在我的系统中返回 0 (fedora 22)。
我复制了一些目录,-a
以便preserve=all
我理解其中包括创建时间:
cp -a ./* /mnt/destination/\n
Run Code Online (Sandbox Code Playgroud)\n检查目标中的结果目录时,它们的创建时间都设置为当前时间,而它们的内容似乎保留了它们的创作时间。
为什么不是创建日期顶层目录保留吗?
源是 HFS+,目标是 btrfs。
\n目的地和来源的目录列表摘录:
\n$ ls -hal --time=creation\ntotal 16K\ndrwxrwxr-x 1 andreas andreas 74 sep 2 23:25 .\ndrwx------ 1 andreas andreas 310 apr 26 17:08 ..\ndrwx------ 1 andreas andreas 2,3K sep 2 23:45 Library\n\n$ ls -hal --time=creation /mnt/source\ntotal 8,1M\ndrwxrwxr-x 1 andreas andreas 15 mar 28 2022 .\ndrwxr-x---+ 3 root root 4,0K aug 9 2022 ..\ndrwx------ 1 andreas andreas 95 apr …
Run Code Online (Sandbox Code Playgroud) 我的目标是在目录中获取当月创建的文件。
该命令似乎是正确的,但没有呈现任何结果:
Date=`date '+%b'`
echo $Date
Oct
ls -l | awk -v d="$Date" '/d/ {print $NF}'
Run Code Online (Sandbox Code Playgroud) 我正在尝试检查特定文件是否存在(但仅当存在时间少于 24 小时时),如果存在,则执行第二次检查以查看名称以“.control”结尾的文件是否存在。如果满足这两个条件,则创建电子邮件和日志条目。如果第一个文件存在但 .control 不存在,则创建一个不同的日志条目。如果不到 24 小时的文件不存在,则继续执行脚本的其余部分。
这是在 Solaris 和 Linux 上使用 Bash 从 cron 启动的 shell 脚本中。
if [ find "$MAINTENANCE_LOCK/testLOCK" -mtime -1 ]; then
if [ -f "$PATH_TO_TRIGGER_FILES/*.control" ]; then
test_log_msg "test_SYSTEM" $NOTICE "Valid Maintenance Lock file found, test actions blocked." "status"
test_log_email " " " " " " "test Actions were blocked because an testLOCK file less than 24hrs old is in place." " "
else
test_log_msg "test_SYSTEM" $NOTICE "Valid Maintenance Lock file in place." "status"
exit …
Run Code Online (Sandbox Code Playgroud)