In this lab we are going to practice with bash
, a shell and command-line language!
-
Fork the repo in your git hub account and then clone the folder "lab-bash" to your machine and navigate to it folder.
-
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
- Stay in the same directory/folder and complete the following exercises.
- 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"
- Create a new directory called
new_dir
.
$ mkdir new_dir
$ ls
exercices/ inputs/ lorem/ lorem-copy/ new_dir/ outputs/ readme.md
- Delete/Remove the directory
new_dir
.
$ rm -r new_dir/
$ ls
exercices/ inputs/ lorem/ lorem-copy/ outputs/ readme.md
- Copy the file
sed.txt
from thelorem
folder and paste it to the folderlorem-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
- Copy the other two files from the
lorem folder
tolorem-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
- Show the
sed.txt
file content from thelorem
folder.
$ cat lorem/sed.txt
- Show the
at.txt
file andlorem.txt
file contents fromlorem
folder.
$ cat lorem/sed.txt lorem/lorem.txt
- Print the first 3 rows in
sed.txt
file from lorem-copy folder.
$ head -n 3 lorem-copy/sed.txt
- Print the last 3 rows in
sed.txt
file from lorem-copy folder.
$ tail -n 3 lorem-copy/sed.txt
- Add
Homo homini lupus.
at the end ofsed.txt
file in thelorem-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.
- Print the last 3 rows in
sed.txt
file fromlorem-copy
folder. You should seeHomo homini lupus.
.
$ tail -c20 lorem-copy/sed.txt
Homo homini lupus.
sed
command is used to replace the text in a file. Use thesed
command to replace all occurances ofet
withET
in the fileat.txt
file present in the folderlorem
. You can use the following link to refer tosed
commands [https://www.linode.com/docs/guides/manipulate-text-from-the-command-line-with-sed/] Check the contents of the sed.txt file usingcat
command.
$ sed 's/et/ET/g' lorem/at.txt
- Find who is the system user.
$ whoami
- Find the current path of the directory you are in.
$ pwd
/c/Users/leo_k/Documents/Ironhack/class_1/lab-bash
- List all files with the extension
.txt
in lorem folder.
$ ls lorem/*.txt
lorem/at.txt lorem/lorem.txt lorem/sed.txt
- Count the rows in
sed.txt
file from lorem folder. Look concatenatecat
andwc
with the pipe|
.
$ cat lorem/sed.txt | wc -l
9
- Count the files which start with
lorem
in all directories.
$ ls -d lorem* | wc -l
2
- Store your
name
in a variable withread
command.
$ read my_name
Leonardo
- Print that variable.
$ echo $my_name
Leonardo
- Create a new directory named with variable
name
.
$ mkdir $my_name
$ ls
Leonardo/ exercices/ inputs/ lorem/ lorem-copy/ outputs/ readme.md
- Remove that directory.
$ rm -r $my_name
$ ls
exercices/ inputs/ lorem/ lorem-copy/ outputs/ readme.md