Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
开发者_运维百科 Improve this questionI want to fetch all the file information viz: "permission","hardlink","owner","group","fsize","month","date","time","filename"
and
MD5 Sum information in one line command. How can I do this?
currently I get the 1st one by running ls -latr /home/asimon
and 2nd 1 by md5sum /home/asimon/filename.sh
(it fetches me info for only 1 file) but instead i want all the information like below
drwxr-xr-x 2 asimon support 4096 Sep 27 11:59 lib de1d8cd98f00b204e9800998ecf842qw
-rwxrwxrwx 1 asimon support 924 Sep 27 12:00 run.sh dqtd8cd98f00b204e9800998ecf84a7a
drwxr-xr-x 6 asimon support 4096 Sep 27 18:13 plugins d41d8cd98f00b204e9800998ecf8427s
-rw-r--r-- 1 asimon support 2572 Sep 28 10:06 servicesFramework.log d51d8cd98f00b204e9800998ecf8427f
you can do it with find very easily:
find . -printf "%m %n %u %g %s %t" -exec md5sum \{\} \;
Instead of the printf and the options you could also do a -ls
but that would print the file name twice (and the ouput from md5sum delimited with a newline char)
Looks rather clumsy, but here you go:
ls -lAtr /home/asimon |grep -v total|awk '{printf($ARGV[1]);printf(" ");system("md5sum $9");}'|tr -d "-"
[EDIT]
note the upper case A
in the ls command
[EDIT2 and 3] Upated command, not spoiling the '-' characters in file names:
ls -lAtr /home/asimon|egrep -v "^d|total"|awk '{printf($ARGV[1]);printf(" ");system("md5sum $9");}'|awk '{$11="";print $ARGV[1]}'
One of the many ways would be to use a for
loop as follows:
for ls_entry in `ls`;do [ -f $ls_entry ] && ls_out=`ls -alth $ls_entry` && md5_out=`md5sum $ls_entry|awk '{print $1}'` && echo "$ls_out $md5_out"; done
Hope this helps!
try: ls -latr /home/asimon; md5sum /home/asimon/*
the semicolon lets you do two commands on one line, and the * will run md5sum for everything in that directory.
精彩评论