我如何可以格式化统计前pression在Linux的Gnome终端输出? [英] How can i format the output of stat expression in Linux Gnome Terminal?

查看:143
本文介绍了我如何可以格式化统计前pression在Linux的Gnome终端输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的在Linux操作系统(Fedora的-20)的新手,我想学习基础知识
我有以下命令

I am really newbie in Linux(Fedora-20) and I am trying to learn basics I have the following command

echo "`stat -c "The file "%n" was modified on ""%y" *Des*`"

此命令返回我这个输出

The file Desktop was modified on 2014-11-01 18:23:29.410148517 +0000

我想把它格式化为这样的:

I want to format it as this:

The file Desktop was modified on 2014-11-01 at 18:23

我怎样才能做到这一点?

How can I do this?

推荐答案

您不能真正做到这一点与与stat (除非你有<$ C的智能版$ C>统计我不知道的)。

You can't really do that with stat (unless you have a smart version of stat I'm not aware of).

很可能,你的日期足够聪明和处理 -r 开关。

Very likely, your date is smart enough and handles the -r switch.

date -r Desktop +"The file Desktop was modified on %F at %R"

由于您的水珠的,你需要一个循环来处理所有匹配的文件 *德* (Bash中):

Because of your glob, you'll need a loop to handle all files that match *Des* (in Bash):

shopt -s nullglob
for file in *Des*; do
    date -r "$file" +"The file ${file//%/%%} was modified on %F at %R"
done

使用找到

很可能你的找到具有丰富的 -printf 选项:

find . -maxdepth 1 -name '*Des*' -printf 'The file %f was modified on %TY-%Tm-%Td at %TH:%TM\n'

我要使用统计

(因为你的日期不处理的 -r 开关,你不希望使用找到或只是因为你喜欢用,因为大多数工具可以即时preSS你妹妹)。那么,在这种情况下,最安全的做法是:

I want to use stat

(because your date doesn't handle the -r switch, you don't want to use find or just because you like using as most tools as possible to impress your little sister). Well, in that case, the safest thing to do is:

date -d "@$(stat -c '%Y' Desktop)" +"The file Desktop was modified on %F at %R"

和与水珠的要求(Bash中):

and with your glob requirement (in Bash):

shopt -s nullglob
for file in *Des*; do
    date -d "@$(stat -c '%Y' -- "$file")" +"The file ${file//%/%%} was modified on %F at %R"
done

这篇关于我如何可以格式化统计前pression在Linux的Gnome终端输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