TWB
v2014.08.07.12.32.46

Shebang

#!/bin/sh

Re-Run the Last Command as Root

sudo !!

Get the Last Occurrence of a Command Without Executing It

!searchterm:p
!sudo:p

Instantly Create a Blank File or Multiple Files

touch filename
touch index.html gallery.html cv.html

dateidatum setzen, bsp.: 2011-01-31 12:01

touch -t 201101311201 theFile

disk usage of a folder (-hs : human readable, summarize)

du -hs FOLDER

List Directory Contents by Modification Date

ls -thor

Kill Processes Using Wildcards

pkill Sam*
kill -u username
kill -u username

simple rekursive copy and chown

cp -R FOLDER/* NEW_FOLDER
chown -R user:users NEW_FOLDER

Dateien und Verzeichnisse rekursiv chmodden

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

Dateien unter Linux nach Datum löschen 30 Tage

find /pfad -mtime +30 | xargs rm

for ...

#!/bin/bash

for file in ./*; do
    echo "$file"
done

rsync von einer Domain remote kopieren

rsync -aurz -e ssh USER@192.168.0.3:~/xxx.sql .
rsync -aurz -e ssh USER@DOMAIN.TLD:~/public_html/* /usr/home/USER/public_html

Download a File from the Web & Watch Progress

curl -O http://url

Test Internet Connection Speed from the Command Line

wget -O /dev/null http://speedtest.wdc01.softlayer.com/downloads/test10.zip

TAR ZIP GZIP RAR

tar

# Archive mit Inhalt von /etc und /home erstellen:
tar cvf test.tar /etc/ /home/
tar cvf - /etc /home | gzip > test.tar.gz
tar czvf test.tar.gz /etc/ /home/         # *GNU tar* Kurzform
tar -czvf test.tar.gz /etc/ /home/        # *GNU tar* Alternative

# Archive entpacken:
tar xvf test.tar
gunzip < test.tar.gz | tar xvf -
tar xzvf test.tar.gz                      # *GNU tar* Kurzform
tar -xzvf test.tar.gz                     # *GNU tar* Alternative

# Archivinhalt ansehen:
tar tvf test.tar
gunzip < test.tar.gz | tar tf -
tar tzvf test.tar.gz                      # *GNU tar* Kurzform
tar -tzvf test.tar.gz                     # *GNU tar* Alternative

zipped rekursiv alle dateien in archiv.zip

zip -r archiv.zip .
unzip xxx.zip

gzip -9 xxx.sql
gzip -d xxx.sql.gzip

rar'd alle dateien rekursiv in multiple archive mit 20 megabyte grösse

~/bin/rar a -v20m -r yapool-pictures.rar .

MAC - Search Spotlight with Live Results from the Command Line

mdfind -time findme

MAC - Making the ~/Library/ Folder Visible from the Command Line

chflags nohidden ~/Library/

MAC - MYSQL start

/usr/local/mysql/bin/mysqld_safe

# besser:
/usr/loca/mysql/support-files/mysql.server  start|restart|stop

# Bsp.
sudo mysql.server start

MAC - Apache

/usr/sbin/apachectl   start|restart|stop

# Bsp.
sudo apachectl start

MAC - php xdebug install

sudo sh -c 'echo "zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so" >> /etc/php.ini'
sudo apachectl restart

locate db update

sudo /usr/libexec/locate.updatedb

MAC - Dock in Ecke

#Dock links (oben)
defaults write com.apple.dock pinning -string start
killall Dock

#Dock rechts (unten)
defaults write com.apple.dock pinning -string end
killall Dock

#Dock wieder mittig
defaults delete com.apple.dock pinning
killall Dock

MAC - rm .DS_Store recursive

find /Users/tobi -name .DS_Store -exec rm {};

MAC - hidden files show and hide

defaults write com.apple.finder AppleShowAllFiles FALSE
killall Finder

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

File backup

#!/bin/sh
myDate=`date '+%y%m%d_%H%M'`
keepDays='+10'

toBackupFolder='./public_html/'
backupFolder='./filebackup/'
backupFile="tobibak_${myDate}"

zip -r ${backupFolder}${backupFile} ${toBackupFolder}

find ${backupFolder} -mtime ${keepDays} | xargs rm

Mysql backup

#!/bin/sh
# tobistyle MySQL Backup Script

myDate=`date '+%y%m%d_%H%M'`
keepDays='+2'
dumpFolder='./mysqldump/'

db='DBNAME'
dbTables='table1 table2 table3 ...'
dbUser='DBUSER'
dbPassword='DBPASSWORD'
dbBackupFile="${dumpFolder}${db}_${myDate}"

mysqldump -u${dbUser} -p${dbPassword} ${db} ${dbTables} > "${dbBackupFile}.sql"

gzip -f -q "${dbBackupFile}.sql"

cp -f "${dbBackupFile}.sql.gz" "${dumpFolder}latest_${db}.sql.gz"

# removes all files older then keepDays (DANGEROUS!)
find ${dumpFolder} -mtime ${keepDays} | xargs rm

mysqldump, email to ...

#!/bin/sh
myDate=`date '+%y%m%d_%H%M'`
db='DBNAME'
dbUser='DBUSER'
dbPassword='DBPASSWORD'
dbBackupFile="${dumpFolder}${db}_${myDate}"
emailAdress='admin@host.de'

mysqldump -u${dbUser} -p${dbPassword} ${db} > ${dbBackupFile}.sql

gzip ${dbBackupFile}.sql

# email file to ...
mpack -s dbbackup_${myDate} ${dbBackupFile}.sql.gz ${emailAdress}

manual mysqldump workflow

# go remote
ssh USER@192.168.1.1

# remote
cd ~/dumpfolder
mysqldump -uDBUSER -pDBPASSWORD DBNAME > DBNAME.DATE.sql
gzip DBNAME.DATE.sql

# local
cd ~/htdocs/PROJECT/_res
rsync -aurz -e ssh USER@192.168.1.1:~/dumpfolder/DBNAME.DATE.sql.gz .
gzip -d DBNAME.DATE.sql.gz
mysql -uroot -p

# local mysql
drop database DBNAME;
create database DBNAME;
exit

# local
mysql -uroot -p DBNAME < DBNAME.DATE.sql


# done!

...