How to filter out all the first-level directories in Oldboy under the known current directory

Source: Internet
Author: User
Tags system log iptables egrep

1th Linux boot process
1.1 Linux boot process
(1) power-on self-test (BIOS) Memory cup (Hardware check)
(2) MBR boot
(3) Grub menu (choose a different kernel)
(4) Load kernel (kernel)
(5) running the INIT process (the first process in Linux, the initialization process)
(6) Read/etc/inittab configuration file (RunLevel profile)
(7) Execute/etc/rc.d/rc.sysinit script (System init script, set host name, set IP address)
(8) Execute/ETC/RC.D/RC script (depending on the cloud level of the system, start different software when booting up)

    1. PATH
      Path is stored under Linux commands (location)
      [Email protected] ~]# echo $PATH
      /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

1.2 Linux Execution Command procedure
1. Whether it is an alias
2. Find out if the command exists in path
1). Tips
Command not Found
2). Execution

Summary:
1.linux Boot Process
2.PATH function
PS1 LANG PATH (three environment variables)
3.linux Executing the command procedure
1.3 Topic 1 Filtering a first-level directory
##.1 How to filter out all the first-level directories in Oldboy that are known to be in the current directory (hint: subdirectories and hidden directories that do not contain directories below the Oldboy directory, that is, only the first level of the directory)?

Create an environment
Mkdir/oldboy-p
Cd/oldboy
mkdir ext/oldboy Test Xiaodong Xiaofan xingfujie-p
Touch Jeacen Oldboy wodi.gz yingsui.gz

1.3.1 Method 1-tree
[Email protected]/oldboy]# TREE-DL 1
.
├──ext
├──test
├──xiaodong
├──xiaofan
└──xingfujie

5 directories

#-d Show only Directories
#-l level shows the maximum number of layers

1.3.2 Method 2-find
[Email protected]/oldboy]# find-maxdepth 1-type D
.
./xiaodong
./xiaofan
./test
./ext
./xingfujie

#-maxdepth maximum depth to show how many layers
1.3.3 Method 3-find
[Email protected]/oldboy]# find-maxdepth 1-type D
.
./xiaodong
./xiaofan
./test
./ext
./xingfujie
Find a directory of points
[Email protected]/oldboy]# find-maxdepth 1-type d-name "."
.
Do not display a directory with points, find command to take anti-find-maxdepth 1-type d! -name "."
[Email protected]/oldboy]# find-maxdepth 1-type d! -name "."
./xiaodong
./xiaofan
./test
./ext
./xingfujie
#! Exclude anti-non-

1.3.4 Method 4 D starts with the
[email protected]/oldboy]# ll |grep "^d"
Drwxr-xr-x 3 root root 4096 Jul 23:59 ext
Drwxr-xr-x. 2 root root 4096 Jul 19:24 test
Drwxr-xr-x 2 root root 4096 Jul 23:59 Xiaodong
Drwxr-xr-x 2 root root 4096 Jul 23:59 Xiaofan
Drwxr-xr-x 2 root root 4096 Jul 23:59 Xingfujie
[Email protected]/oldboy]# #^ to .... The beginning of the line the Three Musketeers use regular expressions

1.3.5 method 5 2nd column greater than 1
[[email protected]/oldboy]# ll |awk ' $2>1 '
Total 3
drwxr-xr-x root root 4096 Jul 23:59 ext
Drwxr-xr-x. 2 root root 4096 Jul 19:24 test
Drwxr-xr-x 2 root root 4096 Jul 23:59 Xiaodong
Dr Wxr-xr-x 2 root root 4096 Jul 23:59 Xiaofan
drwxr-xr-x 2 root root 4096 Jul 23:59 Xingfujie
1.3.6 Method 6-ls
[[email protected]/oldboy]# ls–f Different types of files plus different tag directories/
Alex.txt jeacen oldboy.txt test.sh t.sh.bak XIAODONG/XINGF ujie/
Ext/oldboy test/t.sh wodi.gz xiaofan/yingsui.gz
[[email protected]/oldboy]# #-F Different types of files plus different tag directories/< Br>[[email protected]/oldboy]# ls-f |grep "/"
ext/
test/
xiaodong/
xiaofan/
xingfujie/

