Pages

Saturday, January 11, 2014

Customizing Your SHELL Prompt in Unix with TIME



How to display time in the bash promt ?



# declare -x PS1=" \@ Bash $ "


 05:05 PM Bash $

Setting Permission while creating directories

How to set permission while creating creating directory in linux ?

# mkdir --parents --mode=550 vasanth/backup/january

--mode=m ( -m )—Sets the permission mode (as in chmod )
--parents ( -p )—Makes all necessary directories even if they don’t currently exist



How to classify files and directories in "ls" command ?


How to classify in ls command ?


ls command can classify directories,files,programs,symbolic links and named pipes.



# ls --color=never --classify


The –classify symbols are directories ( / ), programs ( * ), symbolic links ( @ ), pipes ( | ),and Unix domain socket files ( = ).






OR & AND conditions in shell scripts

OR Statement in shell scripts

|| is known as OR statement in shell script.

Eg:


# id user1 || useradd user1

In the above example if the user1 exist in the system the second command will not be executed. If the user1 does not exist second command will be executed.

If first command returns true second will not exist run. if the command is false second will be executed.

AND Statement in shell scripts


 Eg:

&& is known as AND in shell script


#  [ -d /tmp/test ] && rm -rf /tmp/test

 If the first command is true the second command will be executed. If the first
false second command second will not executed.