LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I grep symbols like "minus": - (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-grep-symbols-like-minus-820605/)

Netooo 07-18-2010 08:54 PM

How can I grep symbols like "minus": -
 
Hello, I'm not that newbie to linux but I haven't found a way to grep minus symbol (or any other symbols that might suggest a console command).

For example:
A directory called abc, with subdirectories called: abc-a, def-a, ghi-a, jkl-a, and etc...

If i want to list only the directories that finish with "-a" I might do:
$ ls | grep -a

But sintax -a might be an option switch or something, so it won't let me use it with grep.

How can I grep those directories?

AlucardZero 07-18-2010 09:08 PM

1. Quote AND/OR escape
Code:

ls | grep "\-a"
(that \ is the escape character)
or
2. Use flag "--" to stop switch parsing
Code:

ls | grep -- -a

Netooo 07-18-2010 09:17 PM

...
 
Nice, thanks dude...

grail 07-19-2010 12:34 AM

Please mark as SOLVED once you have a solution.

MTK358 07-19-2010 08:03 AM

Use "--" to stop option parsing.

Also, to find all files ending with "-a" it might be better just to use "ls *-a" instead.


All times are GMT -5. The time now is 10:08 AM.