RHA-124

  • Post author:
  • 帖子最後修改:2022 年 10 月 29 日
				
					
[root@servera ~]# id
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@servera ~]# whoami
root
[root@servera ~]# systemctl enable --now cockpit.socket
Created symlink /etc/systemd/system/sockets.target.wants/cockpit.socket → /usr/lib/systemd/system/cockpit.socket.

https://servera.lab.example.com:9090/ or https://172.25.250.10:9090/


Last failed login: Thu May 28 21:07:16 CST 2020 from 172.25.250.250 on ssh:notty
There was 1 failed login attempt since the last successful login.
[mary@servera ~]$ id
uid=1001(mary) gid=1001(mary) groups=1001(mary) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[mary@servera ~]$ whoami
mary
[mary@servera ~]$ logout
Connection to servera closed.

------------------lANG 語系--------------------
[student@servera ~]$ll /ppp
ls: cannot access '/ppp': No such file or directory
[student@servera ~]$echo $LANG 
en_US.UTF-8
[student@servera ~]$export LANG="zh_TW.UTF-8"
[student@servera ~]$ll /ppp
ls: 無法存取 '/ppp': No such file or directory
[student@servera ~]$

[root@servera ~]# export LANG="zh_TW.UTF-8"
NetaworkManager 
[root@servera ~]# nmtui






				
			

RH124 CH2練習

				
					
[root@servera ~]# ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
------------------------------------------
[student@servera ~]$ ls --all    GNU option
.  ..  .bash_logout  .bash_profile  .bashrc
[student@servera ~]$ ls -a      UNIX Option
.  ..  .bash_logout  .bash_profile  .bashrc

--------------------
[root@servera ~]# ls
anaconda-ks.cfg  original-ks.cfg
[root@servera ~]# ls -a
.   anaconda-ks.cfg  .bash_logout   .bashrc  original-ks.cfg  .tcshrc
..  .bash_history    .bash_profile  .cshrc   .ssh


.   ---the link of currebt directory 
..  ---the link of the upper level directory
[root@servera ~]# ls..
-bash: ls..: command not found
[root@servera ~]# ls ..
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
[root@servera ~]# ls .
anaconda-ks.cfg  original-ks.cfg


[student@servera ~]$ mkdir aaa
[student@servera ~]$ ls -a
.  ..  aaa  .bash_logout  .bash_profile  .bashrc
[student@servera ~]$ mkdir ". "
[student@servera ~]$ ls
aaa
[student@servera ~]$ ls -a
 .  '. '   ..   aaa   .bash_logout   .bash_profile   .bashrc
[student@servera ~]$ ls -la
total 12
drwx------. 4 student student  83 Jun  2 20:54  .
drwxrwxr-x. 2 student student   6 Jun  2 20:54 '. '
drwxr-xr-x. 3 root    root     21 May 22  2019  ..
drwxrwxr-x. 2 student student   6 Jun  2 20:54  aaa
-rw-r--r--. 1 student student  18 Jan 14  2019  .bash_logout
-rw-r--r--. 1 student student 141 Jan 14  2019  .bash_profile
-rw-r--r--. 1 student student 312 Jan 14  2019  .bashrc
#ls -lA 不列出隱藏檔 . ..
[student@servera ~]$ ls -lA
total 12
drwxrwxr-x. 2 student student   6 Jun  2 20:54 '. '
drwxrwxr-x. 2 student student   6 Jun  2 20:54  aaa
-rw-r--r--. 1 student student  18 Jan 14  2019  .bash_logout
-rw-r--r--. 1 student student 141 Jan 14  2019  .bash_profile
-rw-r--r--. 1 student student 312 Jan 14  2019  .bashrc


-r, --reverse              reverse order while sorting
-R, --recursive            list subdirectories recursively
[student@servera ~]$ ls -lAr
total 12
-rw-r--r--. 1 student student 312 Jan 14  2019  .bashrc
-rw-r--r--. 1 student student 141 Jan 14  2019  .bash_profile
-rw-r--r--. 1 student student  18 Jan 14  2019  .bash_logout
drwxrwxr-x. 2 student student   6 Jun  2 20:54  aaa
drwxrwxr-x. 2 student student   6 Jun  2 20:54 '. '
[student@servera ~]$ ls -lAR
.:
total 12
drwxrwxr-x. 2 student student   6 Jun  2 20:54 '. '
drwxrwxr-x. 2 student student   6 Jun  2 20:54  aaa
-rw-r--r--. 1 student student  18 Jan 14  2019  .bash_logout
-rw-r--r--. 1 student student 141 Jan 14  2019  .bash_profile
-rw-r--r--. 1 student student 312 Jan 14  2019  .bashrc

'./. ':
total 0

./aaa:
total 0
[student@servera ~]$ ls -lAS
total 12
0 drwxrwxr-x. 2 student student   6 Jun  2 20:54 '. '
0 drwxrwxr-x. 2 student student   6 Jun  2 20:54  aaa
4 -rw-r--r--. 1 student student  18 Jan 14  2019  .bash_logout
4 -rw-r--r--. 1 student student 141 Jan 14  2019  .bash_profile
4 -rw-r--r--. 1 student student 312 Jan 14  2019  .bashrc
[student@servera ~]$ ls -lAsr
total 12
4 -rw-r--r--. 1 student student 312 Jan 14  2019  .bashrc
4 -rw-r--r--. 1 student student 141 Jan 14  2019  .bash_profile
4 -rw-r--r--. 1 student student  18 Jan 14  2019  .bash_logout
0 drwxrwxr-x. 2 student student   6 Jun  2 20:54  aaa
0 drwxrwxr-x. 2 student student   6 Jun  2 20:54 '. '


 -t                         sort by modification time, newest first
#按修改時間排序,最新的在前
[student@servera ~]$ ls -lAt
total 12
drwxrwxr-x. 2 student student   6 Jun  2 20:54 '. '
drwxrwxr-x. 2 student student   6 Jun  2 20:54  aaa
-rw-r--r--. 1 student student  18 Jan 14  2019  .bash_logout
-rw-r--r--. 1 student student 141 Jan 14  2019  .bash_profile
-rw-r--r--. 1 student student 312 Jan 14  2019  .bashrc

 -u                         with -lt: sort by, and show, access time;
                               with -l: show access time and sort by name;
                               otherwise: sort by access time, newest first
[student@servera ~]$ ls -lAtu
total 12
drwxrwxr-x. 2 student student   6 Jun  2 21:20 '. '
drwxrwxr-x. 2 student student   6 Jun  2 21:20  aaa
-rw-r--r--. 1 student student 141 Jun  2 19:58  .bash_profile
-rw-r--r--. 1 student student 312 Jun  2 19:58  .bashrc
-rw-r--r--. 1 student student  18 Jan 14  2019  .bash_logout
#把上次讀取時間列出,不改變檔案排序列表
[student@servera ~]$ ls -lAu
total 12
drwxrwxr-x. 2 student student   6 Jun  2 21:20 '. '
drwxrwxr-x. 2 student student   6 Jun  2 21:20  aaa
-rw-r--r--. 1 student student  18 Jan 14  2019  .bash_logout
-rw-r--r--. 1 student student 141 Jun  2 19:58  .bash_profile
-rw-r--r--. 1 student student 312 Jun  2 19:58  .bashrc



+++++++++++++++++++++chain command together
#三個指令沒有因果關係用 ; 隔開。
cmmd1 ; cmmd2 ; cmmd3
[root@servera ~]# whoami ; ls /
root
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
#↓ && 指令成功後面指令才會執行
cmmd1 && cmmd2 && cmmd3
[root@servera ~]# whoami && ls /eeee && hostname
root
ls: cannot access '/eeee': No such file or directory
#↓ || 指令失敗,後面指令才會執行
cmmd1 || cmmd2 || cmmd3
[root@servera ~]# whoami && ls /eeee || hostname
root
ls: cannot access '/eeee': No such file or directory
servera.lab.example.com


-----------------------------------------

Command Alias
[student@servera ~]$ ll
total 0
drwxrwxr-x. 2 student student 6 Jun  2 20:54 aaa
[student@servera ~]$ ls -l
total 0
drwxrwxr-x. 2 student student 6 Jun  2 20:54 aaa
#軟連結藍綠色,遇到目錄內容藍色
#設定別名
[student@servera ~]$ alias
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias vi='vim'
alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'
[student@servera ~]$ alias aaa='ls -lAt'
[student@servera ~]$ aaa
total 12
drwxrwxr-x. 2 student student   6 Jun  2 20:54 '. '
drwxrwxr-x. 2 student student   6 Jun  2 20:54  aaa
-rw-r--r--. 1 student student  18 Jan 14  2019  .bash_logout
-rw-r--r--. 1 student student 141 Jan 14  2019  .bash_profile
-rw-r--r--. 1 student student 312 Jan 14  2019  .bashrc

******cancel alias
[student@servera ~]$ unalias aaa
[student@servera ~]$ aaa
-bash: aaa: command not found


+++++++++++++++++++++++++

[student@servera ~]$ date
Tue Jun  2 22:17:33 CST 2020
[student@servera ~]$ timedatectl
               Local time: Tue 2020-06-02 22:18:41 CST
           Universal time: Tue 2020-06-02 14:18:41 UTC
                 RTC time: Tue 2020-06-02 14:18:40
                Time zone: Asia/Taipei (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
[student@servera ~]$ timedatectl --help
timedatectl [OPTIONS...] COMMAND ...

Commands:
  status                   Show current time settings
  show                     Show properties of systemd-timedated
  set-time TIME            Set system time
  set-timezone ZONE        Set system time zone
  list-timezones           Show known time zones
  set-local-rtc BOOL       Control whether RTC is in local time
  set-ntp BOOL             Enable or disable network time synchronization
[kiosk@foundation0 ~]$ date "+%A"
Wednesday
[kiosk@foundation0 ~]$ echo "ppppppp"
ppppppp
[kiosk@foundation0 ~]$ echo "today is www"
today is www
[kiosk@foundation0 ~]$ echo "today is $(date +%A)"
today is Wednesday

[student@servera ~]$ timedatectl  list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
[student@servera ~]$ timedatectl  set-timezone Antarctica/Davis
==== AUTHENTICATING FOR org.freedesktop.timedate1.set-timezone ====
Authentication is required to set the system timezone.
Authenticating as: Student User (student)
Password: student
==== AUTHENTICATION COMPLETE ====
[student@servera ~]$ timedatectl  
               Local time: Tue 2020-06-02 21:22:05 +07
           Universal time: Tue 2020-06-02 14:22:05 UTC
                 RTC time: Tue 2020-06-02 14:22:05
                Time zone: Antarctica/Davis (+07, +0700)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
[student@servera ~]$ timedatectl  set-time 11:11:00
Failed to set time: NTP unit is active
#timedatectl  set-ntp false 網路校時關閉後可設定時間
[student@servera ~]$ timedatectl  set-ntp false
==== AUTHENTICATING FOR org.freedesktop.timedate1.set-ntp ====
Authentication is required to control whether network time synchronization shall be enabled.
Authenticating as: Student User (student)
Password: 
==== AUTHENTICATION COMPLETE ====
#date(utc+本地時間)
[student@servera ~]$ timedatectl  
               Local time: Tue 2020-06-02 21:23:35 +07
           Universal time: Tue 2020-06-02 14:23:35 UTC
                 RTC time: Tue 2020-06-02 14:23:35
                Time zone: Antarctica/Davis (+07, +0700)
System clock synchronized: yes
              NTP service: inactive
          RTC in local TZ: no
[student@servera ~]$ timedatectl  set-time 11:11:00
==== AUTHENTICATING FOR org.freedesktop.timedate1.set-time ====
Authentication is required to set the system time.
Authenticating as: Student User (student)
Password: 
==== AUTHENTICATION COMPLETE ====
[student@servera ~]$ timedatectl  
               Local time: Tue 2020-06-02 11:11:05 +07
           Universal time: Tue 2020-06-02 04:11:05 UTC
                 RTC time: Tue 2020-06-02 04:11:05
                Time zone: Antarctica/Davis (+07, +0700)
System clock synchronized: no
              NTP service: inactive
          RTC in local TZ: no
#timedatectl  set-ntp true  網路校時開啟
[student@servera ~]$ timedatectl  set-ntp true
==== AUTHENTICATING FOR org.freedesktop.timedate1.set-ntp ====
Authentication is required to control whether network time synchronization shall be enabled.
Authenticating as: Student User (student)
Password: 
==== AUTHENTICATION COMPLETE ====
[student@servera ~]$ timedatectl  
               Local time: Tue 2020-06-02 11:11:42 +07
           Universal time: Tue 2020-06-02 04:11:42 UTC
                 RTC time: Tue 2020-06-02 04:11:42
                Time zone: Antarctica/Davis (+07, +0700)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no


[student@servera ~]$ date
Tue Jun  2 21:26:38 +07 2020
[student@servera ~]$ date --help
Usage: date [OPTION]... [+FORMAT]
 %%   a literal %
  %a   locale's abbreviated weekday name (e.g., Sun)
  %A   locale's full weekday name (e.g., Sunday)
  %b   locale's abbreviated month name (e.g., Jan)
  %B   locale's full month name (e.g., January)
  %c   locale's date and time (e.g., Thu Mar  3 23:05:25 2005)
  %C   century; like %Y, except omit last two digits (e.g., 20)
  %d   day of month (e.g., 01)
  %D   date; same as %m/%d/%y
  %e   day of month, space padded; same as %_d
  %F   full date; same as %Y-%m-%d
  %g   last two digits of year of ISO week number (see %G)
  %G   year of ISO week number (see %V); normally useful only with %V
  %h   same as %b
  %H   hour (00..23)
  %I   hour (01..12)
  %j   day of year (001..366)
  %k   hour, space padded ( 0..23); same as %_H
  %l   hour, space padded ( 1..12); same as %_I
  %m   month (01..12)
  %M   minute (00..59)
  %n   a newline
  %N   nanoseconds (000000000..999999999)
  %p   locale's equivalent of either AM or PM; blank if not known
  %P   like %p, but lower case
  %q   quarter of year (1..4)
  %r   locale's 12-hour clock time (e.g., 11:11:04 PM)
  %R   24-hour hour and minute; same as %H:%M
  %s   seconds since 1970-01-01 00:00:00 UTC
  %S   second (00..60)
  %t   a tab
  %T   time; same as %H:%M:%S
  %u   day of week (1..7); 1 is Monday
  %U   week number of year, with Sunday as first day of week (00..53)
  %V   ISO week number, with Monday as first day of week (01..53)
  %w   day of week (0..6); 0 is Sunday
  %W   week number of year, with Monday as first day of week (00..53)
  %x   locale's date representation (e.g., 12/31/99)
  %X   locale's time representation (e.g., 23:13:48)
  %y   last two digits of year (00..99)
  %Y   year
  %z   +hhmm numeric time zone (e.g., -0400)
  %:z  +hh:mm numeric time zone (e.g., -04:00)
  %::z  +hh:mm:ss numeric time zone (e.g., -04:00:00)
  %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)
  %Z   alphabetic time zone abbreviation (e.g., EDT)

[student@servera ~]$ date
Tue Jun  2 21:27:57 +07 2020
[student@servera ~]$ date +%D-%T
06/02/20-21:28:39
[student@servera ~]$ date +%y-%m-%d-%T
20-06-02-21:29:16
[student@servera ~]$ date +%Y-%m-%d-%T
2020-06-02-21:29:28
[student@servera ~]$ date +%Y %m-%d-%T
date: extra operand ‘%m-%d-%T’
Try 'date --help' for more information.
[student@servera ~]$ date "+%Y %m-%d-%T"
2020 06-02-21:30:44
[student@servera ~]$ date "+%Y-%m-%d  %T"
2020-06-02  21:30:57

[student@servera ~]$ passwd
Changing password for user student.
Current password: student
New password: 12345678
BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic
passwd: Authentication token manipulation error
[student@servera ~]$ passwd
Changing password for user student.
Current password: student
New password: IloveApple
Retype new password: 
passwd: all authentication tokens updated successfully.
------------------------20200604

[student@servera ~]$ file /etc/passwd
/etc/passwd: ASCII text
[student@servera ~]$ which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[student@servera ~]$ which cat
/usr/bin/cat
[student@servera ~]$ file $(which cat)
/usr/bin/cat: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=0f160b371d580150eb4d5e152d13ac3726dfb632, stripped, too many notes (256)

#unix File Name 255
辨識檔案的類型
[student@servera ~]$ file $(find /etc -name "a*" )
find: ‘/etc/pki/rsyslog’: Permission denied
find: ‘/etc/dhcp’: Permission denied
find: ‘/etc/lvm/archive’: Permission denied
find: ‘/etc/lvm/backup’: Permission denied
find: ‘/etc/lvm/cache’: Permission denied
find: ‘/etc/polkit-1/rules.d’: Permission denied
find: ‘/etc/polkit-1/localauthority’: Permission denied
find: ‘/etc/sssd’: Permission denied
find: ‘/etc/grub.d’: Permission denied
find: ‘/etc/audit’: Permission denied
find: ‘/etc/firewalld’: Permission denied
find: ‘/etc/sudoers.d’: Permission denied
/etc/dnf/aliases.d:                                         directory
/etc/pki/ca-trust/source/anchors:                           directory
/etc/security/access.conf:                                  ASCII text
/etc/aliases:                                               ASCII text
/etc/pam.d/atd:                                             ASCII text
/etc/adjtime:                                               ASCII text
/etc/systemd/system/multi-user.target.wants/auditd.service: symbolic link to /usr/lib/systemd/system/auditd.service
/etc/systemd/system/multi-user.target.wants/atd.service:    symbolic link to /usr/lib/systemd/system/atd.service
/etc/lvm/archive:                                           directory
/etc/X11/applnk:                                            directory
/etc/sysconfig/rhn/allowed-actions:                         directory
/etc/sysconfig/authconfig:                                  ASCII text
/etc/sysconfig/anaconda:                                    ASCII text
/etc/sysconfig/atd:                                         ASCII text
/etc/xdg/autostart:                                         directory
/etc/alternatives:                                          directory
/etc/anacrontab:                                            ASCII text
/etc/audit:                                                 directory
/etc/authselect:                                            directory
/etc/authselect/authselect.conf:                            ASCII text
/etc/tuned/active_profile:                                  ASCII text
/etc/nftables/all-in-one.nft:                               a /usr/sbin/nft -f script, ASCII text executable
/etc/nftables/arp-filter.nft:                               a /usr/sbin/nft -f script, ASCII text executable
/etc/docker/certs.d/access.redhat.com:                      directory
/etc/at.deny:        
----
[root@servera ~]# file $(find /etc -name "a*" )
/etc/dnf/aliases.d:                                         directory
/etc/pki/ca-trust/source/anchors:                           directory
/etc/security/access.conf:                                  ASCII text
/etc/aliases:                                               ASCII text
/etc/pam.d/atd:                                             ASCII text
/etc/adjtime:                                               ASCII text
/etc/systemd/system/multi-user.target.wants/auditd.service: symbolic link to /usr/lib/systemd/system/auditd.service
/etc/systemd/system/multi-user.target.wants/atd.service:    symbolic link to /usr/lib/systemd/system/atd.service
/etc/lvm/archive:                                           directory
/etc/X11/applnk:                                            directory
/etc/sysconfig/rhn/allowed-actions:                         directory
/etc/sysconfig/authconfig:                                  ASCII text
/etc/sysconfig/anaconda:                                    ASCII text
/etc/sysconfig/atd:                                         ASCII text
/etc/xdg/autostart:                                         directory
/etc/alternatives:                                          directory
/etc/anacrontab:                                            ASCII text
/etc/audit:                                                 directory
/etc/audit/audit-stop.rules:                                ASCII text
/etc/audit/auditd.conf:                                     ASCII text
/etc/audit/plugins.d/af_unix.conf:                          ASCII text
/etc/audit/rules.d/audit.rules:                             ASCII text
/etc/audit/audit.rules:                                     ASCII text
/etc/authselect:                                            directory
/etc/authselect/authselect.conf:                            ASCII text
/etc/tuned/active_profile:                                  ASCII text
/etc/nftables/all-in-one.nft:                               a /usr/sbin/nft -f script, ASCII text executable
/etc/nftables/arp-filter.nft:                               a /usr/sbin/nft -f script, ASCII text executable
/etc/docker/certs.d/access.redhat.com:                      directory
/etc/at.deny:                                               very short file (no magic)

#複合式指令
COMPOUND COMMAND
COMD3 $(COMD2 $(COMD1 FILE))

[student@servera ~]$ file $(find /home -name "*.jpg" )
[student@servera ~]$ file $(find /home -name "*.txt" )



----------------------
[kiosk@foundation0 ~]$ ssh root@servera
Web console: https://servera.lab.example.com:9090/ or https://172.25.250.10:9090/

This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register

Last login: Wed Feb 24 20:54:22 2021 from 172.25.250.9
[root@servera ~]# ll
total 16
-rw-------. 1 root root 6503 Apr 23  2020 anaconda-ks.cfg
-rw-------. 1 root root 6251 Apr 23  2020 original-ks.cfg

cat 
[root@servera ~]# cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s) to standard output.
[root@servera ~]# ll
total 16
-rw-------. 1 root root 6947 Apr  4  2019 anaconda-ks.cfg
-rw-------. 1 root root 6750 Apr  4  2019 original-ks.cfg
[root@servera ~]# cat anaconda-ks.cfg 
#version=RHEL8
ignoredisk --only-use=vda
# System bootloader configuration
bootloader --append="console=ttyS0 console=ttyS0,115200n8 no_timer_check net.ifnames=0  crashkernel=auto" --location=mbr --timeout=1 --boot-drive=vda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Reboot after installation
reboot

[student@servera ~]$ cat /etc/shadow
cat: /etc/shadow: Permission denied
[student@servera ~]$ 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

[student@servera ~]$ cat /etc/passwd |more
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:65534:65534:Kernel Overflow User:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin
/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
unbound:x:997:995:Unbound DNS resolver:/etc/unbound:/sbin/nologin
sssd:x:996:993:User for sssd:/:/sbin/nologin
setroubleshoot:x:995:992::/var/lib/setroubleshoot:/sbin/nologin


enter/space
#把檔案列表 用less 指令
[student@servera ~]$ cat /etc/passwd |less
page up/down , space/ enter ,/kkk n/N, q



---------------------------
#head 列出檔案前面的最10行,指定顯示 head -5
[student@servera ~]$ head /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
[student@servera ~]$ head -15 /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:65534:65534:Kernel Overflow User:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
#列出檔案前面的20行
[student@servera ~]$ head -20 /etc/passwd 
#檔案最後幾行 tail
[student@servera ~]$ tail /etc/passwd 
sssd:x:996:993:User for sssd:/:/sbin/nologin
setroubleshoot:x:995:992::/var/lib/setroubleshoot:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
insights:x:994:991:Red Hat Insights:/var/lib/insights:/sbin/nologin
cockpit-ws:x:993:990:User for cockpit-ws:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
chrony:x:992:989::/var/lib/chrony:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
student:x:1000:1000:Student User:/home/student:/bin/bash
libstoragemgmt:x:991:987:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
[student@servera ~]$ tail -15 /etc/passwd 
systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
unbound:x:997:995:Unbound DNS resolver:/etc/unbound:/sbin/nologin
sssd:x:996:993:User for sssd:/:/sbin/nologin
setroubleshoot:x:995:992::/var/lib/setroubleshoot:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
insights:x:994:991:Red Hat Insights:/var/lib/insights:/sbin/nologin
cockpit-ws:x:993:990:User for cockpit-ws:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
chrony:x:992:989::/var/lib/chrony:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
student:x:1000:1000:Student User:/home/student:/bin/bash
libstoragemgmt:x:991:987:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
[student@servera ~]$ tail -20 /etc/passwd 

#wc -w(多少字) -l(多少行) -c (多少字元)
[student@servera ~]$ wc  /etc/passwd 
  30   66 1563 /etc/passwd
[student@servera ~]$ wc -w  /etc/passwd 
66 /etc/passwd
[student@servera ~]$ wc -l  /etc/passwd 
30 /etc/passwd
[student@servera ~]$ wc -c  /etc/passwd 
1563 /etc/passwd

[student@servera ~]$ pas
passwd  paste   
[student@servera ~]$ pa
package-cleanup      pam_timestamp_check  partx                pathchk
packer               parted               passwd               
pam_console_apply    partprobe            paste         


[student@servera ~]$ useradd --
--base-dir        --gid             --key             --password        --skel
--comment         --groups          --no-create-home  --prefix          --system
--create-home     --help            --no-log-init     --root            --uid
--defaults        --home-dir        --non-unique      --selinux-user    --user-group
--expiredate      --inactive        --no-user-group   --shell    

[student@servera ~]$ ll /usr/share/fonts/dejavu/
total 5516
-rw-r--r--. 1 root root 641716 May 17  2015 DejaVuSans-BoldOblique.ttf
-rw-r--r--. 1 root root 704128 May 17  2015 DejaVuSans-Bold.ttf
-rw-r--r--. 1 root root 610260 May 17  2015 DejaVuSansCondensed-BoldOblique.ttf
-rw-r--r--. 1 root root 663468 May 17  2015 DejaVuSansCondensed-Bold.ttf
-rw-r--r--. 1 root root 597708 May 17  2015 DejaVuSansCondensed-Oblique.ttf
-rw-r--r--. 1 root root 679256 May 17  2015 DejaVuSansCondensed.ttf
-rw-r--r--. 1 root root 355204 May 17  2015 DejaVuSans-ExtraLight.ttf
-rw-r--r--. 1 root root 633836 May 17  2015 DejaVuSans-Oblique.ttf
-rw-r--r--. 1 root root 756072 May 17  2015 DejaVuSans.ttf

***fc-cache

[student@servera ~]$ history
    1  ls
    2  which ls
    3  ls --all
    4  ls -a
    5  mkdir aaa
    6  ls -a
    7  mkdir ". "

[student@servera ~]$ !9
ls -a
 .  '. '   ..   aaa   .bash_history   .bash_logout   .bash_profile   .bashrc   .lesshst



up-arrow down-arrow 



				
			

RH124 CH3練習

				
					http://linux.vbird.org/linux_basic/0210filepermission.php#dir



***absolute path
[student@servera ~]$ pwd
/home/student
[student@servera ~]$ /etc/rc.d/rc.local
[sudo] password for student: 
Sorry, try again.
[sudo] password for student: 
Starting download of student specific variables/keys...
rht-vmsetup-getkeys done
touch: cannot touch '/var/lock/subsys/local': Permission denied

.    
..    
cd command
[student@servera ~]$ cd /etc
[student@servera etc]$ pwd
/etc
[student@servera etc]$ cd
[student@servera ~]$ pwd
/home/student
[student@servera ~]$ echo $HOME
/home/student
[student@servera ~]$ cd /srv
[student@servera srv]$ pwd
/srv
[student@servera srv]$ cd /etc
[student@servera etc]$ pwd
/etc
#以下切換目錄的過程
[student@servera etc]$ cd -
/srv
[student@servera srv]$ cd -
/etc
[student@servera etc]$ alias cd..='cd ..'
[student@servera etc]$ alias cd...='cd ../..'


Relative PaTH
---------------------
[student@servera ~]$ cd /etc
[student@servera etc]$ ls
adjtime                  hosts.deny                rc1.d
aliases                  idmapd.conf               rc2.d
alternatives             init.d                    rc3.d
anacrontab               inittab                   rc4.d
at.deny                  inputrc                   rc5.d
audit                    insights-client           rc6.d
authselect               iproute2                  rc.d--------
[student@servera etc]$ rc.d/rc.local
[sudo] password for student: 
Sorry, try again.
[sudo] password for student: 
Starting download of student specific variables/keys...
rht-vmsetup-getkeys done
touch: cannot touch '/var/lock/subsys/local': Permission denied
[student@servera etc]$ cd rc.d
[student@servera rc.d]$ ll
total 8
drwxr-xr-x. 2 root root   37 Apr  4  2019 init.d
drwxr-xr-x. 2 root root    6 Sep 10  2018 rc0.d
drwxr-xr-x. 2 root root    6 Sep 10  2018 rc1.d
drwxr-xr-x. 2 root root    6 Sep 10  2018 rc2.d
drwxr-xr-x. 2 root root    6 Sep 10  2018 rc3.d
drwxr-xr-x. 2 root root    6 Sep 10  2018 rc4.d
drwxr-xr-x. 2 root root    6 Sep 10  2018 rc5.d
drwxr-xr-x. 2 root root    6 Sep 10  2018 rc6.d
lrwxrwxrwx. 1 root root   12 May 22  2019 rc.local -> rc.local-rht
-rw-r--r--. 1 root root  474 Feb 26  2019 rc.local-prerht
-rwxr-xr-x. 1 root root 1124 May 22  2019 rc.local-rht
#在當前路徑下執行rc.local,linux會當成指令所以會告訴你找不到
[student@servera rc.d]$ rc.local
-bash: rc.local: command not found
[student@servera rc.d]$ echo $PATH
/home/student/.local/bin:/home/student/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
#所以執行當前目錄指令要加以下,./rc.local
[student@servera rc.d]$ ./rc.local
[sudo] password for student: 
Starting download of student specific variables/keys...
rht-vmsetup-getkeys done
touch: cannot touch '/var/lock/subsys/local': Permission denied
---------------------
[root@workstation ~]# stat anaconda-ks.cfg 
  File: anaconda-ks.cfg
  Size: 6503      	Blocks: 16         IO Block: 4096   regular file
Device: fc03h/64515d	Inode: 25170495    Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
#Access: 被讀取 Modify:上次修改時間 Change:被改變
#時間戳記被記錄到小數點後9位
Context: system_u:object_r:admin_home_t:s0
Access 上次讀取時間
Access: 2021-07-11 12:05:13.674486779 +0800  --atime
Modify 上次修改時間
Modify: 2020-04-23 13:24:24.391000000 +0800  --mtime
Change 權限修改時間
Change: 2020-04-23 13:24:24.391000000 +0800  --ctime
 Birth: -


