Cainiao learn Linux-notes on Common commands

Source: Internet
Author: User

FTP: // 192.168.0.1/Biji
Basic commands on the first day
Ls-l install. Log
-: RW-r --: 1: Root: 39410: 11-03 13: 44: Install. Log
File Type: permission: Hard connections: Owner group: file size: last modification date and time: File Name

-Common files
D directory file
L link file
Block B Device Files
C character file
P MPs queue File
S character set file

Ls-l long format-A: show all files except. And.-H in maximum unit
-D: Display directory information-T: sort by time-R: reverse-R: recursive display

Help commands
1. ls -- Help
2. Type LS
Alias LA = 'LS-la'
Unalias la
3. info ls
4. Man

MAN 1 USER command
MAN 2 system call
MAN 3 Library call
MAN 4 special civilization
MAN 5 configuration file
MAN 6 Games
MAN 7 Miscellaneous
MAN 8 system commands
MAN 9 kernel reference

Man-F passwd query keywords are described in those chapters
Makewhatis maintenance man
Man-K passwd fuzzy query

/Directory Function
/Bin/usr/local/bin/commands that can be executed by common users
/Sbin // usr/local/sbin/commands that can be executed by the Administrator
/Root administrator's home directory
/Home common user home directory
/Etc configuration file directory

/Var server data directory
/Usr application directory
/Tmp temporary file directory
/Dev block Device directory
/Boot program directory (kernel boot file Boot Program)
/Lib/usr/local/lib: stores library files and system modules
/Sys pseudo File System
/Proc pseudo File System (Kernel Parameter process information in memory)
/Other MNT mount points
/OPT third-party software catalog
/NET autofs
/MISC autofs
/Main directory of the tftpboot TFTP Server
/SELinux security component usage
/Media Media Directory
/Srv server data directory

CD /..../...~ Or press enter to return the last working directory.

Command for viewing File Content
1. More install. Log
2. Less install. Log
3. Head-N 50 install. Log
Head-50 install. Log
4. Tail-N 50 install. Log
Tail-50 install. Log
Tail-F/var/log/messages Dynamic Monitoring Log File
Service GPM restart mouse
5. Cat install. Log
Cat-N install. log all row numbers
Cat-B install. log only displays valid row numbers
| MPs queue Operator
Cat-N install. log | less

Create a file
Touch aa.txt
Touch cc.txt tt.txt
Touch abc00001..102.16.txt
Touch a424b,c000000001..52.16.txt

Create directory
Mkdir ABCD
Mkdir ABCDE abcdf
Mkdir ABC {1 .. 10}
Mkdir A {B, c} {1 .. 5}
Mkdir-p xx/PP
Mkdir-p-v xx/PP-P recursive-V display creation process

Copy and cut
Copy
CP/root/install. log/tmp/
CP/root/install. log/tmp/test
CP-r/root/desktop // tmp/
Cut
MV
MV/root/tt.txt/tmp/
MV/root/tt.txt/tmp/aa.txt
MV/root/ABCD // TMP
MV ac3.txt uuu.txt

Delete
Rmdir Delete empty directory
Rm aa.txt
Rm-F uuu.txt
Rm-rf xx/
Rm-RF *
Rm-RF *. txt
Rm-rf AB *

Exercise:
1. Create the following directory structure (one command is complete) (and verify)
/AA
/\
Ba/BC/
/\\
Ca/CB/CC/
Mkdir-P/AA/BA/c {a, B}/AA/BC/CC
Tree/AA
Ls-r/AA

2. There are several methods to access the CA directory from the BA directory:

3. Copy/etc/man. config to Ca/Beibei and change man.configname to test.txt.
Mkdir-P/AA/BA/c {a, B}/AA/BC/CC
CP ../etc/man. config ../AA/BA/CA/test.txt
4.cut the CC/directory of the test.txt File
MV/AA/BA/CA/test.txt/AA/BC/CC/
5. If you copy the same file to the same directory twice, the overwriting prompt is not displayed.
\ CP/root/install. log/
/Bin/CP install. log/
Unalias CP
CP/root/install. log/

