Useful Linux commands

Find directory size:
cd to dir which size you want to know
du -chd 1 | sort -h (1 – subdirs shown in output, size output value not affected when changing)


Show HDD space usage:
df -h

Interesting utulity showing extended info about disk usage:


Su as another user:

Sleep in scripts
sleep .5 # Waits 0.5 second.
sleep 5 # Waits 5 seconds.
sleep 5s # Waits 5 seconds.
sleep 5m # Waits 5 minutes.
sleep 5h # Waits 5 hours.
sleep 5d # Waits 5 days.
One can also employ decimals when specifying a time unit; e.g. sleep 1.5s


Find specific word in file:
grep -a “WORD-WE-NEED” /var/log/some.log


Watch for changes in file (usually we need to watch small status log):
watch -n 1 cat /var/log/some-status.log

Lighttpd tricks and tips

How to redirect HTTP requests to HTTPS:

Example 2 – specific url:
$HTTP[“scheme”] == “http” {
$HTTP[“host”] =~ “.*” {
url.redirect = (“^/phpmyadmin/.*” => “https://%0$0”)


Directory Listings:

If you need it only for a specific directory or directories, use conditionals:

$HTTP[“url”] =~ “^/download($|/)” {
dir-listing.activate = “enable”


URL Rewrites with regular expressions:

Regular Expressions
Patterns (“wildcards”) are matched against a string
Special characters (see [] for reference):
. (full stop) – match any character
\* (asterisk) – match zero or more of the previous symbol
\+ (plus) – match one or more of the previous symbol
? (question) – match zero or one of the previous symbol
\\? (backslash-something) – match special characters
^ (caret) – match the start of a string
$ (dollar) – match the end of a string
[set] – match any one of the symbols inside the square braces.
[^set] – match any symbol that is NOT inside the square braces.
(pattern) – grouping, remember what the pattern matched as a special variable
{n,m} – from n to m times matching the previous character (m could be omitted to mean >=n times)
(?!expression) – match anything BUT expression at the current position. Example: “^(/(?!(favicon.ico$|js/|images/)).*)” => “/fgci/$1”

Normal alphanumeric characters are treated as normal


Protect Different Directories With Different Password Files:

$HTTP[“url”] =~ “^/docs/” {
auth.backend = “plain”
auth.backend.plain.userfile = “/home/lighttpd/.lighttpdpassword-DOCS”
auth.require = ( “/docs/” =>
“method” => “basic”,
“realm” => “Password protected area”,
“require” => “user=tom”