最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

Wildcards when do ls in Linux

Linux crifan 1869浏览 0评论

Wildcards when do ls in Linux

Wild card /ShorthandMeaningExamples
*Matches any string or group of characters.$ ls *will show all files
$ ls a*will show all files whose first name is starting with letter ‘a’
$ ls *.cwill show all files having extension .c
$ ls ut*.cwill show all files having extension .c but file name must begin with ‘ut’.
?Matches any single character.$ ls ?will show all files whose names are 1 character long
$ ls fo?will show all files whose names are 3 character long and file name begin with fo
[…]Matches any one of the enclosed characters$ ls [abc]* will show all files beginning with letters a,b,c

Note:
[..-..] A pair of characters separated by a minus sign denotes a range.

Example:
$ ls /bin/[a-c]*

Will show all files name beginning with letter a,b or c like

   /bin/arch           /bin/awk           /bin/bsh     /bin/chmod           /bin/cp
   /bin/ash           /bin/basename   /bin/cat      /bin/chown           /bin/cpio
   /bin/ash.static   /bin/bash          /bin/chgrp   /bin/consolechars /bin/csh

But
$ ls /bin/[!a-o]
$ ls /bin/[^a-o]

If the first character following the [ is a ! or a ^ ,then any character not enclosed is matched i.e. do not show us file name that beginning with a,b,c,e…o, like

   /bin/ps            /bin/rvi              /bin/sleep /bin/touch      /bin/view
   /bin/pwd           /bin/rview        /bin/sort   /bin/true        /bin/wcomp
   /bin/red           /bin/sayHello     /bin/stty   /bin/umount   /bin/xconf
   /bin/remadmin /bin/sed           /bin/su      /bin/uname     /bin/ypdomainname
   /bin/rm            /bin/setserial    /bin/sync   /bin/userconf /bin/zcat
   /bin/rmdir         /bin/sfxload      /bin/tar    /bin/usleep
   /bin/rpm           /bin/sh            /bin/tcsh    /bin/vi

转载请注明:在路上 » Wildcards when do ls in Linux

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
81 queries in 0.175 seconds, using 22.09MB memory