4

How can you ls everything else the the files *{.tex, .aux}?

I run unsuccessfully

ls -I".tex"

migrated from stackoverflow.com Aug 30 '09 at 19:18

This question came from our site for professional and enthusiast programmers.

  • Can someone s/else than/except for/g? – las3rjock Aug 30 '09 at 19:21
2

Thanks to @sth's answer, I finally found an ls command which works with a prefix selection glob pattern (there the hide option doesn't work); consider:

touch MyDocument{.aux,.auxlock,.bbl,.bcf,.blg,.log,.out,.pgf-plot.gnuplot,.run.xml,.tex,.toc}
touch YourDocument{.aux,.auxlock,.bbl,.bcf,.blg,.log,.out,.pgf-plot.gnuplot,.run.xml,.tex,.toc}

ls                                # list all
# MyDocument.aux               YourDocument.aux
# MyDocument.auxlock           YourDocument.auxlock
# MyDocument.bbl               YourDocument.bbl
# MyDocument.bcf               YourDocument.bcf
# MyDocument.blg               YourDocument.blg
# MyDocument.log               YourDocument.log
# MyDocument.out               YourDocument.out
# MyDocument.pgf-plot.gnuplot  YourDocument.pgf-plot.gnuplot
# MyDocument.run.xml           YourDocument.run.xml
# MyDocument.tex               YourDocument.tex
# MyDocument.toc               YourDocument.toc

ls MyDocument.*                   # prefix search glob only, works fine
# MyDocument.aux      MyDocument.bcf  MyDocument.out               MyDocument.tex
# MyDocument.auxlock  MyDocument.blg  MyDocument.pgf-plot.gnuplot  MyDocument.toc
# MyDocument.bbl      MyDocument.log  MyDocument.run.xml

ls --hide='*.tex'                 # works if no search glob is used
# MyDocument.aux      MyDocument.pgf-plot.gnuplot  YourDocument.blg
# MyDocument.auxlock  MyDocument.run.xml           YourDocument.log
# MyDocument.bbl      MyDocument.toc               YourDocument.out
# MyDocument.bcf      YourDocument.aux             YourDocument.pgf-plot.gnuplot
# MyDocument.blg      YourDocument.auxlock         YourDocument.run.xml
# MyDocument.log      YourDocument.bbl             YourDocument.toc
# MyDocument.out      YourDocument.bcf

ls --hide='*.tex' MyDocument.*    # does NOT work with prefix glob!
# MyDocument.aux      MyDocument.bcf  MyDocument.out               MyDocument.tex
# MyDocument.auxlock  MyDocument.blg  MyDocument.pgf-plot.gnuplot  MyDocument.toc
# MyDocument.bbl      MyDocument.log  MyDocument.run.xml

ls MyDocument!(.tex|.aux)         # works with (FULL!) prefix
# MyDocument.auxlock  MyDocument.blg  MyDocument.pgf-plot.gnuplot
# MyDocument.bbl      MyDocument.log  MyDocument.run.xml
# MyDocument.bcf      MyDocument.out  MyDocument.toc

ls MyDocu*!(.tex|.aux)            # does NOT work w/ partial prefix 
                                  # if * pattern does not terminate (is last before !)
# MyDocument.aux      MyDocument.bcf  MyDocument.out               MyDocument.tex
# MyDocument.auxlock  MyDocument.blg  MyDocument.pgf-plot.gnuplot  MyDocument.toc
# MyDocument.bbl      MyDocument.log  MyDocument.run.xml

ls MyDocu*.!(tex|aux)             # does work w/ partial prefix, if * pattern terminates
                                  # (here termination is with dot . coming before ! )
# MyDocument.auxlock  MyDocument.blg  MyDocument.pgf-plot.gnuplot
# MyDocument.bbl      MyDocument.log  MyDocument.run.xml
# MyDocument.bcf      MyDocument.out  MyDocument.toc

So, the answer for this case is to use ls PREFIX*.!(ext1|ext2), or in other words: "list files starting with 'PREFIX' and any characters until a dot '.', which is not followed by ext1 or ext2".

  • 1
    I think this is the best answer because it has the most accurate explanations why the last approach is the correct choice. Thank you for your answer with clear explanation! – Léo Léopold Hertz 준영 Oct 11 '14 at 15:37
10
ls -I*.tex -I*.aux

or

ls --hide=*.tex --hide=*.aux
9

If you use bash and have the extglob shell option set (which is usually the case):

ls !(*.tex|*.aux)
0

If you're using zsh with EXTENDED_GLOB option set:

pattern~negpattern

where 'pattern' is what you want to match, except for anything matching 'negpattern'.

Example:

ls -d *~*.mp3

will list all the files in your cwd except those ending in '.mp3'.

If you're not using zsh, give it a try, this kind of intelligent expansion is everywhere.

0

you may use:

ls | grep -v *.tex | grep -v *.aux
  • I don't think that does what you think it does. grep takes regular expressions as parameters, not shell wildcards. Also, the shell will expand those wildcards first anyway. – Greg Hewgill Aug 30 '09 at 19:22
  • "ls | grep -v .tex | grep -v .aux" seems to work. (On my machine, ls does not take the -I or --hide flags.) – las3rjock Aug 30 '09 at 19:48
  • You could also use a regex with egrep: ls | egrep -v '(aux|tex)$' – mtak Apr 4 '14 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.