[Email protected]/oldboy]# LS-LD */
Drwxr-xr-x 3 root root 4096 Jul 23:59 ext/
Drwxr-xr-x. 2 root root 4096 Jul 19:24 test/
Drwxr-xr-x 2 root root 4096 Jul 23:59 xiaodong/
Drwxr-xr-x 2 root root 4096 Jul 23:59 xiaofan/
Drwxr-xr-x 2 root root 4096 Jul 23:59 xingfujie/

1.4 Summary:
1.tree Find
2.grep awk
3.ls
1.5 Questions 1 Compression decompression
1.6 Classic Faults
Tar Command Classic fault removing leading '/' from member names

Create a compressed package have you seen this hint?
[Email protected]/oldboy]# tar zcf/tmp/etc.tar.gz/etc/
Tar:removing leading '/' from member names
What do you mean?
The process behind:
File or directory absolute path----> relative path during package compression
When you are packing:
/etc/host
/etc/profile
What to look like in a compressed package
Etc/host
Etc/profile

The reason for this hint:
Prevents overwriting of source files when extracting.

#12/etc/directory for the default configuration file and service startup command for Linux systems
A. Please use tar to package/etc the entire directory (packaging and compression).
C. Please unzip the A-point command into the/tmp directory (preferably only with the tar command).
B. Please use TAR to package/etc the entire directory (packaging and compression, but need to exclude/etc/services files).

Windows compression winrar/Good press/2345 compression
Linux Packaged Compressed tar

1.7 #创建压缩包
Tar zcf/tmp/etc.tar.gz/etc/

Tar zcvf/tmp/etc.tar.gz/etc/
After compression, place the target.

#z gzip Compressed by gzip software
Creating a package #c Create
#v Verbose display Process
#f file specified

1.7.1 #查看压缩包内容
Tar ztf/tmp/etc.tar.gz
#t list to display the contents of a compressed package

#解压
Tar etc.tar.gz decompression zxf Z can omit do not write
#x Extract Decompression
Compression
Tar zcf
View
Tar TF

Extract
Tar XF
Show compressed Package information
[Email protected]/tmp]# ll/tmp/etc.tar.gz
-rw-r--r--1 root root 9734648 Jul 01:41/tmp/etc.tar.gz
#解压到/opt extract to the specified location
[Email protected]/tmp]# tar xf/tmp/etc.tar.gz-c/opt/
-C unzip to the specified location
[Email protected]/tmp]# ll/opt/
Total 12
Drwxr-xr-x. 2 root root 4096 Jul 01:16 data
Drwxr-xr-x root root 4096 Jul 20:43 etc
Drwxr-xr-x. 2 root root 4096 Mar-RH

B. Please use TAR to package/etc the entire directory (packaging and compression, but need to exclude/etc/services files).
1.7.2 Exclude/etc/services files
[Email protected]/tmp]# tar zcf/tmp/etc-pai.tar.gz/etc/--exclude/etc/services
Tar:removing leading '/' from member names

After exclusion
[Email protected]/tmp]# tar tf/tmp/etc-pai.tar.gz |grep Services
Etc/init/readahead-disable-services.conf
Before excluding
[Email protected]/tmp]# tar tf/tmp/etc.tar.gz |grep Services
Etc/init/readahead-disable-services.conf
Etc/services

Tar zcf/tmp/etc-pai.tar.gz/etc/--exclude/etc/services
--exclude-from name.txt exclude folders and files

Name.txt
Oldboy.txt
/oldboy/oldboy

Package Compression:
1. Create
2. View
3. Unzip
4. Unzip to the specified location
5. Exclusions (understanding)

#2 If the current directory is

CD-Go to your last location

An argument of-is equivalent to $OLDPWD.

