Wednesday, 4 June 2008

Some usefull shell tricks

Reuse previous arguments


The !$ command returns the last file name parameter used with a command. But what happens if you have a command that used multiple file names and you want to reuse just one of them? The !:1 operator returns the first file name used in a command. The example in Listing 1 shows how you can use this operator in combination with the !$ operator. In the first command, a file is renamed to a more meaningful name, but to preserve use of the original file name, a symbolic link is created. The file kxp12.c is renamed in a more readable manner, then the link command is used to create a symbolic link back to the original file name, in case it's still used elsewhere. The !$ operator returns the file_system_access.c file name, and the !:1 operator returns the kxp12.c file name, which is the first file name of the previous comma nd.


Listing 1. Using !$ and !:1 in combination
$ mv kxp12.c file_system_access.c
$ ln –s !$ !:1



Manage directory navigation with pushd and popd


UNIX supports a wide variety of directory-navigation tools. Two of my favorite productivity tools are pushd and popd. You're certainly aware that the cd command changes your current directory. What happens if you have several directories to navigate, but you want to be able to quickly return to a location? The pushd and popd commands create a virtual directory stack, with the pushd command changing your current directory and storing it on the stack, and the popd command removing the directory from the top of the stack and returning you to that location. You can use the dirs command to display the current directory stack without pushing or popping a new directory. Listing 2 shows how you can use the pushd and popd commands to quickly navigate the directory tree.


Listing 2. Using pushd and popd to navigate the directory tree
$ pushd . ~ ~
$ pushd /etc /etc ~ ~
$ pushd /var /var /etc ~ ~
$ pushd /usr/local/bin /usr/local/bin /var /etc ~ ~
$ dirs /usr/local/bin /var /etc ~ ~
$ popd /var /etc ~ ~
$ popd /etc ~ ~
$ popd ~ ~
$ popd



The pushd and popd commands also support parameters to manipulate the directory stack. Using the +n or -n parameter, where n is a number, you can rotate the stack left or right, as shown in Listing 3.


Listing 3. Rotating the directory stack
$ dirs /usr/local/bin /var /etc ~ ~
$ pushd +1 /var /etc ~ ~ /usr/local/bin
$ pushd -1 ~ /usr/local/bin /var /etc ~

Taken from here.

Wednesday, 28 May 2008

Using X server in Windows for calling remote graphical applications in Unix

Sometimes you need ability to run X apps from remote unix servers.
It is not a problem when you are using unix as a client, but what should you do when you running windows.

The answer:
1. Your can use X servers for windows such as Xming is(I recommend this case if you are sure that this is the onliest task you will perform).
2. You can run X server from Cygwin

Lets examine the second one:
1. Install Cygwin and run it.
2. In shell run:
$XWin -logfile /tmp/asd.log -ac &
3. Connect to the desired host:
$ssh -X host
4. You have to export $DISPLAY variable with a value which points to host you have come from:
host$export DISPLAY=sourcehost:0.0
5. Run your apps:
host$xterm

Enabling shared folder in Citrix Metaframe client

Often you need possibility send and receive files between remote and local machine through Citrix client.
I don't know why it is not enabled by default.
You have to add few lines to its config to [WFClient] section in "$HOME/.ICAClient/wfclient.ini" file:

DrivePathF=<ThePathToSharedFolder>
DriveEnabledF=On
DriveReadAccessF=On
DriveWriteAccessF=On

Tuesday, 27 May 2008

Check what package a file belongs to.

There are two ways on Solaris:
1.pkgchk -p -l
2.grep filename /var/sadm/install/contents

Wednesday, 14 May 2008

Linux kernel interactive map


I have found an interesting project which is very useful for understanding of linux kernel architecture:


Map is being updated ....

Monday, 21 April 2008

Solaris 10 networking configuration tips

Files:
/etc/hostname.$interface - ip address /mask configuration of specific interface.
/etc/dhcp.$interface - if this file exists then dhcp agent will configure this $interface.
/etc/default/dhcpagent - dhcpagent configuration.
/etc/defaultrouter - containing hostnames or ip addresses of default routers.
/etc/nodename - hostname configuration
/etc/inet/ipnodes is a symlink on /etc/inet/hosts in Solaris 10.

Services:
svc:/network/physical:default - responsible for configuring network interfaces

Progs:
ndd - configures and provides information about tcp/ip settings (enable/disable ip forwarding .....)
ifconfig plumb $interface enables physical device.

Thursday, 17 April 2008

sys-unconfig

Sys-unconfig- the very helpful tool when you want to begin configuration of system from scratch.