巴什通配符 - autoexpand几个具体的案例? [英] Bash globbing - autoexpand for a few specific cases?

查看:120
本文介绍了巴什通配符 - autoexpand几个具体的案例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,通配符 * (本身)会以这样的方式展开,这意味着隐藏的文件是在当前文件夹中所有非隐藏文件这些$ p $通过一段pfixed。

有,我会觉得是有用的两个用例,但我不知道如何正确地做:


  1. 你怎么可以使用通配的......在当前文件夹中的所有文件,包括隐藏文件,但不包括 ..


  2. 您如何能在当前文件夹中的glob的......所有隐藏文件(而且只有隐藏文件),但不包括 ..



解决方案

要展开<一个href=\"http://stackoverflow.com/questions/1586477/bash-globbing-autoexpand-for-a-few-specific-cases/1586499#1586499\">paviums回答并回答你问题的第二部分,所有的文件,除了 .. 可指定像这样的:

  {[!] *,*}

根据您的具体使用情况下,它可能会更好,设置 dotglob 外壳选项,这样的bash包括在扩展点文件 * 默认为:

  $禁用了javascript -s dotglob
$回声*
.tst

I understand that the wildcard * (by itself) will expand in such a way that it means "all non-hidden files in the current folder" with hidden files being those prefixed by a period.

There are two use cases that I would think are useful, but I don't know how to properly do:

  1. How can you glob for... "All files in the current folder, including hidden files, but not including . or .."?

  2. How can you glob for... "All hidden files (and only hidden files) in the current folder, but not including . or .."?

解决方案

To expand on paviums answer and answer the second part of your question, all files except . and .. could be specified like this:

{.[!.]*,*}

Depending on your exact use case it might be better to set the dotglob shell option, so that bash includes dotfiles in expansions of * by default:

$ shopt -s dotglob
$ echo *
.tst

这篇关于巴什通配符 - autoexpand几个具体的案例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