jeht
July 9, 2009, 8:09am
1
Use and complete the template provided. If you don't, your post may be deleted!
The problem statement, all variables and given/known data
i need to list all files in date/time order that contain the word "alpha" but not the the word "beta".
Relevant equations
find or ls
The attempt at a solution
find -print | grep -l alpha -I beta
find -print0 | xargs -0 grep alpha
School (University) and Course Number
I am a newbie and self teaching.
if I am in the wrong forum apologise, cant find the correct forum.
ls -ll | grep alpha | grep -v beta
jeht
July 9, 2009, 11:24am
3
tnx lathavim,
if i use how best to display the search "print or type" tried both with no success
zaxxon
July 10, 2009, 4:52am
4
I guess lathavim has a type - he wanted to write -lt instead of -ll.
Nevertheless you can add -r to switch between ascendind descending sort.
$> ls -la
insgesamt 8
drwxr-xr-x 2 isau users 4096 2009-07-10 10:37 .
drwxr-xr-x 6 isau users 4096 2009-05-19 10:24 ..
-rw-r--r-- 1 root root 0 2009-03-02 10:05 aaalphaaa
-rw-r--r-- 1 root root 0 2009-07-10 10:37 aalphaa
-rw-r--r-- 1 root root 0 2009-03-02 10:01 alpha
-rw-r--r-- 1 root root 0 2009-03-02 10:04 bbetaa
-rw-r--r-- 1 root root 0 2009-03-02 10:00 beta
-rw-r--r-- 1 root root 0 2009-07-10 10:37 bla
-rw-r--r-- 1 root root 0 2009-03-02 10:02 blub
-rw-r--r-- 1 root root 0 2009-03-02 10:03 cccetaaa
-rw-r--r-- 1 root root 0 2009-07-10 10:36 infile
-rw-r--r-- 1 root root 0 2009-03-02 10:06 lala
$> ls -lt *alpha*
-rw-r--r-- 1 root root 0 2009-07-10 10:37 aalphaa
-rw-r--r-- 1 root root 0 2009-03-02 10:05 aaalphaaa
-rw-r--r-- 1 root root 0 2009-03-02 10:01 alpha
$> ls -ltr *alpha*
-rw-r--r-- 1 root root 0 2009-03-02 10:01 alpha
-rw-r--r-- 1 root root 0 2009-03-02 10:05 aaalphaaa
-rw-r--r-- 1 root root 0 2009-07-10 10:37 aalphaa
The grep is not really needed - wildcards/metas are sufficient.
otheus
July 10, 2009, 5:00am
5
That was quite close. You're on to something here. You can try:
find -name "*alpha*" \! -name "*beta*" -print | xargs ls -ltr
If you don't want the times printed, replace the lower case l with a 1.
jeht
July 10, 2009, 6:27am
6
thank you very much all, all the solution you have send was working fine.
With Otheus's solution, if I wanted to list all "Alpha" files that contained the word "Aztec" only can I do this instead?
pattern=aztec
find -name "*alpha*" \! -name "*beta*" grep $pattern -print | xargs ls -ltr
otheus
July 10, 2009, 9:03am
7
Yes, but (a) you're missing a pipe, and (b) there's a better way.
find -name "*alpha*" \! -name "*beta*" | grep $pattern -print | xargs ls -ltr
Better way:
find -name "*alpha*" -name "*$pattern*" \! -name "*beta*" -print | xargs ls -ltr
The GNU find lets you match by regex. This might now be part of the POSIX standard
jeht
July 11, 2009, 8:04am
8
Thannk you Otheus...its perfect