Unix - commands
# find all fill with same extension
find -iname "*.cpp" -type f# list dir content line by line
ls | lessdefaults write com.apple.PowerChime ChimeOnAllHardware -bool true; open /System/Library/CoreServices/PowerChime.app &
// to disable
defaults write com.apple.PowerChime ChimeOnAllHardware -bool false;killall PowerChimerm Library/Application\ Support/com.bohemiancoding.sketch3/.sketch3
//------------------------------------------------------------------------------
// Find file by type
find ~/ -iname "*.jpg"
//------------------------------------------------------------------------------
// Find file
find folder_name -name "Y"
//------------------------------------------------------------------------------
// List ip
ifconfig en1
//------------------------------------------------------------------------------
// get public ip address with curl
curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
//------------------------------------------------------------------------------
// Installing FFMPEG
http://ffmpegmac.net/HowTo/
//------------------------------------------------------------------------------
// Create an executable bash shell script
-sudo nano test
-type into editor;
-#!/bin/sh
-then;
-say hello
-CMD+o
-CMD+x
-chmod 755 test
-to run script;
-./test
//------------------------------------------------------------------------------
// display current directory
pwd
//------------------------------------------------------------------------------
// Beautiful dir listing
ls -FlGht
//------------------------------------------------------------------------------
// Create 100 files
touch {1..100}.txt
//------------------------------------------------------------------------------
// Remove everything in folder
rm *
//------------------------------------------------------------------------------
// Disable .ds_store files on Mac OS X
defaults write com.apple.desktopservices DSDontWriteNetworkStores true
//------------------------------------------------------------------------------
A cheat sheet for UNIX.
#SSH
ssh-keygen -t dsa
change the permissions of the .ssh folder
chmod 700 ~/.ssh
change the permissions of the .ssh folders content
chmod 600 ~/.ssh/*
change the rights of EVERY file in my homefolder, this is done with the -R flag. It might be nicer if you dont use it at all and type (chmod 755 /Users/USERNAME/)
$ chmod -R 755 /Users/USERNAME/
SHELL COMMANDS
# get the name of the current shell
ps | grep `echo $$` | awk '{ print $4 }'
# ssh remote commands
ssh user@address 'df -h'
#UBUNTU
# what OS version am i running?
lsb_release -a
#OS X
# what OS version am i running?
sw_vers
# change name of computer
sudo vi /etc/hostname
# ssh ~/.ssh/config file for persistent connections
Host *
Protocol 2
TCPKeepAlive yes
ServerAliveInterval 60
# Remove all .svn folders from a directory
rm -rf $(find . -name .svn)
# generate a checksum
md5sum filename.xxx >> filename.xxx.md5
#check a checksum
md5sum -c filename.xxx.md5
# dump a tar.gz
tar -zxvf xxxxx.tar.gz
#zip directory and sub dirs
tar -cvzf xxxxx.tgz xxxxx/
# word histogram
awk ' NF > 0{ counts[$0] = counts[$0] + 1; } END { for (word in counts) print counts[word], word; }' AllRejected_Usernames.txt | sort -rn > username_counts.txt
#screen
"screen" to start
To detach: Ktrl+a+d
To reattach: screen -r
#mount iso
mkdir /mnt/cd
mount -o loop -t iso9660 mycdrom.iso /mnt/cd
#unmount iso
umount /mnt/cd
#split using Tar
# tar -cf - dbbackup.db | split -b 100m - db_backup.tar
# recreate using tar
# cat db_backup.tara* | (tar x)
# rar
./rar a -s -v250m out_1/FILENAME_1.rar FILENAME_1.iso
# persistent ssh
ssh -o ExitOnForwardFailure=yes -q -N -p 9999 -R 5000:localhost:22 user@host
# peristant ssh loop keep on trying
while [ ! -f /tmp/stop ]; do ssh -o ExitOnForwardFailure=yes -q -N -p 9999 -R 5001:localhost:22 user@host "while nc -zv localhost 2222; do sleep 5; done"; sleep 5;done
# .htaccess
IndexIgnore * // this will prevent index generation for all subdirectories
Curl silent w/User Agent
curl -A "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7" -s "http://news.google ..."
# compiling universal!
gcc -O2 -Wall -force_cpusubtype_ALL -mmacosx-version-min=10.4 -arch i386 -arch ppc *.c -o [outputfile]
So, for ./configure
export CFLAGS="-force_cpusubtype_ALL -mmacosx-version-min=10.4 -arch i386 -arch ppc"
# disk usage
du -h
du -S * | sort -n
# disk free space
df
# Simple Bash Loop
#!/bin/bash
for i in $( ls ); do
echo item: $i
done
#concatenate PDFs
gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf in1.pdf in2.pdf in3.pdf ...
# concatenate movies
catmovie
#split files into X number lines
csplit -s -n 3 -f OUTPUT_FILENAME_PREFIX_ INPUT_FILE.txt 250 {10}
// where 250 is number of lines
#x11 forwarding
ssh -X user@hostname
# ssh tunnel with auto re-connecting using auto ssh and a proxy
/usr/bin/autossh -M 0 -q -f -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -p 443 -R 8898/127.0.0.1/22 user@host -p 443 -R 8899/127.0.0.1/22 user@host
// http://en.gentoo-wiki.com/wiki/Autossh // reference
// uses SSH's own internal checking, thus more reliable than the port method
# count files in sub directory
find . -type f | wc -l
# batch process images in place (resize png images recursively)
find . -name '*.png' -exec mogrify -resize 256\>x256\> '{}' \; -print
# find all entries that do not match *.png
find . ! -name '*.png'
# create user at existing home directory
sudo adduser --home /FULL/PATH/TO/HOME username
# add user to sudoers
vi /etc/sudoers
# add user to group
usermod -G group-name user-name
# add group
groupadd group-name
# remove a user and their home directory, use:
sudo deluser -remove-home <user-name>
# remove all of their files on the server:
sudo deluser -remove-all-files <user-name>
# VI - find replace
:%s/search_string/replacement_string/g
# list active connections
lsof -i
diskutil verifyvolume /dev/xx
diskutil repairvolume /
// List attached volumes
diskutil list
// Format/erase and mount
sudo diskutil eraseDisk FAT32 RASPBIAN MBRFormat /dev/disk2