Saturday, 15 September 2012

UNIX: Word Count and file copy command

For word count type 'wc command.

bash -3.2$wc -l File1

The above command will show the total number of words in a file.
The output will be shown like below:

bash -3.2$wc -l File1
  7   22   104 File1

7 denotes total number of lines in a file
22 denotes total number of words in a file ( like 'unix program' means 2 words )
104 denotes total number of characters in a file.

For copying the file
bash -3.2$cp -i File1 newFile

i denotes here the interactive mode.
In this mode unix will as whether you want to overwrite the file or not.

See the screen shot for more details:


UNIX: Calculator

Calculator in UNIX:

bash -3.2$bc

typing 'bc' you will enter in calculator mode.
Now do any operations like 5*6 or 5+22 , etc press enter and the result will be shown.

If you do 11/2 , then the screen will show you 5 , it will not give results in decimal.

For viewing result in decimal , type
scale=2 
and now do any division , the result will be shown up to two places.

For coming out of the calculator mode , type 'quit' 
See the screen for more details.



Saturday, 8 September 2012

UNIX: Create directory and view files in ascending and descending order

Question 1: Create a directory in UNIX
Answer:
bash -3.2$ mkdir newFile

The above command creates a new directory with name 'newFile' 

Question 2: How to see files in a directory in ascending and descending order ?
Answer : 
bash -3.2$ ls -l
This command displays the files in a directory

bash -3.2$ ls -lt
This command displays the files first which are recently added and then older files. ( like 10AM, 9AM , 8AM ) in this order.

'-lt' means sorted by time

bash -3.2$ ls -ltr sorted by time in reverse order

In the below screen shot please see the time of the files.
See the green arrows to locate the commands.



Unix commands: Create files of zero blocks with figure

Question: Create files in unix of zero blocks.

Answer: The size of file in UNIX is measured in 'blocks'
1 Block= 512 bytes or 1024 bytes , it depends on administrator to set this limit.

bash -3.2$ touch abc pqr xyz

'bash' is the shell in unix.

The above  command will create three files 'abc' , 'pqr' and 'xyz' in unix of zero blocks.

See the below figure for this. The arrow is showing the size of files. In place of zero it can be any number like 2, 25, etc. Hope this makes it clear.

UNIX basic commands 1


Unix Commands


Question 1:  To go to a path or directory in Unix
Answer:  a) –bash -3.2$ cd ..   [ to come to one level up]
                     –bash -3.2$cd ../..   [ to come to two level up ]
                     –bash -3.2$cd /  [ to come to root directory ]
                     –bash -3.2$cd ../..   [ to come to two level up ]

Note : here bash is the shell in unix , as far as i know.

Question 2: What is the meaning of first character when you type ‘ls –l’. The output comes like this  crwx - -x-wx
Answer: if the first character is ‘c’ then it means file with special character
             if the first character is ‘d’ then it means file is a directory
            if the first character is ‘-’ then it means file is a plane text file
The following screen shot will make it clear
                                                                              



       

                                                                      
Question 3: Permissions in UNIX.
Answer: if you see the above screen shot , then after the first character ‘c or d or –‘ there are nine characters in the form of rwx-rx—x

 Small ‘r’ stands for read , small ‘w’ stands for write and small ‘x’ stands for execute

The first three characters are for ‘owners/users’ , then next three characters are for ‘Group’ and final three characters are for others. E.g,

               rwxr-xr- -
i) the first three characters rwx represents that the owners have got read,write and execute permissions on the file

ii) the next three characters r-x represents that ‘group’ has got read and execute permission on the file

iii) the final three characters r - - represents ‘others’ have read only permission on the file.
Hope this example makes permission in unix clear.