I want to find file with specific pattern and print the latest file matching the pattern with full pathfind ../*.gz -type f -print0 | sort -nr | cut -d: -f2- | head -n 1How do I print the full path of the same.As requested by users ls -l:ls -ldrwxrwxr-x 3 xxx xxx 4096 Jun 27 23:29 fa1caae85drwxrwxr-x 3 xxx xxx 4096 Jun 27 23:28 ga1c93edadrwxrwxr-x 3 xxx xxx 4096 Jun 27 23:28 la1cbbh05drwxrwxr-x 3 xxx xxx 4096 Jun 27 23:08 node_modulesdrwxrwxr-x 3 xxx xxx 4096 Jun 27 23:08 _tasksAll top three folders contains require .gz files, however I want to get latest .gz file out of them.
Find files with pattern and get latest one
find;filenames
You can do that by using this command,find $(pwd) -type f -name *.gz -printf %T@ %p\n| sort -n | cut -d' ' -f 2 | tail -n 1