Wednesday, June 11, 2008

How to keep track of your Unix/Linux command execution and its output

By using "script" command, you can keep track of Executed Commands and its output.

Definition: The script command will keep a transcript(written record) of everything you say to the computer and everything that the computer responds to you.

Syntax: script [capturefilename]

*) To start the script command
eg: vjsujay$ script cmdlog

Note: cmdlog will be created in the current dir and also if you are not specifying the filename means, it will create a default filename 'typescript'

*) To stop capturing or script command,
eg: vjsujay$ exit

Different ways of running a Shell Script

1. Executing the Shell Script file as a command in the Shell Prompt
vjsujay@linuxdemon$sample.sh

2. Executing the Shell Script file using specified Shell
vjsujay@linuxdemon$bash sample.sh

3. Executing the Shell Script file in the current Shell
vjsujay@linuxdemon$source sample.sh
or
vjsujay@linuxdemon$. sample.sh

4. Executing the Shell Script file using exec command
vjsujay@linuxdemon$ exec sample.sh

Wednesday, April 16, 2008

Copying longfilenames without retyping

$ ls -l thisismytestfile
-rw-r--r-- 1 Ajay None 13 Apr 17 03:22 thisismytestfile

Ajay@intel ~
$ cp thisismytestfile{,.bk}

Ajay@intel ~
$ ls -l thisismytest*
-rw-r--r-- 1 Ajay None 13 Apr 17 03:22 thisismytestfile
-rw-r--r-- 1 Ajay None 13 Apr 17 03:26 thisismytestfile.bk