grep does not care about file names beginning with period.
Hi.
Why can't grep ((GNU grep) 2.5) find strings in files whose name begins with '.' (period)? Thanks for reading. |
Quote:
|
I assume that OP means that grep abc * does not return results in files starting with a dot although one might expect that. If so, read on
That's not grep, but the shell. The shell interpretes the command that you have typed and will say: hey, grep is the command, let's try to find it hey, abc is an argument, just pass it hey, * is a wildcard so I will try to expand it When you pass the wildcard, the shell will expand it and pass all matching files. However, the shell does not include files starting with a dot. You can test it by running echo * which will display a list of all files in a directory (except the dot files ;) ). Possible other ways around it: use grep abc .* use find with the -exec option influence bash's behaviour (see e.g. http://halisway.blogspot.com/2007/02...dot-files.html) |
try the following:
[09:28][root@francoisvn]~ # ls -al lllllll/ | egrep -e "^-.*[[:space:]]\." -rw-r--r-- 1 root root 0 2008-11-19 07:56 .bla -rw-r--r-- 1 root root 0 2008-11-19 07:56 .werwer |
You could use
grep blah .* to cover those |
The reason is that the dot denotes a hidden file (or folder).
You also can't see it in your file manager, unless you: A) select Show Hidden Files from the View menu, or B) configure the file manager to Show Hidden Files by default. Hope this helps |
Changing the settings of the GUI file manager does not change the behavior of BASH commands in the terminal--at least not on my system.
|
Quote:
Cheers |
It may be better to use the wildcard ".[^\.]*" to prevent a match of "..".
grep pattern .[^\.]* If you also want to include non-hidden files, then you can use "grep pattern .[^\.]* *" for example. |
You all are looking for shopt and the dotglob option (in bash anyway).
|
ls -la | grep abc
seems to get the hidden abc's |
yup, ls's -a also works.
-a, --all do not ignore entries starting with . |
Thank you all, guys. And sorry for the delay.
|
.
It's OK .... :p the blue "Thumbs Up" can be used too. :p http://www.linuxquestions.org/questi...e-read-701224/ |
ENRIQUE:
I have experienced the same. I think the reason for this is that bash treats "." period as the "current directory". So each time I use grep against a .file (hidden) I have to define its directory first. This manner: for example, against the file ~/.dmrc we do: user@host-$ grep 'Session' ./.dmrc Returns: Session=Xfce Hope it helps. Goodluck Enrique, hasta la vista. |
All times are GMT -5. The time now is 12:09 AM. |