[student@workstation ~]$ touch --help
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.
#僅更改訪問時間
 -a                     change only the access time
#專門修改上次時間
 -m                     change only the modification time

-t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time

[student@workstation ~]$ touch aaaaaa
[student@workstation ~]$ ll
total 0
-rw-rw-r--. 1 student student 0 Mar  9 05:22 aaaaaa
[student@workstation ~]$ touch -t 202010301230 aaaaaa 
[student@workstation ~]$ ll
total 0
-rw-rw-r--. 1 student student 0 Oct 30 12:30 aaaaaa
drwxr-xr-x. 2 student student 6 Sep  1  2020 Desktop
drwxr-xr-x. 2 student student 6 Sep  1  2020 Documents
drwxr-xr-x. 2 student student 6 Sep  1  2020 Downloads
drwxr-xr-x. 2 student student 6 Sep  1  2020 Music
drwxr-xr-x. 2 student student 6 Sep  1  2020 Pictures
drwxr-xr-x. 2 student student 6 Sep  1  2020 Public
drwxr-xr-x. 2 student student 6 Sep  1  2020 Templates
drwxr-xr-x. 2 student student 6 Sep  1  2020 Videos
[student@workstation ~]$ stat aaaaaa 
  File: aaaaaa
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fc03h/64515d	Inode: 9381640     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ student)   Gid: ( 1000/ student)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2020-10-30 12:30:00.000000000 +0800
Modify: 2020-10-30 12:30:00.000000000 +0800
Change: 2021-03-09 05:23:38.413514311 +0800
 Birth: -
 #touch修改時間戳記
[student@workstation ~]$ touch -a -t 202101301230 aaaaaa 
[student@workstation ~]$ stat aaaaaa 
  File: aaaaaa
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fc03h/64515d	Inode: 9381640     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/ student)   Gid: ( 1000/ student)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2021-01-30 12:30:00.000000000 +0800
Modify: 2020-10-30 12:30:00.000000000 +0800
Change: 2021-03-09 05:24:52.021125962 +0800
 Birth: -


-------------------------------20200609
#萬用字元 ----filename>檔案名稱的表達
wildcard ----filename globing
#0~1個字
*  ----zero or more character
#1個?專門列出一個字
?  ----one character

[abc]  ---any single character in list
[a-e]  ---any single character in Range
[^a-e] ---any single character NOT  in list/range

ASCII Code
-----------------------------------------

[root@servera ~]# cd /srv
[root@servera srv]# ll
total 0
[root@servera srv]# ls /etc/a*
/etc/adjtime  /etc/aliases  /etc/anacrontab  /etc/at.deny

/etc/alternatives:
cifs-idmap-plugin  ld                      pip3     python3
easy_install-3     libnssckbi.so.x86_64    pydoc-3  python3-man
ifdown             libwbclient.so.0.14-64  pydoc3   pyvenv-3
ifup               pip-3                   python   unversioned-python-man

/etc/audit:
auditd.conf  audit.rules  audit-stop.rules  plugins.d  rules.d

/etc/authselect:
authselect.conf  dconf-locks       password-auth   system-auth
custom           fingerprint-auth  postlogin       user-nsswitch.conf
dconf-db         nsswitch.conf     smartcard-auth
[root@servera srv]# cp  /etc/a* .
cp: -r not specified; omitting directory '/etc/alternatives'
cp: -r not specified; omitting directory '/etc/audit'
cp: -r not specified; omitting directory '/etc/authselect'
[root@servera srv]# ll
total 16
-rw-r--r--. 1 root root   44 Jun  9 19:03 adjtime
-rw-r--r--. 1 root root 1518 Jun  9 19:03 aliases
-rw-r--r--. 1 root root  541 Jun  9 19:03 anacrontab
-rw-r--r--. 1 root root    1 Jun  9 19:03 at.deny
[root@servera srv]# cp  /etc/[bc]* .
cp: -r not specified; omitting directory '/etc/bash_completion.d'
cp: -r not specified; omitting directory '/etc/binfmt.d'
cp: -r not specified; omitting directory '/etc/chkconfig.d'
cp: -r not specified; omitting directory '/etc/cifs-utils'
cp: -r not specified; omitting directory '/etc/cloud'
cp: -r not specified; omitting directory '/etc/cockpit'
cp: -r not specified; omitting directory '/etc/cron.d'
cp: -r not specified; omitting directory '/etc/cron.daily'
cp: -r not specified; omitting directory '/etc/cron.hourly'
cp: -r not specified; omitting directory '/etc/cron.monthly'
cp: -r not specified; omitting directory '/etc/cron.weekly'
cp: -r not specified; omitting directory '/etc/crypto-policies'
[root@servera srv]# ll
total 52
-rw-r--r--. 1 root root   44 Jun  9 19:03 adjtime
-rw-r--r--. 1 root root 1518 Jun  9 19:03 aliases
-rw-r--r--. 1 root root  541 Jun  9 19:03 anacrontab
-rw-r--r--. 1 root root    1 Jun  9 19:03 at.deny
-rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
-rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
-rw-r--r--. 1 root root 1190 Jun  9 19:04 chrony.conf
-rw-r--r--. 1 root root 1083 Jun  9 19:04 chrony.conf-prerht
-rw-r--r--. 1 root root 1190 Jun  9 19:04 chrony.conf-rht
-rw-r-----. 1 root root  481 Jun  9 19:04 chrony.keys
-rw-r--r--. 1 root root    0 Jun  9 19:04 cron.deny
-rw-r--r--. 1 root root  451 Jun  9 19:04 crontab
-rw-------. 1 root root    0 Jun  9 19:04 crypttab
-rw-r--r--. 1 root root 1602 Jun  9 19:04 csh.cshrc
-rw-r--r--. 1 root root  841 Jun  9 19:04 csh.login



[root@servera srv]# ll /home
total 0
drwx------. 4 student student 120 Jun  4 18:55 student
[root@servera srv]# cp /home/student/ .
cp: -r not specified; omitting directory '/home/student/'
#-r 連底下子目錄
[root@servera srv]# cp -r /home/student/ .
[root@servera srv]# ll
total 52
-rw-r--r--. 1 root root   44 Jun  9 19:03 adjtime
-rw-r--r--. 1 root root 1518 Jun  9 19:03 aliases
-rw-r--r--. 1 root root  541 Jun  9 19:03 anacrontab
-rw-r--r--. 1 root root    1 Jun  9 19:03 at.deny
-rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
-rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
-rw-r--r--. 1 root root 1190 Jun  9 19:04 chrony.conf
-rw-r--r--. 1 root root 1083 Jun  9 19:04 chrony.conf-prerht
-rw-r--r--. 1 root root 1190 Jun  9 19:04 chrony.conf-rht
-rw-r-----. 1 root root  481 Jun  9 19:04 chrony.keys
-rw-r--r--. 1 root root    0 Jun  9 19:04 cron.deny
-rw-r--r--. 1 root root  451 Jun  9 19:04 crontab
-rw-------. 1 root root    0 Jun  9 19:04 crypttab
-rw-r--r--. 1 root root 1602 Jun  9 19:04 csh.cshrc
-rw-r--r--. 1 root root  841 Jun  9 19:04 csh.login
drwx------. 4 root root  120 Jun  9 19:08 student
[root@servera srv]# rm  [^b]*
rm: remove regular file 'adjtime'? y
rm: remove regular file 'aliases'? y
rm: remove regular file 'anacrontab'? y
rm: remove regular file 'at.deny'? y
rm: remove regular file 'chrony.conf'? y
rm: remove regular file 'chrony.conf-prerht'? y
rm: remove regular file 'chrony.conf-rht'? y
rm: remove regular file 'chrony.keys'? y
rm: remove regular empty file 'cron.deny'? y
rm: remove regular file 'crontab'? y
rm: remove regular empty file 'crypttab'? y
rm: remove regular file 'csh.cshrc'? y
rm: remove regular file 'csh.login'? y
rm: cannot remove 'student': Is a directory
[root@servera srv]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot'
alias xzegrep='xzegrep --color=auto'
alias xzfgrep='xzfgrep --color=auto'
alias xzgrep='xzgrep --color=auto'
alias zegrep='zegrep --color=auto'
alias zfgrep='zfgrep --color=auto'
alias zgrep='zgrep --color=auto'
[root@servera srv]# rm  -r student/
rm: descend into directory 'student/'? y
rm: remove regular file 'student/.lesshst'? y
rm: remove regular file 'student/.bash_history'? ^C
[root@servera srv]# rm  -rf student/
[root@servera srv]# ll
total 8
-rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
-rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist

[root@servera srv]# cp bashrc xyz
[root@servera srv]# ll
total 12
-rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
-rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
-rw-r--r--. 1 root root 3001 Jun  9 19:34 xyz
[root@servera srv]# ll -i
total 12
12695345 -rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
12695346 -rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
12695322 -rw-r--r--. 1 root root 3001 Jun  9 19:34 xyz
[root@servera srv]# ln xyz abc
[root@servera srv]# ll
total 16
-rw-r--r--. 2 root root 3001 Jun  9 19:34 abc
-rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
-rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
-rw-r--r--. 2 root root 3001 Jun  9 19:34 xyz
[root@servera srv]# ll -i
total 16
12695322 -rw-r--r--. 2 root root 3001 Jun  9 19:34 abc
12695345 -rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
12695346 -rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
12695322 -rw-r--r--. 2 root root 3001 Jun  9 19:34 xyz
[root@servera srv]# cat abc
[root@servera srv]# echo ppp>>abc
[root@servera srv]# cat abc
[root@servera srv]# ll -i
total 16
12695322 -rw-r--r--. 2 root root 3005 Jun  9 19:37 abc
12695345 -rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
12695346 -rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
12695322 -rw-r--r--. 2 root root 3005 Jun  9 19:37 xyz
[root@servera srv]# rm abc
rm: remove regular file 'abc'? y
[root@servera srv]# ll -i
total 12
12695345 -rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
12695346 -rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
12695322 -rw-r--r--. 1 root root 3005 Jun  9 19:37 xyz
[root@servera srv]# man shred


