Showing posts with label Shell Scripting. Show all posts
Showing posts with label Shell Scripting. Show all posts

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>