11/7/2015 Comparing files and directories�

Under windows, I've been happy for 10 years or more with Total Commander. Under linux/MacOSX, Total Commander is not available. There is a tolerable alternative built into the OS command line.

To compare directories, type
diff -rq /{directory1} /{directory2}

-r recurse
-q quick (print filenames only)

On the Mac OS, there is a convenient way to type in long complicated directories without pain. Open them in a Finder window and click-n-drag the icon to the left of the directory name at the top of the Finder window. When you drag this icon into the terminal window, it will show up as the text version of the directory. Viola, min typing!

diff -rq {drag icon} {drag icon} enter.

Alternate method..

diff -qr dirA dirB | grep -v -e 'DS_Store' -e 'Thumbs' | sort > diffs.txt

11/4/2015 Copies file from windows machine over ssh link.

bmmbp:~ brian$ scp -P 49422 User@optiplex:unisontestfile.txt .



kill -USR1 $(pgrep dd$)
watch -n5 'kill -USR1 $(pgrep dd$)'

4/1/2015 Get distribution of file sizes.
find /my/directory -type f -exec ls -l {} + | cut -d' ' -f5 | sort -n | uniq -c

not terribly efficient
if there are many many files it may be better to save intermediate results in a temp file, sort it to another temp file, then "uniq" it
here I use numeric sort so the output will be ordered by ascending file size (nice), but any sort will do as long as equal lines are grouped together
pipe the results in awk '{ print $1 "," $2 }' to get a CSV file to be used in your graphing tool of choice (even spreasheet tools will do)

If your find tool is a GNU find, can use printf
find . -type f -printf '%s\n' | sort -n | uniq -c

3/22/2015 Find a delete a file matching name

$ find {dir} -type f -iname '*.!sync' -exec rm -f {} \;


$ zip -r -X -z mlhack29

12/29/14 Mac OSX file directory comparisons

$ diff -rq folder-1 folder-2


Maybe bad disk surface caused lost clusters? In any case, lots of zero sized files to be found and removed.
$ find {dir} -size 0
$ find {dir} -print -size 0 ! -name "*.xml" (all except a certain name)

12/16/2014 Checking to see if someone is logging into your OSX machine

$ grep sshd /private/var/log/secure.log


$ dig +trace +additional

good DNS zone file info at

9/6/2014 Text Operations

Add to beginning of each line
sed 's/
/add_to_beginning/' file
Add to end of each line
sed 's/$/add_to_end/' file
Add to beginning and end of each line
sed "s/.*/add_to_beginning&add_to_end/" file


$sudo dpkg-reconfigure tzdata
reconfigure the system time zone.

$ettercap -Top -M rap:remote / /
o man in the middle only, (use ethereal to log)
p promiscuous mode

nmap -sS,100
(or use -sP for gentle touch)

ettercap -Tp -cL{logfid} -M arp:remote

nmap -O -vv

netstat -netap {shows who's doing what}

dia - diagram editor GUI
xfdiff - file difference GUI
cmp - binary byte compare
diff - text file comparer (lines)
find - find based on name, exec
rep - find based on internals

1/25/13 learning Linux Mint13 inside VirtualBox..

sudo apt-get install wine
groups - shows groups
id - shows users and numbers
sudo adducer brian vboxusers - adds brian to group vboxusers
groupadd vboxusers - creates a new group
usermod -a -G {user} - capital G adds existing to existing
useradd -G {username} - capital G supplements group onto username

List all groups user is a member of
groups {username}
id -Gn {username}

List groups a user is a member of
egrep "
groupname" /etc/group

List all groups
dscacheutil -q group

List all users
dscacheutil -q user

Monitor network usage..

$ date;ifconfig eth0
$ sudo tcpdump -i eth0

Favorite Command Lines


sudo find /. -type f -iname *.pkg
find all the packages on my computer (looking for where updates are downloaded to). This worked.
sudo find /. -type f -cmin 20
find all the files updated within the last 20 minutes. This didn't find the packages.


find . -type f -cmin -10
List all the files (not directories) that have been changed in the last 10 minutes

chmod -R ugo-x,u+rwX,go+rX {put top directory here}
Recurse through a directory and fix permission bits the way I like them

find . -type f -print0 | xargs -0 chmod 644
Find all the files recursively and change to permissions 644

find . -type d -print0 | xargs -0 chmod 755
Find all the directories recursively and change to permissions 755

xdd {fid}
Hexdump with ASCII interpretation


curl -O "";
download all the ARPC daily files, announcing schools, etc.


for users, set read write, set execute if a directory OR if any current execute bit is set
for group and others, set read only, set execute if a directory OR if any current execute bit is set
for group and others, unset write permission
(for shorter syntax with chmod and process substitution, see file "file-permissions-howto.txt")

find . -type d -print0 | xargs -0 chmod 755
find . -type f -print0 | xargs -0 chmod 644

Long list all files modified in this or subdirectories less than 310 minutes ago, more than 305 minutes ago.
find . -mmin -310 -mmin +305 -ls

although OS X respects case in file names, two files whose names differ only in case may not coexist on the same file system. If such files exist on the Unix side, Unison will report the error but not identify the offending files. Unix users can identify such files with the aid of a script like this:
find . -print | tr A-Z a-z | sort | uniq -c | awk '$1 > 1' |
tee /tmp/duplicates


chmod -R u+rwX,go+rX,go-w path

interpreting the arguments:

-R recurse directories
u+rwX for users, set read write, set execute if a directory OR if any current execute bit is set
go+rX for group and others, set read only, set execute if a directory OR if any current execute bit is set
go-w for group and others, unset write permission

Or, you can do it with find statements:

find . -type d -print0 | xargs -0 chmod 755
find . -type f -print0 | xargs -0 chmod 644

Or, you can do it with the chmod statement, using process substitution (see the bash man page).

chmod 755 $(find . -type d)


bmmbp:~ brian$ ./stroke 1 65535
Port Scanning host:

Open TCP Port: 88 kerberos
Open TCP Port: 139 netbios-ssn
Open TCP Port: 445 microsoft-ds
bmmbp:~ brian$


A command line to mirror FreeBSD might look like:

% rsync -vaz --delete /pub/FreeBSD/

The Apache HTTP Server only supports rsync for updating mirrors.

rsync -avz delete safe-links /path/to/mirror

The preferred (and simplest) way to mirror the PuTTY website to the current directory is to use rsync.

rsync -auH rsync://

A way to mimic the capabilities of Time Machine (Mac OS). Or, use snapshot :-)

date=`date "+%Y-NaVdT%H:%M:%S"`
rsync -aP --link-dest=$HOME/Backups/current /path/to/important_files $HOME/Backups/back-$date
rm -f $HOME/Backups/current
ln -s back-$date $HOME/Backups/current

Created by . Last Modification: Saturday 07 of November, 2015 07:45:16 CST by brian.