简体   繁体   English

用于列出符号链接,目标和目标日期的单行Linux命令?

[英]Single-line Linux command to list symlinks, targets and target dates?

Is there a way I can generate a list of symlinks in a directory that includes the target's date, symlink's name and the target's name separated by a specified delimiter? 有没有办法可以在目录中生成一个符号链接列表,其中包含目标的日期,符号链接的名称和由指定的分隔符分隔的目标名称?

Either of these gives me only the target date and link name: 这些中的任何一个都只给我目标日期和链接名称:

find -L /path/to/dir/* -printf "%TY%Tm%Td%TH%TM%TS|%p\\n"

ls -lH /path/to/dir/*

This... 这个...

find /path/to/dir/* -printf "%TY%Tm%Td%TH%TM%TS|%p|%l\\n"

...I get the link date, link name and target name. ...我得到链接日期,链接名称和目标名称。 %l returns nothing if I include the `-L' parameter, I guess because I guess it loses it's reference when it follows the link. 如果我包含`-L'参数, %l将不返回任何内容,我猜是因为我猜它在链接后面会丢失它的引用。

How can get the link date , link name and target name from a one line command? 如何从一行命令中获取链接日期链接名称目标名称

You could use the -exec switch of find to execute another command (like stat ) on the results making it possible to get properties of the target files. 您可以使用find-exec开关在结果上执行另一个命令(如stat ),从而可以获取目标文件的属性。

Example: 例:

find /path/to/dir/* -printf "%T@|%p|%l" -exec stat -Lc "|%Y.0000000000" {} \\;

This should output something like: 这应该输出如下:

Link Date|Link Name|Target Name|Target Date

You might want to play around with the date format strings to make the dates more human readable. 您可能想要使用日期格式字符串来使日期更具人性化。

This is the final command I'm using, thanks largely to rc0r : 这是我正在使用的最后一个命令,主要归功于rc0r

find /path/to/files/* -printf "%TY%Tm%Td%TH%TM%TS|%p|%l" -exec stat -Lc "|%y" {} \\; | sed -r "s/(.*\\|)([0-9]{4})\\-([0-9]{2})\\-([0-9]{2}) ([0-9]{2})\\:([0-9]{2})\\:([0-9]{2}\\.[0-9]{9}).*/\\1\\2\\3\\4\\5\\6\\7/g"

Augmentations to r0cr's command: r0cr命令的扩充:

  1. Formatted find -printf to give human-readable timestamp instead of Unix timestamp 格式化find -printf以提供人类可读的时间戳而不是Unix时间戳
  2. Used %y instead of %Y in stat to give human-readable timestamp instead of Unix timestamp stat使用%y而不是%Y来提供人类可读的时间戳而不是Unix时间戳
  3. Piped sed to strip extraneous characters from human-readable timestamp output by stat Piped sed通过stat从人类可读的时间戳输出中删除无关字符

This gives me: 这给了我:

SymlinkDate|SymlinkPath|TargetPath|TargetDate

The dates are in human readable format: YYYYMMDDHHMMSS.mmmmmmmmm 日期采用人类可读的格式: YYYYMMDDHHMMSS.mmmmmmmmm

I don't imagine having sed all those back refrences is the most efficient method of stripping chars out of the target date, but I couldn't figure out any other regexp for extracting only [0-9\\.]. 我不想象一下, sed所有回refrences是剥离出字符的目标日期的最有效的方法,但我想不出任何其他的正则表达式只提取[0-9 \\。]。 Efficiency isn't terribly important for this particular implementation. 对于这种特定的实施,效率并不是非常重要。

Thank-you! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM