gpt4 book ai didi

shell - 在shell脚本中打印文件时间

转载 作者:行者123 更新时间:2023-12-04 17:20:50 24 4
gpt4 key购买 nike

我正在尝试使用以下 shell 脚本打印所有文件的时间。但我发现并不总是 42 到 46 字节是时间,因为它会因用户名和其他详细信息中的更多/更少字节而发生变化。还有其他获取时间的方法吗?

#!/bin/sh
for file in `ls `
do
#echo `ls -l $file`
echo `ls -l $file | cut -b 42-46`
done

最佳答案

使用 awk。

试试 ls -l | awk '{ 打印 $6 $7 $8}'

这将打印 ls -l 的第 6、7 和 8 字段,并用空格分隔

如果字段不同,您可以更改数字以调整哪些字段。

关于shell - 在shell脚本中打印文件时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12274255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com