Let's practice with bash, a programming language that runs on the command line!
Open the jupyter notebook in this folder named solutions.ipynb and type in the exercise titles in one cell, and in another cell the command you used to solve the exercises.
- Go to the folder where you are running in the terminal. When you run
ls
$ ls- You should see:
README.md lorem solutions.ipynb- Try to do all the exercises without changing directories.
-
Print
Hello Worldon console. -
Create a new directory named
new_dir. -
Delete that directory.
-
Copy the
sed.txtfile inside the lorem folder to the lorem-copy folder. TIP: It may be necessary to create the lorem-copy folder first. -
Copy the other two files from the lorem folder to the lorem-copy folder in a single line.
-
Displays the contents of the
sed.txtfile inside the lorem folder. -
Displays the contents of the
at.txtandlorem.txtfiles inside the lorem folder. -
Displays the first 3 lines of the
sed.txtfile inside the lorem-copy folder. -
Display the last 3 lines of the file
sed.txtinside the lorem-copy folder. -
Adds
Homo homini lupus.to the end of filesed.txtinside the lorem-copy folder. -
Display the last 3 lines of the
sed.txtfile inside the lorem-copy folder. You should now seeHomo homini lupus.. -
Replace all occurrences of
etwithETfrom theat.txtfile inside the lorem-copy folder. You must usesed. -
Find the active user on the system.
-
Find where you are on your file system.
-
List the files ending with
.txtin the lorem folder. -
Count the number of lines that the file
sed.txthas inside the lorem folder. -
Counts the number of files beginning with
loremthat are in this directory and in internal directories. -
Find all occurrences of
etinat.txtinside the lorem folder. -
Count the number of occurrences of the string
etinat.txtinside the lorem folder. -
Count the number of occurrences of the string
etin all files in the lorem-copy directory.
Any bash command or commands can be stored in a file and executed whenever you want. Obviously you can use your favorite editor. We create the file:
$ touch list_files.sh
And we include the content we want. In this case list files:
#!/bin/bash
lsRun the script:
$ bash list_files.sh
And we will see by console the following output.
README.md lorem solutions.ipynb-
Store in a variable
nameyour name. -
Print that variable.
-
Create a new directory named after the contents of the
namevariable. -
Delete that directory.
-
Displays the processes in hierarchical form that are running on your computer:
- using the top or htop command.
- Using the ps command with arguments
-
Display information about your processor on the screen
-
Create 3 aliases and make them available every time you log in.
-
Compress the lorem and lorem-copy folders into a file called lorem-compressed.tar.gz
-
Unzip the file lorem-compressed.tar.gz into the folder lorem-uncompressed
-
Create a bash script to print the numbers from 1 to 100.