Posts tagged “unix”.

Life in the BASH universe

If you write a lot of scripts to automate tasks, you probably already know this. However, if you don’t, and you are still reading, you are probably a programmer, in which case, you really should be learning how to script in BASH!

A couple of pointers for you:
1. Using a -x, in the shebang line “echo”s every line before executing. This turns out to be quite useful for debugging shell scripts
2. It’s quite easy to make BASH print a countdown.

Exporting XDisplay

In *nix systems, you can make the display, the GUI of an application, appear on another machine.  This if often required, when the machine you want to run the application on is in a lab, and you have access through a desktop machine that has a monitor.

You can do this, by running an XServer on the desktop machine and configuring the client (the one where you run your app) with the XServer details. By default, the XServer instance on your desktop disallows communication from all machines except localhost. Thus, you will need to add the host in the allowed list using the xhost command.

On your machine,  to disable security checks:

$ xhost +

To allow connections from a single  host:

$ xhost +<hostname/ip>

On the client machine where the application is run, set the X Server to display to (for bash shell):

$ export DISPLAY=<hostname>:<displaynumber>.<screennumber>

If you haven’t changed the display-number or screen-number :

$ export DISPLAY=<hostname>:0.0

For a more detailed description of the

How to export your X Display.

Job Control on *NIX systems

If you are not a UNIX user/not a geek, please turn away right now.

Every year, I either chance upon something new, or remind myself of something interesting that I’ve forgotten. This is the latter case. On a *NIX shell, you can push a foreground process to background (obviously without terminating it):


$ ./someprocess
...
...
...
Ctrl-Z
[1]+ Stopped ./someprocess
$ bg
[1]+ ./someprocess &

To bring the process into foreground:


$ fg < -- last process pushed into bkgnd
$ jobs <-- check active jobs
[1] ./someprocess
[2] ./someotherprocess
$ fg 2

via Job Control on UNIX systems.

Unix: removing duplicates from a file

Over the last few months, I have re-discovered some unix commands (it’s been such a long time)

  • Eliminate duplicate lines from a file

#sort -u filename > filename.new

  • List all lines that do not match a condition

#grep -v ajsk filename

  • Copy contents of two files to one

#cat file1 file2 > file3

  • Append output of a command to a file

#cat file1 >> file2