Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
154 lines (153 sloc) 5.18 KB
$ print (*/)#zsh_us.ps
zsh-4.2.3/Doc/zsh_us.ps
$ print **/zsh_us.ps
zsh-4.2.3/Doc/zsh_us.ps
%
# Search for `README' in all Subdirectories
$ ls -l **/README
%
# find directories that contain both "index.php" and "index.html", or in
# general, directories that contain more than one file matching "index.*"
$ ls **/*(D/e:'[[ -e $REPLY/index.php && -e $REPLY/index.html ]]':)
# or
$ ls **/*(D/e:'l=($REPLY/index.*(N)); (( $#l >= 2 ))':)
%
# Find command to search for directory name instead of basename
$ print -rl /**/*~^*/path(|/*)
# or - without Zsh
$ find / | grep -e /path/ -e '/path$'
%
# Print he path of the directories holding the ten biggest C regular files
# in the current directory and subdirectories.
$ print -rl -- **/*.c(D.OL[1,10]:h) | sort -u
%
# Find files with size == 0 and send a mail
$ files=(**/*(ND.L0m+0m-2))
> (( $#files > 0 )) && print -rl -- $files | \
mailx -s "empty files" foo@bar.tdl
%
# recursive chmod
$ chmod 700 **/(.) # Only files
$ chmod 700 **/(/) # Only directories
%
# print out all of the files in that directory in 2 columns
$ print -rC2 -- ${1:[...]}/*(D:t)
# ^- number ob columns
# or - if you feel concerned about special characters - use
$ list=(${1:[...]}/*(ND:t))
$ (($#list)) && print -rC2 -- ${(V)list}
%
# Search all files in /home/*/*-mail/ with a setting ``chmod -s'' flag
# (recursive, include dotfiles) remove the setgid/setuid flag and print
# a message
$ chmod -s /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S))
# or with a small script
$ for file (/home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) {
> print -r -- $file
> chmod -s $file && print -r fixed $file
> }
# or use ``zargs'' (require autoload zargs) prevent the arg list too
# long error
$ zargs /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) -- chmod -s
%
# List files beginning at `foo23' upwards (foo23, foo24, foo25, ..)
$ ls -l foo<23->
%
# get all files that begin with the date strings from June 4 through
# June 9 of 2004
$ ls -l 200406{04..10}*(N)
# or if they are of the form 200406XX (require ``setopt extended_glob''
$ ls -l 200306<4-10>.*
%
# remove spaces from filenames
$ for a in ./**/*\ *(Dod); do mv $a ${a:h}/${a:t:gs/ /_}; done
%
# Show only all *.c and *.h - Files
$ ls -l *.(c|h)
%
# Show only all *.c - files and ignore `foo.c'
$ ls *.c~foo.c
%
# show data to *really* binary format
$ zsh -ec 'while {} {printf %.8x $n;repeat 8 \
> {read -ku0 a printf \ %.8d $(([##2]#a))};print;((n+=8))}' < binary
%
# Show only world-readable files
$ ls -l *(R)
%
# List files in the current directory are not writable by the owner
$ print -l ~/*(ND.^w)
%
# find and delete the files which are older than a given parameter
# (seconds/minutes/hours)
# deletes all regular file in /Dir that are older than 3 hours
$ rm -f /Dir/**/*(.mh+3)
# deletes all symlinks in /Dir that are older than 3 minutes
$ rm -f /Dir/**/*(@mm+3)
# deletes all non dirs in /Dir that are older than 30 seconds
$ rm -f /Dir/**/*(ms+30^/)
# deletes all folders, sub-folders and files older than one hour
$ rm ./**/*(.Dmh+1,.DL0)
# deletes all files more than 6 hours old
$ rm -f **/*(mh+6)
# removes all files but the ten newer ones (delete all but last 10
# files in a directory)
$ rm ./*(Om[1,-11])
Note: If you get a arg list too long, you use the builtin rm. For
example:
$ zmodload zsh/files ; rm -f **/*(mh+6)
or use the zargs function:
$ autoload zargs ; zargs **/*(mh+6) -- rm -f
%
# A User's Guide to the Z-Shell /5.9: Filename Generation and Pattern
# Matching find all files in all subdirectories, searching recursively,
# which have a given name, case insensitive, are at least 50 KB large,
# no more than a week old and owned by the root user, and allowing up
# to a single error in the spelling of the name. In fact, the required
# expression looks like this:
$ ls **/(#ia1)name(LK+50mw-1u0)
%
# Change the UID from 102 to 666
$ chown 666 **/*(u102)
%
# List all files which have not been updated since last 10 hours
$ print -rl -- *(Dmh+10^/)
%
# delete only the oldest file in a directory
$ rm ./*filename*(Om[1])
%
# Sort the output from `ls -l' by file size
$ ls -fld *(OL)
%
# find most recent file in a directory
$ setopt dotglob ; print directory/**/*(om[1])
%
# Show only empty files which nor `group' or `world writable'
$ ls *(L0f.go-w.)
%
# Find - and list - the ten newest files in directories and subdirs.
# (recursive)
$ print -rl -- **/*(Dom[1,10])
%
# Print only 5 lines by "ls" command (like ``ls -laS | head -n 5'').
$ ls -fl *(DOL[1,5])
%
# Display the 5-10 last modified files.
$ print -rl -- /path/to/dir/**/*(D.om[5,10])
%
# Find all files without a valid owner.
$ chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:)
%
# Find all the empty directories in a tree.
$ for f in ***/*(/l2); do foo=($f/*(N)); [[ -z $foo ]] && print $f; done
# Note:Since Zsh 4.2.1 the glob qualifier F indicates a non-empty directory.
# Hence *(F) indicates all subdirectories with entries, *(/^F) means all
# subdirectories with no entries.
$ ls -ld *(/^F)
%
# Remove empty directories afterwards.
$ rmdir ./**/*(/od) 2> /dev/null
%
# Show only files which are owned by group `users'.
$ ls -l *(G[users])
%