List all directories hidden or not hidden


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List all directories hidden or not hidden
# 1  
Old 08-30-2012
List all directories hidden or not hidden

I want to list all directories hidden or not hidden.
ls -ld */ => shows only not hidden directories

so i guess the answer would be to add the a option to show all files
ls -lad */ => not working Smilie

ls -la | grep "^d" => works

But I would like to know why I can't use ls -lad */

Please explain


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by zaxxon; 08-30-2012 at 11:14 AM.. Reason: code tags
# 2  
Old 08-30-2012
That is because the shell wildcard * will not match the starting .. If your shell supports brace expansion, you could try:
Code:
ls -ld {.,?}*/


Last edited by elixir_sinari; 09-08-2012 at 06:51 AM..
This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 08-30-2012
I'm not sure what you are asking, but ls -lad will find other kinds of files than directories.
One way to get only directories:
Code:
ls -al | grep '^d'

This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 08-30-2012
Quote:
Originally Posted by elixir_sinari
That is because the shell wildcard * will not match the starting .. If your shell supports brace expansion, you could try:
Code:
ls -lad {.,?}*/

True, but in bash you could enable the dotglob shell option, and have even a starting "." matched by "*":

Code:
$ shopt -s dotglob
$ ls -ld */
drwxrwxr-x  2 lem     lem        40 2012-08-30 16:36 a1/
drwxrwxr-x  2 lem     lem        40 2012-08-30 16:36 .a2/
...

--
Bye
This User Gave Thanks to Lem For This Post:
# 5  
Old 08-30-2012
Or you can just do ls -d .* ?* which will work in other shells than bash.
This User Gave Thanks to Corona688 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rsync - how to copy hidden folder or hidden files when using full path

Hello. I use this command : rsync -av --include=".*" --dry-run "$A_FULL_PATH_S" "$A_FULL_PATH_D"The data comes from the output of a find command. And no full source directories are in use, only some files. Source example... (2 Replies)
Discussion started by: jcdole
2 Replies

2. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

3. Shell Programming and Scripting

List only hidden files, not use . option

Hi I have a prompt like this: PS1='\\u@\h \\w $(es=$?; ] && echo "\" || echo "\")\$\' It works like it should, but have a bug. Problem is the counting of hidden files $(($(ls -ad .* | wc -l)-2)) echo $(($(ls -ad .* | wc -l)-2)) The . seems to create the problem when I cut and past to... (3 Replies)
Discussion started by: Jotne
3 Replies

4. Red Hat

directories hidden from "ls -al"

Hi: I found some "hidden" directories created by a version control tool that can't be displayed by "ls -al". but user can "cd" into them and see the files inside. My questions are: 1) what commands can reveal those directories when "ls -al" fails? 2) how do you create such... (2 Replies)
Discussion started by: phil518
2 Replies

5. Shell Programming and Scripting

How to see hidden characters.....

I know that cat -v will show me hidden characters in a file.... I for some reason seem to think that there's a bash command that will show me hidden characters in a variable in a script? Or am I just imagining it? Thanks in advance (8 Replies)
Discussion started by: Bashingaway
8 Replies

6. Shell Programming and Scripting

Finding Hidden files and protecting the folder containing hidden files from deletion

Hi. I have a script which is deleting files with a particular extension and older than 45 days.The code is: find <path> -name "<filename_pattern>" -mtime +45 -exec rm {} \; But the problem is that some important files are also getting deleted.To prevent this I have decide to make a dummy... (4 Replies)
Discussion started by: pochaw
4 Replies

7. UNIX for Advanced & Expert Users

Hidden Characters

Hello all, I have two files, that I suspect may contain hidden characters (EG, three spaces instead of a tab). Does anyone know of any tool that can display this (I have tried using diff, but I'm not quite sure it would do the job) (6 Replies)
Discussion started by: Khoomfire
6 Replies
Login or Register to Ask a Question