Showing posts with label Unix. Show all posts
Showing posts with label Unix. Show all posts

Thursday 19 December 2013

System Uptime - Unix

In Unix, you can find how long your system was up by using the uptime command

You could get the output like:

15:34  up 22 days, 29 mins, 4 users, load averages: 0.78 0.82 0.77

Hard Link vs Soft Link - Unix

As you may be aware, in Unix we can create Links to point to a certain program or a file.

We create a link using ln command. We can create a symbolic link (also known as symlink) using the -s switch.

Eg:

ln -s /path to file1/file1.rtf /path to file2/file2.rtf

Now there are 2 types of links : a Hard link and a Soft link

Basically both types point to a certain file or a program. However one key difference is when the original file name is changed or modified.

If the name of original file is modified or renamed or if the original program is deleted from its location then:

a soft link is broken BUT a hard link does NOT break

Secondly, a Hard link cannot point to directories while a Soft link can link directories.


Wednesday 18 December 2013

Exit status of previous command - Unix

In Unix, one is often asked to find out the exit status of previous command i.e whether it was executed successfully or not.

In order to find out, type the foll. in terminal :

echo $?

If the output is 0 then it means the previous command got executed successfully.

If the previous command failed then the output of echo $? would be 127.

Tail the Logs - Unix

Tail is just another basic command in Unix where you can 'tail' a certain file to view its contents Bottoms-up.

Usage:

tail -lines <file-name>

Eg:

To view last ten lines of a file log.txt. Note the -n switch

tail -n 10 log.txt

To view the live results of a logfile use the -f switch

tail -f logfile.txt

Tuesday 17 December 2013

Unix - Remove range of lines from a file

In Unix, we have the ability to remove certain lines from a file by using sed. Sed as you may be aware, is a short for stream editor. Using Sed, we can specify the range of lines which we want to delete.

Usage :

sed -i <beginning line no> <ending line no> <file-name>

Eg:

For deleting lines from 3 to 9 of a file Test.txt, use the following command

sed -i '3,9 d' Test.txt

Monday 16 December 2013

Clearcase Scenario - Reserved Checkouts

While using the Clearcase tool, one might come across a scenario where you are unable to checkout a certain file/folder because some other user has performed a reserved checkout on it.

In a simple scenario, one can ask the other user to either undo the checkout or perform a check-in.

However in a slightly tricky scenario, what if the other user has left the company and his user id is no longer active / functional.

Then in that case check with the administrator. He usually has the rights to remove the views associated with the reserved checkout.

He would most likely identify the view name by finding checkouts. Once the view name is found, he would try to find the view's UUID

Eg : cleartool lsview -long viewname

The UUID is usually of the form dfaa0744.56c611d4.b0da.00:b0:d0:20:d5:9d

Once the UUID is found, one can completely remove the defunct view from the system using rmview.

Eg : cleartool rmview -r -uuid dfaa0744.56c611d4.b0da.00:b0:d0:20:d5:9d

Now since the view associated with the reserved checkout gets deleted, the issue gets solved and the user can smoothly checkout. Hurray!






Rename file in Unix

People new to Unix or linux environment often wonder how to rename a file from the command line.

Just remember, the command to rename is mv

Usage:

mv old_filename new_filename

Eg:

mv file1.txt file1_new.txt


Wednesday 11 December 2013

Shell Scripting - Read User Input

Inorder to accept user defined input in a shell script, make use of the read command. Try a simple example in Terminal.

Eg:

#!/usr/bin/bash
echo "Please enter your name"
read name
echo "Welcome to shell scripting $name"

Make sure the bash interpreter location is correctly defined in the shebang statement. Else you would see the error like - bad interpreter: No such file or directory
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker