MacOSXLinuxCommandLine


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. http://lifehacker.com/compare-the-contents-of-two-folders-with-the-diff-comma-598872057

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 .


8/19/15
smbstatus
smbtree


4/10/15 MONITOR PROGRESS OF DD (OR ANY OTHER COMMAND)

from http://askubuntu.com/questions/215505/how-do-you-monitor-the-progress-of-dd
kill -USR1 $(pgrep dd$)
watch -n5 'kill -USR1 $(pgrep dd$)'


4/1/2015 Get distribution of file sizes.

http://unix.stackexchange.com/questions/55073/how-to-get-the-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 {} \;


12/29/2014 UNZIP A FILE TO A DIRECTORY

$ zip -r -X -z mlhack29.zip mlhack29

12/29/14 Mac OSX file directory comparisons

$ diff -rq folder-1 folder-2

12/22/2014

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

11/9/2014

$ dig +trace +additional increa.com

good DNS zone file info at http://www.slashroot.in/what-dns-zone-file-complete-tutorial-zone-file-and-its-contents

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

2/1/2013 COMMAND LINE MEMORIES


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

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

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

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

nmap -O -vv 192.168.1.11

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

4/9/2012

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.



7/29/2011 FIND RECENTLY CHANGED FILES


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

3/2/12


curl -O "http://www.arpc.afrc.af.mil/shared/media/document/AFD-120322-001-99.pdf";
download all the ARPC daily files, announcing schools, etc.


9/13/2011 SETTING FILE PERMISSIONS


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

6/25/2011


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)

9/13/11


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

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


10/21/11 - HOW TO RYSNC MIRRORS LIKE TIME MACHINE


A command line to mirror FreeBSD might look like:

% rsync -vaz --delete ftp4.de.FreeBSD.org::FreeBSD/ /pub/FreeBSD/

The Apache HTTP Server only supports rsync for updating mirrors.

rsync -avz delete safe-links rsync.apache.org::apache-dist /path/to/mirror

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

rsync -auH rsync://rsync.chiark.greenend.org.uk/ftp/users/sgtatham/putty-website-mirror/

A way to mimic the capabilities of Time Machine (Mac OS). http://blog.interlinked.org/tutorials/rsync_time_machine.html. 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.