The problem you're having isn't a shell issue. It's that your find
commands aren't compatible.
I am guessing that you are running Bash on a Linux box, and Kornshell on Solaris. The problem is that your Linux box has the GNU version of the find
command which has things like the -printf
parameter while the find
command on your other system does not because it's using the BSD or AT&T Unix version of the command.
What you need to do is to use your system's stat
command to pull the information you want from the file:
find "/path/to/pdfs/" -type f -name "$1*.pdf" -exec stat ??? {}\; | sort ...
The problem is I don't know the format of the stat command. Unfortunately, this command varies from system to system. It looks like you're creating a sorting modification date according to the GNU documentation on the find time directives. Here's an equivalent on my Mac running Mavericks:
find "/path/to/pdfs/" -type f -name "$1*.pdf" -exec stat -f "%10Dm %SN" {}\; | sort ...
The -f
parameter specifies a format on how stat will print its information. The "%10Dmspecifies 10 decimal digits (
D) of the modification time
m. The
%SN` specifies the file's name in string format. This prints the date as the number of seconds from the Epoch (usually Jan 1, 1970).
In your original sort, you were specify each and every field of the date time stamp (which wasn't really necessary, so your sort
will be simpler:
find "/path/to/pdfs/" -type f -name "$1*.pdf" -exec stat -f "%10Dm %SN" {}\; \
| sort -k1,1n -k2,2
Unfortunately, that doesn't print out the time in a nice neat format like you want. So, we'll strip off the file name after the sort and pass that through stat
again printing the file
find "/path/to/pdfs/" -type f -name "$1*.pdf" -exec stat -f "%10Dm %SN" {}\; \
| sort -k1,1n -k2,2 sed 's/.* //'
| while read file
do
stat "%-22.22Sm %N" $file
done
This will print out your files as:
Dec 12 15:38:43 2013 /path/to/pdfs/list1.pdf
Not exactly the same, but it's close. Actually, on my Mac, I can take the numeric output of the date from the first stat command, and convert it into the date string in the exact format you want.
Unfortunately, this particular feature of the date command has the same problem as the -printf
parameter in the find
: It's machine specific, so it doesn't work on Linux.