Vim Text Editor

Enter the input mode in command mode
Enter the current character
A: Enter the end of the current row
I input before the current character
I input before the current character
O input the next row of the current row
O input from the last row of the current row
S. Delete the current character and enter
S. After deleting the current row, enter

Home

Command mode
U undo one-step operation
CTRL + R redo
Copy and paste a line of yy p (the next line of the row where the cursor is located)
Copy 50 rows 50yy
Cut a line of dd p Paste
Cut 50 rows 50dd
Delete a DD row
Delete 50 rows of 50dd

^ Beginning and end of the row $
Delete the current character to the beginning of the line d ^ y ^
Delete the current character to the end of the line D $ y $
W. the first character of the next word
YW copies a word DW cut a word
G-tailed line Gg first line 572g
DGG deletes the current row to the first row
DG deletes the current row to the end

Last Row Mode
: W q wq w! Q! WQ!
: W/tmp/newfile saved separately
: 2, 4 w/tmp/newfile2
: E/root/install. Log read files
: R/tmp/newfile2 append read
: E! Re-read the current file

Search
/From top down? From bottom to top N next
Replace
: % S/AB/$/GC % all rows G Global s exchange C interactive replacement
: 3, 6 S/AB/$/3-6 line replacement

Exercise:
1. Replace all the values starting with a with B.
% S/a/B/
2. Remove all tabs (\ t) from the entire file)
% S/\ t // G
3. Remove spaces (\ s) Starting with lines 2-6)
2, 6 S/^ // G
2, 6 S/^ \ S // G
4. Remove all spaces in the entire file.
% S/\ S // G
% S // G
% S/* // G
5. Replace line breaks with spaces (\ n)
% S/\ N // G

Remove empty rows
G/^ $/d
G/^ \ s * $/d

Call up row number
Set nu
Set Nonu
Set autoindent
Set noautoindent

File encryption
X

Vim configuration file/etc/vimrc

Multi-File Operations
Vim aa.txt cc.txt tt.txt
: ARGs: Next: PREV: Last: First Ctrl + 6

Open multiple files on the same screen
Vimdiff aa.txt cc.txt tt.txt
CTRL + W
Vim-O aa.txt cc.txt tt.txt
Vim-O aa.txt cc.txt tt.txt vertical arrangement

Vim Help documentation
/Usr/share/Vim/vim70/tutor. Zh. euc

Iconv-F utf8-T gb18030 tutor. Zh. euc-O test.txt
-F file source Character Set-T output character set-O output file

User Management
UID 0 root (Administrator) gid 0 (Administrator Group)
UID 1-499 (system user) gid 1-499 (system group)
UID 500-60000 (Common User) gid 500-60000 (Common User Group)

Useradd ABC1
User information file/etc/passwd
ABC1: X: 503: 503: Pt:/home/ABC1:/bin/bash
Username: Password placeholder: uid: GID: Description: Home Directory: Shell
Useradd-u 1000-G 503-C hello-D/mnt/abc2-S/bin/bash abc2
-U uid-g gid-C description-D home directory-s shell

Groupadd uplooking
Group information file/etc/group
Abc2: X: 503:
Group Name: Password: GID: username with information
Groupadd-G 2000 uplooking

Exercise:
Add group uplooking GID to 3000
Add the user Tom uid 1200 to the uplooking home directory. In/mnt, shell is Bash.
Groupadd-G 3000 uplooking
Useradd-U 2000-G uplooking-C Oooo-D/mnt/Tom-S/bin/bash Tom

Password
Passwd
File for storing password information/etc/shadow
Abc2: $1 $ cyscxwgt $ s9pwcn0lyaiymd5q6/ilv1: 15654: 0: 99999: 7 :::
Column 1: User Name
Column 2: Password
Column 3: last password change time
Column 4: Minimum Password time
Column 5: Maximum Password time
Column 6: warning time before Password Expiration
Column 7: Account expiration time after Password Expiration
Column 8: account Validity Period
Column 9: reserved column

Modify group information
Groupmod
Groupmod-G 2500 TT2 change GID
Groupmod-N ttnew TT group name

Modify user information
Usermod-u-g-c-d-s Username
Usermod-F account expiration time after password expiration-e account Validity Period
Usermod-l newname oldname
Usermod-l lock account
Usermod-u unlock account

Change password information
Passwd
Passwd-N minimum time-x maximum time-W warning time-I account expiration time after Password Expiration
Passwd-l lock User Password
Passwd-u unlock Password
Passwd-s to view the password status

Exercise:
Create two users, Jack Rose, and set the password to 123 respectively.
Lock Jack account
Lock rose Password
Log on to the terminal to check whether the information is consistent. Can you determine the problem?
In the/etc/shadow file, what are the differences between the two user password segments?

Delete Group
Groupdel group name
Delete a user
Delete userdel-r ABC-r together with home directory

About the user's configuration file
Useradd Eric
/Etc/default/useradd user default file
/Var/spool/mail/user Mail Information Directory
Home =/home
Shell =/bin/bash
Create_mail_spool = Yes

/Etc/login. defs Save the default password information

Useradd-g kf, YW WG
Usermod-a-g boss ABC1
Usermod-g yw, KF ABC1
Useradd-u 0-O Admin

Manual user management
Groupadd RedHat

Vim/etc/groupadd
RedHat: X: 5000:

Useradd Eric

Vim/etc/passwd
ERIC: X: 5000: 5000: ptuser:/home/ERIC:/bin/bash
Mkdir/home/Eric
CP/etc/skel/. Bash */home/Eric/

