Linux運維実訓day 2

5478 ワード

Linuxのインストールと導入
#      
[root@server ~]# date
#      
[root@hd ~]# date
2019  06  22      19:12:04 CST

#    
[root@server ~]# useradd    
      tls   
[root@hd ~]# useradd tls

#    
[root@server ~]#cat /etc/passwd

#      
[root@hd ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
tls:x:1000:1000::/home/tls:/bin/bash

#     100   ,  shell script
for n in `seq 100`;do
        useradd test$n && \
        echo "   test$n      "
done
[root@hd ~]# for n in `seq 100`;do
>         useradd test$n && \
>         echo "   test$n      "
> done
   test1      
   test2      
.......

#    
[root@server ~]# bash user.sh
'root' = login user name
'@' =    
'server' = hostname
'~' = working directory,'~'     
'$' =     
'#' = root  (     )

        :dl_wh_web_01.hs.com

#      
[root@server ~]# whoami

[root@hd ~]# whoami 
root

#         
[root@server ~]# echo $PS1
root:       
server:        
~:       
#:       (root  )
$:    

#         
[root@hd ~]# echo $PS1
[\u@\h \W]\$

PS1         
\d :    ,   weekday month date,  :"Mon Aug 1"
\H :       
\h :            
\t :     24    , :HH:MM:SS
\T :     12    
\A :     24    :HH:MM
\u :         
\v :BASH     
\w :         
\W :  basename        ,          
\# :        
\$ :    ,   root  ,     # ,       $
    
#  
30  40   
31  41   
32  42   
33  43   
34  44   
35  45    
36  46    
37  47   

#    
[root@hd ~]# PS1='\[\[[\u@\h \w \t]\$ \[\e[0m\]'
[root@hd ~ 20:01:05]# 


shell基礎構文
   bash shell,       ,       

#                   
command  [-options] [arguments]

[root@server ~]# ls               //  
[root@server ~]# ls -l            //  +  
[root@server ~]# ls -l /home/     //  +  +  
#  :  shell     
#  :           
    # '-'       (    ),  ”-a“
    # '--'       (    ),  ”--all“
    #             ,    ”-“  ,  ”-la“
#  :         ,   、    
#      ,             

[root@hd ~]# ls
anaconda-ks.cfg  user.sh

[root@hd ~]# ls -l
    8
-rw-------. 1 root root 1275 6   18 09:22 anaconda-ks.cfg
-rw-r--r--  1 root root   93 6   22 19:51 user.sh

[root@hd ~]# ls -l /home/
    0
drwx------ 2 tls tls 62 6   22 19:14 tls

Bashの基本特性
命令補完
	tab
	    
	    
	    

        ,           
[root@server ~]# yum install -y bash-completion


#    
http://vault.centos.org/

コマンドショートカット
                    
Ctrl + a(home)  #                
Ctrl + e(end)   #                
Ctrl + w    #       bash  
Ctrl + c    #         
Ctrl + d    # shell ,ctrl-d      shell。(logout、exit)
Ctrl + z    #     ,    
Ctrl + l    #  , clear    。
Ctrl + k    #             
Ctrl + u    #             
Ctrl + r    #      ,      
Ctrl + s    #  
Ctrl + q    #  
Ctrl +     #          (Xshell   )
ESC  + .    #       

履歴コマンド
       :         ,    ,    ,        ,              ,        :  

-w:          write
-c:        ,       clear
-d:        N  delete
#      
[root@server ~]# history

[root@hd ~]# history 
    1  sed -ri '/(UUID|HWADDR)/d' /etc/sysconfig/network-scripts/ifcfg-ens33
    2  sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
    3  systemctl disable firewalld
    4  cd /etc/yum.repos.d/
    5  ls
    6  mkdir bak
    7  ls 
    8  mv CentOS-* bak/
.......

#      
[root@server ~]# history -c

[root@hd ~]# history -c
[root@hd ~]# history 
    1  history 

#          
[root@server ~]# history -d   

#         
[root@hd ~]# history -d 2
[root@hd ~]# history 
    1  sed -ri '/(UUID|HWADDR)/d' /etc/sysconfig/network-scripts/ifcfg-ens33
    2  systemctl disable firewalld
    3  cd /etc/yum.repos.d/
    4  ls
    5  mkdir bak
    6  ls 
    7  mv CentOS-* bak/
    
#      
[root@server ~]# history -w

#       
[root@server ~]# !!

[root@hd ~]# !!
history 
    1  sed -ri '/(UUID|HWADDR)/d' /etc/sysconfig/network-scripts/ifcfg-ens33
    2  systemctl disable firewalld
    3  cd /etc/yum.repos.d/
    ......

#     ls    
[root@server ~]# !ls

[root@hd ~]# !ls
ls /boot/
config-3.10.0-957.el7.x86_64                             initramfs-3.10.0-957.el7.x86_64.img
efi                                                      symvers-3.10.0-957.el7.x86_64.gz
grub                                                     System.map-3.10.0-957.el7.x86_64
grub2                                                    vmlinuz-0-rescue-44427be481944bc487868b5f1c0cc533
initramfs-0-rescue-44427be481944bc487868b5f1c0cc533.img  vmlinuz-3.10.0-957.el7.x8

#         n   
[root@server ~]# !n

#         4   
[root@hd ~]# !4
ls
anaconda-ks.cfg  done  useradd