#cd-= = = CD $OLDPWD

Cd.
Cp/mv
Cd..
cd ~ = = = CD

#3.
[Email protected]/tmp]# cd/etc/
[email protected]/etc]# Touch oldboy.txt

Ls-lrt
#-r reverse Order
#-t by modified Time

#6 Debugging system Services, you want to see the system log/var/log/secure updates in real time, how to do?

-F
-F = =-F--try If the file does not exist, it will retry continuously

Tail-f/var/log/secure
Tailf/var/log/secure

1.8 Questions 3 Print configuration file nginx.conf
How do I #7 the line number and content of the nginx.conf content of the print profile?

[[email protected]/oldboy]# #{1..5} generate sequence
[[email protected]/oldboy]# echo {1..10}
1 2 3 4 5 6 7 8 9 10
[[email protected]/oldboy]# echo {01..10}
01 02 03 04 05 06 07 08 09 10
[Email protected]/oldboy]# echo stu{01..10} |xargs-n1
Stu01
Stu02
stu03
Stu04
Stu05
Stu06
Stu07
Stu08
Stu09
Stu10
[[email protected]/oldboy]# echo stu{01..10} |xargs-n1 >nginx.conf
Generate a column and append it to the nginx.conf file

1.8.1 Method 1 Cat
[[email protected]/oldboy]# cat-n nginx.conf-n show serial number
1 stu01
2 stu02
3 stu03
4 stu04
5 stu05
6 stu06
7 stu07
8 stu08
9 stu09
Ten STU10

1.8.2 Method 2 Vim
Vim nginx.conf
: Set Nu #显示行号
#nu = = = Number

: Set Nonu #取消显示行号
1.8.3 Method 3 awk
Show a column
[[email protected] ~]# awk ' {print nr,$1} '/oldboy/nginx.conf
1 stu01
2 stu02
3 stu03
4 stu04
5 stu05
6 stu06
7 stu07
8 stu08
9 stu09
Ten STU10

NR line number
Column 1th
$2nd Column
A full line of content

Displays the line number of the/proc/mounts file and the 1th and 3rd columns
awk ' {print nr,$1,$3} '/proc/mounts

1.8.4 Method 4 Grep-n

Grep-n "." Nginx.conf

. Any one character of the regular expression
-N Display Line number

1.8.5 Method 5 NL Number of lines
NL nginx.conf

1.8.6 Method 6 SED
sed = nginx.conf
Sed ' = ' nginx.conf |xargs-n2
[[Email protected] ~]# sed ' = ' nginx.conf
[[Email protected] ~]# sed "=" nginx.conf
= line number is displayed
Summary:
1.cat-n/vim (must be)
2.grep awk (must be)
3.nl SED
1.9 Questions 4
The access log for the Nginx service is known to be logged by day in the server local directory/app/logs, because of the tight disk space, now requires only the last 7 days of access logs! How can I resolve this? Please provide a workaround or configure or process the command.

Delete logs up to 7 days ago

Mkdir-p/app/logs
Cd/app/logs
For time in {01..20};d o date-s "201805$time"; Touch Accesswww$ (date +%f). Log;d One
Date-s "20180520 00:00:00"

Date Display time Modification time
Find
-mtime Modify Time Modified

[Email protected]/app/logs]# find-mtime +7|xargs ls-l
-rw-r--r--1 root root 0 May 1 00:00./access_www_2018-05-01.log
-rw-r--r--1 root root 0 May 2 00:00./access_www_2018-05-02.log
-rw-r--r--1 root root 0 May 3 00:00./access_www_2018-05-03.log
-rw-r--r--1 root root 0 May 4 00:00./access_www_2018-05-04.log
-rw-r--r--1 root root 0 May 5 00:00./access_www_2018-05-05.log
-rw-r--r--1 root root 0 May 6 00:00./access_www_2018-05-06.log
-rw-r--r--1 root root 0 May 7 00:00./access_www_2018-05-07.log
-rw-r--r--1 root root 0 May 8 00:00./access_www_2018-05-08.log
-rw-r--r--1 root root 0 May 9 00:00./access_www_2018-05-09.log
-rw-r--r--1 root root 0 00:00./access_www_2018-05-10.log
-rw-r--r--1 root root 0 may 00:00./access_www_2018-05-11.log
-rw-r--r--1 root root 0 may 00:00./access_www_2018-05-12.log

