Friday, August 15, 2008

Pipe

Pipe

Pipe command can use to combine two commands or more. That means output of one command will input for the next command.
command 1 | command 2


As an example
ls -l | less
This command displays ls -l results page by page. We can move up and down using arrow keys.

'more' is smiler to less command. But more doesn't support for arrow keys.

Example with more than two commands
ls -l| head -4| tail -1



important : command connected using pipe are execute separately and simultaneously.
Normally in piping standard output is redirected to the next command. That means not the standard error.
Let's see
ls -l myFolder | wc -l
where myFolder directory doesn't exist.
This command makes the output as 0.

Thursday, August 14, 2008

i-node

i-node store everything about files other than the content.
i-node stores the addresses where the content is stored.


Create a link to a file
First create a file with one or two sentences.
eg: example1.txt
Then create a link to that file using following command
ln example1.txt example2.txt
This is different from cp example1.txt and example2.txt, because in ln command both files share the same i-node.


Therefore when type ls –i we can see the i-node and number of links for the same i-node.
Then edit the content of one file (as an example : example1.txt). The content of other file is automatically changed. We can see that by typing cat example2.txt.


If change the permission of one file,
eg: chmod 751 example2.txt
Then permission of other file which linked to that one is automatically changed.

Tuesday, August 12, 2008

Wildcards

Wildcards are *, ?, [].
To list files and directories starting from a,
ls a*


To find files and directories with a in their name,
ls *a*


Consider the following example
ls ?a*
In here ‘?’ represents only one character. That means this command lists all files and directories with a as second character in their name.


ls M[ia]*
This command lists files and directories starts with M and second character is either i or a


ls ?[va]*
This command lists files those have v or a as a second character


We can use wildcards when coping, moving and deleting files.
Example
cp f* demo
This command copies all the files starting from f to directory called demo


Important:
Wildcards are very powerful, but be careful, because lots of damage can be happen very easily specially when deleting.

Monday, August 11, 2008

Identify the permission

When we are working in UNIX how can we get to know about the permission of current working directory?
We can use
ls –ld for that.

If not we can use ls –l ..
In this case output can have lots of directories.
Therefore first one is more convenient.

Permission is divided in to three categories. Those are write permission, read permission and execute permission. And permission is granted to three groups. First one is owner of the file, next is the group of owners and the other one is rest of others.

Permission is represented in binary format with eight combinations.

R W E
22 21 20
0 0 1 Value 1 means execute only
0 1 0 Value 2 means read only
1 0 0 Value 4 means write only
1 1 1 Value 7 means read, write and execute

Likewise there are eight combinations.

Another way to change the permission
chmod g+w example1.sh
This command gives write permission to group