Saturday, 10 December 2016

Use of paste command

Paste : This command is used to join files horizontally by delimiter.
                                       Syntax:$paste <filename1> <filename2>....<filenamen>
default delimiter is tab.
Ex:
$paste employees departments
Ex:
$paste -d ":" employees departments
Ex :
$paste employees salary departments
Ex:
$paste -d ":" employees salary departments


Friday, 9 December 2016

Use of cut command

Cut : This command is used to extract or divide specific fields and characters from a given file based on delimiters.
                           Syntax:$cut (fields) or (delimiter) or (character) <filename>
Ex:
$cut -f 1,3 jobs
It displays 1st and 3rd fields from jobs file.
-f means field by field.
Note: Default delimiter is tab.
When default delimiter is tab that's why no need to mention it,but if delimiter is other than tab we have to mention that delimiter.

Ex:
$cut -f 2-4 jobs
It displays 2nd fields to 4th fields.
Ex:
$cut -f 2- jobs
It displays 2nd field to last field from jobs file.
Ex:
$cut -d "," -f 1,3 countries
It displays 1st and 3rd fields from countries file.
Here in countries file all fields separated by comm delimiter.So, we have to mention it,

Ex:
$cut -c 1-10 jobs
It displays every row 1st character to 10th character from jobs file.

Ex:
$cut 1-5,10-15 jobs
It displays every row 1st character to 5th character and from 10th character to 15th character.

Friday, 2 December 2016

Use of wild card characters

Wild card characters

a) * : It is used to matches 0 or more characters
b) ? : It is used to matches any single character.
c) [ ] : It is used to matches any single character in the given list.
d) [-] : It is used to matches any single character in the given range.

Ex:
i)$ls f*
ii)$ls *c
iii)$ls f?
iv)$ls f????
v)$ls [abcdef]*
vi)$ls [a-z]*

vii)$rm *
viii)$rm -i*
ix)rm a*



Thursday, 1 December 2016

Use of date command

To print date

a)date : This command is used to represent date.
                                         Syntax:$date

b)date +%d : To display day in number from date.
c)date +%a : To display weekday in word from date.
d)date +%y : To display year in number from date.

Ex:
$date +%d-%b-%y



Use of history command

history : This command is used to display the previous commands which is executed  on the terminal.
                                          Syntax:$history

history -c : This command is used to to clear the history from the terminal.
                                          Syntax:$history -c

After running history -c command history is cleared.We can check it by using history command.

Use of ls command

Viewing list of files

a)ls : This command is used to display current directory all files and directories in the ascending order based on ASCII values.By default files and directories display order is ascending.
                                  Syntax:$ls

b)ls -r : This command is used to display current directory all files and directories in the descending order or reverse order.
                                  Syntax:$ls -r

c)ls -R : This command is used to display current directory all files and directories recursively.
                                  Syntax:$ls -R

d)ls -a : This command is used to display current directory all files and directories including hidden files.
                                  Syntax:$ls -a

e)ls -u : This command is used to display current directory all files and directories based on when they were last used.
                                  Syntax:$ls -u

f)ls -t : This command is used to display current directory all files and directories based on date and of creation.
                                  Syntax:$ls -t

g)ls -l : This command is used to display list of all files in long list format.
                                  Syntax:$ls -l
Here
d and - represent file type.
rwrwxr-x and rw-rw-r represents file permissions
3 and 1 represents Number of links.
practice and practice represents owner name.
practice and practice represents group name.
4096,0,46,10 represents size in bytes.
Dec 1,Nov 30 represents date.
18:52,23:51 represents time.
ABC,f1,f2 are filename.

h)ls -lr : This command is used to display current directory all files and directories in the descending order or reverse order in long list format.
                                   Syntax:$ls -lr
i)ls -lR : This command is used to display current directory all files and directories recursively in long list format.
                                   Syntax:$ls -lR

j)ls -la : This command is used to display current directory all files and directories including hidden files in long list format.
                                   Syntax:$ls -la

k)ls -lu : This command is used to display current directory all files and directories based on when they were last used in long list format.
                                   Syntax:$ls -lu
l)ls -lt : This command is used to display current directory all files and directories based on date and of creation in long list format.
                                  Syntax:$ls -lt

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



Wednesday, 9 March 2016

Creating,logging and Deleting User in Unix/Linux

To create a new user first we have to login as root user (or) with # prompt


# system administrator prompt
$ user working prompt
Login:root 
Password:

To create a new user
: useradd is used to create a new user.                                   
                                     syntax: #useradd <username>
Ex: #useradd practice

To create a new password : passwd is used to create a new password
                                              syntax: #passwd <username>

Ex: #passwd practice
                                           


Login through created user 
goto terminal windows f1-f6 and login 

Login :<username>
Password :

Ex: Login : practice
       Password :
                                                                      
                                 

To display current user login name 
logname is used to display current user login name

Ex: $
logname
                                             
                               

To delete a user
We must have to login as root user to deleting user and the user which we want to delete should not be login in any terminal.

To delete a user : userdel is used to to delete a user.
                             syntax: #userdel -r <username>

Ex: #userdel -r <username>
                                                                           



Monday, 7 March 2016

Creating a file using cat and touch command and Deleting files using rm command

Cat: This command is used to display,concatenate files,create new files ,open and append data in existing files.


a)Create a new file:
                             Syntax:$cat >  <filename>
                                                  ---statements---
                                                      control d
Ex:
$cat>file1
India is a beautiful country and with huge population.In India people belongs to different-different religion and culture living together peacefully.
control d                                    

b)Open an existing file:
                                   Syntax:$cat< <filename>
                                                          or
                                               $cat <filename>
Ex:
$cat file1                                                                      

c)Appending data to the file:
                                                Synatx:$cat>> <filename>
Ex:
$cat>>file1
                                                                   
After append
                                                                         

To open multiple files:
                                      Syntax:$cat <filename1> <filename2> <filename3>...<filenamen>
Ex:
$cat file1 file2 file3
                                                                           

d)touch: Touch is standard unix command line interface program which is used to create empty file (zero byte file). Basically it is used to update the access date and/or modification  date of a file or directory. In it's default usage, it is equivalent of creating or opening a file and saving it without any change to the file contents.
Touch command is used to create several empty files quickly and also it does not allow to store anything in a file.

                                      Syntax:$touch <filename>
Ex:
$touch Demo

we can also create multiple empty file(zero byte) files using touch command
                                Syntax:$touch <filename1><filename2><filename3>.......<filenamen>
Ex:
$touch f1 f2 f3

touch command having following options:
i) -a, change the access time only
ii) -c, if the file does not exist, do not create it
iii) -d, update the access and modification times
iv) -m, change the modification time only
v) -r, use the access and modification times of file
vi) -t, creates a file using a specified time

Deleting Files:
                     
a) rm: rm command is used to delete a file
                                      Syntax:$rm <filename>
Ex:
$rm file1
                                     

b)rm -i <filename> : It deletes a file with confirmation.
Ex:
$rm -i file2
It ask for confirmation, press y for yes or n for no
                                                                   

c)rm -f <filename> : It deletes a file forcibly.
Ex:
$rm -f file3


To deleting multiple files : By using rm command we can delete multiple files.
                                    Syntax:$rm <filename1> <filename2><filename3>...<filenamen>
Ex:
$rm f1 f2 f3
d)rm * : To remove all files from current directory.
first we check all files in current directory by using ls command and then then remove all files using rm * command.