BIT-101
Bill Gates touched my MacBook Pro
Just a bunch of useful command line scripts to do various things. These are all prime candidates for aliases.
For example, I alias du -d 1 | sort -hr | column -t -R 1 -N Size,Folder -l 2
to dui
. The i
doesn’t stand for anything, but it’s easy to remember!
Can add -type f
or -type d
to only look for files or directories.
Simple glob patterns, not regex.
find . -name "*foo*"
Case insensitive
find . -iname "*foo*"
Regex
find . -regex ".*foo.*"
Matching multiple names with AND.
find . -name "*foo*" -and -name "*bar*"
Shorter…
find . -name "*foo*" -a -name "*bar*"
And is implied.
find . -name "*foo*" -name "*bar*"
Matching multiple names with OR.
find . -name "*foo*" -or -name "*bar*"
Shorter…
find . -name "*foo*" -o -name "*bar*"
Reject file name matches. Can use -and
or -a
here too.
find . -name "*foo*" -not -name "*foo-bar*"
find . -name "*.ext"
find . -type f | wc -l
find . -type d | wc -l
Simple
find . -type f | sed -e 's/.*\.//' | sed -e 's/.*\///' | sort -u
With counts, and sorted
find . -type f | awk -F'.' '{print $NF}' | sort| uniq -c | sort -gr
find . type -d -empty
find . type -f -empty
-links
= 1 for current dir, 1 for parent dir, 1 for each nested dir.
find . -type d -links 2
Hidden
find . -type f -name ".*"
NOT hidden
find . -type f -not -name ".*"
Hidden, ignoring current dir “.”
find . -type d -name ".*" -not -name "."
NOT hidden
find . -type d -not -name ".*"
Be careful here!!!
find . -name "*foo*" -delete
find . -type f -exec ls -lhS {} + | head -n 10
dui -d 1 -h
-d
to control depth.du -d 1 | sort -hr | column -t -R 1 -N Size,Folder -l 2
new_command $_
# or
new_command !$
# single
new_command !:n
# series
new_command !:n-m
# arbitrary
new_command !:n !:p
Comments? Best way to shout at me is on Mastodon