Wednesday, 23 November 2016

Use of wc and file commands

Use of wc and file commands

wc : This command is used to count total number of words,characters and lines in a given file.
                                         Syntax:$wc <filename>
Ex:
$wc f1

Here wc counts total number of lines 3,number of words 6,number of character 28 and filename f1.

We can also use wc commands like
a)$wc -l f1 :To count number of lines in a file
b)$wc -w f1 :To count number of words in a file.
c)$wc -c f1 :To count number of characters in a file.
d)$wc -lw f1 :To count number of lines and words in a file.
e)$wc -wc f1 :To count number of words and characters in a file.
f)$w -lc f1 :To count number of lines and characters in a file.



file : This command is used to given file type.
                                        Syntax:$file <filename>
Ex:
$file capitals
capitals is a ascii text file.
Ex:
$file ABC
ABC is a directory.




Use of diff and cmp commands

Use of diff and cmp commands

diff : This command is used to display different lines between 2 files.
                                        Syntax:$diff  <FirstFileName> <SecondFileName>
Ex: $diff f1 f2

cmp : This command is used to compare character by character, if no output, then files are same otherwise,the files are not same.
                                          Syntax:$cmp <FirstFileName> <SecondFileName>
Ex : $cmp f1 f2
Here f1 f2 are files.


diff3 : This command is used to display different lines between 3 files.
                                             Syntax:$diff3 <filename1> <filename2> <filename3>
Ex:$diff3 xyz subjects file
Here xyz,subjects ad file are different files.



Tuesday, 15 November 2016

Creating hidden files and unhide the hidden files

Creating hidden file

"." : This . dot symbol is used to make a file or directory as hidden.By using "." dot symbol start of the filename or directory we can make it hidden.
                                        Syntax:$cat>.<filename>          
                                                               or
                                                     $cat>.<directoryname>
Ex:
$cat>.Number_File
Hidden files will not display in the list of file and directory when you are using ls command.

mv :To unhide existing hidden files we use mv command.
                                        Syntax :$mv .<filename> <filename>
Here filename will be same.
Ex:
$mv .Number_File Number_File
Now,By using ls command we can see Number_File in file list.

mv :
To hide the existing unhidden files we use mv command.
                                           Syntax:$mv <filename> .<filename>
Here filename will be same.
Ex:
$mv locations .locations
Now,if we use ls command locations file will not display in file list.

Creating hidden directory
                                           Syntax:$mkdir .<directoryname>
Ex:
$mkdir .Sample
Here,hidden files or directory will not display in filelist.So,we can not see it by using ls command.

mv : To unhide directory.
                                         Syntax:$mv .<directoryname> <directoryname>
Here directoryname will be same.
Ex:
$mv .Sample Sample
Now,By using ls command we can see Sample in file list.


Renaming files and directory

mv : This command is used to rename the file or directory.
                                    Syntax:$mv <Oldfilename> <Newfilename>
                                                                   or
                                    Synatx:$mv <Olddirname> <Newdirname>
Ex:
$mv cities locations
Here we have cities file,by using mv command we rename it with locations.
and also we have directory called abc we rename it as ABC by using mv command.
after renamed we verify by using ls command.

Sunday, 13 November 2016

To copy files using cp command

CP : This command is use to copy data from source file to target file.Source file may be a new file or may be a existing file.
                                           Syntax:$cp <source file name> <target file name>
Ex:
$cp cities capitals
Here source file cities contains cities name and target file capitals is empty file.

a)To Copy files from one directory to other directory.
                                        Syntax:$cp <source directory name>/<filename>  <target directory name>
Ex:
$cp abc/countries pqr
Here abc and pqr is directory and countries is a file.

b)Multiple files copy into on directory.
                                       Syntax:$cp <sourcefilename1><sourcefilename2>...<target directory name>
Ex:
$cp capitals cities file lmn
Here capitals,cities and file are files and lmn is a directory.
c)Copy source directory to target directory.
                                        Syntax:$cp -R <source directory name> <target directory name>
Ex:
$cp -R lmn xyz
Here lmn directory copied into xyz directory.

Saturday, 12 November 2016

Creating,Changing and Removing Directory

Mkdir : Mkdir means make directory, This command is used to create a new directory in current logged user.

a)Create a new directory:
                                           Syntax:$mkdir <directoryname>
Ex:
$mkdir abc
Here if we are checking the created directory using ls command then the directory represented in blue colour and files are in white colour.

We can also create any number of files and directories in current directory.

cd : This command is used to change directory from one dir to other.

b)Change a directory:
                                     Syntax:$cd <directoryname>
Ex:
$cd xyz
In directory we can create file or directory

cd .. : This command is used to come out from current directory.

c)Come out from current directory.
                                     Syntax:$cd ..
Ex:
$cd ..

cd / : This command is used to changes to root directory.

d)Changes root directory.
                                    Syntax:$cd /
Ex:
$cd /
Here we see after cd command dir change to xyz.
Note: use space after cd command when we come out from current directory.

e)Creating multiple directories.
                                     Syntax:$mkdir <directoryname>
Ex:
$mkdir d1 d2 d3

Rm : This command is used for remove directory.

f)Removing directories.
i)$rmdir : This command is used to remove directory but directory must be empty.
                                     Syntax:$rmdir<directoryname>
Ex:
$rmdir xyz
Here, we check dir and files in the current directory by using ls command,Changing dir from current dir to xyz and check weather xyz dir is empty or not by using ls. xyz is not a empty directory.So,if we try to remove this directory it is showing message "Directory not empty".but when we are Then we are deleting a empty directory,we can delete it easily.

ii)Recursively deletes entire directory structure.
                                   Syntax:$rm -r  <directoryname
Ex:
$rm -r xyz

iii)Recursively deletes entire directory structure with confirmation.
                                  Syntax:$rm -ri <directoryname>
Ex:
$rm -ri d2
Here press y for yes and n for no.

iv)Recursively deletes entire directory structure forcibly.
                                    Syntax:$rm -rf <directoryname>
Ex:
$rm -rf d3