Example 1-1 find out the files below/app/logs 7 days before the end of. Log show Details (ls-l) (3 methods)

find/app/logs/-type f-name "*.log"-mtime +7

Method 1
find/app/logs/-type f-name "*.log"-mtime +7|xargs ls-l

Method 2
Ls-l $ (find/app/logs/-type f-name ". Log"-mtime +7)
Ls-l ' find/app/logs/-type f-name "
. Log"-mtime +7 '

Method 3
find/app/logs/-type f-name "*.log"-mtime +7-exec ls-l {} \;

Example 1-2 8 Linux system operating level is generally 0-6, please write down the meaning of each level respectively.

1) 0-6
2)
RunLevel
3)
Init

Chapter 2nd Question 5
2.1 iptable
9 after the system is installed, you want to let the network File Sharing service NFS (iptables), only on the 3 level on the boot, how to do?
Let iptables boot from the boot?

[[email protected] ~]# chkconfig--level 3 iptables on
[Email protected] ~]# Chkconfig |grep IPT
Iptables 0:off 1:off 2:off 3:on 4:off 5:off 6:off

Chapter 3rd Question 6
3.1 Garbled Character Set
Linux system to view Chinese, but garbled, how to solve the garbled problem?

Garbled reason: different character sets
How to troubleshoot: see if a character set is the same
How to FIX: Modify character sets

Chapter 4th question 7
4.1 The following commands and results are known:
[Email protected] ~]$ Mkdir/oldboy; echo "I am Oldboy,myqq is 31333741" >/oldboy/oldboy.txt
[email protected] ~]$ cat Oldboy.txt
I am OLDBOY,MYQQ is 31333741
A Now you need to filter out the "Oldboy" and "31333741" strings from the file, give the command.
b If you need to filter out the "oldboy,31333741" string from the file, please give the command again.
A Now you need to filter out the "Oldboy" and "31333741" strings from the file, give the command.

4.2 Method 1 Sed+awk
[[Email protected]/oldboy]# sed ' s#,# #g ' oldboy.txt
I am Oldboy myqq is 31333741
[[Email protected]/oldboy]# sed ' s#,# #g ' oldboy.txt |awk ' {print $3,$6} '
Oldboy 31333741

4.3 Method 2 Tr+awk
[[Email protected]/oldboy]# tr "," "" <oldboy.txt
I am Oldboy myqq is 31333741
[[Email protected]/oldboy]# tr "," "" <oldboy.txt |awk ' {print $3,$6} '
Oldboy 31333741
TR sed command castrated edition
[[email protected]/oldboy]# echo 123123|tr "123" "ABC"
Abcabc
[[email protected]/oldboy]# echo 112233|tr "123" "ABC"
Aabbcc
[[email protected]/oldboy]# #tr 1-to-1 replacement

4.4 Method 3 Tr+cut
[Email protected]/oldboy]# cut-d ""-f2,3,4 oldboy.txt
Am OLDBOY,MYQQ is
[Email protected]/oldboy]# cut-d ""-f2-5 oldboy.txt
Am OLDBOY,MYQQ is 31333741
-D Specify delimiter (Chopper)
-F a column

A Now you need to filter out the "Oldboy" and "31333741" strings from the file, give the command.

