Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I run unsuccessfully

ls -I".tex"
share|improve this question

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
up vote 1 down vote accepted

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

share|improve this answer
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! – Masi Oct 11 '14 at 15:37
ls -I*.tex -I*.aux

or

ls --hide=*.tex --hide=*.aux
share|improve this answer

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

ls !(*.tex|*.aux)
share|improve this answer
1  
This is the one. See this same question over at ServerFault: serverfault.com/questions/41783/… – Telemachus Aug 30 '09 at 19:53
1  
Or this question at Stack Overflow: stackoverflow.com/questions/670460/move-all-files-except-one Which is a question by the same user where I already gave the same answer... – sth Aug 30 '09 at 20:21
1  
@Sth: Well, you got two upvotes out of it from me at least. (I only remembered the thread on Serverfault, since I learned this trick there.) – Telemachus Aug 30 '09 at 21:12

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.

share|improve this answer

you may use:

ls | grep -v *.tex | grep -v *.aux
share|improve this answer
    
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .