# My solutions to cmdchallenge

DevFeed: [My solutions to cmdchallenge](<https://devfeed.tech/articles/my-solutions-to-cmdchallenge-21529.md>)

Original publisher: [Read original article](<http://lifepluslinux.blogspot.com/2017/01/my-solutions-to-cmdchallenge.html>)

Author: Suresh Alse (noreply@blogger.com)

Published: 2017-01-28T16:36:00Z

Content type: tutorial

Language: en

Sources: [Life Plus Linux](<https://devfeed.tech/sources/life-plus-linux.md>)

Topics: [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Bash](<https://devfeed.tech/topics/bash.md>), [Scripting, bash](<https://devfeed.tech/topics/scripting-bash.md>), [ls](<https://devfeed.tech/topics/ls.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [files](<https://devfeed.tech/tags/files.md>), [ip](<https://devfeed.tech/tags/ip.md>), [linux](<https://devfeed.tech/tags/linux.md>), [list](<https://devfeed.tech/tags/list.md>), [search](<https://devfeed.tech/tags/search.md>)

## AI overview

The article presents Bash one-line solutions for challenges from cmdchallenge.com, covering tasks such as printing the working directory, listing files, searching logs, extracting IP addresses, deleting files, and counting files.

## Source excerpt

I recently stumbled upon https://cmdchallenge.com which sort of tests your command line knowledge and comfortability. You have to basically solve all the challenges in a single line of bash. It is pretty simple and fun. You should give it a try before checking the solutions. hello_world/ # 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! # Solution: echo "hello world" current_working_directory/ # Print the current working directory. # Solution: pwd list_files/ # List all of the files in the current # directory, one file per line. # Solution: ls -1 last_lines/ # Print the last 5 lines of "access.log". # Solution: tail -5 access.log find_string_in_a_file/ # There is a file named "access.log" in the # current working directory. Print all lines # in this file that contains the string "GET". # Solution: grep GET access.log search_for_files_containing_string/ # Print all files, one per line that contain # the string "500". # Solution: grep -rl * -e 500 search_for_files_by_extension/ # Print the relative file paths, one path # per line for all files that start with # "access.log" in the current directory. # Solution: find . -name "access.log*" search_for_string_in_files_recursive/ # 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". # Solution: find . -name "access.log*" | xargs grep -h 500 extract_ip_addresses/ # Extract all IP addreses from files that # that start with "access.log" printing one # IP address per line. # Solution: find . -name "access.log*" | xargs grep -Eo '^[^ ]+' delete_files/ # Delete all of the files in this challenge # directory including all subdirectories and # their contents. # Solution: find . -delete count_files/ # Count the number of files in the current # working directory. Print the number of # files as a single intege