LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-18-2010, 09:54 PM   #1
Netooo
LQ Newbie
 
Registered: Jun 2010
Location: Guadalajara, Jalisco, Mexico
Distribution: Slackware
Posts: 20

Rep: Reputation: 0
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?

Last edited by Netooo; 07-18-2010 at 10:03 PM. Reason: Wrong English XD
 
Old 07-18-2010, 10:08 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,808

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
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
 
Old 07-18-2010, 10:17 PM   #3
Netooo
LQ Newbie
 
Registered: Jun 2010
Location: Guadalajara, Jalisco, Mexico
Distribution: Slackware
Posts: 20

Original Poster
Rep: Reputation: 0
Thumbs up ...

Nice, thanks dude...
 
Old 07-19-2010, 01:34 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,254

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Please mark as SOLVED once you have a solution.
 
Old 07-19-2010, 09:03 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Use "--" to stop option parsing.

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I "cat" or "grep" a file to ignore lines starting with "#" ??? callagga Linux - Newbie 7 08-16-2013 07:58 AM
Problem "$value=`mpstat 1 1 | grep "Average"`;" Alias pipe return nothing adamlucansky Linux - General 8 09-25-2009 08:26 AM
Stupid question: if [ "$i" == `$(cat ${LOGFILESSHD} | grep "${i}" )` ] ; then frenchn00b Programming 6 05-19-2008 06:16 PM
delete a file that starts if a "-" (minus) sign Four Linux - Newbie 2 03-14-2008 05:55 PM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 04:11 PM


All times are GMT -5. The time now is 07:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration