Directory related command, MKDIR, cd, RMDIR, create file , display, sorting copying from file to another, move, remove, word, filter and pipes, tail, more, grep,

 

 

DIRECTORY RELATED COMMANDS :

1.Present Working Directory Command :

To print the complete path of the current working directory.

Syntax :$pwd

Example:$pwd

Output:          /home/tcs

 

2.MKDIR Command :

To create or make a new directory in a current directory .

Syntax :$mkdir<directory name>

Example:$mkdir example

Output:    
$ls  -l
total 1
drwxr-xr-x 2 raghuraghu 4096 2012-07-06 14:09 example

3.CD Command :

To change or move the directory to the mentioned directory.

Syntax :$cd <directory name.

Example:cd Desktop

Output:        ~/Desktop$

 

4.RMDIR Command :

To remove a directory in the current directory & not the current directory itself.

Syntax :$rmdir  directory name

Example:

Output:    

 

FILE RELATED COMMANDS :

 

1.CREATE A FILE :

 

To create a new file in the current directory we use CAT command.

Syntax :$cat >  filename.

The > symbol is redirectory we use cat command.

Example:To create a file “college”

cat> college

Output:My college name is HIT (user input)

 

2.DISPLAY A FILE :

 

To display the content of file mentioned we use CAT command without „> operator.

Syntax :$cat <filename.

Options –s = to neglect the warning /error message.

Example: 

Output:

 

4.SORTING A FILE :

To sort the contents in alphabetical order in reverse order.

Syntax :

$sort  filename

Option :$ sort –r  filename

Example:

Output:   

 

5.COPYING CONTENTS FROM ONE FILE TO ANOTHER :

To copy the contents from source to destination file .so that both contents are same.

Syntax :$cp<source filename><destination filename>

$cp<source filename path ><destination filename path>

Example:#cp file1 file2

Output:         
                    $ls -l example/
                    total 4
                   -rw-r--r-- 1 raghuraghu 0 2012-07-06 16:10 file1
                   -rw-r--r-- 1 raghuraghu 0 2012-07-06 16:10 file2
                   -rw-r--r-- 1 raghuraghu 491 2012-07-06 16:07 listing_copy.txt

 

6.MOVE Command :

To completely move the contents from source file to destination file and to remove the source file.

Syntax :$ mv <source filename><destination filename>

Example:$mv listing_copy.txt usrcopy

Output:
$ ls -l
total 6
drwxr-xr-x 2 raghuraghu 4096 2012-07-06 16:10 example
-rw-r--r-- 1 raghuraghu 0 2012-07-06 14:20 file1
-rw-r--r-- 1 raghuraghu 0 2012-07-06 14:20 file2
-rw-r--r-- 1 raghuraghu 0 2012-07-06 14:20 file3
-rw-r--r-- 1 raghuraghu 491 2012-07-06 16:02 usrcopy
-rw-r--r-- 1 raghuraghu 491 2012-07-06 14:23 usrlisting

                    Here, 'listing_copy.txt' is moved with the name 'usrcopy' in the same directory (or you can say that it has been renamed).

 

7.REMOVE Command :

To permanently remove the file we use this command .

Syntax :$rm<filename>

Example:

Output:   

 

8.WORD Command :

To list the content count of no of lines , words, characters .

Syntax :$wc<filename>

Options :

-c – to display no of characters.

-l – to display only the lines.

-w – to display the no of words.

Example:

$wc  [Count the no of word in college 5]

Output:      

college 5

 

9. FILTERS AND PIPES

HEAD :It is used to display the top ten lines of file.

Syntax :$head<filename>

Example:vi a1.sh

A

B

C

D

E

F

G

H

I

J

K

L

 

Output:       $head a1.sh

A

B

C

D

E

F

G

H

I

J

 

TAIL :This command is used to display the last ten lines of file.

Syntax :$tail<filename>

Example:vi a1.sh

A

B

C

D

E

F

G

H

I

J

K

L

 

Output:      $tail a1.sh

C

D

E

F

G

H

I

J

K

L

 

MORE :It also displays the file page by page .To continue scrolling with more command , press the space bar key.

Syntax :$morefilename

Example:vi a1.sh

A

B

C

D

 

Output:  more a1.sh

A

B

C

D

 

GREP :This command is used to search and print the specified patterns from the file. Syntax: $grep [option] pattern <filename>

Example:grep –e filename

Output:  

hello()

echo “hello students”

hello

SORT :This command is used to sort the data in some order.

Syntax :$sort<filename>

Example:vi a1.sh

                   B

                   A

                   C

           D

Output:      sort a1.sh

                   A

B

C

D

 

PIPE :It is a mechanism by which the output of one command can be channeled into the input of another command.

Syntax :: $who | wc -l

Example:who |wc –w

 

Output:       10

 

 

 

 

Comments

Popular posts from this blog

what is Machenical Engineering

PHOTO ( CHINESE LADKA)

Arithmatic operations, factorial of a number, while loop, prime number, etc