Skip to content

Latest commit

 

History

History

0x02-shell_redirections

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

img

shell I/O redirections and filters

Intro

Deep dive into shell I/O redirection, special characters and filters

Resources

  1. Shell IO
  2. Special characters

Man or Help

  • echo
  • cat
  • head
  • tail
  • find
  • wc
  • sort
  • uniq
  • grep
  • tr
  • rev
  • cut
  • passwd (5) (i.e. man 5 passwd)

Learning objectives

By the end of this project, you should be able to explain to anyone Without the help of google the following concepts

Shell I/O redirection

  • What do the commands head, tail, find, wc, sort, uniq, grep, tr do
  • How to redirect standard output to a file
  • How to get standard input from a file instead of the keyboard
  • How to send the output from one program to the input of another program
  • How to combine commands and filters with redirections

Special characters

  • What are special characters
  • Understand what do the white spaces, single quotes, double quotes, backslash, comment, pipe, command separator, tilde and how and when to use them

Other man pages

  • How to display a line of text
  • How to concatenate files and print on the standard output
  • How to reverse a string
  • How to remove sections from each line of files
  • What is the /etc/passwd file and what is its format
  • What is the /etc/shadow file and what is its format

More info

Read your /etc/passwd and /etc/shadow files.

Note: You do not have to learn about fmt, pr, du, gzip, tar, lpr, sed and awk yet.

Tasks

  1. Hello World : A script that prints Hello, World, followed by a new line to the standard output.
  2. Confused smiley : A script that displays a confused smiley: "(Ôo)'.
  3. Let's display a file : A script that displays the content of the /etc/passwd file.
  4. What about 2? : A scipt that displays content of /etc/passwd and /etc/hosts.
  5. Last lines of a file : A script that displays the last 10 lines of /etc/passwd.
  6. I'd prefer the first ones actually : A scipt that displays the first 10 lines of etc/passwd.
  7. Line #2 : A script that displays the third line of the file iacta.
    • The file iacta will be in the working directory and you are not allowed to use sed.
  8. It is a good file that cuts iron without making a noise : A script that creates a file named exactly \*\\'"Holberton School"\'\\*$\?\*\*\*\*\*:) containing the text Holberton School ending by a new line.
    • For this challenge, remember to use a single backslash \ to escape special characters and double backslash \\ to escape the backslash itself.
  9. Save current state of directory : A script that writes into the file ls_cwd_content the result of the command ls -la. If the file ls_cwd_content already exists, it should be overwritten. If the file ls_cwd_contentdoes not exist, create it.
  10. Duplicate last line : A script that duplicates the last line of the file iacta.
  11. No more javascript : A script that deletes all the regular files (not the directories) with a .js extension that are present in the current directory and all its subfolders.
  12. Don't just count your directories, make your directories count : A script that counts the number of directories and sub-directories in the current directory.
    • The current and present directories should not be taken into account.
    • Hidden directories should be counted.
      • Solution: mindepth 1 ; To exclude root directory
      • Others: maxdepth 1 ; To avoid parsing sub directories. (you may need this in future.)
  13. Whats12's new : A script that prints the 10 newest files in the current directory.
    • The output should be; one file per line and sorted from the newest to the oldest.
  14. Being unique is better than being perfect : A script that takes a list of words as input and prints only words that appear exactly once.
    • Input and Output format is; One word per line.
    • Words should be sorted. (use this list as your input to see if the challenge will work. 😊) cat list | ./13-unique
  15. It must be in that file : A script that prints lines containing the pattern "root" from the file /etc/passwd.
  16. Count that word : A script that displays the number of lines that contain the pattern "bin" in the file /etc/passwd.
  17. What's next? : A script that containing the pattern "root" and 3 lines after them in the file /etc/passwd.
    • B : This shows the lines before your pattern match.
    • A : This shows the lines after your pattern match.
  18. I hate bins : A script that displays all the lines in the file /etc/passwd that do not contain the pattern "bin".
  19. Letters only please : A script that displays all lines of the file /ect/ssh/sshd_config starting with a letter, including capital letters as well.
    • This also works : grep ^[[:alpha:]] /etc/ssh/sshd_config
  20. A to Z : A script that replaces all characters A and C from input to Z and E respectively.
  21. Without C, you would live in hiago : A script that removes all letters c and C from input.
  22. esreveR : A script that reverse its input.
  23. DJ Cut Killer : A scipt that displays all users and their home directories, sorted by users, based on the /etc/passwd file.
  24. Empty casks make the most noise : A script that finds all empty files and directories in the current directory and all sub-directories.
    • Only names of the files and directories should be displayed (not the entire path.)
    • Hidden files should be listed also, one file name per line and the listing should end with a new line.
    • You are not allowed to use basename, grep, egrep, fgrep or rgrep.
  25. A gif is worth ten thousand words : A script that lists all the files with a .gif extension in the current directory and all its sub-directories.
    • Hidden files should be listed.
    • Only regular files (not directories) should be listed.
    • The names of the files should be displayed without their extensions.
    • The files should be sorted by byte values, but case-insensitive (file aaa should be listed before file bbb, file .b should be listed before file a, and file Rona should be listed after file jay)
    • One file name per line.
    • The listing should end with a new line.
    • You are not allowed to use basename, grep, egrep, fgrep or rgrep.
  26. Acrostic : A script that decodes acrostics that use the first letter of each line.
    • What to decode: An acrostic is a poem (or other form of writing) in which the first letter (or syllable, or word) of each line (or paragraph, or other recurring feature in the text) spells out a word, message or the alphabet. The word comes from the French acrostiche from post-classical Latin acrostichis). As a form of constrained writing, an acrostic can be used as a mnemonic device to aid memory retrieval. Read more here
    • The ‘decoded’ message has to end with a new line.
    • You are not allowed to use grep, egrep, fgrep or rgrep.
  27. The biggest fan : A script that parses web servers logs in TSV format as input and displays the 11 hosts or IP addresses which did the most requests.
    • Download this file: wget http://indeedeng.github.io/imhotep/files/nasa_19950801.tsv
    • Run command this way: ./103-the_biggest_fan < nasa_19950801.tsv.
    • Order by number of requests, most active host or IP at the top.
    • You are not allowed to use grep, egrep, fgrep or rgrep.