• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
OpenTechTips

OpenTechTips

Comprehensive IT Guides for Pros and Enthusiasts

MENUMENU
  • HOME
  • ALL TOPICS
    • Exchange
    • InfoSec
    • Linux
    • Networking
    • Scripting
      • PowerShell
    • SSL
    • Tools
    • Virtualization
    • Web
    • Windows
  • ABOUT
  • SUBSCRIBE
Home » Use the ls command to list only a directory, NOT it’s contents in Linux

Use the ls command to list only a directory, NOT it’s contents in Linux

June 28, 2021 - by Zsolt Agoston - last edited on May 1, 2025

Directory Info vs Directory Contents

In bash when using the ls command to list the content of the filesystem the shell behaves in a quite annoying way: when specifying a directory to be shown, the command instead of showing information about the directory itself (permissions, timestamp info, etc) it shows the content of the directory.

For instance here we try to get the info about the '/var/log' directory:

# 'll' is an alias for 'ls -lah'
# so feel free to use 'ls -lah /var/log' instead

user@TC21:/$ ll /var/log
total 332
drwxrwxr-x 1 root      syslog             512 Jun  4 00:09 ./
drwxr-xr-x 1 root      root               512 Jun  3 23:41 ../
-rw-r--r-- 1 root      root               434 Jun  4 00:09 alternatives.log
drwxr-xr-x 1 root      root               512 Jun  4 00:09 apt/
-rw-rw---- 1 root      utmp                 0 Jun  3 23:41 btmp
drwxr-xr-x 1 root      root               512 May 14 01:38 dist-upgrade/
-rw-r--r-- 1 root      root             41015 Jun  4 00:09 dpkg.log
drwxr-sr-x 1 root      systemd-journal    512 Jun  3 23:39 journal/
drwxr-xr-x 1 landscape landscape          512 Jun 28 18:21 landscape/
-rw-rw-r-- 1 root      utmp            292292 Jun 28 18:21 lastlog
drwxr-x--- 1 root      adm                512 Jul 21  2020 unattended-upgrades/
-rw-rw-r-- 1 root      utmp                 0 Jun  3 23:41 wtmp
user@TC21:/$

 

List Only the Directory Itself

To list information only about the directory in question (in our example /var/log), use the '-d' switch with the ls command

# List directory info
user@TC21:/$ ll -d /var/log
drwxrwxr-x 1 root syslog 512 Jun  4 00:09 /var/log

# If the 'll' alias is not set for you, use the 'ls -lah' command itself instead
user@TC21:/$ ls -lahd /var/log
drwxrwxr-x 1 root syslog 512 Jun  4 00:09 /var/log

 

 

Reader Interactions

Comments Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tools

Secondary Sidebar

CONTENTS

  • Directory Info vs Directory Contents
  • List Only the Directory Itself

  • Terms of Use
  • Disclaimer
  • Privacy Policy
Manage your privacy

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}
Manage your privacy
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}