Command based day3 (20190929)

Keywords: Linux network Windows Mobile

1. What is an order?

1. Linux commands

Instructions or programs used to implement a certain type of function
When Linux executes most commands, it must find the appropriate program.
Green: Executable Procedures

2. General format of command line

Basic Usage

Command word [option]... [parameter 1] [parameter 2]...

[root@nsd ~]# cat --help #View Help Information for Commands
[root@nsd ~]# cat -n /etc/shells #set number
[root@nsd ~]# cat -n /etc/redhat-release
[root@nsd ~]# cat -n /etc/passwd
[root@nsd ~]# cat -n /etc/shadow
[root@nsd ~]# cat -n /etc/fstab

- l: Use a longer format to list information and display details

[root@nsd ~]# ls /etc/passwd
[root @ NSD ~] ා LS - L / etc / passwd ා display the detailed properties of the file
[root@nsd~] ls-l/root/ Displays detailed attributes of directory content
[root@nsd ~]# ls -l /etc/shadow

Unit of capacity: EB
1EB=1024PB
1PB=1024TB

Quick Editing Skills

* Tab key auto-completion
- Complete command words, options, parameters, file paths, software names, service names

[root@nsd ~]# if(Tab)(Tab) #Display all commands starting with if

[root@nsd ~]# ifco(Tab)

[root@nsd ~]# cat /et(Tab)/red(Tab)

[root@nsd ~]# ls /etc/sysconfig/network-scripts/ifcfg-eth0

]# ls /et(Tab)/sysco(Tab)/netw(Tab)-(Tab)/ifc(Tab)-e(Tab)

Shortcut keys

Ctrl + l: Clear the entire screen
Ctrl + c: Abolish the command line currently edited (end the running command)
- Esc +. or Alt +: Paste the parameters of a command

Ctrl + u: Clear to the beginning of the line
Ctrl + w: Delete a word back (defined by spaces)

[root@nsd ~]# ls /etc/shells
/etc/shells
[root@nsd ~]# cat ALT + .
[root@nsd ~]# cat -n ALT + .

[root@nsd ~]# ls -l ALT + .

Mount mount operation: make directory the access point of device

1. Obtain numerous software packages from CD-ROM
2. Let Linux System Display All Contents of CD-ROM

Windows:
CD-ROM File - - - - > CD-ROM Device - - - - > CD Driver (Icon) Access Point

Linux:
CD-ROM Files - - - - > CD-ROM Devices - - - - > Access Points (Directory)
/dev/hdc

3. Graphics Put CD-ROM Files into Virtual CD-ROM Devices
4. Create directories and mount them
[root@nsd ~]# mkdir/dvd # Create directories as Mount Points
[root@nsd ~]# ls /dvd
Use mount command
Format: mount device path mountpoint directory
Blue: Shortcut
[root@nsd/] ls/dev/cdrom Shortcut to view CD-ROM devices
[root@nsd /]# ls -l /dev/cdrom
[root@nsd /]# mount /dev/cdrom /dvd/
mount: /dev/sr0 write protection, mounted read-only

[root@nsd /]# ls /dvd/
[root@nsd /]# ls /dvd/Packages/
5. uninstall
[root@nsd ~]# umount /dvd/
[root@nsd ~]# ls /dvd/

[root@nsd ~]# mkdir /nsd
[root@nsd ~]# mount /dev/cdrom /nsd
[root@nsd ~]# ls /nsd
[root@nsd ~]# umount /nsd
[root@nsd ~]# ls /nsd
Matters needing attention:
1. When uninstalling, the current path cannot be a mount point
[root@nsd dvd]# umount /dvd/
umount: /dvd: busy target.

2.Linux allows one device with multiple different mount points
3. It is strongly recommended that mountpoint directories be created by themselves.

3. cd-Change Directory

Use: Switch working directories
Format: cd [destination folder location]

~: Home directory for users

/ root: Administrator user's home directory
/ Home: Store all common user home directories

[root@nsd/] cd~root To the root user's home directory
[root@nsd ~]# pwd

[root@nsd lisi] useradd tom create user tom
[root@nsd lisi] cd~tom to Tom user's home directory
[root@nsd tom]# pwd

[root@nsd tom] useradd harry Create user harry
[root@nsd tom] cd~harry to the home directory of Harry users
[root@nsd harry]# pwd

Represents the current directory

4. ls lists documents and attributes

• ls — List
Format: ls [Options]... [Directory or File Name]

Common command options
- l: Displays detailed attributes in long format
- d: Display the properties of the directory itself, not the content
- h: Provides readable units of capacity (K, M, etc.)

