I am currently trying to use the "find" command with symbollic links created by a tcl script that are pointing at another file in another directory (RH5). My script is written in bash, however:

find /home/directory/subdirectory -name *.gz -type f -printf '%T@ %p\n' | sort -n | tail -n 1 | awk'{print $1}'

I use this as my go to line to find the epoch time of the latest file that populated the directory given the search criteria that I can change as I need. For some reason, it doesn't work with link files. It returns no results.

I know rubberman will probably answer first lol.

Recommended Answers

All 2 Replies

:-) LOL! Correct! ... You need to use the -L option with find to follow symbolic links. From the "find" man page:

        -L     Follow  symbolic links.  When find examines or prints information about files, the information used shall be taken
              from the properties of the file to which the link points, not from the link itself (unless it is a broken symbolic
              link or find is unable to examine the file to which the link points).  Use of this option implies -noleaf.  If you
              later use the -P option, -noleaf will still be in effect.  If -L is in effect and find discovers a  symbolic  link
              to a subdirectory during its search, the subdirectory pointed to by the symbolic link will be searched.

              When  the  -L  option is in effect, the -type predicate will always match against the type of the file that a sym-
              bolic link points to rather than the link itself (unless the symbolic link is broken).  Using -L causes the -lname
              and -ilname predicates always to return false.

Well I just changed the line to this:

1.find /home/directory/subdirectory -name *.gz -type l -printf '%T@ %p\n' | sort -n | tail -n 1 | awk'{print $1}' 

And now it works. I thought the l behind "-type" should be uppercase; that is not the case here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.