shred --random-source=/dev/urandom -n 200 -u file
硬連結:
軟連結:
[root@servera srv]# mv xyz yyy
[root@servera srv]# ll -i
total 12
12695345 -rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
12695346 -rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
12695322 -rw-r--r--. 1 root root 3005 Jun  9 19:37 yyy
[root@servera srv]# mkdir qqq
[root@servera srv]# mv yyy qqq
[root@servera srv]# ll -i
total 8
12695345 -rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
12695346 -rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
20971654 drwxr-xr-x. 2 root root   17 Jun  9 19:50 qqq
[root@servera srv]# ll -i qqq
total 4
12695322 -rw-r--r--. 1 root root 3005 Jun  9 19:37 yyy

[root@servera srv]# mkdir aa/bb/dd
mkdir: cannot create directory ‘aa/bb/dd’: No such file or directory
[root@servera srv]# mkdir aa
[root@servera srv]# mkdir aa/bb/dd
mkdir: cannot create directory ‘aa/bb/dd’: No such file or directory
[root@servera srv]# mkdir aa/bb
[root@servera srv]# mkdir aa/bb/dd
[root@servera srv]# tree aa
aa
└── bb
    └── dd

2 directories, 0 files
[root@servera srv]# rmdir aa
rmdir: failed to remove 'aa': Directory not empty
[root@servera srv]# rm -rf aa
[root@servera srv]# mkdir -p aa/bb/dd
[root@servera srv]# tree aa
aa
└── bb
    └── dd

2 directories, 0 files
[root@servera srv]# touch aa/cc
[root@servera srv]# touch aa/bb/ee
[root@servera srv]# tree aa
aa
├── bb
│   ├── dd
│   └── ee
└── cc

2 directories, 2 files
[root@servera srv]# ll
total 8
drwxr-xr-x. 3 root root   26 Jun  9 19:55 aa
-rw-r--r--. 1 root root 3001 Jun  9 19:04 bashrc
-rw-r--r--. 1 root root  429 Jun  9 19:04 bindresvport.blacklist
drwxr-xr-x. 2 root root   17 Jun  9 19:50 qqq
[root@servera srv]# ln -s /srv/bashrc /root/abc
[root@servera srv]# ll /root
total 16
lrwxrwxrwx. 1 root root   11 Jun  9 20:11 abc -> /srv/bashrc
-rw-------. 1 root root 6947 Apr  4  2019 anaconda-ks.cfg
-rw-------. 1 root root 6750 Apr  4  2019 original-ks.cfg

---------------------------------------------
[root@servera ~]# echo {a..e}.txt
a.txt b.txt c.txt d.txt e.txt
[root@servera ~]# echo {a..e}.[1..5}
a.[1..5} b.[1..5} c.[1..5} d.[1..5} e.[1..5}
[root@servera ~]# echo {a..e}.{1..5}
a.1 a.2 a.3 a.4 a.5 b.1 b.2 b.3 b.4 b.5 c.1 c.2 c.3 c.4 c.5 d.1 d.2 d.3 d.4 d.5 e.1 e.2 e.3 e.4 e.5
[root@workstation srv]# echo  {a..g}.{1,2,6}
a.1 a.2 a.6 b.1 b.2 b.6 c.1 c.2 c.6 d.1 d.2 d.6 e.1 e.2 e.6 f.1 f.2 f.6 g.1 g.2 g.6

[root@servera ~]# var=john
[root@servera ~]# echo $var
john
[root@servera ~]# var=123
[root@servera ~]# echo $var
123
[root@servera ~]# echo var
var
[root@servera ~]# echo $var
123
[root@servera ~]# echo $var-linux
123-linux
[root@servera ~]# echo $varlinux

[root@servera ~]# echo ${var}linux
123linux
------
[root@servera ~]# ls
a.1  a.3              a.txt  b.2  b.txt  c.2  c.txt            vvv
a.2  anaconda-ks.cfg  b.1    b.3  c.1    c.3  original-ks.cfg
[root@servera ~]# var=ls
[root@servera ~]# echo ${var}
ls
[root@servera ~]# echo "this is a $var"
this is a ls
[root@servera ~]# echo 'this is a $var'
this is a $var
#凡是被放置$()內,會被當指令執行
[root@servera ~]# echo "this is a $($var)"
this is a a.1
a.2
a.3
anaconda-ks.cfg
a.txt
b.1
b.2
b.3
b.txt
c.1
c.2
c.3
c.txt
original-ks.cfg
vvv
[root@servera ~]# rm $(ls *.[1-3])
rm: remove regular empty file 'a.1'? y 
rm: remove regular empty file 'a.2'? y
rm: remove regular empty file 'a.3'? y
rm: remove regular empty file 'b.1'? y
rm: remove regular empty file 'b.2'? ^C
[root@servera ~]# rm -f $(ls *.[1-3])
[root@servera ~]# ll
total 16
-rw-------. 1 root root 6503 Apr 23  2020 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 Mar 10 19:44 a.txt
-rw-r--r--. 1 root root    0 Mar 10 19:44 b.txt
-rw-r--r--. 1 root root    0 Mar 10 19:44 c.txt
-rw-------. 1 root root 6251 Apr 23  2020 original-ks.cfg
drwxr-xr-x. 2 root root    6 Mar 10 19:25 vvv

				
			

RH124 CH4練習

				
					http://linux.vbird.org/linux_basic/0160startlinux.php#manual
#手冊可能在被考試的時候被砍掉。
student@servera ~]$ which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[student@servera ~]$ whatis ls
ls: nothing appropriate.

[student@servera ~]$ sudo mandb
[sudo] password for student: 
Processing manual pages under /usr/share/man/overrides...
Updating index cache for path `/usr/share/man/overrides/man7'. Wait...done.


[root@servera srv]# mandb
Processing manual pages under /usr/share/man...
Updating index cache for path `/usr/share/man/man1'. Wait...mandb: warning: /usr/share/man/man1/gdk-pixbuf-query-loaders.1.gz: whatis parse for gdk-pixbuf-query-loaders(1) failed



[student@servera ~]$ whatis ls
ls (1)               - list directory contents
ls (1p)              - list directory contents
[student@servera ~]$ whatis passwd
openssl-passwd (1ssl) - compute password hashes
passwd (1)           - update user's authentication tokens
passwd (5)           - password file
[student@servera ~]$ man passwd
[student@servera ~]$ man 5 passwd
[student@servera ~]$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz

[student@servera ~]$ man -k pass
chage (1)            - change user password expiry information
chgpasswd (8)        - update group passwords in batch mode
chpasswd (8)         - update passwords in batch mode
cracklib-check (8)   - Check passwords using libcrack2
create-cracklib-dict (8) - Check passwords using libcrack2
[student@servera ~]$ man -k resize
fsadm (8)            - utility to resize or check filesystem on a device
lvresize (8)         - Resize a logical volume
pvresize (8)         - Resize physical volume(s)
resize2fs (8)        - ext2/ext3/ext4 file system resizer
resizecons (8)       - change kernel idea of the console size
resizepart (8)       - tell the kernel about the new size of a partition
sg_format (8)        - format, resize a SCSI disk or format a tape
[student@servera ~]$ man -k xfs
attr (1)             - extended attributes on XFS filesystem objects
filesystems (5)      - Linux filesystem types: ext, ext2, ext3, ext4, hpfs, iso9660, ...
fs (5)               - Linux filesystem types: ext, ext2, ext3, ext4, hpfs, iso9660, ...
fsck.xfs (8)         - do nothing, successfully
fsfreeze (8)         - suspend access to a filesystem (Ext3/4, ReiserFS, JFS, XFS)
mkfs.xfs (8)         - construct an XFS filesystem
xfs (5)              - layout, mount options, and supported file attributes for the X...
xfs_admin (8)        - change parameters of an XFS filesystem
xfs_bmap (8)         - print block mapping for an XFS file

				
			
				
					http://linux.vbird.org/linux_basic/0160startlinux.php#manual

student@servera ~]$ which ls
alias ls='ls --color=auto'
	/usr/bin/ls
[student@servera ~]$ whatis ls
ls: nothing appropriate.

[student@servera ~]$ sudo mandb
[sudo] password for student: 
Processing manual pages under /usr/share/man/overrides...
Updating index cache for path `/usr/share/man/overrides/man7'. Wait...done.


[root@servera srv]# mandb
Processing manual pages under /usr/share/man...
Updating index cache for path `/usr/share/man/man1'. Wait...mandb: warning: /usr/share/man/man1/gdk-pixbuf-query-loaders.1.gz: whatis parse for gdk-pixbuf-query-loaders(1) failed



[student@servera ~]$ whatis ls
ls (1)               - list directory contents
ls (1p)              - list directory contents
[student@servera ~]$ whatis passwd
openssl-passwd (1ssl) - compute password hashes
passwd (1)           - update user's authentication tokens
passwd (5)           - password file
[student@servera ~]$ man passwd
[student@servera ~]$ man 5 passwd
[student@servera ~]$ whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz

[student@servera ~]$ man -k pass
chage (1)            - change user password expiry information
chgpasswd (8)        - update group passwords in batch mode
chpasswd (8)         - update passwords in batch mode
cracklib-check (8)   - Check passwords using libcrack2
create-cracklib-dict (8) - Check passwords using libcrack2
[student@servera ~]$ man -k resize
fsadm (8)            - utility to resize or check filesystem on a device
lvresize (8)         - Resize a logical volume
pvresize (8)         - Resize physical volume(s)
resize2fs (8)        - ext2/ext3/ext4 file system resizer
resizecons (8)       - change kernel idea of the console size
resizepart (8)       - tell the kernel about the new size of a partition
sg_format (8)        - format, resize a SCSI disk or format a tape
[student@servera ~]$ man -k xfs
attr (1)             - extended attributes on XFS filesystem objects
filesystems (5)      - Linux filesystem types: ext, ext2, ext3, ext4, hpfs, iso9660, ...
fs (5)               - Linux filesystem types: ext, ext2, ext3, ext4, hpfs, iso9660, ...
fsck.xfs (8)         - do nothing, successfully
fsfreeze (8)         - suspend access to a filesystem (Ext3/4, ReiserFS, JFS, XFS)
mkfs.xfs (8)         - construct an XFS filesystem
xfs (5)              - layout, mount options, and supported file attributes for the X...
xfs_admin (8)        - change parameters of an XFS filesystem
xfs_bmap (8)         - print block mapping for an XFS file

				
			
				
					[student@servera ~]$ ls -l /etcp 
