문제

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.

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.

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:

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:

  1. Formatted find -printf to give human-readable timestamp instead of Unix timestamp
  2. Used %y instead of %Y in stat to give human-readable timestamp instead of Unix timestamp
  3. Piped sed to strip extraneous characters from human-readable timestamp output by stat

This gives me:

SymlinkDate|SymlinkPath|TargetPath|TargetDate

The dates are in human readable format: 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\.]. Efficiency isn't terribly important for this particular implementation.

Thank-you!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top