Get last modified and change date of file in linux

Short post to keep things simple, and i also have better things to do:

You had a great script doing skynet stuff on your server, but you noticed it stopped tracking the missile network sometime last week. Could someone have changed it? You know the last time you edited it, sometime around november 1976, so let’s check if someone else edited it since then.

|Read the Rest of the Entry…

Find Apache httpd.conf file location

So i was in the middle of a serious error debug session where some of the errors seemed to be apache’s fault. Probably some configuration adjustments, but for that i needed to see the current configuration (and change it if need be). But where is the httpd.conf file? After some practice, we easily look for it on the default places, depending on the linux distro (oh, i am assuming we are looking for it on a linux server), but let’s imagine we dont have a clue where it is. Now what? Read on.

Several ways to do it. But let’s take some time explaining the process:

[user]$ ps -ef

the ps -ef command lists all processes. You can pipe it to less to make it scrollable. Hell, you can pipe it to kingdom come, since its linux.

[user]$ ps -ef|grep apache

The grep apache command looks for the word “apache” on the ps -ef command results

You will get something like this (depending on your server and on how well you are into typing commands without messing up):

apache 20760 20753 0 Oct11 ? 00:00:56 /usr/sbin/httpd

Knowing that path, you can do this:

[user]$ /usr/sbin/httpd -V

That -V switch will show the httpd compile settings, where you will see tons of info (out of this post’s scope).
The line you want is:

-D SERVER_CONFIG_FILE="[your httpd.conf path will be here]"

To make things easier, we can do another grep on the results to get the exact info we need:

[user]$ /usr/sbin/httpd -V|grep SERVER_CONFIG_FILE

Which will get you just the line you need:

-D SERVER_CONFIG_FILE="conf/httpd.conf"

Again, your results may vary.

A note:

Like the example above, your path can show as relative and not absolute. But relative to what? With the /usr/sbin/httpd -V command, you will also get info about HTTPD_ROOT:

-D HTTPD_ROOT="/etc/httpd"

So your config file location will be relative to exactly that.

[user]$ cd /etc/httpd/conf

or go straight for the kill:

[user]$ sudo nano /etc/httpd/conf/httpd.conf

Hope this helps someone. Yes, either of the 4 people that read this.


commanigy post about this
– linux reference about the ps command
– linux reference about the grep command

How to get current year, month, day, etc. in python

Ok, so you have been coding for quite some long hours this week and you suddenly realie you dont even know what day it is. Or even year (yes, it happens). Since you are on the python command line, here’s what you can do:

(ok, so the scenario could be slightly different…still, the method to retrieve the date parameters are relevant anyway)

from datetime importdatetime

currentYear =
currentMonth =
currentDay =
currentHour =
currentMinute =
currentMicrosec =
currentWeekday = # weekday as integer - 0 is monday, 1 is tuesday, etc.

There’s lots of cool datetime calculations, methods and magic to be learned. Check the documentation link below.

Some reference reading:

Python docs: datetime — Basic date and time types
From blog “Programming By A Tool”

Django template to respect plain text field linebreaks

If you have a text field with linebreaks in your nice django admin and your cool template refuses to respect them, use this in your template:

{{ variable|linebreaks }}

this replaces newlines with HTML

<br />

and newlines with blank lines with


Learn tons of great stuff from your trusty Django docs:
Built-in template tags and filters

Remove repeated adjacent characters from string

Given a string like:

we want to output:


here are a few ways to do it in Python:

|Read the Rest of the Entry…

Quickly change a Django user password

So you have this nice django site, you try to access the admin to change some minor thing and you completely forgot (and didnt save somewhere) the password of the only user in the system – so many dont’s in that sentence, but anyway…

Since you are the developer, you can simply do this (assuming you at least know the user’s username):

python changepassword [username]

You will be prompted for a new password, and confirmation, and its done. Then you can go login to your nice admin and smile.

Please note that if you are using a virtualenv, you have to activate it first.

Read more about this and learn new things here:
Using the Django authentication system (opens in a new window)

PostgreSQL – PostGIS versions

Login to your postgresql on some database and go:

To get PostgreSQL version:

SELECT version();

To get versions for PostGIS, GEO, etc.:

SELECT PostGIS_full_version();

How to list and alter table sequences in PostgreSQL

So you screwed up with your ninja manual inserts on some lost and forgotten table. In such a way that when your shiny django backoffice gives you a fullscreen yellow error about duplicate keys. What now? Well, you read and i will show you how to circumvent the system (well, kind of).

|Read the Rest of the Entry…

How to add robots.txt to a Django project

So we had this nice, unfinished project, publicly shared on a public server being indexed like a pig’s behind on google servers. Some searches on google had hits to full length urls to this unfinished project on the test server. Easily stopped using the robots.txt, except that its a Django site and its not as simple as putting the file on the server’s root. Its not that hard either, but you have to know how.

Anyway, here are a few solutions i found:

|Read the Rest of the Entry…

Javascript Functions optional parameters

Ok, you want to create a function to be used several times (well, isnt that the main purpose of them?), but, depending on the call, you can have 1 argument or several. How do you go about doing it? Enter the world of optional parameter functions. Or something like that…after the jump.

Here are three ways:

|Read the Rest of the Entry…

%d bloggers like this: