List Files and Directory

Use and complete the template provided. If you don't, your post may be deleted!

  1. 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".

  2. Relevant equations
    find or ls

  3. The attempt at a solution
    find -print | grep -l alpha -I beta
    find -print0 | xargs -0 grep alpha

  4. 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

tnx lathavim,
if i use how best to display the search "print or type" tried both with no success

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.

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.

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

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

Thannk you Otheus...its perfect