Friday 30 June 2017

Linux-5

                                                          Linux Commands

When dealing with the Linux operating system, commands are required as inputs to inform or direct a computer program to perform a specific operation. Understanding the most basic Linux commands will allow you to successfully navigate directories, manipulate files, change permissions, display information such as disk space, and more. Obtaining basic knowledge of the most common commands will help you easily execute tasks via the command line.


[root@server1 dhoni]# ls –ll file1

-rwxrwxrwx. 1 dhoni dhoni   18 Jun 30 05:11 file1

àThe chown command is used to change the owner and group of files, directories and links. ... new_owner is the user name or the numeric user ID (UID) of the new owner, and object is the name of the target file, directory or link. The ownership of any number of objects can be changed simultaneously.

Chown user:group filename

 [root@server1 dhoni]# chown root:root file1
[root@server1 dhoni]# ls –ll file1
-rwxrwxrwx. 1 root  root    18 Jun 30 05:11 file1



àtouch is a standard Unix command-line interface program which is used to update the access date and / or modification date of a file or directory. In its default usage, it is the equivalent of creating or opening a file and saving it without any change to the file contents

[root@server1 ~]# touch file22

àThe cat (short for “concatenate“) command is one of the most frequently used command in Linux/Unix like operating systems. cat command allows us to create single or multiple files, view contain of file, concatenate files and redirect output in terminal or files.Then press ctrl+d to stop

[root@server1 ~]# cat> file22

Hai this is information for you

àto show the file contents.

[root@server1 ~]# cat file22

Hai this is information for you

àto store data into variable like var1 stores  text as hai 

[dhoni@server1 ~]$ var1="hai"


à to display the var content use $ symbol and echo to print the content

[dhoni@server1 ~]$ echo $var1

Hai

àBy default most Linux distro displays hostname and current working directory. You can easily customize your prompt to display information . 
Prompt is control via a special shell variable. You need to set PS1, PS2, PS3 and PS4 variable. If set, the value is executed as a command prior to issuing each primary prompt.
PS1 – The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is \s-\v\$ .
PS2 – The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is >
PS3 – The value of this parameter is used as the prompt for the select command
PS4 – The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is +

# now the $ changed to =>

[dhoni@server1 ~]$ PS1='=>'

=>

=>

àto change prompt test as follows

Here

u for username

h for host name

t  for time

[dhoni@server1]=>PS1='[\u@\h \t]$'


àto display the date use the below command

[dhoni@server1 09:02:13 Fri Jun 30]$date

Fri Jun 30 09:02:19 UTC 2017

àto display the calendar for the month use the following command

[dhoni@server1 09:02:19 Fri Jun 30]$cal

      June 2017
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30


àlook here incomplete echo statement will display > symbol in second line after we press enter until 

it closes properly.

 [dhoni@server1]$echo "hai

> kdk

> ldldl"

hai

kdk

ldldl


à to change the symbol ‘>’ to ‘–‘ use the following command with PS2

[dhoni@server1]$PS2='-'

[dhoni@server1]$echo hai

-how

- are you“

Hai

How

are you.


à to change to ‘>’ follow below

[dhoni@server1]$PS2='>’

[dhoni@server1]$echo "ggg
>g
>hgg"
ggg
g
hgg


à Grep command is used to search for a file using pattern maching as below

Here iam searching for file having Jun characters in it

[dhoni@server1]$ls -l | grep "Jun"

drwx------. 4 dhoni   dhoni   4096 Jun 30 07:15 dhoni

drwx------. 5 test    test    4096 Jun 18 16:31 test

drwx------. 2 test2   test2   4096 Jun 30 07:23 test2



If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team

No comments:

Post a Comment