Passwd Eric
Vim/etc/shadow
ERIC: 15654: 0: 99999: 7 :::

Grub-md5-crypt

Terminal login Test password created file aa.txt

Multi-user import
1. Touch user.txt
AA: X: 5500: 5500:/home/AA:/bin/bash
BB: X: 5600: 5600:/home/BB:/bin/bash

Newusers <user.txt

2. Touch passwd.txt
AA: 123
BB: 123.

Chpasswd <passwd.txt

Roles of files in the Home Directory
. Bash_history records the history commands executed by the user.
. Bash_logout Command executed when the user exits
. Bashrc nologin-shell-level environment configuration file
. Bash_profile login-shell login-level environment configuration file

/Etc/bashrc
/Etc/profile

Loading Sequence
/Etc/profile
~ /. Bash_profile
~ /. Bashrc
/Etc/bashrc

Permission management
-RW-r -- 1 Eric uplooking 39410 11-03 13:44 install. Log

RW-| r --
User
Group Other
Eric uplooking others
U g o
Root (0) ------> uid = Eric -----> group (uplooking) ----> Other

File
R ---------- cat head tail more
W ---------- Vim >>>
X ----------./run
Directory
R ---------- ls R-x query details
W ---------- touch Rm-WX to create a file
X ---------- CD

Tt.txt rwxrwxrwx Root

Tom Rm-RF tt.txt

/Test/rwxr-x --- Root
/Test/TT/rwxrwxrwx
/Test/TT/aa.txt rwxrwxrwx

Tom Rm-RF aa.txt

Chmod U + R file/Dir
Chmod U + R, G-W file/Dir
Chmod U + R, G-r, O + RW file/Dir
Chmod ug + RW, o-RW file/Dir
Chmod Ugo + rwx file/Dir
Chmod A + rwx file/Dir

Chmod u = r file/Dir
Chmod u = RW, G = RX file/Dir
Chmod u = R, G = RX, O = rwx file/Dir
Chmod ug = RW, O = TX file/Dir
Chmod Ugo = rwx file/Dir
Chmod A = rwx file/Dir

Chmod-r 777 test/

R ------ 4 W ------ 2 x ------ 1
Rwxrwxrwx-777

561 R-xrw --- X-WX-W --- X 321
234-w -- WXR --

/755
/Etc 755

/Bin 755
/Sbin 755

/Var 755
 
/Tmp 1777

/Etc/shadow 400.
/Etc/passwd 644
The default permission of the root administrator to create a file is 644.
The default permission of the root administrator to create a directory is 755.
The default permission of a common user to create a file is 664.
The default permission of a common user to create a directory is 775.
/Root 750

/Home/Home Directory of common users: 700

Chown Tom file/Dir
Chgrp uplooking file/Dir
Chown Tom. uplooking file/Dir
Chown Tom: uplooking file/Dir
Chown. uplooking file/Dir
Chown-r Tom. uplooking file/Dir

Exercise:
1. Create the directory test under the tmp directory and create the file aa.txt under the testdirectory to create the user Zorro.
Requirements:
Zorrousers can delete aa.txt but cannot read or write
Mkdir/tmp/test/root Root rwxr-XR-x
Touch/tmp/test/aa.txt Root RW-r --
Chmod o-r/tmp/test/aa.txt
Chmod o + w/tmp/test

2. Create the directory test under the tmp directory and create the file aa.txt under the testdirectory to create the user Zorro Eric
Requirements:
Zorrousers can read, write, and delete aa.txt files.
Ericusers cannot read, write, and delete aa.txt.
/Tmp/test/Eric root rwxr-XR-x
/Tmp/test/aa.txt Zorro root RW-r -----
Zorro
Eric

Chown Zorro/tmp/test/aa.txt
Chmod o-r/tmp/test/aa.txt
Chown Eric/tmp/test/

3. Create the abc.txt file under/root/and create three users Zorro, Shrek, and Seker as follows:
Sekercan read and write abc.txt files but cannot be deleted
Zorroonly reading abc.txt files cannot be deleted
Shrek cannot read and write the abc.txt file, but it can be deleted.

/Root Root rwxrwxr-x
/Root/abc.txt Seker Zorro RW-r -----

Seker
Zorro
Shrek ----> root

Chmod 640 abc.txt
Chown Seker. Zorro abc.txt
Chmod 775/root/
Usermod-a-g root Shrek
Shrek, hello, Root

Advanced Permissions
SUID permission
SUID can only be added to user
Chmod U + S File
SUID can only work on files (binary executable files)
Purpose: when a user executes a command with SUID permission, the command is executed as the command owner.

Exercise:
Requirement: You can use Tom to view the shadow content in cat without changing the/etc/shadow permission.
Which cat
Chmod U + S/bin/cat

SGID
Can only be added to a group
Chmod g + s dir/
It can only work on directories.
Purpose: when a user creates a file (directory) under a directory with the sgid permission, the files created are in the same group as those in the directory.
If a directory is created, the directory inherits the sgid permission.
Exercise:
Create the test directory in the/tmp directory. The directory has the permission of 777 to create the user Tom.
Tom creates the aa.txt javasaa.txt file in the/tmp/testdirectory.
Add the sgid permission to the test directory.
Tom creates the tt.txt upload tt.txt file in the/tmp/testdirectory.
Tom creates a directory dir under the/tmp/test directory to view the information of the Directory dir.

Sticky (t) adventure bit, paste bit
Can only be added to other
Chmod o + t dir/
It can only work on directories.
Purpose: any file created by a user in a directory containing the T permission can only be deleted by the owner, and others cannot be deleted (except root)

Exercise:
Create the test directory under the/tmp directory with the permission of 777. create user Tom to create user Jerry
Use Tom to create the tom.txt file in the testdirectory.
Use Jerry to create the file jerry.txt in the testdirectory.
Try using tomdelete jerry.txt using jerrydelete tom.txt
Can I delete it?

Use Tom to create the tom.txt file in the testdirectory.
Use Jerry to create the file jerry.txt in the testdirectory.
Add the T permission to the test directory.
Try using tomdelete jerry.txt using jerrydelete tom.txt
Can I delete it?
Can I delete it using the administrator root?

Use Tom to create the tom.txt file in the testdirectory.
Use Jerry to create the file jerry.txt in the testdirectory.
Add the user Zorro and change the test directory owner to Zorro.
Can I use zorro to remove tom.txt jerry.txt?

