cmd/bash/linux tantangan

0
173

jika kamu hobi berkutat dengan linux kamu bisa coba tantangan ini

berikut adalah berbagai tantangan yang dapat kamu coba di situs tantangan tersebut. (ups ini bocoran jawabnya hehe)

########## START BEGINNER

description: |

Print “hello world”.
Hint: There are many ways to print text on
the command line, one way is with the ‘echo’
command.

example: echo ‘hello world’

description: |
Print the current working directory.

example: pwd

description: |
List names of all the files in the current
directory, one file per line.

example: ls

description: |
List all of the files in the current directory, display a slash (`/’) immediately after
each pathname that is a directory, an asterisk (`*’) after each that is executable,
an at sign (`@’) after each symbolic link. Output one file per line.
Hint: directories are suffixed with ‘/’, executables with ‘*’.
You will need to restrict the number of columns too.

example: ls -laF -C1

description: |
There is a file:
./…/ /. .the flag.txt
Show its contents on the screen.
example: cat ./…/\ \ /.\ .the\ flag.txt

description: |
There is a file named “access.log” in the
current directory. Print the contents.

example: cat access.log
description: |
Print the last 5 lines of “access.log”.
example: tail -n 5 access.log

description: |
There is a file named “access.log” in the
current working directory. Print all lines
in this file that contains the string “GET”.
example: grep ‘GET’ access.log

description: |
How many lines contain tab characters in
the file named “file-with-tabs.txt” in the
current directory.

example: grep -P ‘\t’ file-with-tabs.txt | wc -l

description: |
Print all files in the current directory,
one per line (not the path, just the filename)
that contain the string “500”.

example: grep -l 500 *
description: |
Print the relative file paths, one path
per line for all filenames that start with
“access.log” in the current directory.

example: find . -name ‘access.log*’

description: |
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.
example: grep -h 500 **/access.log*

description: |
Extract all IP addreses from files
that start with “access.log” printing one
IP address per line.
example: grep -Pho ‘^\d+\.\d+\.\d+\.\d+’ **/access.log*

description: |
Delete all of the files in this challenge
directory including all subdirectories and
their contents.

example: find . -delete

description: |
Count the number of files in the current
working directory. Print the number of
files as a single integer.

example: ls | wc -l

description: |
Print the contents of access.log
sorted.

example: sort access.log

description: |
Print the number of lines
in access.log that contain the string
“GET”.

example: grep -c “GET” access.log

description: |
The file split-me.txt contains a list of
numbers separated by a ‘;’ character.
Split the numbers on the ‘;’ character,
one number per line.
example: tr ‘;’ ‘\n’ < split-me.txt

description: |
Print the numbers 1 to 100 separated
by spaces.
example: echo $(seq 1 100)

description: |
There are some files in this directory that
start with a dash in the filename.
Remove those files.
example: rm ./-*

description: |
There are files in this challenge with
different file extensions.
Remove all files with the .doc extension
recursively in the current working directory.

example: rm **/*.doc

description: |
There are files in this challenge with
different file extensions.
Remove all files without the .txt and .exe extensions
recursively in the current working directory.
example: find . -type f -regextype posix-extended ! -regex “.*(\.txt|\.exe)$” -exec rm {} +

########## END BEGINNER

########### START INTERMEDIATE
description: |
This challenge has text files (with a .txt extension)
that contain the phrase “challenges are difficult”.
Delete this phrase recursively from all text files.
Note that some files are in subdirectories so you will
need to search for them.

example: paste -sd+ sum-me.txt | bc
description: |
Print all files in the current directory
recursively without the leading directory path.

example: find -type f -printf ‘%f\n’

description: |
Rename all files removing the extension from
them in the current directory recursively.

example: for f in $(find . -type f -name “*.*”); do mv “$f” “${f%.*}”; done

description: |
The files in this challenge contain spaces.
List all of the files (filenames only) in the
current directory but replace all spaces with
a ‘.’ character.

example: ls | tr ‘ ‘ ‘.’

description: |
There are a mix of files in this directory
that start with letters and numbers. Print
the filenames (just the filenames) of all
files that start with a number recursively
in the current directory.
example: find . -type f -name ‘[[:digit:]]*’ -printf ‘%f\n’

description: |
Print the 25th line of the file faces.txt

example: sed -n ’25p’ faces.txt

description: |
Print the file faces.txt, but only print the first instance of each
duplicate line, even if the duplicates don’t appear next to each other.
Note that order matters so don’t sort the lines before removing duplicates.

example: awk ‘!x[$0]++’ faces.txt

disp_title: Removing extra ‘!’ characters from text

example: perl -pne ‘s/!(?![ \n])//g;’ war_and_peace.txt | perl -pne ‘s/(?<=[.])!//g’ | perl -pne ‘s/!(?= [a-z])//g’

description: |
The following excerpt from War and Peace is saved to
the file ‘war_and_peace.txt’:

She is betraying us! Russia alone must save Europe.
Our gracious sovereign recognizes his high vocation
and will be true to it. That is the one thing I have
faith in! Our good and wonderful sovereign has to
perform the noblest role on earth, and he is so virtuous
and noble that God will not forsake him. He will fulfill
his vocation and crush the hydra of revolution, which
has become more terrible than ever in the person of this
murderer and villain!

The file however has been corrupted, there are random ‘!’
marks inserted throughout. Print the original text.

example: “comm -12 <(cut -d’ ‘ -f1 access.log.1 | sort) <(cut -d’ ‘ -f1 access.log.2 | sort)”

description: |
access.log.1 and access.log.2 are http server logs. Print the IP
addresses common to both files, one per line.

example: “for i in $(ls *.bin); do if [[ `cmp base.bin $i` ]]; then echo $i; fi; done”

Terimakasih untuk https://cmdchallenge.com/

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments