Home » Questions » Computers [ Ask a new question ]

Listing everything else than *{.tex, .aux} by ls

Listing everything else than *{.tex, .aux} by ls

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

Asked by: Guest | Views: 16
Total answers/comments: 2
Guest [Entry]

"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""."
Guest [Entry]

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

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