Linux Daily notes 2

Source: Internet
Author: User
Tags touch touch command ssh

DAY01 Linux system's first experience

Linux Introduction

Linux system installation (CentOS 7.4)

Operating interface for Linux systems

1) Graphical desktop

2) command-line operating environment

Configure the Network



DAY02 playing Linux command line

Managing Directories and Files

Use the Vim editor to create and modify files

Manage user and group accounts


First, the Command Line Foundation

1. 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: Includes the name with the. Hidden document at the beginning

-L: Display in long format

-H: Must be combined with-l to provide 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 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 Ask


2.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

1.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/*


2.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/*


3.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

1. Three 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

2. Toggle

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

3. Vim filename

Open this file if filename is present

Create a new file if filename does not exist


Experiment

1. Create a new file in the/root/directory hello.sh

1) input content "Hello world!!!"

2) Confirm file contents with cat command after saving

2. Modify the System files/etc/hosts

1) Add a line at the end "127.0.0.1 www.baidu.com"

2) using the ping command to test the connectivity to the 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 Create 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 Daily notes 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.