Thursday, July 17, 2008

Simple_Shell_Scripting/Help/Command_Usage

1.To create multiple file copies with various links. After this both oldfile newfile refer to the same name.
$ln Page1 Book1
syntax: ln {oldfile} {newfile}

2. $wc //gives word count of the file.

3. grep {word to find} {filename} //finds word in the file

4. sort -r //reverse normal order.
sort -nr //numeric reverse order.
sort -n //numeric order sorting.

5.Printing last/first line of given file.
tail -+ {line number} {filename}
will print the last number of lines of the file
by default will print 10 last lines of file.
you can use head and tail command with -sign to get respectively the top and bottom lines of
the file.

6. To check how many files in the system
$ls /-R wc -l
As it will take a lot of time.. we can run this in background using "&"
Our command becomes now $ ls / -R wc -l &

7. To list all files in directory subdirectory we can do.
$ ls -lR

8. To get info about all running process:
$ ps -ag

9. To stop all process except the shell do:
$kill 0 //zero

10. Take this. u did $ ls
$ echo $?
If it returns 0 on the screen, this denotes successful completion of the command.(here ls).

11. $lsmore One full page of output at a time.

12. $ls -lwc -l prints no of files in current directory.

13. $ tail +20 hlist
here head is the filter which takes its input from tail command and passes this lines to input to head, whose output is redirected to hlist file.

14. if you copy ur shell script to bin.. u can execute it by its name itself.
so if ur script name is "first"
then do : $cp first ~/bin
$ first shud execute now.

15.echo is used to print the thing on console

16. chmod +x give execute rights to all

17. $ls a* will show all files whose name begin with 'a'.
$ls ? searches for file with name of single letter.
$ls /bin/[!a-o] OR $ls /bin/[^a-o] . if the first character following the [is a ! or ^ then any
char not enclosed is matched i.e. do not show us file name that begining with a,b,c ...o.\

18. Operator Meaning
! expression Logical NOT
expression1 -a expression 2 Logical AND
expression 1 -o expression 2 Logical OR

No comments: