FAlinux01-1 basics

A wildcard

* Zero, all characters

? One and only one character

[0-9] matches a single 0-9

[abc] Match any number of characters abc

[^abc] The character except abc

[[:lower:]] matches a single lowercase letter uppercase digit number

Two variables $ call variable reference variable

unset D cancel variable

Local variables are only useful in the current terminal

/etc/profile defines global environment variables and  reads this file by default when logging in. It is valid for all users

The user environment variable ~/.bash_profile is only valid for the current user. If there is a user-defined one, the user is the main one, and it will overwrite the global variable

PATH variable The command is stored in the directory. The command execution will only search and execute the current directory           /bin/bash Command interpreter

Three shell script operation and maintenance management.sh end

#!/bin/bash The statement starts with bash shell

Four redirection pipeline

Command redirection symbol file

> Output redirection overwrite original file

>> add   

Pipe symbol |

Command 1 | Command 2 | ...

Command 1 result as input for command 2

Five text processing tools

cat |grep filter View file content

ls -IR file|more paged display 

head -n 5 file Display the first 5 lines of the file The default display of the first 10 lines

tail -n 5 file Display the last 5 lines of the file, the default last 10 lines

grep option keywords 

grep keyword file filtering keyword -w word word -i ignore case -iw -A how many lines after -B how many lines before

|grep /bin/bash$ filter what ends with $ 

|grep -v ^';' |grep -v ^# |grep -v'#' Filter out lines beginning with; #, including #  

-v Reverse selection ^#Filter to start with #  ^$ blank line

|awk'{print $5}' Take the column as the filter unit. The fifth column -F: followed by the split symbol:, split,

|sed's/%//' sed search and replace s search% and replace empty

/var/log Log append method to locate files

tail -f /var/log/*     View the last 10 lines of the file in real time

tail -f / var / log / * | grep -iE -A3 -B3 '(warn | err)'

demand:

1. Intercept the users who can log in in the system and export these users to the /root/userlist.txt file

cat /etc/passwd |grep /bin/bash$ |awk -F: '{print $1}' >> /root/userlist.txt

2. Filter all non-comment lines and non-blank lines in /etc/samba/smb.conf and export them to the /root/smb.conf file

cat /etc/samba/smb.conf | grep -v ^ ';' | grep -v '#' | grep -v ^ $> /root/smb.conf

cat /etc/samba/smb.conf |grep -vE '(^;|#|^$)' >> /root/smb.conf


Guess you like

Origin blog.51cto.com/14234935/2595621