[[TOC]] = !SysAdmin Tips = == Renaming multiple files == {{{ for i in *.avi; do j=`echo $i | sed 's/find/replace/g'`; mv "$i" "$j"; done }}} {{{ for i in *.phtml; do mv $i ${i%.phtml}.php; done }}} == Deleting files matching a pattern == {{{ find opt/Products -name "*.pyc" -exec rm '{}' \; }}} == Sed: Stream Editor == Search/Replace: {{{ sed 's/old/new/g' input.txt > output.txt }}} Faster: {{{ sed '/old/ s/old/new/g' input.txt > output.txt }}} Do on a folder full of files: {{{ #! /bin/sh # Source files are saved as "filename.txt.bak" in case of error # The '&&' after cp is an additional safety feature for file in *.txt do cp $file $file.bak && sed 's/foo/bar/g' $file.bak >$file done }}} Insert paragraph: * e.g. search for lines `#include ' and then write: {{{ #ifdef SYSV #include #else #include #endif }}} Now, for writing the same script on one line, the -e mechanism is needed... what follows each -e can be considered as an input line from a sed script file, so nothing kept us from doing: {{{ sed -e '/#include /{' \ -e 'i\' \ -e '#ifdef SYSV' \ -e 'a\' \ -e '#else\' \ -e '#include \' \ -e '#endif' \ -e '}' }}} 1-liners: * http://sed.sourceforge.net/sed1line.txt Tutorial: * http://sed.sourceforge.net/grabbag/tutorials/do_it_with_sed.txt Collected resources: * http://sed.sf.net/ == Adding a swapfile == If you have a live system which you need to give extra swapspace too without a reboot, then can add a swapfile. Note that a swapfile is much slower than a swap partition, which is -of course- slower than memory. The reason for this is to save the ship when the boat's going down, not increase preformance. The right way to fix an OOM issue is to fix the leaky program. Create file: {{{ dd if=/dev/zero of=/swapfile count=[size of swap, in 512B blocks] }}} Format it: {{{ mkswap /swapfile }}} Tell the kernel to use it at an lower priority (i.e. only use when swap parition is full): {{{ swapon -p -2 /swapfile }}} == Changing editors == In ubuntu (or any shared system really), you will often find that you don't have the option to use your favourite editor. Ubuntu offers a farirly sophisticated way to dictate which editor you wish to use. Try: {{{ man update-alternatives }}} and: {{{ update-alternatives --config editor }}} ---- MaintenanceGuidelines MaintenanceGuidelines MaintenanceGuidelines