Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@LeeXun
Last active February 6, 2017 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeeXun/f2208682dc8daa300a16eb5c6599ff71 to your computer and use it in GitHub Desktop.
Save LeeXun/f2208682dc8daa300a16eb5c6599ff71 to your computer and use it in GitHub Desktop.
@LeeXun
Copy link
Author

LeeXun commented Feb 6, 2017

hello_world/

echo "hello world"

current_working_directory/

echo $PWD || pwd

list_files/

ls -1

print_file_contents/

cat access.log

last_lines/

tail -5 access.log

find_string_in_a_file/

grep GET access.log

find_tabs_in_a_file/

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

search_for_files_containing_string/

grep -rl * -e 500

search_for_files_by_extension/

find . -name "access.log*"

search_for_string_in_files_recursive/

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

extract_ip_addresses/

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

delete_files/

find . | xargs rm -rf

count_files/

ls | wc -l

simple_sort/

sort access.log

count_string_in_line/

grep access.log -e "GET" | wc -l

split_on_a_char/

cat split-me.txt | tr ';' '\n'

print_number_sequence/

echo {1..100} || printf "%d " {1..100}

remove_files_with_a_dash/

find -name "-*" | xargs rm -f

remove_files_with_extension/

find . -name "*.doc" | xargs rm

remove_files_without_extension/

find . ! -name ".exe" ! -name ".txt" | xargs rm -f

replace_text_in_files

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

sum_all_numbers

awk '{s+=$1} END {print s}'

just_the_files

find -type f -not -name "." | rev | cut -d '/' -f 1 | rev

remove_extensions_from_files

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

replace_spaces_in_filenames/

ls | xargs -0 -I {} echo {} | tr ' ' '.'

files_starting_with_a_number/

find . -name '[0-9]*' -type f -printf "%f\n"

print_nth_line/

sed '25p;d' faces.txt

remove_duplicate_lines/

awk '!a[$0]++' faces.txt

corrupted_text/

print_common_lines/

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment