linux
installation
- Installation
- Virtual machine resource allocation can not exceed the unit's own resources
- LAN: NAT mode, only windows to access the machine, the machine can not access the other network. Bridge: the other machine within the network can also be accessed
- Install windows linux vm tools that interact with
table of Contents
- Features linux directory structure?
With '/' root directory tree structure. In linux directory everything is a file - Common catalog
- / Dev hardware device mapping file
- / Media U disk loading at
- / Root super-user's home directory
- / Bin storing most frequently used instructions
- / Lib shared dynamic link library
- / Opt installation package
- / Boot system configuration
- / Mnt share files at
- / Etc configuration files and subdirectories my.config
- / Home folder for each user-specific repository
- / Usr software installed at
- / Usr / local software installation directory
- / Var frequently modified files. Such as logs
Remote Connection
- How remote connection?
By XShell like the software to connect, to determine linux sshd service is turned on before connecting. Input through the terminalsetup
to view
through xftp used to transfer files
vi 与 I came
What is the vi and vim?
Text editor, vim is an enhanced version- Three common mode
- Insert
Press i I o O a AR to any one of the letters to enter edit mode - Command line
: entry mode quit q q wq save and exit forced to quit! - Normal
vim into the other mode by entering the ESC mode
- Insert
Common shortcuts
yy copies the current line normal mode
5yy normal copy mode line 5
p paste in the normal mode
dd delete the current line normal mode
under the normal mode 5dd delete rows 5
G document last line in the normal mode
gg the first line in the document under normal mode
u revoked in normal mode
20 shift g jump to the line 20 normal mode
/ hello hello look at the command line mode
: set nu show line numbers in the command line mode
: set nonu cancel OK the next number in the command line mode
Boot and reboot and logoff
Shutdown restart
shutdown
shutdown -h now
shutdown immediately
shutdown -h 1
one minute shutdown
shutdown -r now
immediately restart
halt
shutdown
reboot
to restart the
sync
synchronization instruction memory, the data is written to memoryUser login logout
login by ordinary users, do not try to root login
logout
logout users
User Management
- User groups
each user belongs to at least one user group - Add User
useradd [选项] 用户名
successfully added automatically creates a corresponding home directory - And add the user to specify their home directory corresponding
useradd -d /home/test/ xiaoming
- Specify a password
passwd xiaoming
- delete users
userdel 用户名
- Delete the corresponding retained home
userdel xiaoming
- Delete does not retain the corresponding home
userdel -r xiaoming
- Query User Information
id 用户名
- Switch User
su 用户名
- Return by the user
exit
- The current user queries
whoami
- Add Group
groupadd 组名
- Adding user-specified group
useradd -g 用户组 用户名
- Modifying User Groups
usermod -g 用户组 用户名
- User information stored?
/ etc / passwd - User group information stored?
/ etc / group - Password information stored?
/ etc / shadow
Run Level
- linux operating level seven minutes analogy Windows normal mode and security mode, the configuration file etc / inittab
off 0-
1-mono user
2- multiuser no network
3- multi-user network
4- unused reserved for system users
5 - GUI
6- system reboot
init[0123456]
Help command
- View Help Contents
man ls
help cd
File Directory class
- How to display the absolute path to the current directory?
pwd
- How to view the current contents of the directory?
ls -al
: Display all, including hidden
ls -l
: the information displayed in a list - How to switch directory?
cd ..
On a
cd ~
home directory - How to create a table of contents?
mkdir /home/dog
Create a single-level directory
mkdir -p /home/animals/tiger
to create multi-level directory - How do I delete a directory?
mkdir /home/dog
Delete empty directory
rm -rf /home/tigers
to delete non-empty directory - How to create a file?
touch 文件名称
- How to copy a file?
cp source dest
Copy individual files
cp -r source dest
recursively copy folders
\cp -r source dest
recursively copy the folder does not cover tips - How to remove a file or directory?
rm /home/aaa
rm -r /home/aaa
Recursively delete the entire folder
rm -rf /home/aaa
recursively deleted without prompt - How to rename or move?
mv oldName newName
Rename
mv fileName /temp/
Move to Folder - How to view the files?
cat /etc/profile
Read-only files
cat -n /etc/profile | more
show pages and line numbers have - How to Redirect and append?
ls -l>fileName
Overwritten file content list
ls -al>>=fileName
listing additional content written to a file in
cat fileName1>fileName2
the file to a file cover 2
echo "txt">>fileName
- How to output the content to the console?
echo [选项] [内容]
echo $path 输出环境变量
- View part of the file?
head /etc/profile
The default view files before 10 rows
head -n 5 /etc/profile
5 rows before viewing the file
tail /etc/profile
after the default view file 10 line
tail -n 5 /etc/profile
after line 5 to view the file
tail -f /etc/profile
dynamic tracking monitor file for viewing log - How to view instructions have been executed?
history
See all command
history 10
to view 10 history instruction
!33
execution section 33 history instruction
The date and time
- How to display the current time?
date
date +%Y
On display
date +%m
display month
date +%d
and day are displayed
date "+%Y-%m-%d"
format prescribed display time - How to set time?
date -s "2019-10-10 11:22:22"
Content specified time by a string - How to view the calendar?
cal
Display month
cal 2020
display a given year
Search Find
- How do I find?
find /home -name hello.txt
In the scope of the home directory lookup by file name
find /opt -user nobody
in the directory opt essay by file name to find a home user
find / -size +20M
to search by file size in the root directory lookup
find / -name *.txt
to find all the txt file in the root directory - Filtration and pipeline applications?
cat hello.txt | grep yes
cat View files, pipes | viewing the contents of the cat to grep command Search by yes conditions
cat hello.txt | grep -n yes
with line numbers
cat hello.txt | grep -i yes
ignore case
Extracting archive
- How to extract compressed files?
gzip hello.txt
Hello.txt compressed file and does not retain the original file
gunzip hello.txt.gz
to extract the files - How to extract the compressed files and directories?
zip -r test.zip /home/
Recursive compression in test.zip entire home directory in
unzip -d /opt/tmp test.zip
the extract to test.zip / opt / tmp directory - How to pack and unpack?
tar -zcvf a.tar.gz a1.txt a2.txt
The two files are packaged a1.txt a2.txt a.tar.gz compressed in the
tar -zcvf home.tar.gz /home/
recursive package an entire home directory zcvf
tar -zxvf home.tar.gz
extract the entire packet zxvf
tar -zxvf home.tar.gz -C /opt/
extract to the / opt directory
Group management and rights management
Owner of the file, where the group and other groups. Not necessarily the same owner and all groups.
ls -ahl
Check the file owner
chown root test.txt
to modify the file owner
chgrp centos test.txt
to modify the file's group
usermod -g root centos
to modify the root group centosWhat file types?
-
Ordinary file
d:
directory
l
soft link
c
character device, the keyboard
b
block devices, hard disk- Check the file permissions how?
Check the file permissions to view a file, the previous owner of the first shows, where the group, the other group of three privilege level
privilege level read and write operations are divided into
-rw-r--r-- 1 tom police 6 3月 20 19:24 ok.txt
0-9-bit
-
type file
rw-
read and write permissions to the owner of the
r--
file where the group only read access
r--
other groups only read permission file
1
number of the number of subdirectories or hardwired
6
file size in bytes, folder 4096 is constant
- Kinds of permissions rwx?
For file rwx read, modify, execute
the directory read rwx ls view, modify, delete rename mkdir to create a directory, you can run the cd into the directory - How to modify permissions?
r = 4 w = 2 x = 1 array notation
. 7 = rwx
. 6 = RW
. 5 = RX
. 3 = WX
0 = No rights
u: Owner g: where the group o: others a: all
chmod u=rwx,g=rx,o=rx abc
modifications abc rights owners rwx, rx others, where the group rx
chmod u-x,g+w abc
owner cancel x permission to increase the rights of all groups w - How to modify the file owner?
chown -R tom kkk/
Recursive folder kkk modify the owner of all files to tom How to modify the file owner?
chgrp -R bandit kkk/
Task scheduling
crontab
- How to set the schedule file?
Stored in / etc / crontab - Understanding of the schedule file?
crontab -e
Into the schedule file editing, deployment scheduling tasks. Tasks can be written directly by calling or writing task command file sh, sh command file to set the x permission.
*/1 * * * * ls -l /etc >> /tmp/to.txt
Every minute representation, etc the list of additional write /tmo/to.txt - How practical application?
vim matask.sh
Sh edit a file, execute written contentdate >> /tmp/mydate
, mytaskx given permission, bycorntab -e
entering the deployment file, write*/1 * * * * /home/mytask.sh
For example application?
Two daily automatic backup mysql in testdb to a file in mydb.bak
Partition
- How to view the partition and mount the case of system?
lsblk -f - How to query the disk situation?
df -lh
- How to use a directory inquiries?
du -ach --max-depth=1 /opt
-s specified directory (or the current directory)
-h with units of measurement
-a file containing
--max-depth = 1 subdirectories depth
-c listed in detail at the same time - ? Practical instruction
ls -l /home | grep "^-" | wc -l
first query, use grep filter "-" get all files with wc statistics.
ls -lR /home | grep "^-" | wc -l
First query, use grep filter "-" get all files with wc statistics. -R recursive
tree
tree showing files
Network Configuration
- Automatically obtain IP of the shortcomings?
IP address may be changed, not suitable for server applications. - How fixed IP?
By configuring the / etc / system / network -scripts / ifcfg-eth0 - How to view the network situation?
-an
A certain order
-p
shows which processes the call
netstat -anp | more
to see all network
netstat -anp | sshd
view of network conditions sshd
Process Management
- How to view the process performed by the system?
ps -a
All the current terminal process information
ps -u
users format process information
ps -x
background process parameter
ps -aux | grep sshd
view sshd related processes - How to view the parent process?
ps -ef | more
View parent ppid - How to terminate the process?
kill -9 3333
By 3333 kill process process ID, -9 forced to commit suicide
killall gedit
to kill all of the same name process by process name - View the process tree
pstree
process tree
pstree -p
process tree with a process ID
pstree -u
process tree with the process belongs to the user - Dynamic monitoring process?
top
3 seconds refresh
input u and then enter a user name, a user in the top of the monitor
input k in the top re-enter the process id number, to kill a process
input N in the top, press the PID sorting
input M in the top, a sort of memory
in the top of the input P, sorted by CPU
top -d 10
10 seconds refresh
Service Management
- In fact, the essence of the service process running in the background, listening on a port, waiting for the requestor.
- Common commands and parameters?
service service name [start | stop | restart | reload | status] is used in centos7 systemctl - How to detect whether the port is listening?
telnet 192.168.52.3 22
windows instructions, see the 22-port server. - See all services?
setup
ls -l /etc/init.d/
- Services run level?
chkconfig --list
View all services whether or not to start at different run levels
chkconfig --level 5 sshd off
sshd service does not start automatically when the 5 level.
rpm package
- rpm, analog setup.exe
- How to check rpm?
rpm -qa | grep firefox
Access to firefox not installed
rpm -qi firefox
inquiries installation information
rpm -ql firefox
query file path to the installation and installation of
rpm -qf /etc/passwd
a query which package a file belongs - rpm uninstall?
rpm -e firefox
Uninstall firefox
rpm -e --nodeps firefox
forced uninstall firefox - rpm installation
rpm -ivh firefox.rpm
install firefox
-i
install
-v
prompt
-h
progress bar
yum follicles
- Automatically install dependencies based management rpm, advantages
yum list | grep firefox
Seekyum install firefox
run