logo_ironhack_blue 7

Lab | Bash

Introduction

In this lab we are going to practice with bash, a shell and command-line language!

Setup

  1. Fork the repo in your git hub account and then clone the folder "lab-bash" to your machine and navigate to it folder.

  2. Check the contents of the folder using the "ls" command

$ ls

and you should see the following:

exercises  inputs  lorem  lorem-copy  modules  outputs  README.md
  1. Stay in the same directory/folder and complete the following exercises.

Exercises

  1. Using the echo command print in console "Hello World". Here is some info about echo command [https://discuss.codecademy.com/t/what-are-practical-uses-of-the-echo-command/394788]
echo "Hello World"
  1. Create a new directory called new_dir.
$ mkdir new_dir

$ ls

exercices/  inputs/  lorem/  lorem-copy/  new_dir/  outputs/  readme.md
  1. Delete/Remove the directory new_dir.
$ rm -r new_dir/

$ ls 

exercices/  inputs/  lorem/  lorem-copy/  outputs/  readme.md
  1. Copy the file sed.txt from the lorem folder and paste it to the folder lorem-copy folder.
$ cp lorem/sed.txt lorem-copy/

$ ls lorem
at.txt  at.txte  lorem.txt  sed.txt

$ ls lorem-copy/
dummy_file.txt  sed.txt
  1. Copy the other two files from the lorem folder to lorem-copy folder in just one line using semicolon ;.
$ cp lorem/at.txt lorem-copy/; cp lorem/lorem.txt lorem-copy/ 

$ ls lorem
at.txt  at.txte  lorem.txt  sed.txt

$ ls lorem-copy/
at.txt  dummy_file.txt  lorem.txt  sed.txt
  1. Show the sed.txt file content from the lorem folder.
$ cat lorem/sed.txt
  1. Show the at.txt file and lorem.txt file contents from lorem folder.
$ cat lorem/sed.txt lorem/lorem.txt
  1. Print the first 3 rows in sed.txt file from lorem-copy folder.
$ head -n 3 lorem-copy/sed.txt
  1. Print the last 3 rows in sed.txt file from lorem-copy folder.
$ tail -n 3 lorem-copy/sed.txt
  1. Add Homo homini lupus. at the end of sed.txt file in the lorem-copy folder.
$ echo "Homo homini lupus." >> lorem-copy/sed.txt

$ tail -n 2 lorem-copy/sed.txt

vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?Homo homini lupus
Homo homini lupus.
  1. Print the last 3 rows in sed.txt file from lorem-copy folder. You should see Homo homini lupus..
$ tail -c20 lorem-copy/sed.txt

Homo homini lupus.
  1. sed command is used to replace the text in a file. Use the sed command to replace all occurances of et with ET in the file at.txt file present in the folder lorem. You can use the following link to refer to sed commands [https://www.linode.com/docs/guides/manipulate-text-from-the-command-line-with-sed/] Check the contents of the sed.txt file using cat command.
$ sed 's/et/ET/g' lorem/at.txt
  1. Find who is the system user.
$ whoami
  1. Find the current path of the directory you are in.
$ pwd

/c/Users/leo_k/Documents/Ironhack/class_1/lab-bash
  1. List all files with the extension .txt in lorem folder.
$ ls lorem/*.txt

lorem/at.txt  lorem/lorem.txt  lorem/sed.txt
  1. Count the rows in sed.txt file from lorem folder. Look concatenate cat and wc with the pipe |.
$ cat lorem/sed.txt | wc -l

9
  1. Count the files which start with lorem in all directories.
$ ls -d lorem* | wc -l

2

Bonus

  1. Store your name in a variable with read command.
$ read my_name

Leonardo
  1. Print that variable.
$ echo $my_name

Leonardo
  1. Create a new directory named with variable name.
$ mkdir $my_name

$ ls

Leonardo/  exercices/  inputs/  lorem/  lorem-copy/  outputs/  readme.md
  1. Remove that directory.
$ rm -r $my_name

$ ls

exercices/  inputs/  lorem/  lorem-copy/  outputs/  readme.md