Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Friday 20 December 2013

Remove directories - Unix

The command to delete or remove directories is rmdir

Note that rmdir can delete only empty directories. You CANNOT delete non-empty directories using rmdir.

In order to remove non-empty directories use the rm -rf command instead. Use the -r switch with caution since it deletes the inner contents of a directory recursively.

Disk Space - Unix

In Unix, in order to find the disk space statistics of mounted volumes, use the following command:

df -h

The output will show the size of volume, the used space and the available free space in the Mb and Gb format.

Eg:

Filesystem        Size      Used    Avail   Capacity  Mounted on
/dev/disk0s2     465Gi   275Gi  190Gi     60%            /

Thursday 19 December 2013

Process Status - Unix

The ps command is quite a useful command in Unix to find out information related to processes.

There are a lot of switches for the ps command for doing a bunch of things.

Most frequently used switch is -ef  This can be used to to list all the running processes alongwith their PID's (process ID)

  • If you want to find out all processes of a specific user then use the foll.


ps -u <username>

Eg: ps -u root


  • If you want to find the PID of a certain process, searching by its process name then use the following command: 
ps -ef | grep <process name string>

Eg: ps -ef | grep jrockit  (Narrow down the output of ps command by piping it to a grep statement)

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