使用 ls 列出除 *{.tex, .aux} 之外的所有内容

使用 ls 列出除 *{.tex, .aux} 之外的所有内容

您如何能将ls其他所有内容都保存到文件中*{.tex, .aux}

我跑不成功

ls -I".tex"

答案1

谢谢@某事的回答,我终于找到了一个ls可以与前缀选择全局模式一起使用的命令(其中隐藏选项不起作用);考虑:

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

因此,这种情况的答案是使用ls PREFIX*.!(ext1|ext2),或者换句话说:“列出以‘PREFIX’开头的任何字符直到点‘.’,其后不是 ext1 或 ext2”的文件。

答案2

ls -I*.tex -I*.aux

或者

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

答案3

如果您使用 bash 并且extglob设置了 shell 选项(通常是这种情况):

ls !(*.tex|*.aux)

答案4

您可以使用:

ls | grep -v *.tex | grep -v *.aux

相关内容