Stat
stat -f "%Sc" -t "%Y%m%d" filename
$string = preg_replace("/(\S*)(:\/\/)(\S*)/","\\1\\2\\3",$string);
Rename Files
for i in *; do mv "$i" "${i/whatsinheregoesaway/andisreplacedbythis}"; done for i in *; do mv "$i" "${i}.doc"; done
Make your swap partitions twice the size of your RAM amount.
df - how much space is being used on storage devices
A good filesystem benchmark: IOZone
Cool Linux Command:ps aux --forestTo change mode of only files or directories - DO NOT USE THESE LIGHTLY!!!!:
Remove .DS_Store files:
find . -name '.DS_Store' -exec rm {} \;
Get all the users in a group:
grep "groupname" /etc/group | awk -F: '{print $4}'
Remove command history:
ln -s /dev/null $HOME/.mysql_history
or
ln -s /dev/null $HOME/.bash_history
Count # of files:ls -1Ra | wc | awk '{printf("There are %s files in this directory!\n",$1-2)}'
Define the following function, skill, aka "Super Kill" in your .bashrc file. It finds the programs and terminate all the programs containing the give name!!
skill ()
{
kill -9 `ps ax | grep $1 | grep -v grep | awk '{print $1}'`
}
For example, skill netscape will terminate all the Netscape related programs. Use this command with care. skill xterm will terminate all the running "xterm"s. If you are scared, you can replace the first "$1" with a program name you need to kill frequently, such as "netscape", and name the function as "killnet". Here is an example.
killnet ()
{
kill -9 ps ax | grep netscape | grep -v grep | awk '{print $1}'
}
</verbatim>
Patches:diff -Naur old_dirorfile newdirorfile > name_of_patch.patch patch -p0 < patch-file-name-hereFind
find ./ -type d -exec chmod 0700 {} \;No Space:
for f in *; do file=$(echo $f | tr A-Z a-z | tr -d '-') mv "$f" $file doneDetox
Useful for truncating and normalizing filenames
Untar to specific directory:tar -C /var -xzf var-backup.tar.gzRESUME
rsync --progress --partial -e ssh ...mount Samba share on linux:
mount -t smbfs //hostname/share /targetdir/
Mac, Linux, and Windows Compatibility
The role of Partitions
mysqldump -u hostname -ppassword dbname | gzip -c | ssh -c blowfish username@hostname "gunzip -c | mysql -u username -ppassword dbname"