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!)

Find directories with trailing spaces

// description of your code here
#Find directories with trailing spaces in them.
find . -type d -iregex '.* '

prevent script execution upload directories php shtml

// description of your code here

<Directory "/Library/MediaWiki/web/images">
   # Ignore .htaccess files
   AllowOverride None
 
   # Serve HTML as plaintext, don't execute SHTML
   AddType text/plain .html .htm .shtml
 
   # Don't run arbitrary PHP code.
   php_admin_flag engine off
 
   # If you've other scripting languages, disable them too.
</Directory>

md5 compute compare files

// description of your code here

md5sum <filename>

recursive find grep

// description of your code here

printf junk avoids problems with single quotes in results returned by find

find . -name "*.txt" -printf '"%p"\n' | xargs grep some_pattern


This example will show path+file but not matching lines.
find . -name "*.php" -printf '"%p"\n' | xargs grep "http://rst.void.ru" | cut -d: -f1


make a script of it and place it in .bashrc
deepfind () { echo "Searching for $1"; find . -type f -printf '"%p"\n' | xargs grep "$1" | cut -d: -f1;}

postfix mail queue watch monitor outgoing email

// description of your code here

postcat

The postcat command displays the content of a message in a mail queue.

To read a message in a mail queue, you need its queue ID. Run mailq for a list of queue IDs. For example, the queue ID of the following message is F2B9715C0B3:

After obtaining a queue ID, use it as an option to postcat to see the contents of the queue file:

mailq
F2B9715C0B3 2464 Mon Oct 13 15:29:39 markus.herrmann@example.com
            (connect to mail.example.com[217.6.113.151]: Connection timed out)
            torsten.hecke@example.net
-- 2 Kbytes in 1 Requests.

postcat -q F2B9715C0B3


Delete all mail in queue
postsuper -d ALL

ubuntu linux date time set update adjust

// description of your code here

date mmddHHMMYYyy

so
date 121520152005
Dec 15 8:15 2005

kill linux process

// description of your code here

find process id first via

ps -alx | grep <string>


then kill it with

kill <PID>


or kill stubborn processes with

kill -9 <PID>

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