Do not create a "ls-based" alias. ls
just does not do what you are asking for. This is the job of stat
.
If you don't like the stat
command, you can call the stat()
function directly:
#include <stdio.h>
#include <sys/stat.h>
int main(int argc, char *argv[]) {
int i;
struct stat st;
for (i = 1; i < argc; i++) {
if (stat(argv[i], &st) < 0)
perror("stat");
else
printf("%06o %s\n", st.st_mode, argv[i]);
}
return 0;
}
#!/usr/bin/env perl
printf("%06o %s\n", (stat($_))[2], $_) for @ARGV
#!/usr/bin/env ruby
ARGV.each do |f|
printf "%06o %s\n", File::stat(f).mode, f
end
#!/usr/bin/env python
import os, sys
for f in sys.argv[1:]:
sys.stdout.write("%06o %s\n" % (os.stat(f).st_mode, f))
#!/usr/bin/env php
<?php
for ($i = 1; $i < $argc; $i++)
printf("%06o %s\n", fileperms($argv[$i]), $argv[$i]);
#!/usr/bin/env tclsh
foreach file $argv {
file stat $file st
puts [format "%06o %s" $st(mode) $file]
}
Well, that's pretty thorough. I guess I was hoping to find an easy way to reproduce the output of ls -la with only 1 difference: print permissions in octal instead of the rwxr--r-- format. – ashr – 2011-11-22T05:13:32.773
@ashr: Then that's what you should have written in your post. – user1686 – 2011-11-22T07:51:15.857