ls command - Unix

This is a discussion on ls command - Unix ; Hi all I am having a directory having hundreds of files with the extensin .txt . Now i wish to list only those files that are not having the extension .txt . Can i do this directly with ls command ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: ls command

  1. ls command

    Hi all

    I am having a directory having hundreds of files with the
    extensin .txt . Now i wish to list only those files that are not
    having the extension .txt .

    Can i do this directly with ls command or will i have to go for a
    script ?

    Thanks,
    Manish.


  2. Re: ls command

    2007-04-5, 06:08(-07), manish:
    > Hi all
    >
    > I am having a directory having hundreds of files with the
    > extensin .txt . Now i wish to list only those files that are not
    > having the extension .txt .
    >
    > Can i do this directly with ls command or will i have to go for a
    > script ?

    [...]

    ls | grep -v '\.txt$'

    (supposing that no filename contains any newline characters).

    Or at your prompt, your shell might have a globbing syntax for
    that.

    zsh:

    setopt extendedglob
    cmd -- ^*.txt

    ksh or bash with extglob option or zsh with kshglob option:

    cmd -- !(*.txt)

    Replace cmd with printf '%s\n' if you want to just diplay the
    list or ls -ld if you want to list the file attributes...

    --
    Stéphane

  3. Re: ls command

    On Apr 5, 6:16 pm, Stephane CHAZELAS wrote:
    > 2007-04-5, 06:08(-07), manish:> Hi all
    >
    > > I am having a directory having hundreds of files with the
    > > extensin .txt . Now i wish to list only those files that are not
    > > having the extension .txt .

    >
    > > Can i do this directly with ls command or will i have to go for a
    > > script ?

    >
    > [...]
    >
    > ls | grep -v '\.txt$'
    >
    > (supposing that no filename contains any newline characters).
    >
    > Or at your prompt, your shell might have a globbing syntax for
    > that.
    >
    > zsh:
    >
    > setopt extendedglob
    > cmd -- ^*.txt
    >
    > ksh or bash with extglob option or zsh with kshglob option:
    >
    > cmd -- !(*.txt)
    >
    > Replace cmd with printf '%s\n' if you want to just diplay the
    > list or ls -ld if you want to list the file attributes...
    >
    > --
    > Stéphane


    Thanks Stéphane :-) it works ...


+ Reply to Thread