12/12/2016 - 12:36 AM

search & find

search & find

search all files and match keywords;

grep -r -H "some keywords" /path/to/search/folder

search all files and match multiple keywords;

grep -r 'multiple|keywords|here' /path/to/files

search contents of file for specific keyword;

grep "keyword" someFile.txt

serch for upper CaSe;

grep "<[A-Z].*" fileName

search for lower CaSe;

grep "<[a-z].*" fileName

search folders created within past 2 days;

find . -type d -mtime -2 -name "someDirectory*"

show metadata for file;

mdls fileName.txt

folder structure of computer;

man hier

create newline file containing matched files;

ls . > info.txt

create newline file containing matched directories;

ls /path/to/folder > info.txt

show path for specific app;

which appName

show path for specific app;

whereis appName

show users currently logged in;


show current user;


show hard drives/partitions;

diskutil list

show calendar;

cal 2017

determine file type;

file fileName

show file content;

cat fileName

show first 3 letters of first word;

cut -c1-3 file.txt

search home dir and all sub-dirs for a file;

find $HOME -name 'someFile.txt'

search home dir and all sub-dirs for both UPPER and lower cAsE .txt files;

find $HOME -iname '*.txt'

search home dir for txt files 5mb or greater(can use k, m, & g);

find $HOME -iname '*.txt' -type f -size +5m

search home dir for files opened/used in 30 days or greater;

find $HOME -atime +30

combo of above examples;

find $HOME -iname '*.txt' -atime +30

search for both .txt and .zip files;

find $HOME -iname '.txt' -o -iname '.zip'

find all files with .gz and display their size;

find $HOME -name '*.gz' -type f -exec du -h '{}' ;

combine and display contents of two files;

sdiff file1 file2

display shell options;


rearrange file contents in alphanumeric order and display;

sort fileName

display last part of a file;

tail someFile

display first part of a file;

head someFile

trace route to host;


display listening ports;

netstat -tun

display user account services;

finger userName

user and system times;


compare two files;

cmp file1 file2

compare two sorted files line by line;

comm file1 file2

sort folders and files from biggest to smallest;

du | sort -n

sort folders and files by size;

du -h | sort -n

display file system;


display disk usage;

du /path/to/folder

display running processes (q to quit);


display user and group IDs;

id userName

display active jobs;


display host info;


display machine info;


display architecture;



uname -m

uname -r

uname -s

uname -v

view disabled services;

$ find /var/db/ -type f -print -exec defaults read {} ; 2>/dev/null

display what a system launch daemon or agent does;

defaults read /System/Library/LaunchDaemons/