/var$ ls
backups cache host lib local lock log mail opt run spool tmp
/var$ ls -d *[^osht]*
backups cache lib local lock log mail opt run spool tmp
Of course this approach fails if you have an anagram so it should never be used for coding something serious. Yet its useful enough when you want to narrow something down when playing around or if you know for sure that you don't have anagrams to worry about.
e.g. ls -d /tmp/*[^.txt] will list all the files without the .txt extension
e.g. ls -d /tmp/*[^.xtt] does the same.. so be careful =)
Also if you don't mind playing with shell options you can more simply set the extglob option, yet I don't really recommend shoptions much since you can easily forget that your env is different and they tend to make things unpredictable and less portable (e.g. leaning tower of babel).
/var$ shopt -s extglob
/var$ ls -d !(host)
backups cache lib local lock log mail opt run spool tmp
No comments:
Post a Comment