Sunday, May 5, 2024
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 13414  / 3 Years ago, thu, may 20, 2021, 5:08:55

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


More From » command-line

 Answers
5

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.


[#11973] Friday, May 21, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gigglcept

Total Points: 113
Total Questions: 105
Total Answers: 125

Location: Christmas Island
Member since Wed, Jan 13, 2021
3 Years ago
;