Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding all commands excluding "."

Tags:

bash

shell

So far I have this:

ls /usr/bin | grep "^[\.]" 

The cmd still gets files with a "." in there.

I have looked at [[:punct:]] but still returns the same thing.

like image 847
What IsMyName Avatar asked May 18 '26 06:05

What IsMyName


2 Answers

There's grep -v to exclude things. So try

ls /usr/bin | grep -v \\.

man grep says

 -v, --invert-match
         Selected lines are those not matching any of the specified patterns.
like image 154
Henrik N Avatar answered May 20 '26 20:05

Henrik N


It's generally considered a bad idea to parse ls.

If I understand you correctly, you want all files in /usr/bin that don't have a dot in the name. You can use find to do that:

find /usr/bin -not -name "*.*"

It is more portable (thanks @Adrian) to use a ! instead of -not:

find /usr/bin ! -name "*.*"
like image 28
Tom Fenech Avatar answered May 20 '26 20:05

Tom Fenech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!