Sunday, April 12, 2015

Day 9: The Linux Command Line Ch7 Notes


Chapter 7 -Seeing The World As The Shell Sees It

It's Sunday and its raining :(. I can't go skating, but I can practice Linux.

Commands:
echo – Display a line of text


Lab 3

1. Using echo command display all the files in current directory (including hidden ones starting with .). Ensure that parent directory (..) is not listed.

2. Using ls command accomplish the same results as in step 1.

3. Using echo command display the same as output below: 

4. Use the Shell for arithmetic. Perform calculation 2 to the power of 8. Then 1024 divided by 8.

5. Using echo and curly braces the the numbers from: 01 up to 30.

6. Create tmp directory and change working directory to tmp all in one line.

7. Create a number of directories in tmp. They should look like year-month (starting with year 2014 ending with 2015). Use curly braces with the right expansion to accomplish this.

8. Display a long list of those directories and then rm the tmp directory along with its content

9. Using echo command display today's date

10. If filenames have more than one word, how would you display them on a screen?

11. If text is placed in double quotes, all special characters lose their meaning. What are the three exceptions?

12. Double quotes preserves word splitting. Check this using two commands:

13. Display the value of variables: USER and PATH. Use echo command to accomplish this.

14. Using echo command display the following message: It is not about being an "average" but about accomplishing true finesse!"

15. Using echo command display the following message: This is backslash \. Do not use quotes to accomplish this.

16. Using echo command display the following message: This is backslash "\".


Lab 3 Solution

1. Using echo command display all the files in current directory (including hidden ones starting with .). Ensure that parent directory (..) is not listed.

$ echo .[!.]* *

2. Using ls command accomplish the same results as in step 1.

$ ls -A

3. Using echo command display the same as output below: 

pi@raspberrypi ~ $ pwd
/home/pi
pi@raspberrypi ~ $ 

$ echo ~

4. Use the Shell for arithmetic. Perform calculation 2 to the power of 8. Then 1024 divided by 8.

$ echo $((2 ** 8))
$ echo $((1024 / 8))

5. Using echo and curly braces the the numbers from: 01 up to 30.

$ echo {01..30}

6. Create tmp directory and change working directory to tmp all in one line.

$ mkdir tmp; cd tmp

7. Create a number of directories in tmp. They should look like year-month (starting with year 2014 ending with 2015). Use curly braces with the right expansion to accomplish this.

$ mkdir {2014..2015}-{01..12}

8. Display a long list of those directories and then rm the tmp directory along with its content.

$ ls -l
$ cd ..; rm -r tmp

9. Using echo command display today's date.

$ echo $(date)

or

$ echo `date`

Notice!
The back quote is used (sometimes called back tick)

10. If filenames have more than one word, how would you display them on a screen?

Using double quotes, for instance: ls "file name with many words.txt"

11. If text is placed in double quotes, all special characters lose their meaning. What are the three exceptions?

The exceptions are: $, \, `

12. Double quotes preserves word splitting. Check this using two commands:

$ echo $(cal)

$ echo "$(cal)"

13. Display the value of variables: USER and PATH. Use echo command to accomplish this.

$ echo $USER
$ echo $PATH

14. Using echo command display the following message: It is not about being an "average" but about accomplishing true finesse!"

$ echo 'It is not about being an "average" but about accomplishing true finesse!'

15. Using echo command display the following message: This is backslash \. Do not use quotes to accomplish this.

$ echo This is backslash \\

16. Using echo command display the following message: This is backslash "\".

$ echo This is backslash '"\"'