Notification texts go here Contact Us Buy Now!

[Writeup] Command Challenge!

cmdchallenge.com

Gần đây tôi biết đến một trang web thú vị là Command Challenge. Đúng như tên gọi của nó, trang này có những thử thách dưới dạng dòng lệnh Bash Shell. Vừa hay tôi cũng đang tìm hiểu về Bash Shell vì vậy mà tôi sẽ viết writeup để lưu giữ những kiến thức đã học được.

1. Your first challenge is to print “hello world” on the terminal in a single command.
echo "hello world"
Kết quả:
hello world

2. Print the current working directory.
pwd
Kết quả:
/var/challenges/current_working_director

3. List names of all the files in the current directory, one file per line.
ls
Kết quả:
01-take.txt
02-the.txt
03-command.txt
04-challenge.txt

4. There is a file named access.log in the current directory. Print the contents.
cat access.log
Kết quả:
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

5. Print the last 5 lines of "access.log".
tail -5 access.log
Kết quả:
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

6. Create an empty file named take-the-command-challenge in the current working directory.
touch take-the-command-challenge

7. Create a directory named tmp/files in the current working directory

Hint: The directory tmp/" doesn't exist, with one command you need to create both "tmp/" and "
tmp/files"
mkdir -p tmp/files

8. Copy the file named take-the-command-challenge to the directory tmp/files
cp take-the-command-challenge tmp/files/take-the-command-challenge

9. Move the file named take-the-command-challenge to the directory tmp/files
mv take-the-command-challenge tmp/files/take-the-command-challenge
10. A symbolic link is a type of file that is a reference to another file.

Create a symbolic link named take-the-command-challenge that points to the file tmp/files/take-the-command-challenge.
ln -s tmp/files/take-the-command-challenge "take-the-command-challenge"

11. Delete all of the files in this challenge directory including all subdirectories and their contents.

Hint: There are files and directories that start with a dot ".", "rm -rf *" won't work here!
find -delete
12. There are files in this challenge with different file extensions. Remove all files with the .doc extension recursively in the current working directory.
find . -name "*.doc" -delete
13. There is a file named access.log in the current working directory. Print all lines in this file that contains the string "GET".
grep GET access.log
Kết quả:
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

14. Print all files in the current directory, one per line (not the path, just the filename) that contain the string "500".
grep -l 500 *
Kết quả:
access.log
access.log.1

15. Print the relative file paths, one path per line for all filenames that start with "access.log" in the current directory.
ls
Kết quả:
access.log
access.log.1
access.log.2

16. 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.
grep -rh 500
Kết quả:
69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/tạo 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/trang/tạo HTTP/1.0" 500 2477

17. Extract all IP addresses from files that start with "access.log" printing one IP address per line.
grep -ro ^[0-9.]*
Kết quả:
var/log/httpd/access.log:163.56.115.58
var/log/httpd/access.log:75.113.188.234
var/log/httpd/access.log:69.16.40.148
var/log/httpd/access.log:225.219.54.140
var/log/httpd/access.log:207.243.19.2
var/log/httpd/access.log:199.37.62.156
var/log/httpd/access.log:55.74.240.123
var/log/httpd/access.log:251.111.109.143
var/log/httpd/access.log:101.163.230.250
var/log/httpd/access.log:200.19.168.148
var/log/httpd/access.log.1:108.68.174.15
var/log/httpd/access.log.1:17.2.20.139
var/log/httpd/access.log.1:28.151.137.59
var/log/httpd/access.log.1:199.150.241.179
var/log/httpd/access.log.1:2.71.250.27
var/log/httpd/access.log.1:17.137.186.194
var/log/httpd/access.log.1:151.84.119.34
var/log/httpd/access.log.1:4.180.204.195
var/log/httpd/access.log.1:9.230.96.54
var/log/httpd/access.log.1:157.143.233.21

18. Count the number of files in the current working directory. Print the number of files as a single integer.
grep -ro ^[0-9.]*
Kết quả: Correct!

19. Print the contents of access.log sorted.
sort access.log
Kết quả:
101.163.230.250 - - [09/Jan/2017:22:52:31 +0100] "DELETE /posts/2/display HTTP/1.0" 404 2477
163.56.115.58 - - [09/Jan/2017:22:29:57 +0100] "GET /posts/2/display HTTP/1.0" 200 3240
199.37.62.156 - - [09/Jan/2017:22:42:18 +0100] "GET /posts/1/display 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
207.243.19.2 - - [09/Jan/2017:22:38:03 +0100] "GET /bar/create HTTP/1.0" 200 1116
225.219.54.140 - - [09/Jan/2017:22:35:30 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 500 2477
251.111.109.143 - - [09/Jan/2017:22:49:02 +0100] "GET /posts/foo?appID=xxxx 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
69.16.40.148 - - [09/Jan/2017:22:34:33 +0100] "GET /pages/create HTTP/1.0" 500 3471
75.113.188.234 - - [09/Jan/2017:22:30:43 +0100] "GET /posts/foo?appID=xxxx HTTP/1.0" 200 1116


20. Print the number of lines in access.log that contain the string "GET".
grep -ro ^[0-9.]*
Kết quả: 













Đăng nhận xét

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.