Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

6 Answers 6

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 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 at 6:48

@Greg it works but one looses the color coding of ls which at times is very helpful

ls --hide="?*.tex" --hide="?*.aux"

preserves the color coding too.

share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  50-3 Apr 4 at 7:12
    
i complemented the answer and pointed out the deficiency in a given solution. I don't think every post is supposed to be the exact answer to the question. beauty of the forum is that answers can also be discussed and remarked upon. still I modified my post with exact answer. i couldn't comment on Greg's post that's why I had to post it here –  comiventor Apr 4 at 7:21
    
Ire has made the same answer as this one. See the accepted answer of this thread. –  Masi Apr 5 at 5:52
    
It is similar but not same ... at times, only shell pattern works (i.e. using '?' to represent any character) . I faced problem and using '?' worked –  comiventor Apr 7 at 5:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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