Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
Hi,

does anyone know of the command (using ls i'm guessing) that would display the files in a directory with at least 2 dots (.)
 

superbovine

macrumors 68030
Nov 7, 2003
2,872
0
I don't know what 2 dots you are referring to, but "ls -al" will probably display what you want including hidden files that start with a dot.
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
39,782
7,514
Los Angeles
If you want to see all files, except those starting with a period:
ls​

If you want to see all files, including those starting with a period:
ls -a​

If you want to see all files that contain two more more periods in their name, except those starting with a period:
ls | grep '\.[^.]*\.'​

If you want to see all files that contain two more more periods in their name, including those starting with a period:
ls -a | grep '\.[^.]*\.'​

The expression \.[^.]*\. means this:
\. = a period
[^.] = anything other than a period
* = zero or more of the preceding item, i.e., zero or more non-periods
\. = a period​
So when you put them together it means two periods separated by zero or more non-periods, and that string can occur anywhere within the filename.

If you want exactly two periods or other variations, the pattern can be tinkered.
 

balamw

Moderator emeritus
Aug 16, 2005
19,366
979
New England
As usual in unix there are many ways to skin a cat.

How about:

Code:
 find -name \*\.\*\.\* -print

You need to escape the * and . so the shell doesn't try to interpret them.

B
 

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
thx.
i have a new problem now.

using grep i need to find lines with only 1 character
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
scan said:
thx.
i have a new problem now.

using grep i need to find lines with only 1 character

grep '^.$' <filename>

iMeowbot said:
grep ^.$ filename

Is this school work?

Damn. You beat me to it. You should quote the search string though as $ is meaningful to the shell...
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
^ = start of line
. = Any character
$ = end of line

So we are looking for lines with one character (any) between the start and end.

The quotes are because $ is the start of an environment variable and we don't want the shell to treat it as an environment variable.
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
robbieduncan said:
Damn. You beat me to it. You should quote the search string though as $ is meaningful to the shell...
It's just text if followed by space. I love the way the shell parses things, it's clearly the work of sick minds :)
 

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
lines with only digits

tried: grep [:digit:] * but doesn't work
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
scan said:
lines with only digits

tried: grep [:digit:] * but doesn't work

Those character class things are special, even though they have brackets of their own they still need brackets to enclose them.

So:

grep [[:digit:]] *

Or, the more traditional way:

grep [0-9] *
 

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
iMeowbot said:
Those character class things are special, even though they have brackets of their own they still need brackets to enclose them.

So:

grep [[:digit:]] *

Or, the more traditional way:

grep [0-9] *

tried that already. the problem is it included lines with digits as well as letters. I need lines with only digits
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Have you considered reading the documentation. Or learning from the previous examples.

grep '^[0-9]*$' <filename>

will print lines that consist of only numbers. You could add whitespace as well if you want.
 

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
robbieduncan said:
Have you considered reading the documentation. Or learning from the previous examples.

grep '^[0-9]*$' <filename>

will print lines that consist of only numbers. You could add whitespace as well if you want.

thanks

i use the man pages but nothing really helped me with this question. We also not given any resources so its kind of "figure it out on your own" type of deal.
 

iMeowbot

macrumors G3
Aug 30, 2003
8,634
0
scan said:
tried that already. the problem is it included lines with digits as well as letters. I need lines with only digits
To do that in one pass, you would probably want to use egrep.

egrep '^[0-9]+$' filename

The ^ and $ mean beginning and end of line as before, and the + means to find one or more occurrence of the preceding expression.

=-=-=-=

If you really need to use non-extended grep, you could also do it in two passes, once to find digits and again to filter out non-digits:

grep [0-9] filename | grep -v '[^0-9]'

The first part, grep [0-9] , finds lines containing digits.

The second part, grep '[^0-9]' , finds lines containing things that aren't digits. Because the -v flag is on there, we instead get the opposite (lines not containing non-digit characters).

robbieduncan said:
grep '^[0-9]*$' <filename>

will print lines that consist of only numbers.
That will return empty lines too :( ^[0-9][0-9]*$ would do the right thing though.
 

fisty

macrumors member
Jan 30, 2006
95
0
for any command in unix there is something VERY usefull command "man"
just type man "command youd like to know more about"
e.g. man ls

it opens a manual to that particular command usually....hope it helps
 

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
How can I use "find" command to list the subdirectories of a directory??
 

fisty

macrumors member
Jan 30, 2006
95
0
scan said:
How can I use "find" command to list the subdirectories of a directory??


dude....
read what i posted....grrrrrrrrrrrrrrrr


i hate when people just dont know anything and want the easy way....i told ya how to find out whatever u like on any unix box MAN command....if that isnt clear enough or well too complicated google it, there are plenty of websites for beginners on the matter....

its not entirly directed at you....but £%£$^"£ try and find out for urself these little things....u know gives ya some reward too by finding out things urself and get a few things self thought rather than just ask on a forum where you have to wait....

if you would have googled this information any questiens on that regard you would have known by now and even more than me by the time im actually typing this msg...

dont want to sound mean....but hey cmon....you have the bigest bloody library infront of your eyes when u stare at your monitor USE IT
 

scan

macrumors 6502
Original poster
Oct 24, 2005
344
0
"dude" if you read any of my earlier posts I DO USE THE MAN PAGES.

if i'm asking for help, beleive me, i've already looked there. I also googled for help too. I'm not looking for any kind of easy way out since i'm trying to learn this stuff. you don't want to help, dont' bother posting.

I can list the subdirectories and files but I think what I want is just the subdirectories, which I don't know how to do.

fisty said:
dude....
read what i posted....grrrrrrrrrrrrrrrr


i hate when people just dont know anything and want the easy way....i told ya how to find out whatever u like on any unix box MAN command....if that isnt clear enough or well too complicated google it, there are plenty of websites for beginners on the matter....

its not entirly directed at you....but £%£$^"£ try and find out for urself these little things....u know gives ya some reward too by finding out things urself and get a few things self thought rather than just ask on a forum where you have to wait....

if you would have googled this information any questiens on that regard you would have known by now and even more than me by the time im actually typing this msg...

dont want to sound mean....but hey cmon....you have the bigest bloody library infront of your eyes when u stare at your monitor USE IT
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.