Linux Basic Course Notes

Source: Internet
Author: User
Tags chmod parent directory time and date tmp file file permissions

Linux system Installation
1.1 Disk Partitioning
/root Partition

/boot system boot partition
PS: It is recommended to separate the/boot partition to facilitate the system fault

The swap partition simulates the space of the hard disk into memory space, which is provided to the computer for use

     ps:分区大小建议内存为4G,swap分区为2G                     内存为4G-16G,swap分区为4G                     内存为16G-64G,swap分区为16G

/home Partition

/var partitions are used to store logs (if required)

1.2 Kdump (Kernel dump)
The main function is to prevent the kernel crash, the memory will default less 128MB
General OPS personnel can turn off this feature

    1. Linux Usage Basics
      2.1 Linux System Login
      2.1.1 Graphical interface Login
      If the login mode for the graphical interface Ctrl+alt+f2-f6 switch to the command line, CTRL+ALT+F1 cut back to the graphical interface

      Init 3 Plain character interface, applications that do not run a graphical interface
      2.1.2-Character Interface login
      StartX, start to enable the graphical interface program

      If the login is a character-interface Ctrl+alt+f7 graphical interface, the CTRL+ALT+F1-F6 character interface

2.2 Home Directory
Each user generates a folder of the user's user name in the home directory, which is used to store the user's file
Useradd user1 will be in the build/home/user1

2.3 Add new user, add password, change password, delete user
Useradd Admin Add User

passwd admin XXXX User Add password

passwd XXXX To modify the user password in the state of this user's login

Userdel-r Admin Delete User


2.4 Changing user identities
The 2.4.1 command prompt consists of
[\[email protected]\h \w]# u= User variables, h= host name, w= directory
[Email protected] home]#

2.4.2 Switching user identities
Ps:su user1 and Su-user1 are different

2.4.3 Viewing users ' information

ps:用户的身份之间不要切来切去,如果要切的话建议su - admin  exitsu - root     exitsu - user1   exit

2.5 Use the TAB key to command
Use the TAB key as much as possible to ensure efficiency and accuracy
2.6 Viewing history, historical commands
There is a. Bash_history used to record history, so the user can still see the history after the reboot

 使用历史记录将参数补齐 Alt+.

Vim Text Editor
The difference between 3.1 VI and VIM
Vim is an upgraded version of VI with all the functions of VI
The VI font is black
Vim files are colored and support syntax detection. If there is a problem with the grammar, the color will turn red
3.2 Vim's three modes, command mode, insert mode and last line mode

 3.2.1命令模式 d,删除一个字符,按u还原一个字符 G    文件中跳到最后一行 dd   删除整行,使用u还原整行 ps:dd有两个作用如果你粘贴就是剪切,如果你不粘贴就是删除 p                             粘贴到当前行的下面 P                             粘贴到当前行的上面 y y进行复制,粘贴使用p/P 3.2.2 插入模式  i (insert模式)              要修改内容

3.2.3 Last-line mode
Set nu view number of rows in text


: wq! /q! Save exit/No warranty exit

    1. Man Help
      4.1 Composition of the command
      ls [OPTION] ... [FILE] ...
      Ls-l/etc/ls to command-l for option/etc/parameter
      The option is band-parameter is not with-

      LS--help represents the back of a whole cannot be split

      Ls-la ls-l-A multiple options can be written together or separately

      Ls-l; Cp/etc/passwd/tmp using two commands in a one-hop command

      (Cal 2007; CAL) >cal.txt output redirect

4.2 Syntax Rules
4.2.1 Date: Used to display time and date
Man Date
4.2.2 Date Syntax structure
Date [OPTION] ... [+format]

OPTION is followed by ... Delegates can follow multiple options
There is no ... after format, only one format is added

     date +%Y-%m-%d%H:%M:%S     date +‘%Y-%m-%d %H:%M%S‘      date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]  修改date日期   4.2.3 cal 语法结构        cal [-smjy13] [[[day] month] year]

4.3 Man document
Q exit
/q for finding-Q
n Look down.
N go up.

5 File System Management
5.1 Structure of the file system
Each partition in Windows is a separate number that does not affect each other.
Linux everything is starting from the root

File system Structure

/bin,/user/bin,/user/local/bin user can execute command
/sbin,/usr/sbin,/usr/local/sbin Administrator-Executable commands
/media,/mnt mount point
/etc Configuration Directory
/tmp temp file
PS: Can delete all files under TMP but it is best not to delete/tmp file
/boot directory and boot program
/Var,/srv Store service data
/proc,/sys system during startup and memory-related
/dev All the devices are in/dev
PS:S:SCSI type of device D:disk A: Number of hard drive 1/2: partition

Inux there is no registry below, so Linux does not have the concept of extension
All filenames are strictly case sensitive
All commands are strictly case sensitive

5.2 File System Management
5.2.1 Relative Path Absolute path
Absolute path is everything starting from the root
How to cp/etc/passwd/data/an absolute path

The relative path is the starting point from the current position.
Cp.. /etc/passwd. How to approach relative paths

. Current directory: Parent Directory

CD (changing directories) entry Directory
Cd.. Go back to the previous level directory CD-Go back to the previous directory
Cd/etc/yum/etc/yum directory from the root directory
CD etc from the current directory into the ETC directory

LS View the files in the current directory
CD Directory Name

5.2.2 File Management Commands
PWD LS touch CP MV RM Stat

PWD View the current working directory

LS lists the contents of the directory

ls  -a                      显示目录下的所有文件,所有隐藏文件都会被显示出来                                PS: 删除文件时,隐藏文件不会被删除

Ls-l listing the details of a file
PS: Blue for folders, black for ordinary files, green for executables, light blue for shortcuts, red yellow for special permissions

Touch Create File
Touch Text.txt

CP Source Destination Copy

cp/root/cal.txt/tmp/Copying a single file
cp/root/cal.txt/root/inital.setup-ks.cfg/tmp/Copying multiple files

Cp-r/etc//tmp/Copy the folder, use a recursive copy, all the sub-files in the directory copy the past

Cp-p cal.txt/tmp/copy files without modifying the original file user rights

CP-RP cal.txt/tmp Copy folder can also retain permissions

MV Cut files can also be renamed

RM Delete File
RM-RF etc/recursively delete all files under the current directory, etc

Stat View File Timestamp

5.2.3 Directory Management Commands
mkdir rmdir

mkdir Creating a Folder
mkdir Redhat

RmDir Deleting files

5.2.4 See text command
Cat, TAC, more, less, head, tail

The cat is connected and displayed, displaying the contents of the text file completely
Cat-n each row when displayed

TAC in turn displays the text file

More, less split screen display command

more                            支持向后翻,不支持向前翻less                                支持向前翻,按q才会退出

Head view first n rows of the file (n default = 10)
Head-n 1/etc/initab View Previous line
Head-n 2/etc/initab View first two lines

Tail viewing the following n rows of a file
Tail-n 5/etc/initab

    1. User group permissions
      6.1 Users
      User: A unique user ID (UID) is created for each person created
      UID 0 is Root
      UID RH7 allocation starting from 1000 RH6 starting from 500
      PID Process Number

      #useradd-U 1003 zhangsan The UID of the specified user
      The system only recognizes numbers, and people are identified by file names or system names.
      The system recognizes that a user is identified by the UID and the person is identified by the user name

6.1.1 user information stored in/etc/passwd

cat /etc/passwd |grep adminadmin:x:501:501::/home/admin:/bin/bash      admin                      代表用户名    x                          代表是否需要身份验证    501:501                    UID GID     /home/admin                用户家目录    /bin/bash                   shell,解释语言

6.2 User Groups
User groups: Add users to groups, add corresponding permissions (GID) to groups

6.2.1 User group information storage/etc/group
Cat/etc/group |grep Users
Admin Representative Group name
X represents whether authentication is required
501 on behalf of GID
What members are in the user group

6.3 Creating users and user groups
6.3.1 Creating a user
Useradd User1 creation Process
Create User1 user
2. Create a User1/home/user1
3. Create a User1 group
4. Add the User1 user to the User1 group

6.3.2 Modifying user groups
Usermod-ag Admin User1 adds user1 to the Admin group and retains the original group

Id user View the added group
6.3.3 Creating a user group
Groupadd User2
6.3.4 Deleting a user group
Groupdel User2
6.3.5 Modifying user groups
Groupmod-g modifying GID
-N Modify User group name
6.4 How to view and set file permissions
Each file should have a UID and GID
Each process should also have a UID and gids

6.4.1 Linux divides the users who access files into three categories
File Master (User) U
Filegroup (Group) G
Other users (Other) O