- A: Includes hidden documents beginning with. name
- R: Recursive display of content

[root@nsd /]# ls -l /home/

[root@nsd /]# ls -ld /home/ #Display the detailed attributes of the directory
[root@nsd /]# ls -ld /

[root@nsd /]# ls -lh /boot/ #Display detailed attributes, plus readable units of capacity
[root@nsd /]# ls -lh /root
[root@nsd /]# ls -lh /etc/passwd

[root@nsd /]# touch /opt/.xixi.txt
[root@nsd /]# ls /opt/
[root@nsd /]# ls -A /opt/

[root@nsd /]# ls -R /opt
[root@nsd /]# ls -R /root
[root@nsd /]# ls -R /boot

5. Use wildcards

Special characters for uncertain document names
'*: Any number of arbitrary characters
- single character

[root@nsd/] ls/boot/v Data starting with V
[root@nsd/] ls/dev/tty data starting with TTY
[root@nsd/] ls/etc/tab tab-terminated data
[root@nsd/] ls/etc/.conf data ending in.conf

[root@nsd/] ls/dev/tty? There is only one character after the beginning of TTY
[root@nsd/] ls/dev/tty?? TTY must have two characters after the beginning
[root@nsd/] ls/etc/?? tab tab must have two characters before the end

Special characters for uncertain document names
[a-z]: One of several characters or consecutive ranges, if not ignored
'{a,min,xy}: Multiple sets of different strings, fully matched

[root@nsd /]# ls /dev/tty[3-8]
[root@nsd /]# ls /dev/tty[1-9]

[root@nsd /]# ls /dev/tty{1,3,5,7,9,27}
[root@nsd /]# ls /dev/tty{1,3,5,7,9,40}
[root@nsd /]# ls /dev/tty{1,3,5,7,9,S0}

6. Definition of aliases: simplifying complex commands

Look at the aliases that have been set
- alias [alias name]

Define new aliases
- alias alias alias alias name ='command line actually executed'

Remove aliases that have been set
unalias [alias name]

[root@nsd /]# hostname
[root@nsd /]# hn
bash: hn: No command found...

[root@nsd /]# alias hn='hostname' #Define aliases
[root@nsd /]# hn #Alias execution
[root@nsd /]# alias #Aliases showing the current system in effect

[root@nsd /]# alias myls='ls -lhd'
[root@nsd /]# myls /opt/

[root@nsd /]# unalias myls #Delete aliases
[root@nsd /]# alias

################################################

7. mkdir Creating Directories

• mkdir — Make Directory
– format:mkdir [-p] [/Route/]Directory name...

]# mkdir -p /vod/movie/cartoon #-p Represents the creation of a parent directory together
]# ls -R /vod

]# mkdir -p /opt/aa/bb/cc/dd
]# ls -R /opt/aa

]# mkdir -p /opt/nsd/1909
]# ls -R /nsd/

8. rm deletion

• rm — Remove
Format: rm [Options]... Files or directories...

Common command options

 – -r,-f:Recursive deletion(Containing directory),Mandatory deletion

~~[root@nsd /]# touch  /opt/1.txt
     [root@nsd /]# mkdir  /opt/nsd01
      [root@nsd /]# rm  -rf  /opt/1.txt
      [root@nsd /]# ls  /opt

[root@nsd /]# rm  -rf  /opt/nsd01
[root@nsd /]# ls  /opt~~

9. Finding Text Content

Extracting text lines based on string patterns
grep [option]'matching mode'text file...

Common command options
 - v, take inverse matching
 - i, ignore case

[root@nsd /]# grep root /etc/passwd
[root@nsd /]# grep -v root /etc/passwd

[root@nsd /]# grep ROOT /etc/passwd
[root@nsd /]# grep -i ROOT /etc/passwd

Common matching patterns
'^ word begins with the string word
Word $ends with a string word

[root@nsd /]# grep ^root /etc/passwd
[root@nsd /]# grep root$ /etc/passwd
[root@nsd /]# grep bash$ /etc/passwd

9. Mobile/renamed mv

• mv — Move
Format: mv [option]... original file... target path

[root@nsd /]# rm -rf /opt/*
[root@nsd /]# touch /opt/1.txt
[root@nsd /]# mkdir /opt/nsd01
[root@nsd /]# ls /opt/

[root@nsd /]# mv /opt/1.txt /opt/nsd01/
[root@nsd /]# ls /opt/

[root@nsd /]# ls /opt/nsd01

