Unix çekirdeği üzerine inşa edilen tüm işletim sistemileri bir komut işleme uygulamasına (bash) sahiptir. Linux ve macOS işletim sistemlerinde Terminal, Windows’ta ise CMD uygulaması aracılığıyla komut satırına erişilir ve sistemle ilgili birçok işlem bu uygulamalar aracılığıyla gerçekleştirilir.

Komut satırı sayesinde ön tanımlı birçok komut aracılığıyla işletim sistemini yönetmek mümkün. İşletim sistemleriyle yoğun haşır neşir olanlar bu komutları zaman içerisinde içselleştirirler ve “şu işlemi yapmak için hangi komutu yazıyorduk” şeklindeki bir soruya anında cevap verebilir hâle gelirler.

cmdchallenge.com adresinde bulunan Commanline Challenge ismindeki uygulama hem bu anlamda yeteneklerini test etmek isteyenler hem de komut satırı uygulamalarına kendini geliştirmek isteyenler için eğlenceli bir web sayfası. Adım adım verilen görevleri sağlayacak komutları yazıyorsunuz. Örneğin ilk görevde basitçe ekrana “hello world” yazmanız isteniyor. Sonrasında ise adım adım verilen görevler zorlaşıyor.

Tüm görevlere ait komutları ezbere bilmiyor olabilirsiniz. Bu sebeple her birinin cevabını aşağıda paylaşıyorum. Bu cevaplara internette arama yaparak da ulaşabilirsiniz tabii, kolaylık olsun diye hepsini bir araya topladım.

Ancak doğrudan cevapları incelemek yerine önce kendinizi zorlamanızı ve denemenizi tavsiye ederim. Baktınız olmuyor, cevaplar şöyle. 🙂

Görev #1 – Print “hello world”

  • echo "hello world"

Görev #2 – Print the current working directory

  • pwd

Görev #3 – List names of all the files in the current directory, one file per line

  • ls

Görev #4 – There is a file named access.log in the current directory. Print the contents

  • cat access.log

Görev #5 – Print the last 5 lines of “access.log”

  • tail -5 access.log

Görev #6 – 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

Görev #7 – Print all files in the current directory, one per line (not the path, just the filename) that contain the string “500”

  • grep -l '500' *

Görev #8 – Print the relative file paths, one path per line for all filenames that start with “access.log” in the current directory

  • find . -name "access.log*"

Görev #9 – 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”

  • find . -name "access.log*" | xargs grep -h 500

Görev #10 – Extract all IP addresses from files that start with “access.log” printing one IP address per line

  • find . -name "access.log*" | xargs grep -Eo '^[^ ]+'

Görev #11 – Delete all of the files in this challenge directory including all subdirectories and their contents

  • find . -delete

Görev #12 – Count the number of files in the current working directory. Print the number of files as a single integer

  • ls -l | wc -l

Görev #13 – Print the contents of access.log sorted

  • cat access.log|sort

Görev #14 – Print the number of lines in access.log that contain the string “GET”

  • grep -c 'GET' ./access.log

Görev #15 – The file split-me.txt contains a list of numbers separated by a ; character. Split the numbers on the ; character, one number per line

  • cat ./split-me.txt | sed s/\;/\\n/g

Görev #16 – Print the numbers 1 to 100 separated by spaces

  • echo {1..100}

Görev #17 – 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

Görev #18 – This challenge has text files (with a .txt extension) that contain the phrase “challenges are difficult”. Delete this phrase recursively from all text files

  • find . -name "*.txt" -exec sed -i 's/challenges are difficult//g' {} +

Görev #19 – The file sum-me.txt has a list of numbers, one per line. Print the sum of these numbers

  • awk '{s+=$1} END {print s}' sum-me.txt

Görev #20 – Print all files in the current directory recursively without the leading directory path

  • find . -type f -printf "%f\n"

Görev #21 – Rename all files removing the extension from them in the current directory recursively

  • find `pwd` -type f -exec bash -c 'mv "$1" "${1%.*}"' - '{}' \;

Görev #22 – 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

  • ls | tr ' ' '.'

Görev #23 – In this challenge there are some directories containing files with different extensions. Print all directories, one per line without duplicates that contain one or more files with a “.tf” extension

  • find . -name "*.tf" -type f -exec dirname {} \; | sort | uniq

Görev #24 – 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

  • find . -type f -name '[[:digit:]]*' -printf '%f\n'

Görev #25 – Print the 25th line of the file faces.txt

  • sed -n '25p' faces.txt

Görev #26 – Print the lines of the file reverse-me.txt in this directory in reverse line order so that the last line is printed first and the first line is printed last

  • tac reverse-me.txt

Görev #27 – 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

  • awk '!x[$0]++' faces.txt

Görev #28 – The file “table.csv” contains the following comma-separated lines:

id,name,count

4,susan,11

33,alice,22

1772,joe,33

Print the rows as a table, like the following:

id name count

4 susan 11

33 alice 22

1772 joe 33

  • cat table.csv | column -t -s","

Görev #29 – The file random-numbers.txt contains a list of 100 random integers. Print the number of unique prime numbers contained in the file

  • for num in $(cat random-numbers.txt); do [[ $num == $(factor $num | cut -d" " -f2) ]] && echo $num; done | sort | uniq | wc -l

Görev #30 – access.log.1 and access.log.2 are http server logs. Print the IP addresses common to both files, one per line

  • comm -12 <(cut -d' ' -f1 access.log.1 | sort) <(cut -d' ' -f1 access.log.2 | sort)

Görev #31 – Print all matching lines (without the filename or the file path) in all files under the current directory that start with “access.log”, where the next line contains the string “404”

  • awk '/404/{print a}{a=$0}' **/access.log*

Görev #32 – Print all files with a .bin extension in the current directory that are different than the file named base.bin

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

Görev #33 – There is a file: ./…/ /. .the flag.txt Show its contents on the screen

  • cat ./.../\ \ /.\ .the\ flag.txt

Görev #34 – How many lines contain tab characters in the file named file-with-tabs.txt in the current directory

  • grep -P '\t' file-with-tabs.txt | wc -l

Görev #35 – 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

  • find . -type f -regextype posix-extended ! -regex ".*(\.txt|\.exe)$" -exec rm {} +

Görev #36 – There are some files in this directory that start with a dash in the filename. Remove those files

  • rm ./-* -

Görev #37 – There are two files in this directory, ps-ef1 and ps-ef2. Print the contents of both files sorted by PID and delete repeated lines

  • cat ps-ef1 > aux; sed '1 d' ps-ef2 >> aux; cat aux | sort -nk2,2 | uniq

Görev #38 – In the current directory there is a file called netstat.out. Print all the IPv4 listening ports sorted from the higher to lower

  • egrep "tcp\ .*:**LISTEN" netstat.out | awk '{print $4}' | sed -e 's/.*\://g' | sort -nr

Yazar Hakkında

Muhammed Tutar

bilgisayar mühendisi, bilgi güvenliği uzmanı. önce okur, sonra yazar.

Tüm yazıları göster