printf '%o', (stat $filename)[2] & 07777; # Updated: Thanks to [duff] $unixmode = (stat $filename)[2] & 07777; # Updated. One too few 7s.