Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Does ls have a way to show negated conditions like "all files which are not a symlink"? I use the latter a lot in a project directory but other negations would be useful as well.

For now, my research has only lead to creating an alias to something "like":

find . -maxdepth 1 ! -type l | sort # (...)

but obviously this way I don't get the colouring of ls, the column formatting, etc...

I am on Bash v3 on OS X 10.8.2 and Bash v4 on Pangolin sometimes.

share|improve this question
    
Grazie dell'edit, Matteo. –  Robottinosino Oct 5 '12 at 4:27

1 Answer 1

up vote 12 down vote accepted

Instead of piping it to sort, use ls.

find . -maxdepth 1 \! -type l -exec ls -d {} +

find . -maxdepth 1 \! -type l | xargs ls -d

If you used the zsh shell you could use their non-portable glob extensions:

ls -d *(^@)
share|improve this answer
    
Thx 4 the answer! Why do you escape !? It seems to be working even without.. What I am risking by not escaping it? Interesting how you use a final + and not \;, please explain? –  Robottinosino Oct 5 '12 at 4:25
2  
@Robottinosino The + makes it send all to a single ls command instead of running it separately for each file (this way ls can do the columns and sorting). I escaped the ! because it is a special character to some shells even though yours seems to accept it fine. –  Random832 Oct 5 '12 at 4:27
    
Gotcha. Great stuff! Do you agree that it's a bit laborious though, just to negate a predicate in a simple ls? Could there be a better way? –  Robottinosino Oct 5 '12 at 4:30
1  
@Robottinosino Edited with something zsh can do. I don't think bash can do it though. –  Random832 Oct 5 '12 at 4:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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