Docunext


Linux Notes

October 29th, 2006

Stat

stat -f "%Sc" -t "%Y%m%d" filename

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 --forest

!To change mode of only files or directories - DO NOT USE THESE LIGHTLY!!!!: <verbatim>

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-here

!Find

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

done

!Detox

Useful for truncating and normalizing filenames

!Untar to specific directory: tar -C /var -xzf var-backup.tar.gz

!RESUME

rsync --progress --partial -e ssh

!mount Samba share on linux:

mount -t smbfs //hostname/share /targetdir/

Mac, Linux, and Windows Compatibility

  • Apparently Linux supports HFS+ as a kernel module, it also supports AFP and Samba, which makes it very useful for transferring files between different types of hosts.
  • Mac saves ._* resource forks on non-HFS volumes, that is pretty lame. It might make sense to have an HFS+ filesystem on the LAN for Mac access, which is shared via Samba to PCs, and AFP to Macs.

The role of Partitions

  • Partitions are very useful: you can have multiple OS's, and install the OS on a small partition for easier backup. Same with / and /boot/, you can back those up too. And just like the Gentoo manual says, you can have a partition for mail, or web, without worrying about the OS partition running out of room for basic functions like logging.

mysqldump -u hostname -ppassword dbname | gzip -c | ssh -c blowfish username@hostname "gunzip -c | mysql -u username -ppassword dbname"

Yearly Indexes: 2003 2004 2006 2007 2008 2009 2010 2011 2012 2013 2015 2019 2020 2022