Friday, July 24, 2009

ls colors - green only if the file has exec permission

In my system, all the .sh are displayed in green color when I use the ls command. It is displayed in green color even if the execute bit is not set in the permissions. It confused me because by seeing the green color, I think that the file is executable. When I try to run it with ./.sh it says 'Permission denied'. Only then I will know that the .sh file doesn't have execute permission. So I wanted the files to be displayed in green only if the execute permission is set.

In linux the command 'dircolors' prints out the commands to set the LS_COLORS environment variable. But it doesn't print out what is set in your LS_COLORS variable. Without knowing this, I was first confused why dircolors and 'echo $LS_COLORS' prints out different things. In the LS_COLORS there was an entry for .sh files (*.sh=00;32). This is reponsible for ls to print all the sh files in green color. From where did the LS_COLORS get this entry? I searched in the /etc/DIR_COLORS file. It had an entry, but even after commenting out that LS_COLORS still had that entry in my system.

While trying to find out what is initializing the LS_COLORS with that entry, I came across this page
Wednesday Why: Colour ls that clearly explains how the LS_COLORS variable is initialized.

This script, which is also responsible for setting up the ls alias, gets the colors from one of several possible configuration files; these are from highest to lowest priority: ~/.dir_colors.$TERM, ~/.dir_colors, ~/.dircolors.$TERM, ~/.dircolors, /etc/DIR_COLORS.$TERM, or /etc/DIR_COLORS (where $TERM is your current terminal type as specified by the TERM environment variable).


In my system, /etc/DIR_COLORS.xterm had this line (".sh 00;32"). After commenting that line I got what I expected ie. sh files to be displayed in green only if it has executable permission. I had to the same thing for .bat, .csh also.

Thursday, July 23, 2009

Processes accessing a file

'fuser' command can be used to get the processes that are accessing the file.

'fuser /tmp/hello.txt' - lists the process ids of all the processes accessing the file '/tmp/hello.txt'.

You need to have the required permission. root can view all the processes that are accessing the file.

fuser can also be used if you want to kill (send signal) the process that is accessing the file. The option for that is -k.

Thursday, July 9, 2009

Status messages

Some of the status messages I used in Pidgin. All messages are copied from the web.

From http://en.wikiquote.org/wiki/Linus_Torvalds
1. Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen an angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
2. When you say "I wrote a program that crashed Windows people just stare at you blankly and say 'Hey, I got those with the system, *for free*'.
3. Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect.
4. Microsoft isn't evil, they just make really crappy operating systems.

From other sites:
1. Bill Gates left his university to start Micro$oft. Steve Jobs sold his Wolkswagen bus to start Apple.Linus Torvalds made a new thread in a forum and put a file on a ftp server. - http://linustorvaldsfacts.com/english.html
2. Not using Version control system is like driving a car too fast: it's fun and you might get to your destination faster, but an accident is inevitable. - http://www.ibm.com/developerworks/linux/library/l-vercon/
3. A simple description of ssh is that it's a secure version of telnet, but that's like saying a Porsche is a just a better version of a Volkswagen bug. - http://www.linuxjournal.com/content/creating-secure-tunnels-ssh
4. You cannot, by accident, build an airplane that actually flies. - http://www.techflash.com/How_a_Microsoft_veteran_learned_to_love_Linux_and_why_it_matters_48542167.html



Display threads in Linux

ps man page has the following information

To get info about threads:
ps -eLf
ps axms

When I tried "ps -eLf" in my machine, a portion of the output is

UID PID PPID LWP C NLWP STIME TTY TIME CMD
pratheep 3386 3364 3386 7 6 12:40 ? 00:00:55 /usr/lib/firefox-3.0.11/firefox
pratheep 3386 3364 3389 0 6 12:40 ? 00:00:00 /usr/lib/firefox-3.0.11/firefox
pratheep 3386 3364 3393 0 6 12:40 ? 00:00:02 /usr/lib/firefox-3.0.11/firefox
pratheep 3386 3364 3423 0 6 12:40 ? 00:00:00 /usr/lib/firefox-3.0.11/firefox
pratheep 3386 3364 3424 0 6 12:40 ? 00:00:00 /usr/lib/firefox-3.0.11/firefox
pratheep 3386 3364 3425 0 6 12:40 ? 00:00:00 /usr/lib/firefox-3.0.11/firefox
pratheep 3396 3137 3396 0 2 12:40 ? 00:00:00 kdeinit4: kio_http [kd up
pratheep 3396 3137 3409 0 2 12:40 ? 00:00:00 kdeinit4: kio_http [kd up
pratheep 3398 3137 3398 0 2 12:40 ? 00:00:00 kdeinit4: kio_http [kd up
pratheep 3398 3137 3408 0 2 12:40 ? 00:00:00 kdeinit4: kio_http [kd up


LWP - lwp (light weight process, or thread) ID of the lwp being reported.
NLWP - number of lwps (threads) in the process.
C - processor utilization. Currently, this is the integer value of the percent usage over the lifetime of the process.

First post

I am starting a new blog that contains some of the small things that I learn / interesting things I read in the web.