1.python bald people
2.python bald people
3.python bald people
4. live today swap shell base language learning
---------------------------------- me is the dividing line ------------ -------------------------------
One. Start
shell program in the form of schools are one-line command to execute (the lack of logic)
the difference:
Use the linux shell for batch management, rather than to develop applications
two. Knowledge Overview
shell (python, perl) shell-compatible operating system better
pip install ipython
1, bash basic features
ctrl+l
The key
history
2, IO and redirection pipe character
3, Programming Basics
Principles of Programming (object-oriented, process-oriented)
Program: perform a certain function of the code it
Program: instructions (commands) + data (variable) + (logic)
4, grep and regular expressions! ! ! ! !
Linux Three Musketeers
pattern "mode"
5 logic, statement
if
for *** (not easy to enter an infinite loop)
Add to the list for the cycle
while
Loop condition is true
until
Loop condition is false
(Do not enter an infinite loop)
case (write Linux program startup script)
break
continue
exit (Returns the value of the specified program to be executed)
read(input())
echo(print())
variable**
6.Linux Three Musketeers
sed stream editor
Switch between the two modes
awk (report generator)
An independent programming language
7. function
(Numeric, character)
A fixed code block
Array
Lists, tuples, dictionaries
String (process)
Repeat: must be continuous and the same data (first sorted again weight)
three. The basic characteristics of Bash
1. Command History
Effect: Commands used before viewing
About command history file:
Each user's home directory below .bash_history
When turned off, it will automatically be written once
(History -r command manually written to disk memory)
Variables on command history (environment variables)
Check the environment variable env //
set // View more detailed environmental variable parameters
HISTSIZE = 1000 number
HISTCONTROL=ignoredups
L history of common operations
View command history
! # # Execute command line
! string matches a string of recent
! ! The previous command
******! The last parameter of a command on $
ls /etc
ls! $
ESC+.
Common options:
-a append history lines to the history file
-d
-c
Recent history # # show command line
2. Command Completion
Tab key, tab \ t represents the four spacebar
1, suggesting that
2, automatic completion
3. Directory completion
Tab key
1, suggesting that
2, automatic completion
4. Expand the -date command command
{}
Linux directories need to follow any rules? --FHS Listing Rules
Attribute 1 Attribute 2
A 1
B 2
pv mkdir / var / {a, b} - {1,2}
date command to create a directory based on date
date +% F change date output format
When the% F% H% M% S seconds% T min time hh: mm: ss
%D mm/dd/yy
Exercise: Create a log file for a month's statement cycle; .log
Examples: 2019-08-6.http.log
touch `Date +%F`
for i in {1..31};do
touch `date +%Y-%m-$i`.http.log;
done
tar (archiving tool)
Features: This compression operation can only manipulate files, directories can not be.
Compression tools: gzip, bzip2, xz, zcat (see the contents of compressed files without decompression [])
Common parameters of tar:
Archiving tools: You can operate the directory
-j bzip2
-J xz
-z gzip
-c create compression
-x extract decompression // can not specify a decompression tool
-f specify the file name
verbose [-v] Show Details
tar cjvf 2018-08.http.log.bz2 2018-08-*.http.log
tar xvz 2018-08.http.log.bz2 -C abc
Exercise: to write scripts, 02:20 daily backups / etc / directory of all files named today's date; and save the file as a compressed file;
例:crontab – 20 2 * * * /root/xxx.sh
vim xxx.sh
#!/bin/bash
tar cJvf /var/`date +%F`.xz /etc/
chmod +x xxx.sh
supplement:
clock / hwclock view the hardware clock (How to synchronize the system clock with the hardware clock)
cal: Calendar
The command execution status
In linux, each command execution, there will be two results:
Command returns the content itself
Secondly, the command execution result status
$? Variables, command execution is used to store state
0 indicates a successful state (and python just the opposite)
1-255 represents a failed state
[$? -eq 0]&& exit 0|| exit1
6. shortcut commands
ctrl + l clear screen
ctrl +c
ctrl + u to delete the character before the cursor
ctrl + k character after cursor is deleted
ctrl + a cursor to jump to the head
the cursor jumps to the end ctrl + e
ctrl + w as a space separator, the file to delete
ctrl + r interactive interface enters a command, a search for recently used (for input string)
7.alias alias
Read the special file system startup sequence
例:alias cdnet=”cd /etc/sysconfig/network-scripts/”
alias // defined in this way can only take effect in the current shell;
/ Etc / profile: define environment variables (for all users, uppercase) - EXPORT HISTCONTTROL = XXX
/ Etc / bashrc: define local variables (alias, lowercase)
~ / .Bash_profile: define environment variables (designated user, who wrote under the home directory is who)
~ / .Bashrc: define local variables (alias, user specified)
sources / etc / profile or the entry into force of ./etc/profile #
8. file wildcard -globbing
[File] not a regular expression wildcard
? Any single character
* Any character of any length
[] Any one character in the specified range
^ Written [^] outside the specified range of any character
[^ 0-9a-Za-z], [0-9], [AZ], [z] [A-Za-z]
Specify a character class (you have to add [] when calling)
[: Alnum:] matches any letter or number
[: Alpha:] matches any letter
[:cntrl:]
[: Digit:] matches any digital
[:graph:]
[: Lower:] matches any lowercase letter
[:print:]
[:point:]
[:space:]
[: Upper:] matches any one capital letter
[:xdigit:]