ls: cannot access '/etcp': No such file or directory
[student@servera ~]$ ls -l /etc 1> file1 
[student@servera ~]$ ll
total 16
drwxrwxr-x. 2 student student     6 Jun  2 19:54 aaa
drwxrwxr-x. 3 student student    27 Jun  9 20:43 Documents
-rw-rw-r--. 1 student student 12590 Jun  9 21:41 file1


[student@servera ~]$ ls -l /etcppp 1> file1 
ls: cannot access '/etcppp': No such file or directory

[student@servera ~]$ ll
total 0
-rw-rw-r--. 1 student student 0 Jul 11 15:31 file1
[student@servera ~]$ ls -l /etcppp 1> file1 2> err
[student@servera ~]$ ll
total 4
drwxrwxr-x. 2 student student  6 Jun  2 19:54 aaa
drwxrwxr-x. 3 student student 27 Jun  9 20:43 Documents
-rw-rw-r--. 1 student student 55 Jun  9 21:42 err
-rw-rw-r--. 1 student student  0 Jun  9 21:42 file1
[student@servera ~]$ ls -l /etc 1> file1 2> err
[student@servera ~]$ ll
total 16
drwxrwxr-x. 2 student student     6 Jun  2 19:54 aaa
drwxrwxr-x. 3 student student    27 Jun  9 20:43 Documents
-rw-rw-r--. 1 student student     0 Jun  9 21:42 err
-rw-rw-r--. 1 student student 12590 Jun  9 21:42 file1
[student@servera ~]$ ls -l /etc >> file1 2>> err
[student@servera ~]$ ll
total 28
drwxrwxr-x. 2 student student     6 Jun  2 19:54 aaa
drwxrwxr-x. 3 student student    27 Jun  9 20:43 Documents
-rw-rw-r--. 1 student student     0 Jun  9 21:42 err
-rw-rw-r--. 1 student student 25180 Jun  9 21:44 file1
[student@servera ~]$ ls -l /etcpp >> file1 2>> err
[student@servera ~]$ ll
total 32
drwxrwxr-x. 2 student student     6 Jun  2 19:54 aaa
drwxrwxr-x. 3 student student    27 Jun  9 20:43 Documents
-rw-rw-r--. 1 student student    54 Jun  9 21:44 err
-rw-rw-r--. 1 student student 25180 Jun  9 21:44 file1
[student@servera ~]$ ls -l /etcpp >> file1 2>&1
[student@servera ~]$ ll
total 32
drwxrwxr-x. 2 student student     6 Jun  2 19:54 aaa
drwxrwxr-x. 3 student student    27 Jun  9 20:43 Documents
-rw-rw-r--. 1 student student    54 Jun  9 21:44 err
-rw-rw-r--. 1 student student 25234 Jun  9 21:47 file1
[student@servera ~]$ ls -l /etcpp &>> file1 
[student@servera ~]$ ll
total 32
drwxrwxr-x. 2 student student     6 Jun  2 19:54 aaa
drwxrwxr-x. 3 student student    27 Jun  9 20:43 Documents
-rw-rw-r--. 1 student student    54 Jun  9 21:44 err
-rw-rw-r--. 1 student student 25288 Jun  9 21:47 file1

[student@servera ~]$ ll
total 32
-rw-rw-r--. 1 student student 25480 Jul 11 15:36 file1
-rw-rw-r--. 1 student student    55 Jul 11 15:35 file2
[student@servera ~]$ ping -c 1 -W 1 172.25.254.254 && echo "classroom ok"
PING 172.25.254.254 (172.25.254.254) 56(84) bytes of data.
64 bytes from 172.25.254.254: icmp_seq=1 ttl=63 time=0.736 ms

--- 172.25.254.254 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.736/0.736/0.736/0.000 ms
classroom ok
[student@servera ~]$ ping -c 1 -W 1 172.25.254.254 > /dev/null && echo "classroom ok"
classroom ok

--------------------------20200611
82  cat err
   83  cat err >> file1
   84  ll
   85  cat file1 
   86  ll
   87  cat file1 err > file2
   88  cat file2


[student@servera ~]$ echo hhhhhhh > file1
[student@servera ~]$ ll
total 36
drwxrwxr-x. 2 student student     6 Jun  2 19:54 aaa
drwxrwxr-x. 3 student student    27 Jun  9 20:43 Documents
-rw-rw-r--. 1 student student    54 Jun  9 21:44 err
-rw-rw-r--. 1 student student     8 Jun 11 18:22 file1
-rw-rw-r--. 1 student student 25396 Jun 11 18:18 file2
[student@servera ~]$ cat err  > file1

[student@servera ~]$ ll
total 0
[student@servera ~]$ echo hhhhhhh> file1
[student@servera ~]$ ll
total 4
-rw-rw-r--. 1 student student 8 Mar 15 19:16 file1
[student@servera ~]$ cp file1 file3
[student@servera ~]$ ll
total 8
-rw-rw-r--. 1 student student 8 Mar 15 19:16 file1
-rw-rw-r--. 1 student student 8 Mar 15 19:16 file3
[student@servera ~]$ ll -i
total 8
8514961 -rw-rw-r--. 1 student student 8 Mar 15 19:16 file1
8530957 -rw-rw-r--. 1 student student 8 Mar 15 19:16 file3
[student@servera ~]$ cmp file1 file3
[student@servera ~]$ ls -l /etc > file1
[student@servera ~]$ ls -l /etc > file3
[student@servera ~]$ cmp file1 file3
[student@servera ~]$ nano file3    ---ctrl-O save file ---ctrl-X exit
[student@servera ~]$ cmp file1 file3
file1 file3 differ: byte 4179, line 72
[student@servera ~]$ diff file1 file3
72c72
< -rw-r--r--.  1 root root     4849 Mar  9  2020 idmapd.conf
---
> -rw-r-or--.  1 root root     4849 Mar  9  2020 idmapd.conf
90c90
< drwxr-xr-x.  6 root root       70 Apr 23  2020 libreport
---
> drwxr-xr9x.  6 root root       70 Apr 23  2020 libreport
[student@servera ~]$ sum file1 file3
53677    13 file1
00490    13 file3
[student@servera ~]$ md5sum file1 file3
670c340d2376f19573dcf385d1e78d9b  file1
16772ff1dc0f06cb13ec0fce0e84710a  file3
[student@servera ~]$ sha256sum file1 file3
8c6be943d353baaab42b26e4f43d5d5567075014e439b292a6d508e20b266220  file1
2d8bc087eb0c7ae5b07d5c6cd525f15f93f166cc35565aa1eb43eb4b289a5af4  file3
[student@servera ~]$ sha512sum file1 file3
5c106efaf493c098a36e04670f2634ee24cb0ac88e4f623be24268c094e047722769fee87c986546e516704c4dcd0784a6da7f9d571e404f1ef3c1ba8034f17d  file1
b9f07963099c7e566f6a7eb0172f71a19ab88502646b15b6074f8b1dd77d7cc0f80b945da23b35b680ad27d15d136dd1460d990b0db5ae508111d9d641681b36  file3

[student@servera ~]$ find /etc -name passwd
find: ‘/etc/pki/rsyslog’: Permission denied
find: ‘/etc/dhcp’: Permission denied
/etc/pam.d/passwd
/etc/passwd
find: ‘/etc/lvm/archive’: Permission denied
find: ‘/etc/lvm/backup’: Permission denied
find: ‘/etc/lvm/cache’: Permission denied
find: ‘/etc/polkit-1/rules.d’: Permission denied
find: ‘/etc/polkit-1/localauthority’: Permission denied
find: ‘/etc/sssd’: Permission denied
find: ‘/etc/grub.d’: Permission denied
find: ‘/etc/audit’: Permission denied
find: ‘/etc/firewalld’: Permission denied
find: ‘/etc/sudoers.d’: Permission denied
[student@servera ~]$ find /etc -name passwd 2> /dev/null
/etc/pam.d/passwd
/etc/passwd

----p129
http://linux.vbird.org/linux_basic/0320bash.php

http://linux.vbird.org/linux_basic/0320bash.php#pipe
THE SPIRIT OF UNIX************

[student@servera ~]$ cat /etc/passwd |more
[student@servera ~]$ cat /etc/passwd |less


[root@servera srv]# cp $(which cat) .
[root@servera srv]# ll
total 60
drwxr-xr-x. 3 root root    26 Jun  9 19:55 aa
-rw-r--r--. 1 root root  3001 Jun  9 19:04 bashrc
-rw-r--r--. 1 root root   429 Jun  9 19:04 bindresvport.blacklist
-rwxr-xr-x. 1 root root 51856 Jun 11 18:52 cat
drwxr-xr-x. 2 root root    17 Jun  9 19:50 qqq
[root@servera srv]# xxd cat |less
oot@servera srv]# cat cat
------------------------------
[student@servera ~]$ cat /etc/passwd |sort 
adm:x:3:4:adm:/var/adm:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
chrony:x:992:989::/var/lib/chrony:/sbin/nologin
cockpit-ws:x:993:990:User for cockpit-ws:/:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
[root@workstation srv]# cat /etc/passwd |sort -r
[root@workstation srv]# cat /etc/passwd |sort -t : -k 3
[root@workstation srv]# cat /etc/passwd |sort -t : -k 3 -n 
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


[student@servera ~]$ cat /etc/passwd |sort |nl
     1	adm:x:3:4:adm:/var/adm:/sbin/nologin
     2	bin:x:1:1:bin:/bin:/sbin/nologin
     3	chrony:x:992:989::/var/lib/chrony:/sbin/nologin
     4	cockpit-ws:x:993:990:User for cockpit-ws:/:/sbin/nologin
     5	daemon:x:2:2:daemon:/sbin:/sbin/nologin
     6	dbus:x:81:81:System message bus:/:/sbin/nologin
     7	ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
     8	games:x:12:100:games:/usr/games:/sbin/nologin
     9	halt:x:7:0:halt:/sbin:/sbin/halt
    10	insights:x:994:991:Red Hat Insights:/var/lib/insights:/sbin/nologin