Rename: Path-invariant Movements

[root@nsd /]# mv /opt/nsd01 /opt/student
[root@nsd /]# ls /opt/
[root@nsd /]# mv /opt/student/ /opt/haha
[root@nsd /]# ls /opt/
[root@nsd /]# mv /opt/haha/ /opt/xixi
[root@nsd /]# ls /opt/

10. cp replication

• cp — Copy
 Format: cp [option]... original file... target path

Common command options
 - r: Recursively, you must have this option when copying directories

[root@nsd /]# cp /etc/passwd /opt/
[root@nsd /]# ls /opt/

[root@nsd /]# cp /etc/redhat-release /opt/
[root@nsd /]# ls /opt/

[root@nsd /]# cp /etc/fstab /opt/
[root@nsd /]# ls /opt/

[root@nsd /]# cp -r /home/ /opt/
[root@nsd /]# ls /opt/

[root@nsd /]# cp -r /boot/ /opt/
[root@nsd /]# ls /opt/

Copy with the same name to achieve mandatory coverage

[root@nsd /]# cp -r /boot/ /opt/
[root@nsd/] cp-r/boot/opt/ In this operation, the alias is temporarily cancelled

Multiple parameters can be supported in replication, and the last parameter is always considered the target, and all other parameters are considered the source.
]# rm -rf /opt/*
]# cp -r /boot/ /home/ /etc/passwd /etc/fstab /opt/
]# ls /opt/

Duplication and Point Connection: Represents the Current Path

[root@nsd /]# cd /opt/
[root@nsd opt]# pwd
[root@nsd opt]# cp /etc/shells .
[root@nsd opt]# ls

~~[root@nsd opt]# cd /etc/sysconfig/network-scripts/
[root@nsd network-scripts]# cp /etc/shadow .
[root@nsd network-scripts]# ls ~~

Copy to the target path and rename it

[root@nsd /]# cp /etc/group /opt/g.txt
[root@nsd /]# ls /opt/

[root@nsd /]# cp /etc/passwd /opt/p.txt
[root@nsd /]# ls /opt/

[root@nsd /]# cp /etc/fstab /opt/f.txt
[root@nsd /]# ls /opt/

[root@nsd /]# cp -r /boot/ /opt/nsd19
[root@nsd /]# ls /opt/

11. Redirection: write the output of the previous command to a text file

Coverage redirection >: pursuit and aggravation orientation

[root@nsd /]# ls --help > /opt/ls.txt

[root@nsd /]# hostname > /opt/ls.txt
[root@nsd /]# cat /opt/ls.txt

[root@nsd /]# hostname >> /opt/ls.txt
[root@nsd /]# cat /opt/ls.txt

[root@nsd /]# cat /etc/redhat-release
[root@nsd /]# cat /etc/redhat-release >> /opt/ls.txt
[root@nsd /]# cat /opt/ls.txt

[root@nsd /]# echo hello
hello
[root@nsd /]# echo 123456
123456

[root@nsd /]# cat /opt/ls.txt
[root@nsd /]# echo 123456 >> /opt/ls.txt
[root@nsd /]# cat /opt/ls.txt

[root@nsd /]# echo hello >> /opt/ls.txt
[root@nsd /]# cat /opt/ls.txt

[root@nsd /]# echo linux >> /opt/ls.txt
[root@nsd /]# cat /opt/ls.txt

Date: View date and time

[root@nsd /]# date
2019 Sunday, 29 September, 17:13:44 CST

[root@nsd /]# date -s' year month day hour: minute: second '

[root@nsd /]# date -s '2008-10-1 12:00:01'
 [root@nsd /]# date

[root@nsd /]# date -s '2019-9-29 17:17:00'  #Modify to the correct time
[root@nsd /]# date

bc: Interactive Calculator
[root@nsd /]# bc
  //Add+subtract-multiply*divide/take remainder operation%

Ctrl +c Exit

12. Pipeline operation: the output result of the previous command is passed to the later command as the parameter of the latter command.

Display 8 to 12 lines of the / etc/passwd file?

[root@nsd /]# head -12 /etc/passwd | tail -5

[root@nsd /]# head -12 /etc/passwd | tail -5 | cat -n
[root@nsd /]# cat -n /etc/passwd | head -12 | tail -5

[root@nsd /]# ifconfig | head -2
[root@nsd /]# ifconfig | less

[root@nsd /]# echo 1+1 | bc
[root@nsd /]# echo 3*6 | bc

Posted by robman2100 on Fri, 11 Oct 2019 07:41:42 -0700