glob 

Send to Kindle
home » snippets » zsh » glob



Glob Qualifiers

Ref: Glob Qualifiers and man zshexpn.

Qualifier Description
/ directories
F ‘full’ (i.e. non-empty) directories. Note that the opposite sense (^F) expands to empty directories and all non-directories. Use (/^F) for empty directories.
. plain files
@ symbolic links

Snippets

# Find all executable files called chrome under the current directory.
print -rl -- **/chrome(#qx.)

# Find all directories called chrome under the current directory.
print -rl -- **/chrome(#q/)
ls -ld **/chrome(#q/)  # Same thing.

# Find all directories and symbolic links to directories.
print -rl -- **/chrome(#q-/)

# Ref: http://unix.stackexchange.com/a/31505
# Top 5 filez by size owned by the current user, over 1MB, last modified more than
# 7 days ago in descending order of size.
#
# U -> files owned by the effective user ID
# Lm+1 -> Length up to 1M.  The m right after L indicates MB and the +1 means more than 1Mb.
# m+7 -> modified more than 7 days ago
#   An optional character between m and the +/- can
#   specify the units.  ‘M’: 30 day months, ‘w’:weeks, ‘h’:hours, ‘m’:minutes,
#   ‘s’:seconds or ‘d’:days (days is the default.)
# OL -> descending order of size.
#   O -> descending
#   o -> ascending
#   L -> length, l -> num links, a -> last access, m -> last
#   modified, or c -> inode creation time.
# [1,5] -> subscript notation like for arrays to limit the results.
print -rl -- *(ULm+1m+7OL[1,5])


# Adding a prefix (will become a separate shell word).
#
# Without prefix.  (Fyi, limiting to results [2,6] for brevity.)
print_args **/chrome(#q/[2,6])
#   Received 5 args
#   1: 'repo_git/dart/sdk/lib/chrome'
#   2: 'repo_git/dart/tests/chrome'
#   3: 'repo_git/dart/third_party/chrome'
#   4: 'repo_git/dart/tools/dom/src/chrome'
#   5: 'repo_git/dart/tools/testing/extensions/chrome'
#
# WITH prefix.
print_args **/chrome(#q/[2,6]P:-i:)
#   Received 10 args
#   1: '-i'
#   2: 'repo_git/dart/sdk/lib/chrome'
#   3: '-i'
#   4: 'repo_git/dart/tests/chrome'
#   5: '-i'
#   6: 'repo_git/dart/third_party/chrome'
#   7: '-i'
#   8: 'repo_git/dart/tools/dom/src/chrome'
#   9: '-i'
#   10: 'repo_git/dart/tools/testing/extensions/chrome'

# 10 oldest files.
print -rl -- *(Om[1,10])

# From zshlovers: http://grml.org/zsh/zsh-lovers.html#_unsorted_misc_examples
# Get the names of all files that *don't* match a pattern *anywhere* on the file.
# (and without ``-L'' because its GNUish)
print -rl -- *(.^e{'grep -q pattern $REPLY'})

# Show me all the .c files for which there doesn't exist a .o file.
print -rl -- *.c(e_'[[ ! -e $REPLY(:r.o) ]]'_)

# Matching all files which do not have a dot in filename.
ls *~*.*(.)

# List all non-executable files that do not have extensions listed in `fignore'
ls **/*~*(${~${(j/|/)fignore}})(.^*)