[[Email protected]/oldboy]# tr "," "" <oldboy.txt
I am Oldboy myqq is 31333741
[Email protected]/oldboy]# tr "," "" <oldboy.txt |cut-d ""-f3,6
Oldboy 31333741
4.5 Method 4 Awk
[email protected]/oldboy]# cat Oldboy.txt
I am OLDBOY,MYQQ is 31333741
[[email protected]/oldboy]# awk-f "," ' {print $} ' Oldboy.txt
MYQQ is 31333741
#-f specifying separators (Chopper)
#-f Specifying multiple separators
[[email protected]/oldboy]# awk-f "[,]" ' {print $} ' Oldboy.txt
Oldboy

4.6 Method 5 sed sed
[[email protected]/oldboy]# CA when T Oldboy.txt
I am OLDBOY,MYQQ is 31333741
[Email protected]/oldboy]# sed ' s#i am # #g ' Oldboy.txt
OLDBOY,MYQQ is 31333741
[Email protected]/oldboy]# sed ' s#i am # #g ' oldboy.txt |sed ' s#,myqq is# #g '
Oldboy 31333741

4.6.1 Summary:
1.SED/TR + Awk/cut These two must be
2.awk

4.6.2 If you need to filter out the "oldboy,31333741" string from the file, please give the command again.

[[email protected]/oldboy]# awk-f "[,]" ' {print $ '_' $NF} ' oldboy.txt
Oldboy_31333741
[[email protected]/oldboy]# awk-f "[,]" ' {print $ ':) ' $NF} ' oldboy.txt
Oldboy:) 31333741
[Email protected]/oldboy]# awk-f "[,]" ' {print $ $ ', ' $NF} ' oldboy.txt
oldboy,31333741

4.7 Display/etc/passwd The contents of columns 1th and 3rd require the format to be displayed as:
USER: 1th Column content UID: 3rd column Content
USER: 1th Column content UID: 3rd column Content
USER: 1th Column content UID: 3rd column Content
USER: 1th Column content UID: 3rd column Content
USER: 1th Column content UID: 3rd column Content

[[email protected]/oldboy]# awk-f ":" ' {print ' USER: "$," UID: "$ $} '/etc/passwd
User:root uid:0
User:bin uid:1
User:daemon Uid:2
User:adm Uid:3
USER:LP Uid:4
User:sync Uid:5

[[email protected]/oldboy]# awk-f ":" ' {print ' USER: "$," UID: "$ $} '/etc/passwd|column-t
User:root uid:0
User:bin uid:1
User:daemon Uid:2
User:adm Uid:3
USER:LP Uid:4

Chapter 5th Question 8
14 How do I see how many lines are in the/etc/services file?
Show line numbers keep only the last line
[Email protected]/oldboy]# wc/etc/services
10774 58108 641020/etc/services
[Email protected]/oldboy]# wc-l/etc/services
10774/etc/services

5.1 Total Statistics
Count the number of files in the/etc directory that end with. conf

| The word is passed
|xargs is passing the file name

[Email protected]/oldboy]# find/etc/-type f-name "*.conf" | Wc-l
195

Chapter 6th Question 9
15 filter out the/etc/services file contains the contents of the line containing the 3306 or 15,212 digits.

Egrep "3306 or 1521"/etc/services

Egrep "3306|1521"/etc/services
MySQL 3306/tcp # mysql
MySQL 3306/udp # mysql
NCUBE-LM 1521/tcp # Ncube License Manager
NCUBE-LM 1521/udp # Ncube License Manager

| Extended Regular Expression Egrep = = Grep-e

6.1 Summary:
1.Linux Start-up process
2.PATH function
3. Find grep awk
4. Packaging compression: Create VIEW decompression decompression to XXX
5. Basic commands
6. Display Line Numbers

7th VMware Classic Failure:
The virtual machine appears to be in use.

If the virtual machine is not in use, press the Get Ownership (T) button to take ownership of it. Otherwise, press the "Cancel (C)" button to prevent damage.

Configuration file: G:\VMware\ template machine 01\ old boy Education 50-template machine 01.vmx.

Method 1: Restart the computer
Method 2. Search by everything. LCK Delete the virtual machine name. lck Directory Restart VMware

How to filter out all the first-level directories in Oldboy under the known current directory

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.