Whether the source file has the X permission difference
Chmod + x aa.txt
[Root @ localhost TMP] # ll aa.txt
-Rwsrwsrwt 1 Root 0 11-11 14:20 aa.txt
[Root @ localhost TMP] # chmod-x aa.txt
[Root @ localhost TMP] # ll aa.txt
-Rwsrwsrwt 1 Root 0 11-11 14:20 AA. TX

SUID ------- 4
SGID ------- 2
Sticky ----- 1

1777
2777
4777
3777

Process Management
PS-ef
PS aux

Top

Frontend and backend Switch
Xclock-Update 1 &
Xclock-Update 1
CTRL + z
Jobs
BG No.
FG No.

Kill % No. Kill

Kill Process
Kill-15 PID
Kill-9 PID
Pkill process name
Killall process name
Xkill

Priority adjustment (-20 ~ 19)
Nice-n-20 xclock-Update 1
Renice 10-P 6020 (PID)

Advanced commands
Cat-N/etc/passwd | head-20 | tail-2 | rev | tac
WC-l rows-w words-C characters
Sort-N sort by number-u remove duplicate rows-r reverse sort
Uniq remove duplicate rows-u show non-duplicate rows-d only show repeated rows-C count the number of duplicates
Grep root/etc/passwd
Grep ^ root/etc/passwd
Grep halt $/etc/passwd
Grep-V halt $/etc/passwd Inverse

Cut
Cut-D:-F 1/etc/passwd
Cut-D:-F 1,6/etc/passwd
Cut-D:-F 1-3/etc/passwd
Cut-D:-F 1-3, 6/etc/passwd

Cut-C 1, 3/etc/passwd | head-2
Cut-C 1-6/etc/passwd | head-2

Exercise:
1. Calculate the number of users in your system that can log on to the system.
CAT/etc/passwd | grep-C bash
CAT/etc/passwd | grep/bin/bash | WC-l
CAT/etc/passwd | grep/bin/bash | cut-D:-F7 | uniq-C
Cat-N/etc/passwd | grep/bin/bash | cut-D:-F1, 7 | cat-n

2. ifconfig eth0 | awk-F': | + ''/bcast/{print $4 }'
192.168.1.1

Ifconfig eth0 | head-2 | tail-1 | cut-D:-F 2 | cut-D ''-F1
Ifconfig eth0 | grep bcast | cut-D:-F 2 | cut-D ''-F 1

3. Stat aa.txt
File: “aa.txt"
Size: 34 blocks: 8 Io block: 4096 General Files
Device: 802 H/2050d inode: 48922685 links: 1
Access: (0644/-RW-r --) uid: (0/root) gid: (0/root)
Access: 12:06:11. 000000000 + 0800
Modify: 12:06:11. 000000000 + 0800
Change: 12:06:11. 000000000 + 0800

Show only time
12:06:11
12:06:11

Stat aa.txt | tail-3 | cut-D ''-F3 | cut-D.-F 1

Shell Basics
!! ! $! Ser

Redirection character
>>>
> The standard output is correct. If the file exists, the output is overwritten. If the file does not exist, the output is created.
> The standard output is correct. If the file exists, it is appended. If the file does not exist, it is created.
2> standard error output. If the file exists, it will overwrite it. If the file does not exist, it will be created.
2> standard error output. If the file exists, it is appended. If the file does not exist, it is created.
0 standard input
&>

Cyclic script
#! /Bin/bash
# Add User scripts
For I in {1 .. 10}
Do
Echo "create user $ I now !!!!! Please wait !!!! "
Sleep 1
Useradd user $ I
Echo "Set User $ I password now !!!!! "
Echo 123 | passwd -- stdin user $ I &>/dev/null
Echo "The create user $ I success !!!!! "
Done

Script judgment
#! /Bin/bash
# Determining whether a file exists
If [-F/tmp/aa.txt]
Then
Echo "the file is cunzai !!!!! Display now !!! 1"
Sleep 1
Ls-L/tmp/aa.txt
Else
Echo "the file is now cunzai !!! Create it now !!!! "
Sleep 1
Touch/tmp/aa.txt
Fi

