Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

http://installingcats.com

argument list too long rm delete in directory

// description of your code here

find . -maxdepth 1 -name '*.jpg' -exec rm {} \;

list files recursively

// list files recursively using ls

ls -R


while searching for files


ls -R | grep 'searchterm'

vim backreference on search and replace

// description of your code here

Use \(\) to denote an atom.
Use \1 to specify the first atom.

<this is your search and replacement terms>

:%s'\(<stuff_to_find>\)'\1<new_stuff>'gc

symbolically link entire directory contents

// description of your code here

ln -s /full/dir/path/to_files /full/dir/path/destination

Run script just before linux reboot (runlevel 6 / rc6.d)

update-rc.d is the program (script) which creates the necessary symbolic links to the /etc/rcX.d directories.

Here we are running the script found at /etc/init.d/updatedb_start, within runlevel 6, which is reboot.

Running this will create a symbolic link to the actual script file which lives within /etc/init.d (as it always should).

So, within /etc/rc6.d/ we'll see a symbolic link to our script.

The period at the end of the command is required. Tells update-rc.d that we're finished with the command (no further runlevels to edit).

We're using "stop" instead of "start" because we want to run the script during the killing off scripts part of the rc6.d scripts.
This causes the script to be run with a "stop" parameter, for example: updatedb_start stop
We don't actually use the stop parameter in this case, it's just ignored.

update-rc.d updatedb_start stop 18 6 .

log to syslog

how to log something to syslog

logger This is my message to syslog

activate root in ubuntu after install

After this you can run su.

sudo passwd root

running scheduled programs in linux

use crontab

Edit the current configuration for crontab with:
crontab -e


Normally we'd created bash script files located in /usr/local/bin and have them specified for execution within our crontab configuration.

grep - search for a string within files within a directory (and sub directories)

// description of your code here

-r gives you recursion
"redeem reward" is the string being searched for
/home/tom is the directory to start the search from

grep -r "redeem reward" /home/tom

postfix - flush queues / logs

Using the program: postsuper

There are three queues (active, deferred, incoming) and four log directories (bounce, defer, trace, flush).

To remove all mails in the deferred queue:

postsuper -d ALL deferred


Note that all of the queues and log dirs are located in:
/var/spool/postfix