暗无天日

=============>DarkSun的个人博客

Bash挑战赛

发现一个网站 https://cmdchallenge.com 可以在线测试你的 shell 能力,我居然卡在了删除文件那一节了,有大神帮忙吗 :(

下面是我的解答过程

On your way to becoming a super-duper commandline hacker.
Test failed, files or directories remain. - try again
# Print "hello world".
# Hint: There are many ways to print text on
# the command line, one way is with the 'echo'
# command.
# 
# Try it below and good luck!
# 
bash(0)> echo hello world
hello world
# 👍 👍 👍  Correct!
# You have a new challenge!
# Print the current working directory.
# 
bash(0)> pwd
/var/challenges/current_working_directory
# 👍 👍 👍  Correct!
# You have a new challenge!
# List names of all the files in the current
# directory, one file per line.
# 
bash(0)> ls -l
total 8
-rw-r--r--. 1 501 dialout 107 Apr 29 17:44 README
bash(0)> ls
README
# 👍 👍 👍  Correct!
# You have a new challenge!
# There is a file named "access.log" in the
# current directory. Print the contents.
# 
bash(0)> cat access.log
163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
# 👍 👍 👍  Correct!
# You have a new challenge!
# Print the last 5 lines of "access.log".
# 
bash(0)> tail -5 access.log
199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
# 👍 👍 👍  Correct!
# You have a new challenge!
# There is a file named "access.log" in the
# current working directory. Print all lines
# in this file that contains the string "GET".
# 
bash(0)> grep GET access.log
163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
# 👍 👍 👍  Correct!
# You have a new challenge!
# Print all files in the current directory,
# one per line (not the path, just the filename)
# that contain the string "500".
# 
bash(0)> grep -l 500 *
README
access.log
access.log.1
# 👍 👍 👍  Correct!
# You have a new challenge!
# Print the relative file paths, one path
# per line for all filenames that start with
# "access.log" in the current directory.
# 
bash(0)> ls access.log*
access.log
access.log.1
access.log.2
# 👍 👍 👍  Correct!
# You have a new challenge!
# Print all matching lines (without the filename
# or the file path) in all files under the current
# directory that start with "access.log" that
# contain the string "500". Note that there are no
# files named "access.log" in the current directory,
# you will need to search recursively.
# 
bash(0)> find . -name "access.log*" |xargs -I{} grep 500 {}
Docker connection error
bash(☠️)> find . -name "access.log*" |xargs -I{} grep 500 {}
Docker connection error
bash(☠️)> find . -name "access.log*" -e
Docker connection error
bash(☠️)> find . -name "access.log*" -exec grep 500 
find: missing argument to `-exec'
bash(1)> find . -name "access.log*" -exec grep 500 \;
bash(0)> find . -name "access.log*" -exec grep 500 \;
bash(0)> find . -name "access.log*"
./var/log/httpd/access.log.2
./var/log/httpd/access.log
./var/log/httpd/access.log.1
bash(0)> find . -name "access.log*" -exec grep 500 {} \;
69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
2.71.250.27 - - [09/Jan/2017:22:41:26 +0100] "GET /pages/create HTTP/1.0" 500 2477
# 👍 👍 👍  Correct!
# You have a new challenge!
# Extract all IP addresses from files
# that start with "access.log" printing one
# IP address per line.
# 
bash(0)> find . -name "access.log*" -exec grep -E -o "[0-9]*\.[0-9]*\.[0-9]*\."
Docker connection error
bash(☠️)> find . -name "access.log*" -exec grep -E -o "[0-9]*\.[0-9]*\.[0-9]*\." {} \;
Docker connection error
bash(☠️)> 
bash(☠️)> 
bash(☠️)> 
bash(☠️)> find . -name "access.log*" -exec grep -E -o "[0-9]*" {} \;
Docker connection error
bash(☠️)> find . -name "access.log*"
./var/log/httpd/access.log
./var/log/httpd/access.log.1
bash(0)> find . -name "access.log*" -exec grep -E -o "[0-9]" {} \;
Docker connection error
bash(☠️)> find . -name "access.log*" -exec grep -E "[0-9]" {} \;
163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
108.68.174.15 - - [09/Jan/2017:22:32:19 +0100] "GET /foo/create HTTP/1.0" 200 2477
17.2.20.139 - - [09/Jan/2017:22:33:48 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
28.151.137.59 - - [09/Jan/2017:22:37:57 +0100] "GET /foo/create HTTP/1.0" 200 1116
199.150.241.179 - - [09/Jan/2017:22:38:34 +0100] "GET /bar/create HTTP/1.0" 200 3240
2.71.250.27 - - [09/Jan/2017:22:41:26 +0100] "GET /pages/create HTTP/1.0" 500 2477
17.137.186.194 - - [09/Jan/2017:22:43:17 +0100] "GET /pages/create HTTP/1.0" 200 1116
151.84.119.34 - - [09/Jan/2017:22:47:51 +0100] "GET /posts/1/display HTTP/1.0" 404 3471
4.180.204.195 - - [09/Jan/2017:22:49:53 +0100] "GET /foo/create HTTP/1.0" 502 1116
9.230.96.54 - - [09/Jan/2017:22:52:58 +0100] "GET /bar/create HTTP/1.0" 200 1116
157.143.233.21 - - [09/Jan/2017:22:53:50 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 502 1083
bash(0)> find . -name "access.log*" -exec grep -E "[0-9]*\." {} \;
Docker connection error
bash(☠️)> find . -name "access.log*" -exec grep -E "[0-9]*." {} \;
Docker connection error
bash(☠️)> find . -name "access.log*" -exec grep -E "[0-9]*" {} \;
Docker connection error
bash(☠️)> find . -name "access.log*" -exec grep -E "[0-9]{1,3}" {} \;
108.68.174.15 - - [09/Jan/2017:22:32:19 +0100] "GET /foo/create HTTP/1.0" 200 2477
17.2.20.139 - - [09/Jan/2017:22:33:48 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
28.151.137.59 - - [09/Jan/2017:22:37:57 +0100] "GET /foo/create HTTP/1.0" 200 1116
199.150.241.179 - - [09/Jan/2017:22:38:34 +0100] "GET /bar/create HTTP/1.0" 200 3240
2.71.250.27 - - [09/Jan/2017:22:41:26 +0100] "GET /pages/create HTTP/1.0" 500 2477
17.137.186.194 - - [09/Jan/2017:22:43:17 +0100] "GET /pages/create HTTP/1.0" 200 1116
151.84.119.34 - - [09/Jan/2017:22:47:51 +0100] "GET /posts/1/display HTTP/1.0" 404 3471
4.180.204.195 - - [09/Jan/2017:22:49:53 +0100] "GET /foo/create HTTP/1.0" 502 1116
9.230.96.54 - - [09/Jan/2017:22:52:58 +0100] "GET /bar/create HTTP/1.0" 200 1116
157.143.233.21 - - [09/Jan/2017:22:53:50 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 502 1083
163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
bash(☠️)> find . -name "access.log*" -exec grep -Eo "[0-9]{1,3}" {} \;
163
56
115
58
09
201
7
22
29
57
010
0
2
1
0
200
324
0
75
113
188
234
09
201
7
22
30
43
010
0
1
0
200
111
6
69
16
40
148
09
201
7
22
34
33
010
0
1
0
500
347
1
225
219
54
140
09
201
7
22
35
30
010
0
1
0
500
247
7
207
243
19
2
09
201
7
22
38
03
010
0
1
0
200
111
6
199
37
62
156
09
201
7
22
42
18
010
0
1
1
0
200
247
7
55
74
240
123
09
201
7
22
44
25
010
0
1
1
0
200
347
1
251
111
109
143
09
201
7
22
49
02
010
0
1
0
200
247
7
101
163
230
250
09
201
7
22
52
31
010
0
2
1
0
404
247
7
200
19
168
148
09
201
7
22
57
11
010
0
1
0
200
347
1
108
68
174
15
09
201
7
22
32
19
010
0
1
0
200
247
7
17
2
20
139
09
201
7
22
33
48
010
0
1
0
200
247
7
28
151
137
59
09
201
7
22
37
57
010
0
1
0
200
111
6
199
150
241
179
09
201
7
22
38
34
010
0
1
0
200
324
0
2
71
250
27
09
201
7
22
41
26
010
0
1
0
500
247
7
17
137
186
194
09
201
7
22
43
17
010
0
1
0
200
111
6
151
84
119
34
09
201
7
22
47
51
010
0
1
1
0
404
347
1
4
180
204
195
09
201
7
22
49
53
010
0
1
0
502
111
6
9
230
96
54
09
201
7
22
52
58
010
0
1
0
200
111
6
157
143
233
21
09
201
7
22
53
50
010
0
1
0
502
108
3
bash(0)> find . -name "access.log*" -exec grep -Eo "[0-9]{1,3}." {} \;
Docker connection error
bash(☠️)> find . -name "access.log*" -exec grep -Eo "[0-9]{1,3}\." {} \;
Docker connection error
bash(☠️)> find . -name "access.log*" -exec grep -E "[0-9]{1,3}" {} \;
108.68.174.15 - - [09/Jan/2017:22:32:19 +0100] "GET /foo/create HTTP/1.0" 200 2477
17.2.20.139 - - [09/Jan/2017:22:33:48 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
28.151.137.59 - - [09/Jan/2017:22:37:57 +0100] "GET /foo/create HTTP/1.0" 200 1116
199.150.241.179 - - [09/Jan/2017:22:38:34 +0100] "GET /bar/create HTTP/1.0" 200 3240
2.71.250.27 - - [09/Jan/2017:22:41:26 +0100] "GET /pages/create HTTP/1.0" 500 2477
17.137.186.194 - - [09/Jan/2017:22:43:17 +0100] "GET /pages/create HTTP/1.0" 200 1116
151.84.119.34 - - [09/Jan/2017:22:47:51 +0100] "GET /posts/1/display HTTP/1.0" 404 3471
4.180.204.195 - - [09/Jan/2017:22:49:53 +0100] "GET /foo/create HTTP/1.0" 502 1116
9.230.96.54 - - [09/Jan/2017:22:52:58 +0100] "GET /bar/create HTTP/1.0" 200 1116
157.143.233.21 - - [09/Jan/2017:22:53:50 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 502 1083
163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116
69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display HTTP/1.0" 200 2477
55.74.240.123 - - [09/Jan/2017:22:44:25 +0100] "POST /posts/1/display HTTP/1.0" 200 3471
251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 2477
101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
200.19.168.148 - - [09/Jan/2017:22:57:11 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 3471
bash(0)> find . -name "access.log*" -exec awk '{print $1}' {} \;
163.56.115.58
75.113.188.234
69.16.40.148
225.219.54.140
207.243.19.2
199.37.62.156
55.74.240.123
251.111.109.143
101.163.230.250
200.19.168.148
108.68.174.15
17.2.20.139
28.151.137.59
199.150.241.179
2.71.250.27
17.137.186.194
151.84.119.34
4.180.204.195
9.230.96.54
157.143.233.21
# 👍 👍 👍  Correct!
# You have a new challenge!
# Delete all of the files in this challenge
# directory including all subdirectories and
# their contents.
# 
bash(0)> rm -rf *
bash(0)> cd ..
bash(1)> rm -rf *
bash(☠️)> rm -rf * ;ls
Docker connection error
bash(0)> rm -r *
bash(0)> sudo rm *
sudo: command not found
bash(127)> 
rm -rf ../*

我在执行 rm -rf ../* 后发现似乎卡死了,好无奈啊。。。

另外有一点需要注意的是,你的答案只能是一条命令,每次命令执行后就会检查结果,若结果不符合条件则会还原环境。