Network
MII-Tool
Ifconfig
Ifconfig eth0
Ifconfig eth0 192.168.1.100/24

Setup

Configuration File
/Etc/sysconfig/network-scripts/ifcfg-eth *

Nic alias
Ifconfig eth0: 0 10.10.10.1

Ifconfig eth0 up
Ifconfig eth0 down

IFUP eth0
Ifdown eth0

; The Front Command is executed no matter whether the execution is successful or not.
& The front-end command is successfully executed, and the back-end command is executed

Arping 192.168.1.33
ARP

Route-n
Route add default GW 192.168.1.1
Route del default GW 192.168.1.1
Traceroute

Hostname query Host Name
Hostname zhb.com
Vim/etc/sysconfig/network Permanent modification
Hostname = zhb.com

Note: The ing between host name and IP address
/Etc/hosts

Enable route forwarding
CAT/proc/sys/NET/IPv4/ip_forward
Echo 1>/proc/sys/NET/IPv4/ip_forward
CAT/proc/sys/NET/IPv4/ip_forward

Compress, package, and install software
Gzip Bzip2
Dd If =/dev/Zero of = data BS = 100 m COUNT = 2 create a M file

Gzip data
Gunzip date.gz
Bzip2 data
Bunzip2 data.bz2

Tar
Tar-CVF boot.tar/boot
Tar-tvf boot.tar
Tar-RVF boot.tar data
Tar-xvf boot.tar

Tar-CVF/home/boot.tar/boot/
Tar-xvf boot.tar-C/home/

Tar-zcvf boot.tar.gz/boot
Tar-ztvf boot.tar.gz
Tar-zxvf boot.tar.gz

Tar-jcvf boot.tar.bz2/boot
Tar-jtvf boot.tar.bz2
Tar-jxvf boot.tar.bz2

Tar-zcvf/home/boot.tar.gz/boot/
Tar-zxvf boot.tar-C/home/

Mount)
Mount-T iso9660/dev/CDROM/mnt
Mount
Umount/dev/CDROM
Umount/mnt
-L force uninstall

Create an image
CAT/dev/CDROM>/rhel5u8. ISO
Dd If =/dev/CDROM of =/rhel5u8. ISO
Attach an image
Mount-T iso9660/rhel5u8. ISO/mnt-o loop

Software Installation
Rpm-IVH httpd-2.2.3-63.el5.i386.rpm Installation
Rpm-Q httpd
Rpm-Qa | grep httpd query all software packages installed with the httpd keyword
Run the rpm-QL httpd command to query the installation path of the software package.
Run the rpm-QF httpd. conf command to check whether the file was installed by the software package.
Rpm-QF 'which mount' is preferentially executed as above''
Rpm-Qi httpd: Query httpd package information
Rpm-e httpd uninstall software package

Uninstalled Software Package
Rpm-QPI httpd-2.2.3-63.el5.i386.rpm Not Installed
Rpm-qpl httpd-2.2.3-63.el5.i386.rpm path after installation

Rpm-e Apr-devel -- nodeps does not detect dependency uninstallation
Rpm-IVH httpd-2.2.3-63.el5.i386.rpm-force Installation

Build and use the yum Library

1. Mount/dev/CDROM/mnt
2. Vim/etc/yum. conf
Gpgcheck = 0
3. CD/etc/yum. Repos. d/
Touch yum. Repo
Vim yum. Repo
[Yum]
Name = Yum Server
Baseurl = file: // MNT/Server
Enabled = 1
Gpgcheck = 0

Yum list
Yum install httpd-devel
Yum remove httpd-devel
Yum reinstall httpd-devel
Yum clean all

Rpm -- import rpm-GPG-key-RedHat-release import key

Create Yum Library
Database creation commands
Rpm-IVH createrepo-0.4.11-3.el5.noarch.rpm
/Yum contains all software packages.
Createrepo/yum

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.