5

Does it show hidden file names inside all directories? Or just the current directory (including any directory inside it)? I cannot understand why ls -ld .* returns different results (it shows hidden files and directories ONLY in current directory, not showing files inside any other directory inside it)? Also What does -d do alone (ls -d)?

8

ls -al .* shows the contents of all directories in the current directory whose names begin with . (ie all those matching the shell glob .*)

In Bash, the .* glob resolves to . and .. as well. Since . represents the current directory, and .. the parent directory, the contents of both of these directories, including any hidden files and directories, are shown too.1

.* also catches hidden files in the current directory, but they are listed anyway as contents of .

As explained in What does `ls --directory` stand for? the -d flag causes the directories themselves to be displayed, instead of their contents.


1this is also the case in dash, which is the shell symlinked to sh in Ubuntu. However, other shells, including zsh and mksh, behave more intuitively and don't include . and .. when expanding .*. It is also worth noting that, while most commands will operate on .. and . when they are included in a .* glob (including chmod and chown - you can really mess up your system with those), the rm command will helpfully fail by design to do so.

2

It will return all the hidden files, or files starting with . in that directory. To view all files (including hidden) in a directory, use ls -al

2

It will list down all the files + directories including hidden files/directories in the current directory along with the files starting with . in their names.

ls means listing of the directories along with files in the current directory.
a denotes all the files in the directory, both hidden and not.
l denotes the long listing of information about files+directory with their permissions and last updated time.
.* denotes all the hidden files in the current directory starting with . in their name.

  • Edited. I have Explained in detail now. Thanks :) – jatingoel1349 Mar 6 '17 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.