First, the Command Line Foundation
- Command format
Basic usage
command word [options] ... [Parameter 1] [Parameter 2] ...
[] indicates that the contents are optional
Command word must exist when executing a command, options and parameters are optional
There must be a space between the command word option arguments
Resolution of each component
Options: Used to control the execution mode
Single character general use-
The word is generally used--
eg
Ls-l
LS--help
Parameters: Command action object, such as the document's storage path, user name, etc.
2. Command-line editing tips
TAB key
Function: command or path completion, if the input content uniquely identifies a command or path, tab will be automatically filled in one time. If you do not display all the commands or paths that begin with the input, only a tab2 time
Wrong shot.
3. Shortcut keys
Ctrl + L: Empty the entire screen
Ctrl + C: Discard the currently edited command line
esc+.: Paste the arguments of the previous command
Second, browse directories and files
1.ls command
Format: ls [options] ... [Directory or file path]
Common Command Options
A: Include the name with. Hidden document at the beginning
L: Display in long format
H: Must be used in conjunction with-L, providing easy-to-read capacity units (K, M, etc.)
D: Display the properties of a directory
eg
Ls/root
Ls-l/root
Ls-a/root
Ls-lh/root
Add:
Absolute path: The path that begins with/
Relative path: A path that does not start with/
Wildcard characters * and?
Match any 0-more characters
? Match any single character
eg
ls/dev/tty*
Ls/dev/tty?
Ls/dev/tty??
2.cat command
View the contents of a file
cat/etc/resolv.conf//View DNS Address
Cat/etc/redhat-release//View a small version of the system
Iii. Creating directories and files
1.mkdir command
Create a Directory
-p recursively Create a directory
eg
[Email protected]/]# cd/opt/
[[email protected] opt]# ls
[Email protected] opt]# mkdir ntd1711
[[email protected] opt]# ls
[Email protected] opt]# mkdir ntd1712
[[email protected] opt]# ls
[Email protected] opt]# mkdir Ntd1801/group1/huangsir
[Email protected] opt]# mkdir-p Ntd1801/group1/huangsir
[[email protected] opt]# ls
[[email protected] opt]# ls ntd1801/
[[email protected] opt]# ls ntd1801/group1/
[Email protected] opt]# ls-r ntd1801/
Ask questions
A. How many directories are created by the following command?
B. Where are these directories created separately?
Mkdir-p Ntd1802/group2/xushuai excuse me?
Touch command
Create a file
Touch file name ...
eg
Cd/vod/movie/cartoon
Mkdir-p/vod/movie/cartoon
cd/vod/movie/cartoon/
Touch Mulan.mp4 Nezhanaohai.mp4
LS-LH *.mp4
Iv. copy, move, delete
CP command
Format: CP [Options] ... Original file ... Target path
Common Command Options
R: Recursive, must have this option when copying directories
P: Keep the original file permissions, modification time and other properties unchanged
eg
[Email protected] ~]# Ls-ld/backup
[Email protected] ~]# Mkdir/backup
[Email protected] ~]# Ls-ld/backup
[Email protected] ~]# cp-r/boot/grub2/etc/host.conf/backup/
[Email protected] ~]# ls-ld/backup/
[Email protected] ~]# cp/boot//backup/
[Email protected] ~]# ls-ld/backup/
[Email protected] ~]# cp-r/boot//backup/
[Email protected] ~]# ls-ld/backup/*
RM Delete
Format: RM [Options] ... File or directory ...
Common Command Options
R,-f: Recursive delete (with directory), forced delete
eg
[Email protected] ~]# ls-ld/backup/
[Email protected] ~]# rm/backup/host.conf
[Email protected] ~]# rm-f/backup/grub2/
[Email protected] ~]# rm-rf/backup/grub2/
[Email protected] ~]# rm-rf/backup/boot/
[Email protected] ~]# ls-ld/backup/
MV Move or rename
Format: MV [options] ... Original file ... Target path
eg
[Email protected] ~]# ls-l/vod/movie/cartoon/mulan.mp4
[Email protected] ~]# mv/vod/movie/cartoon/mulan.mp4/backup/
[Email protected] ~]# ls-l/backup/
[Email protected] ~]# Mv/backup/mulan.mp4/backup/huamulan.mp4
[Email protected] ~]# ls-l/backup/
Four, vim text editor
Three different modes
Command mode: The default mode after the file is opened, can only view the contents of the file cannot be modified
Input mode: can be edited and modified
Last-line mode: Save exit
Switch
Command mode--input mode press the I key
Command mode--and last line mode press: Key
Input mode and last-line mode--command mode press the ESC key
Note: The input mode and the last line mode cannot be switched directly, and need to go through the command mode
Vim filename
Open this file if filename is present
Create a new file if filename does not exist
Experiment
Create a new file under the/root/directory hello.sh
Input content "Hello world!!!"
Confirm file contents with cat command after saving
modifying system files/etc/hosts
Add a line to the end "127.0.0.1 www.baidu.com"
Using the ping command to test connectivity to www.baidu.com, observe the results
ls/root/hello.sh
vim/root/hello.sh
Press the I key
Enter Hello world!!!
Press the ESC key
By:
wq!
ls/root/hello.sh
cat/root/hello.sh
4. Command mode operation
In-line adjustment of cursor
^ = Home key Move cursor to beginning of line
$ = END key moves the cursor to the end of the line
Adjustment of the cursor between rows
GG jumps to the first line of the file
G jump to the last line of the file
Copy, paste, delete
YY copy when moving forward
#yy copy current down # line
P Paste under current cursor
Delete Deletes the single character where the current cursor is located
DD Delete (cut) when moving forward
#dd Delete (cut) The current cursor down to the # line
Find
/world Current cursor down search for world
N Next
eg
[Email protected] ~]# rm-rf/tmp/*
[Email protected] ~]# mkdir/tmp/test01
[Email protected] ~]# cp/etc/mail.rc/tmp/test01/
[Email protected] ~]# ls/tmp/test01/mail.rc
[Email protected] ~]# vim/tmp/test01/mail.rc
5. Last-line mode operation
: W Save
: Q exit
: Wq Save and exit
: wq! Force Save and exit
: W/root/xxx.file Save current file as/root/xxx.file
: R/root/xxx.file loading/root/xxx.file file into the current file
6. Find Replacements
: S/old/new replaces the current line the first old is new
: S/old/new/g replaces the current line all old is new
: N,m s/old/new/g replaces line n-m all old is new
:% s/old/new/g replaces all old in file with new
U undo
eg
[Email protected] test01]# LS/ETC/PASSWD/TMP/TEST01/PASSWD
[Email protected] test01]# cp/etc/passwd/tmp/test01/
[Email protected] test01]# LS/ETC/PASSWD/TMP/TEST01/PASSWD
[Email protected] test01]# VIM/TMP/TEST01/PASSWD
Enter in the last line mode
/root
: S/root/feige
U
: s/root/feige/g
U
: 1,10s/root/feige/g
U
:%s/root/feige/g
U
: q!
Display and close line numbers
: Set Nu|nonu
V. Managing Users and Groups
1. User Management
A. User classification
Super User: Admin account root UID is 0
System User: System service generated UID range 1 ~ 999
Normal User: Account created by Administrator himself, UID range 1000 ~ 60000
B. Creating a user
ID account name Verify that the system exists for this account
Useradd Account name Creation account
C. Setting a password
#passwd Account Setup Password
D. Modify account information
#usermod
-L new Account old account change login name
E. Deleting an account
Delete an account #userdel account
-R along with home directory delete
Summarize:
When a normal user is created by default, a folder with the same name is created under/home.
This folder is where the user's home directory is created
eg
[[email protected] ~]# ID nvshen
[Email protected] ~]# Useradd Nvshen
[[email protected] ~]# ID nvshen
[Email protected] ~]# passwd nvshen
[[email protected] ~]# ID Miaodt
[[email protected] ~]# ID nvshen
[Email protected] ~]# usermod-l Miaodt nvshen
[[email protected] ~]# ID Miaodt
[[email protected] ~]# ID nvshen
[Email protected] ~]# usermod-l nvshen Miaodt
[[email protected] ~]# ID Miaodt
[[email protected] ~]# ID nvshen
[Email protected] ~]# Userdel Nvshen
Experiment:
1. Create a new user account named Nvshen and set the password to 1234567
Testing with user Nvshen Telnet to the native system
2. Migrate this user's home directory to the/opt/nvshen directory
Re-login the native system with user Nvshen to confirm the current PWD working directory location
3. Completely delete the user account named Nvshen
Check its ID information to see the prompt results. Check if the home directory is available
[[email protected] ~]# ID nvshen
[Email protected] ~]# Useradd Nvshen
[[email protected] ~]# ID nvshen
[Email protected] ~]# passwd nvshen
[[email protected] ~]# ssh [email protected]
[Email protected] ~]$ pwd
[Email protected] ~]$ WhoAmI
[[Email protected] ~]$ exit
[Email protected] ~]# Ls-ld/opt/nvshen
[Email protected] ~]# ls-ld/home/nvshen/
[Email protected] ~]# usermod-d/opt/nvshen nvshen
[Email protected] ~]# Ls-ld/opt/nvshen
[Email protected] ~]# mv/home/nvshen//opt/
[Email protected] ~]# Ls-ld/opt/nvshen
[[email protected] ~]# ssh [email protected]
[Email protected] ~]$ pwd
[[Email protected] ~]$ exit
[[email protected] ~]# ID nvshen
[Email protected] ~]# ls-ld/opt/nvshen/
[Email protected] ~]# Userdel Nvshen
[[email protected] ~]# ID nvshen
[Email protected] ~]# ls-ld/opt/nvshen/
2. Group Management
A. Creating a group
#groupadd Group Name
-G GID specifies GID when creating group
B. Adding a Delete member (user) to a group
#gpasswd
-A: Add specified user as group member
-D: Delete the specified member user from within the group
C. Deleting a group
#groupdel
eg
[[email protected] ~]# ID nvshen
[Email protected] ~]# Useradd Nvshen
[[email protected] ~]# ID nvshen
[Email protected] ~]# groupadd-g STUGRP
[Email protected] ~]# gpasswd-a nvshen stugrp
[[email protected] ~]# ID nvshen
[Email protected] ~]# Groupdel STUGRP
[[email protected] ~]# ID nvshen
Linux Getting Started note 2