6.4.2 common file and directory file permissions
-rw-r--r--. 1 root root 1463 Jul 17:10/etc/passwd
Dr-xr-xr-x. 5 root root 1024x768 June 14:18 Boot

    • Represents a common file
      R: Representative has read the contents of this file
      W: Representative has modified the contents of the file content
      X: The file can be executed

D represents the catalog file
R: Represents the LS to list content in the directory
W: You can create and delete files in this folder
X: Execute permissions, CD into the directory
PS: For a directory file, R-x is together, there is no meaning alone

6.4.3 Change file Owner
Chown:change owner of modified file

chown [OPTION] ... [OWNER] [: [GROUP]] FILE ...
Chown User1 Group

Chown user1/data/only modifies the file itself
Chown-r user1/data/Recursive modification

Chown Zhangsan:user2/data the owner and the own group.

6.4.4 change of file genus Group
Chgrp:change Group modify file owned groups

Chgrp admin/data/

6.4.5 chmod Modify read and write execution permissions for a file
Chmod:change Mode Modify file permissions Modify a certain bit or some bit permissions for a class of users
chmod user category +|-MODE file ...

chmod u-w/data/
chmod ugo-w/data/
chmod ugo-rx/data/
chmod ugo+r/data/
Chmod-r Ugo-x/data/ Modify permissions for a class of user or some class of user
chmod user category =mode file,...

chmod G=R,O=R/TMP/ABC
Chmode GO=WRX/TMP/ABC Modifying permissions for three categories of users
Use numbers to represent different permissions

chmod MODE File,...
chmod 755/data/
7: Permission of the owner
5: Permission to have a group
5: Other people's rights

Alias aliases
Alias ll= ' Ls-l--color=auto '

    1. Standard I/O and piping
      7.1 of three standard I/O
      Standard input: Default keyboard input

      Standard output: Default display output

      Standard error Output: Default display output
      7.2 Output redirection
      When we want to pour the standard output or standard error to another file, we need the output redirect
      Command operator: command-filename of the filename operator

: Correct output redirect find/etc/-name passwd >find.out

2>: Incorrect output redirection find/etc/-name passwd 2>find.err

&>: All output redirects find/etc/-name passwd &>find.all

find/etc/-name passwd >find.out 2>find.err

echo Hello
echo Hello > Find.out
When we do output redirection, the original file is overwritten by default
7.3 Additional redirects

>: Append if the target file already has content we use append, add new content to the target file finally, the original content is unchanged

2>>: Error Append

&>>: Append All

7.4 Pipe Break
We want to export the result of one command to another command, we use the pipe

Command1 |command2: Command1 execution results as input to Command2

7.5 grep Filter

grep ' user1 '/etc/passwd
' Keywords '
cat/etc/passwed |grep User1

cat/etc/passwed |grep-w user1 exact match keyword

cat/etc/passwed |grep-i User1 ignoring case

cat/etc/passwed |grep-v User1 Reverse Selection

RPM-QA |grep FTP

Package installation, uninstallation, upgrade, query

9.1 RPM Package format and
mount/dev/cdrom/media/mount the optical drive to the media directory

RPM Package Format: zsh-4.3.11-4.el6.x86_64.rpm

RPM File/package
Version versions
Release releases
Arch OS kernel version, 32/64
RPM extension
Uname-r viewing the operating system kernel version

1. Installation of the package Install/upgrade
Rpm-i | -U rpmfile
Rpm-i vsftpd-3.0.2-9.el7.x86_64.rpm I stands for installation
RPM-IVH IVH The progress of this installation

    1. Package Uninstall
      RPM-E Pakage E for uninstallation
      When you delete the RPM package, the system automatically saves you a copy of the configuration file.
      If you reinstall the file, redirect the backup file to the file in the configuration

    2. Reinstall RPM Package
      RPM-IVH Rpmfile--force

    3. Downgrade the package--oldpackage

5. Ignore conflicts between packages--replacefile

6. Ignore the dependency relationship of the package--nodeps

7. Query of the package
Rpm-q vsftp/httpd
-Q must know the complete name of the package, it can not blur

RPM-QA all packages in the query system
Rpm-qa |vsft

Querying package file List
RPM-QL vsftpd

View package configuration Files
RPM-QC vsftp


Linux Basic Course Notes

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.