I need to know how what command or commands I can use in a bash script that would give me a directory listing like this (note the extra lines at the end).
total 24
drwxr-xr-x 2 dshoe users 4096 2010-10-28 18:41 backups
drwxr-xr-x 2 dshoe users 4096 2010-10-28 18:41 bin
drwxr-xr-x 2 dshoe users 4096 2010-10-28 18:41 c_source
drwxr-xr-x 2 dshoe users 4096 2010-10-28 18:41 cgi_files
drwxr-xr-x 2 dshoe users 4096 2010-10-28 18:41 cgi_scripts
drwxr-xr-x 4 dshoe users 4096 2010-10-28 18:41 ny
drwxr-xr-x 2 dshoe users 4096 2010-10-28 18:41 perl
-rw-r--r-- 1 dshoe users 1954 2010-10-28 18:41 pers
drwxrwxrwx 2 dshoe users 4096 2010-10-28 18:41 public_html
-rw-r--r-- 1 dshoe users 3392 2010-10-28 18:41 sales
-rwxr--r-- 1 dshoe users 228 2010-10-28 18:41 sargs
drwx------ 2 dshoe users 4096 2010-10-28 18:41 scripts
-rw-r--r-- 1 dshoe users 131 2010-10-28 18:41 setup
Total bytes: 17899
Total files: 4
Directories: 9
And scripts: 1
The standard ls command cannot do this so I’m wondering what I can use in my bash script to achieve this.
The base command you want to use is
ls -lbut you’re going to need to post-process the output to get those last four lines.For example, here’s one that will get you the first three items plus the fourth which I’ve assumed is the number of regular files with the execute bit set for the owner:
which outputs:
However, I’m not entirely sure how you’re deciding what a script is. If it’s different to what I assumed, it’s still doable, you just have to figure out what the actual command is (tell us what you want to measure to get the value).