Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6778191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:14:17+00:00 2026-05-26T16:14:17+00:00

I need to know how what command or commands I can use in a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:14:17+00:00Added an answer on May 26, 2026 at 4:14 pm

    The base command you want to use is ls -l but 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:

    #!/usr/bin/bash
    tmpfile=/tmp/tmpfile.$$
    ls -l | tee ${tmpfile}
    echo
    echo "Total bytes:" $(awk '{sum += $5} END {print sum}' ${tmpfile})
    echo "Total files:" $(grep -v '^total ' ${tmpfile} | grep -v '^d' | wc -l)
    echo "Directories:" $(grep -v '^total ' ${tmpfile} | grep '^d' | wc -l)
    echo "And scripts:" $(grep -v '^total ' ${tmpfile} | grep '^-..x' | wc -l)
    rm -f ${tmpfile}
    

    which outputs:

    total 1589
    -rwxr-xr-x   1 pax root      57 Oct  3 14:24 Cygwin.bat
    -rw-r--r--   1 pax root    7022 Oct  3 14:24 Cygwin.ico
    drwxr-xr-x+  1 pax root 1048576 Oct  3 14:20 bin
    dr-xr-xr-x   4 pax None       0 Nov  3 17:06 cygdrive
    drwxrwxr-x+  1 pax None       0 Oct  3 14:05 dev
    drwxr-xr-x+  1 pax root   32768 Oct  3 14:20 etc
    drwxrwxrwt+  1 pax root       0 Oct  3 14:13 home
    drwxr-xr-x+  1 pax root  524288 Oct  3 14:19 lib
    drwxr-xr-x+  1 pax root       0 Oct  3 13:35 opt
    dr-xr-xr-x  10 pax None       0 Nov  3 17:06 proc
    drwxr-xr-x+  1 pax root       0 Oct  3 13:59 sbin
    drwxr-xr-x+  1 pax None       0 Oct  3 14:10 srv
    drwxrwxrwt+  1 pax root    4096 Nov  3 17:06 tmp
    drwxr-xr-x+  1 pax root    4096 Oct  3 14:10 usr
    drwxr-xr-x+  1 pax root    4096 Oct  3 14:20 var
    
    Total bytes: 1624999
    Total files: 2
    Directories: 13
    And scripts: 1
    

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to know this so that i could send DTMF and that is going
I need to have a command handler for a ToggleButton that can take multiple
I need to be able to handle data that can look like: set setting1
Possible Duplicate: Deflate command line tool Yes, I know I can use PHP itself
I don't really know that much about bash scripts OR imagemagick, but I am
I need to know how we can control the environment setting in the application
What command line util can i use to create a thumbnail preview of a
who can give me a short example where i call some system command and
I would like to implement what I know as a CVAR System, I'm not
I need to execute some periodic console applications that give me some results (on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.