Archive for November 27th, 2010

Set current day time in Linux to BIOS hardware clock

Saturday, November 27th, 2010

Strangely enough my date showed one hour earlier than the local time that is actually here in Holland.
I don’t understand why this happened but obviously the hardware clock of my BIOS has been turned back with one hour.

To fix the situation I’ve used the hwclock – query and set the hardware clock (RTC) command.

It took me a while until I remember how exactly I did it before but after a quick consult with the manul I came up with the right option to Set the Hardware Clock to the current System Time on my Debian Linux.

Here is the command which set the hardware clock to the current system time for me;

debian:~# hwclock --systohc

Cheers 🙂

How to show all sub-directories beloging to a directory with find in Linux

Saturday, November 27th, 2010

I’ve recently had to write a shell script for which I was required to list all the subdirectories that belongs to a certain directory to do so I had to execute the following simple command line;

find . -type d -ls|awk '{ print $11 }'

Before executing the above linux find command you will need to go to the directory in which you’d like to list all the subdirectories.

cd /some/directory/

Now the list of all sub-directories will appear. This command is very useful if it’s combined with a for bash cycle in my script I used the sub-directories find with the following for bash loop;

for f in $(find . -type d -ls|awk '{ print $11 }'); do
# place here something to do with each of the element of the subdirectory list
done

In my case I used it to download some pictures from a remote website to which I had no access but had the general structure of it, so within the loop I used the wget to fetch my missing pictures after extracting the pictures names from the mysql database.
Still the usage of the above loop and find command can be combined and probably be useful for many other admin tasks to achieve.