[root@workstation srv]# cat /etc/passwd |sort |nl |head
[root@workstation srv]# cat /etc/passwd |sort |nl |tail -20

[student@servera ~]$ cat /etc/passwd |sort |nl |tail 
    21	shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
    22	sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
    23	sssd:x:996:993:User for sssd:/:/sbin/nologin
    24	student:x:1000:1000:Student User:/home/student:/bin/bash
    25	sync:x:5:0:sync:/sbin:/bin/sync
    26	systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
    27	systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
    28	tcpdump:x:72:72::/:/sbin/nologin
    29	tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
    30	unbound:x:997:995:Unbound DNS resolver:/etc/unbound:/sbin/nologin


[student@servera ~]$ cat /etc/passwd |sort |nl |tail > file1
[student@servera ~]$ ll
total 4
-rw-rw-r--. 1 student student 637 Jun 11 19:05 file1


[student@servera ~]$ cat /etc/passwd |sort |tee aaa| nl |tee bbb |tail > file1

[student@servera ~]$ ll
total 12
-rw-rw-r--. 1 student student 1563 Jun 11 19:08 aaa
-rw-rw-r--. 1 student student 1773 Jun 11 19:08 bbb
-rw-rw-r--. 1 student student  637 Jun 11 19:08 file1

[student@servera ~]$ cat /etc/passwd |sort |nl|tee file3 |head -20|tail
    11	halt:x:7:0:halt:/sbin:/sbin/halt
    12	libstoragemgmt:x:990:986:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
    13	lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
    14	mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
    15	nobody:x:65534:65534:Kernel Overflow User:/:/sbin/nologin
    16	operator:x:11:0:operator:/root:/sbin/nologin
    17	polkitd:x:998:996:User for polkitd:/:/sbin/nologin
    18	rngd:x:991:988:Random Number Generator Daemon:/var/lib/rngd:/sbin/nologin
    19	root:x:0:0:root:/root:/bin/bash
    20	rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
[student@servera ~]$ cat /etc/passwd |sort |nl|tee file3 |head -30|tail
    21	rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
    22	setroubleshoot:x:995:992::/var/lib/setroubleshoot:/sbin/nologin
    23	shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
    24	sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
    25	sssd:x:996:993:User for sssd:/:/sbin/nologin
    26	student:x:1000:1000:Student User:/home/student:/bin/bash
    27	sync:x:5:0:sync:/sbin:/bin/sync
    28	systemd-coredump:x:999:997:systemd Core Dumper:/:/sbin/nologin
    29	systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
    30	tcpdump:x:72:72::/:/sbin/nologin

[student@servera ~]$ cat /etc/passwd |sort |nl|tee file3 |head -30|tail |tr [a-z] [A-Z]
    21	RPC:X:32:32:RPCBIND DAEMON:/VAR/LIB/RPCBIND:/SBIN/NOLOGIN
    22	SETROUBLESHOOT:X:995:992::/VAR/LIB/SETROUBLESHOOT:/SBIN/NOLOGIN
    23	SHUTDOWN:X:6:0:SHUTDOWN:/SBIN:/SBIN/SHUTDOWN
    24	SSHD:X:74:74:PRIVILEGE-SEPARATED SSH:/VAR/EMPTY/SSHD:/SBIN/NOLOGIN
    25	SSSD:X:996:993:USER FOR SSSD:/:/SBIN/NOLOGIN
    26	STUDENT:X:1000:1000:STUDENT USER:/HOME/STUDENT:/BIN/BASH
    27	SYNC:X:5:0:SYNC:/SBIN:/BIN/SYNC
    28	SYSTEMD-COREDUMP:X:999:997:SYSTEMD CORE DUMPER:/:/SBIN/NOLOGIN
    29	SYSTEMD-RESOLVE:X:193:193:SYSTEMD RESOLVER:/:/SBIN/NOLOGIN
    30	TCPDUMP:X:72:72::/:/SBIN/NOLOGIN
[student@servera ~]$ ll
total 8
-rw-rw-r--. 1 student student  583 Mar 15 20:20 file1
-rw-rw-r--. 1 student student 1953 Mar 15 20:32 file3
[student@servera ~]$ cat > file1 << eof
> 
>     直接用 student 身份執行『 cat 』這個指令,然後隨意輸入兩串文字,查閱指令執行的結果為何?
>     要結束指令的輸入請執行 [ctrl]+d 結束 (並不是 [ctrl]+c 喔!)
>     若輸入的字串可以直接轉存成為 mycat.txt 檔案,該如何下達指令?
>     將 /etc/hosts 透過 cat 讀入 (使用兩種方式,直接讀入與透過 < 方式讀入)
>     將 /etc/hosts 透過 cat 以 < 的方式讀入後,累加輸出到 mycat.txt 檔案內
> eof
[student@servera ~]$ cat file1

    直接用 student 身份執行『 cat 』這個指令,然後隨意輸入兩串文字,查閱指令執行的結果為何?
    要結束指令的輸入請執行 [ctrl]+d 結束 (並不是 [ctrl]+c 喔!)
    若輸入的字串可以直接轉存成為 mycat.txt 檔案,該如何下達指令?
    將 /etc/hosts 透過 cat 讀入 (使用兩種方式,直接讀入與透過 < 方式讀入)
    將 /etc/hosts 透過 cat 以 < 的方式讀入後,累加輸出到 mycat.txt 檔案內

------------------------off road
 cut - remove sections from each line of files
[student@servera ~]$ cat /etc/passwd|cut -d : -f 1,5,7
root:root:/bin/bash
bin:bin:/sbin/nologin
daemon:daemon:/sbin/nologin
adm:adm:/sbin/nologin
lp:lp:/sbin/nologin
sync:sync:/bin/sync

[student@servera ~]$ cat /etc/passwd|cut -d : -f 1,3,5
root:0:root
bin:1:bin
daemon:2:daemon
adm:3:adm
lp:4:lp

[student@servera ~]$ cut -d : -f 1,3 /etc/passwd
root:0
bin:1
daemon:2
adm:3
lp:4

[student@servera ~]$ ll
total 12
-rw-rw-r--. 1 student student 1563 Jun 11 19:08 aaa
-rw-rw-r--. 1 student student 1773 Jun 11 19:08 bbb
-rw-rw-r--. 1 student student  637 Jun 11 19:08 file1
[student@servera ~]$ ll |cut -c -20
total 12
-rw-rw-r--. 1 studen
-rw-rw-r--. 1 studen
-rw-rw-r--. 1 studen
[student@servera ~]$ ll |cut -c -30
total 12
-rw-rw-r--. 1 student student 
-rw-rw-r--. 1 student student 
-rw-rw-r--. 1 student student 
[student@servera ~]$ ll |cut -c -32
total 12
-rw-rw-r--. 1 student student 15
-rw-rw-r--. 1 student student 17
-rw-rw-r--. 1 student student  6
[student@servera ~]$ ll |cut -c 30-

 1563 Jun 11 19:08 aaa
 1773 Jun 11 19:08 bbb
  637 Jun 11 19:08 file1
[student@servera ~]$ ll |cut -c 31-

1563 Jun 11 19:08 aaa
1773 Jun 11 19:08 bbb
 637 Jun 11 19:08 file1
[student@servera ~]$ ll |cut -c 31-34

1563
1773
 637
[student@servera ~]$ ll |cut -c 31-34,43-

156319:08 aaa
177319:08 bbb
 63719:08 file1
[student@servera ~]$ ll |cut -c 31-34,46-

156308 aaa
177308 bbb
 63708 file1

-----
grep    --keyword

[student@servera ~]$ cat /etc/passwd |grep bash
root:x:0:0:root:/root:/bin/bash
student:x:1000:1000:Student User:/home/student:/bin/bash
[student@servera ~]$ cat /etc/passwd |grep -n bash
1:root:x:0:0:root:/root:/bin/bash
29:student:x:1000:1000:Student User:/home/student:/bin/bash
[student@servera ~]$ man passwd > pass1
[student@servera ~]$ grep -n password pass1
15:       and utilizes configured  password  modules  to  authenticate  and  then
16:       update a user's password.
23:        # a proposed password before updating it.
25:        passwd password requisite pam_cracklib.so retry=3
26:        passwd password required pam_unix.so use_authtok
35:              for expired authentication tokens (passwords); the  user  wishes
39:              This  option  is  used to lock the password of specified account
41:              rendering the encrypted password into an invalid string (by pre‐
49:              password from standard input, which can be a pipe.
53:              account password by removing the ! prefix. This option is avail‐
55:              passwordless  account  (it  will  not unlock an account that has
56:              only "!" as a password). The force option -f will override  this
60:              This is a quick way to delete a password for an account. It will
61:              set the named account passwordless. Available to root only.
63:              Note that if the password was locked,  this  implicitly  removes
64:              the password lock as well.
67:              This  is  a  quick  way to expire a password for an account. The
68:              user will be forced to change the password during the next login
75:              This  will  set  the  minimum password lifetime, in days, if the
76:              user's account supports password lifetimes.  Available  to  root
80:              This  will  set  the  maximum password lifetime, in days, if the
81:              user's account supports password lifetimes.  Available  to  root
86:              receiving warnings that her password will expire, if the  user's
87:              account supports password lifetimes.  Available to root only.
91:              expired password for this account will be taken to mean that the
93:              account supports password lifetimes.  Available to root only.
97:              password for a given account. The status information consists of
99:              field  indicates  if the user account has a locked password (L),
100:              has no password (NP), or has a usable password  (P).  The  third
101:              field  gives the date of the last password change. The next four
103:              inactivity  period for the password. These ages are expressed in
106:              Notes: The date of the last password change is stored as a  num‐
108:              passwd -S username may show the date of the last password change
109:              that is different from the real date of the last password change
115:       Protect your password.
116:              Don't write down your password - memorize  it.   In  particular,
118:              an unencrypted file!  Use unrelated passwords for  systems  con‐
120:              password, in particular to someone claiming to be from  computer
122:              password.  Don't enter your password to  a  computer  you  don't
124:              your password.  Use the password for a limited time  and  change
127:       Choose a hard-to-guess password.
129:              to prevent you from choosing a really bad password, but it isn't
130:              foolproof;  create  your  password  wisely.  Don't use something
140:              as well as digits or punctuation.  When choosing a new password,
141:              make sure it's unrelated to  any  previous  password.  Use  long
142:              passwords  (say  at  least  8 characters long).  You might use a
166:           bad arguments or passwordless account



[student@servera ~]$ grep -nw "passwords" pass1
35:              for expired authentication tokens (passwords); the  user  wishes
118:              an unencrypted file!  Use unrelated passwords for  systems  con‐
142:              passwords  (say  at  least  8 characters long).  You might use a

[student@servera ~]$ grep -nw "pass" pass1
90:              This  will  set  the  number  of  days which will pass before an

dmtsai@study ~]$ grep [-acinv] [--color=auto] '搜尋字串' filename
選項與參數:
-a :將 binary 檔案以 text 檔案的方式搜尋資料
-c :計算找到 '搜尋字串' 的次數
-i :忽略大小寫的不同,所以大小寫視為相同
-n :順便輸出行號
-v :反向選擇,亦即顯示出沒有 '搜尋字串' 內容的那一行!
-w : word
--color=auto :可以將找到的關鍵字部分加上顏色的顯示喔!
THE SPIRIT OF UNIX
[student@servera ~]$ wget http://classroom.example.com/pub/rh124/access_log
--2021-07-11 17:21:06--  http://classroom.example.com/pub/rh124/access_log
Resolving classroom.example.com (classroom.example.com)... 172.25.254.254
Connecting to classroom.example.com (classroom.example.com)|172.25.254.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 732060 (715K)
Saving to: ‘access_log’

