Score:-4

General question about ls -d

ga flag

When I run the command ls -d, I just see a dot, nothing else.

It is always the same wherever I am. What does that mean? What does Linux show me here?

I use a RHEL 8.6, but it is relevant for all linux systems I guess.

Pilot6 avatar
cn flag
You didn't tell what sort of "linux" you are using. Output of comannds depends on a used shell.
Artur Meinild avatar
vn flag
Why the close votes? Question is rather easy to answer if you know a bit about the Linux filesystem, which is also applicable for Ubuntu.
Pilot6 avatar
cn flag
@ArturMeinild It has nothing to do with the Linux filesystem. It can also work on NTFS, HFS+, etc. Close votes are probably because OP didn't mention OS at all.
Pilot6 avatar
cn flag
RHEL is off-topic here. This is AskUbuntu, not a generic Linux site. There is [linux.se]
guiverc avatar
cn flag
Please refer https://askubuntu.com/help/on-topic, Ubuntu and official *flavors* of Ubuntu (https://ubuntu.com/download/flavours) are on-topic on this site. The on-topic link provides alternate SE sites for non-Ubuntu OSes.
Score:1
cn flag

First of all it is not Linux you are sending commands to. You are running /usr/bin/ls. This program can be used with other OS's on any sort of filesystem.

ls -d lists directories.

If you run ls -d without arguments, it outputs . that means the current directory.

If you run e.g. ls -d ~, it will show the path to your Home directory.

If you run ls -d ~/*, you'll see a list of all directories in your $HOME.

The confusing part is that ls -d gives the path of the directory used as an argument, not the contents of it. If you don't use globs, it is almost useless.

It can be used to output a full path to a directory, e.g.

pilot6@Pilot6:~$ ls -d ~
/home/pilot6
Tricia279 avatar
ga flag
Understood the argument was missing
Score:1
vn flag

In most Unix/Linux filesystems (and represented through the shell), the single dot . represents your current directory (see here).

Also, from man ls:

   -d, --directory
          list directories themselves, not their contents

This means if you run ls -d in any directory (which indicated by .), the command just outputs this single dot. No need to say this command is rather useless.

A valid use for ls -d would be to use it combined with other options, and on another directory, like:

ls -lad /usr/bin/

This would display some more properties for the directory /usr/bin itself.

Pilot6 avatar
cn flag
It is not "In the Unix/Linux filesystem" it is in bash or similar shell.
Tricia279 avatar
ga flag
Understood the argument was missing
mook765 avatar
cn flag
@Pilot6 `.` is a hardlink, so it is part of the filesystem. Why should `ls` display something shell-specific if I ask for directory properties? The relativ path to the current directory is `.`.
Pilot6 avatar
cn flag
@mook765 Because `ls` is a SHELL command it is shell-specific.
Artur Meinild avatar
vn flag
@Pilot6 no it isn't. `type ls` -> `ls is /usr/bin/ls`. `type cd` -> `cd is a shell builtin`
mook765 avatar
cn flag
@Pilot6 You wrote `It is not "In the Unix/Linux filesystem" `, but it is, since `.` is a hardlink. I doubt that hardlinks are stored in a shell.
Pilot6 avatar
cn flag
@ArturMeinild OK. `ls` isn't a shell command, it is separate app.
Score:0
ag flag

Your best bet for questions like these is to simply read the manual.

You can do this by typing the command man in the command line or just Google it.

In that case man ls

For the option -d or --directory we got: list directories themselves, not their contents

That description is pretty self explanatory.

To view the man in your Browser: https://man7.org/linux/man-pages/man1/ls.1.html

Also I'd like to point out Pilot's comment. The outputs differ based on what shell you use. But since you're new on here I assume you use the terminal on Ubuntu.

Edit to match the answer to the comments:

The command just outputs the current directory. If you have a folder x with 3 items inside and run the command inside that folder you will get the single dot. The items inside the folder are NOT listed. Just the folder itself.

It will not always output the dot however. If you use the ls command on another folder it will output that path.

f.e.

ls -d /usr/bin

will output /usr/bin.

Like the other answers already said: Alone this command is rather useless. It simply prints the folder, which you already know. However: If you are in the terminal of a specific folder and want to view the permissions of that folder, without moving out of it you could use ls -dl.

drwxrwxr-x 2 test test 4096 Feb 16 13:53 .

Using ls -l without the d option will simply print the permission masks of the contents.

Let's say we want to change the permissions now and revoke the write permission for everyone. We are in that folder called test.

We could now do chmod a-w `ls -d`

Keep in mind that chmod changes the permissions, a stands for all (owner, group and others) and the -w revokes the write permission. If we now retype the ls -dl command from before we get:

dr-xr-xr-x 2 test test 4096 Feb 16 13:53 .

In summary

If you want to target the folder you are inside you can use the -d command. Using it alone with ls will simply do nothing. This command is not necessary however. You can simply work around by targeting the folder from outside it, f.e. just do cd . and apply chmod on the test folder. But if for whatever reason you don't want to leave the folder you can use this comand.

I hope now everything is clear.

Pilot6 avatar
cn flag
So why `ls -d` in Ubuntu shell outputs `.` E.g in `$HOME`. It's not very obvious.
Tricia279 avatar
ga flag
I know man ls, but I did NOT understood what was written there
SickerDude43 avatar
ag flag
I edited my answer. hope it's clear now
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.