Wednesday, August 31, 2011

Bash: copy directory structure without the files

Here's a one-liner to do that. Go to the source directory and say

user@host:source$ find * -type d -exec mkdir destination/\{\} \;

Tuesday, August 9, 2011

Changing display resolution on Ubuntu when the resolution option doesn't show up

It is very annoying when you have a good monitor (an NEC MultiSync LCD1970NX in my case), capable of supporting 1280x1024 or some such high resolution, whereas Ubuntu simply cannot see beyond 832x624.

Earlier versions of Ubuntu had the xorg.conf file which is no longer present, although if you craft it by hand it is still going to be used. That seems like a dangerous proposition, though - a simple mistake could screw up at least something that is working.

I found the savior in the command xrandr, thanks to X/Config/Resolution page on the ubuntu wiki. And here is what I have done so far:

1. I first ran the command xrandr to make sure that the VGA1 indeed existed. As it turns out, that command can also tell you what is the highest resolution your monitor can support:
sudipta@Springfield:~$ xrandr
Screen 0: minimum 320 x 200, current 832 x 624, maximum 4096 x 4096
VGA1 connected 832x624+0+0 (normal left inverted right x axis y axis) 376mm x 301mm
   1280x1024      60.0 +   75.0 
   1280x960       60.0 
   1152x864       75.0 
   1024x768       75.1     70.1     60.0 
   832x624        74.6*
   800x600        72.2     75.0     60.3     56.2 
   640x480        72.8     75.0     66.7     60.0 
   720x400        70.1 
LVDS1 connected 832x624+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1280x720       60.0 +
   832x624        74.6*
   800x600        85.1     72.2     75.0     60.3     56.2 
   640x480        85.0     72.8     75.0     59.9 
   720x400        85.0 
   640x400        85.1 
   640x350        85.1 
See that 1280x1024 at the top of the list? That is how high my monitor could go. And see that line in the middle with a * at the end (832x624        74.6* in my case) - that one is what I am currently running. And strangely enough, although xrandr knew the highest possible on available, the monitor options only showed 832x624 to be the highest:

So all I had to do to rectify the situation was to open up the gnome terminal and run
xrandr --output VGA1 --mode 1280x1024
which was the highest one supported by my monitor, as mentioned above. Note that I did not specify a refresh rate (using --rate 75 or 60): I let the computer decide for itself. And voila! I had a 1280x1024 screen on my monitor!

I will post an update about how to make the change permanent as well, although the wiki already mentions some options.

Thursday, July 7, 2011

ln -sf gives ?[01;32mFILENAME?[0m

So I was trying to link to a few files from a script and it kept getting me these strange links instead of the actual file name. This is what I had in my shell prompt:

for i in `ls /var/www | grep FILENAME`; do ln -sf $i .; done

[The grep is there because of multiple files which began by the same name]. But then what I got instead in the folder where I was running this script was this:

sudipta@Hogwarts:~/html$ ls -l
total 156
lrwxrwxrwx 1 sudipta sudipta     25 2011-07-06 23:08 ?[01;32mFILENAME?[0m -> ?[01;32mFILENAME?[0m

lrwxrwxrwx 1 sudipta sudipta     34 2011-07-06 23:08 FILENAME.txt -> FILENAME.txt

I had no idea where this strange file was from or why it was here. Also, only a few files were getting affected by this. A simple "ls -l" showed that this was happening only to those files which had the executable file set

After some time, I realized that this was a permissions problem. I gave the local directory write permission by www-data, and then sudo-ed myself into www-data and re-executed my script again.

sudipta@dev:~/html$ rm -f FILENAME*sudipta@dev:~/html$ chmod a+w .
sudipta@dev:~/html$ sudo su www-data
[sudo] password for sudipta:
$
for i in `ls /var/www | grep FILENAME`; do ln -sf $i .; done
$^D
And that did it! All I needed was to run the thing as www-data with write permission in my current directory.
sudipta@Hogwarts:~/html$ ls -l
total 156
lrwxrwxrwx 1 sudipta sudipta     25 2011-07-06 23:08 FILENAME -> FILENAME

lrwxrwxrwx 1 sudipta sudipta     34 2011-07-06 23:08 FILENAME.txt -> FILENAME.txt

Monday, February 14, 2011

Deleting all panels on GNOME desktop

Apparently, deleting all panels is not the easiest thing to do on a GNOME desktop.

Open gconf-editor and goto /apps/panel/toplevels and set these values:
auto_hide: yes


auto_hide_size: 1
expand: no
hide_delay: 1
monitor: 3
unhide_delay: 10000
x: 10000
y: 10000

This will hide the panel permanently.