access_log               100%[================================>] 714.90K  --.-KB/s    in 0.002s  

2021-07-11 17:21:06 (351 MB/s) - ‘access_log’ saved [732060/732060]
[student@servera ~]$ ll
total 728
-rw-rw-r--. 1 student student 732060 Jul 11 03:44 access_log

[student@servera ~]$ cut -d " " -f 1 access_log 

[student@servera ~]$ cut -d " " -f 1 access_log |sort
[student@servera ~]$ cut -d " " -f 1 access_log |sort |uniq|wc -l
623
[student@servera ~]$ cut -d " " -f 1 access_log |sort |uniq -c
     48 ::1
      1 100.33.75.206
     77 101.10.105.30
      6 101.10.60.249

[student@servera ~]$ cut -d " " -f 1 access_log |sort |uniq -c |sort -nr
    386 156.96.155.243
    225 106.104.76.122
    154 111.241.1.133
    107 218.35.128.119
     99 45.146.164.110
     90 114.25.26.249
     80 36.225.42.198
     77 36.227.252.205
     77 101.10.105.30
     69 115.43.157.168

[student@servera ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:00:fa:0a brd ff:ff:ff:ff:ff:ff
    inet 172.25.250.10/24 brd 172.25.250.255 scope global noprefixroute enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::e6c5:468e:edb6:9b52/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[student@servera ~]$ ip a | grep inet
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
    inet 172.25.250.10/24 brd 172.25.250.255 scope global noprefixroute enp1s0
    inet6 fe80::e6c5:468e:edb6:9b52/64 scope link noprefixroute 
[student@servera ~]$ ip a | grep -w inet
    inet 127.0.0.1/8 scope host lo
    inet 172.25.250.10/24 brd 172.25.250.255 scope global noprefixroute enp1s0
[student@servera ~]$ ip a | grep -w inet|cut -d "/" -f 1
    inet 127.0.0.1
    inet 172.25.250.10
[student@servera ~]$ ip a | grep -w inet|cut -d "/" -f 1|cut -c 8-
t 127.0.0.1
t 172.25.250.10
[student@servera ~]$ ip a | grep -w inet|cut -d "/" -f 1|cut -c 10-
127.0.0.1
172.25.250.10


[student@servera ~]$ ifconfig
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.250.10  netmask 255.255.255.0  broadcast 172.25.250.255
        inet6 fe80::e6c5:468e:edb6:9b52  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:00:fa:0a  txqueuelen 1000  (Ethernet)
        RX packets 6373  bytes 446725 (436.2 KiB)
        RX errors 0  dropped 3193  overruns 0  frame 0
        TX packets 2379  bytes 649985 (634.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 6  bytes 416 (416.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6  bytes 416 (416.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[student@servera ~]$ ifconfig |grep inet
        inet 172.25.250.10  netmask 255.255.255.0  broadcast 172.25.250.255
        inet6 fe80::e6c5:468e:edb6:9b52  prefixlen 64  scopeid 0x20<link>
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
[student@servera ~]$ ifconfig |grep -w inet
        inet 172.25.250.10  netmask 255.255.255.0  broadcast 172.25.250.255
        inet 127.0.0.1  netmask 255.0.0.0
[student@servera ~]$ ifconfig |grep -w inet|cut -d " " -f 8


[student@servera ~]$ ifconfig |grep -w inet|cut -d " " -f 10
172.25.250.10
127.0.0.1

[student@servera ~]$ grep bash /etc/passwd
root:x:0:0:root:/root:/bin/bash
student:x:1000:1000:Student User:/home/student:/bin/bash
[student@servera ~]$ grep -v bash /etc/passwd
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


-----------------------------------
http://linux.vbird.org/linux_basic/0310vi.php

[student@servera ~]$ ll -a
total 60
drwx------. 3 student student  185 Jun 11 20:31  .
drwxrwxr-x. 2 student student    6 Jun  2 19:54 '. '
drwxr-xr-x. 3 root    root      21 May 22  2019  ..
-rw-rw-r--. 1 student student 1563 Jun 11 19:08  aaa
-rw-------. 1 student student 1113 Jun  9 22:02  .bash_history
-rw-r--r--. 1 student student   18 Jan 14  2019  .bash_logout
-rw-r--r--. 1 student student  141 Jan 14  2019  .bash_profile
-rw-r--r--. 1 student student  312 Jan 14  2019  .bashrc
-rw-rw-r--. 1 student student 1773 Jun 11 19:08  bbb
-rw-rw-r--. 1 student student  637 Jun 11 19:08  file1
-rw-rw-r--. 1 student student 8570 Jun 11 20:31  hhhh
-rw-------. 1 student student   46 Jun 11 18:50  .lesshst
-rw-rw-r--. 1 student student 8570 Jun 11 20:31  pass1
-rw-------. 1 student student 1751 Jun 11 20:31  .viminfo
[student@servera ~]$ vim pass1 

******close terminal

-rw-rw-r--. 1 student student  8570 Jun 11 20:31  pass1
-rw-r--r--. 1 student student 20480 Jun 11 20:34  .pass1.swp

------------------------------------------
VARIABLE


VARIABLE SUBSTITUTION
[student@servera ~]$ var=pass1
[student@servera ~]$ echo var
var
[student@servera ~]$ echo $var
pass1
[student@servera ~]$ echo this is $var
this is pass1
[student@servera ~]$ echo "this is $var"
this is pass1
[student@servera ~]$ echo 'this is $var'
this is $var
[student@servera ~]$ echo "the $var is $var"
the pass1 is pass1
[student@servera ~]$ echo "the \$var is $var"
the $var is pass1
[student@servera ~]$ echo "the '$var' is $var"
the 'pass1' is pass1

***COMMAND SUBSTITUTION
[student@servera ~]$ echo `cat $var`
[student@servera ~]$ echo $(cat $var)

[student@servera ~]$ set |less
[student@servera ~]$ env |less
[student@servera ~]$ echo $PS1
[\u@\h \W]\$
[student@servera ~]$ PS1="C:\>"
C:\>
C:\>
C:\>
C:\>PS1="[\u@\h \W]\$"
[student@servera ~]$
[student@servera ~]$
[student@servera ~]$PS1="[\u@\h \W \t]\$"
[student@servera ~ 21:41:01]$
[student@servera ~ 21:41:01]$nano pass1
[student@servera ~ 21:46:47]$export EDITOR=nano
[student@servera ~ 21:47:33]$crontab -e
no crontab for student - using an empty one
crontab: no changes made to crontab
[student@servera ~ 21:47:54]$export EDITOR=vim
[student@servera ~ 21:48:00]$crontab -e
no crontab for student - using an empty one
crontab: no changes made to crontab


++++++++++++++
[root@servera ~]# yum install -y postfix mutt
[root@servera ~]# systemctl enable --now postfix
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@servera ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-03-17 19:15:21 CST; 3s ago
  Process: 25780 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 25777 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCC>
  Process: 25773 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
 Main PID: 25847 (master)
    Tasks: 3 (limit: 11345)
   Memory: 5.2M
   CGroup: /system.slice/postfix.service
           ├─25847 /usr/libexec/postfix/master -w
           ├─25848 pickup -l -t unix -u
           └─25849 qmgr -l -t unix -u
[root@servera ~]# mutt
[root@servera ~]# cd /var/spool/mail/
[root@servera mail]# ll
total 4
-rw-rw----. 1 devops  mail   0 May  7  2020 devops
-rw-rw----. 1 rpc     mail   0 Apr 23  2020 rpc
-rw-rw----. 1 student mail 756 Mar 17 19:17 student
[root@servera mail]# cat student 
From root@servera.lab.example.com  Wed Mar 17 19:17:53 2021
Return-Path: <root@servera.lab.example.com>
X-Original-To: student@servera.lab.example.com
Delivered-To: student@servera.lab.example.com
Received: by servera.lab.example.com (Postfix, from userid 0)
	id C0D881044B86; Wed, 17 Mar 2021 19:17:53 +0800 (CST)
Date: Wed, 17 Mar 2021 19:17:53 +0800
From: root <root@servera.lab.example.com>
To: Student User <student@servera.lab.example.com>
Subject: hello
Message-ID: <20210317111753.GA25856@servera.lab.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.10.1 (2018-07-13)
Status: RO
Content-Length: 67
Lines: 5

lkjgkljgkjgh
this is a book
good news for you
you win the prize!!


[root@servera mail]# vim student 

[student@servera ~ 三  3月 17-19:24:34]$export EDITOR=nano
[student@servera ~ 三  3月 17-19:25:35]$mutt