Skip to main content

Lab OS 3

__________________________________________________

** Before we start the lab, please Install and Launch Linux. **

__________________________________________________

 The .bashrc file

There are many environment variables we can look at and change. There is a special file, named .bashrc, which is used to store your settings. It is located in the user's home directory.

1. This is a .bashrc file from one of my system : 

-Symbol # is used to comment a line.

-Command "alias" is used to create an alias.

-Control statements used using "if" clause.

-If you modified your .bashrc file, do remember to source it using the dot operator.
    -For example,  ". .bashrc"

__________________________________________________

Dealing with blanks and special characters in filenames

The shell treats each item after a blank as another file or parameter. A solution is to use quotes, the backslash, or the Tab key.

-I created 3 files with bad names inside folder "bad_names", which are "-startwithdash.txt", "use>.txt", "with space.txt".

-When I use command "ls -la -startwithdash.txt", error occurs.

-To fix it, I add symbol ./ before the file name.

    ls -la ./-startwithdash.txt

-When I use command "ls -la use>.txt", error occurs.

-To fix it, I enclose the file name using symbol "".

    ls -la "use>.txt"

-When I use command "ls -la with space.txt", error occurs.

-To fix it, I enclose the file name using symbol "".

    ls -la "with space.txt"

-Another way to fix this is using Tab after "ls -la with".

**The Tab key is very useful. It works really well for almost every case. 

**If the file starts with a dash, use the ./ operator. It means to refer to the file in the current directory. 

__________________________________________________

Understanding the $? variable

-First, I use the command "ping -c 1 packt.com". 

-Then, I use the command "echo $?". The output is '0' because the command is a success.

-After I use command "ping -c 1 phooey", the output of "echo $?" is 2.

-In a conclusion, if command "echo $?" returns zero, then the command is success; if non-zero return, this means that an error occured. 

__________________________________________________

Redirection and piping

1. After he command "ifconfig > file.txt", no output is shown because the output is copied to the file. 

2. After running command "cat file1.txt", the output is shown. 

3. Another way to do this is using command "sort < file1.txt". This can read from the file selected. 

4. By using command "sort < file1.txt > output-file.txt", the output is copied to the file named "output-file.txt".

5. You can also send the output to another command using the pipe operator. For example, I use command "route | grep local-link". The command will display only the lines from route that contain the phrase "local-link".

6. Command "locate crc.c" is use to find all the C program files.

7. Command "locate crc.c | xargs ls -la" will show the time and date of each file.

__________________________________________________

Sending output from one terminal to another

**Please open 2 terminals before doing this. 

-In one terminal, run command "tty". 

-Run command "route" at another terminal. The output will shown in the other terminal.


-Now, try run command "route > /dev/pts/0" in the same terminal. (the number maybe different, follow the output of the command "tty")

-The output will be shown in another terminal.

**Terminals on Linux systems are devices that have their own buffer space. By referring to the device by name you can write to it.

__________________________________________________

Using the Screen program

**Before you can carry out the commands below, please type in command "apt install screen". You will see output as below. 

**Then, type in command "screen". The output is as follow : 

__________________________________________________

The following are some of the examples of command available with Screen : 

__________________________________________________

1. In a terminal run the screen -L command.

    -This will create a new window. (window 0)

2. Now press Ctrl + A and then press C. This will create another window.

3. Repeat this two more times.

    -Now we have 4 windows. (window 0, window 1, window 2, window 3)

4. Type in command Ctrl + A + 0. (repeat this one more time)

    -You will see output at bottom left corner that tells you which window you are in : 

5. Type in command Ctrl + A + 3. (repeat this one more time)

6. If you type in command Ctrl + A + 4, you will see output as below : 

    -This is because window 4 does not exist.

__________________________________________________

The following is a list of frequently used commands:

    - "screen -list" : This will show all the windows.

    - "screen <program>" : This will create a new window and run that program in it. 

__________________________________________________

Thank you for reading. Feel free to ask me if you have any questions.
__________________________________________________

Comments

Popular posts from this blog

LAB 1 : D'ARSONVAL GALVANOMETER

--------------------------------------------------------------------------- Please ensure you have installed Multisim software before proceeding.  Click the link here if you want to install the software :   https://www.ni.com/en-my/support/downloads/software-products/download.multisim.html#312060 --------------------------------------------------------------------------- Objectives 1. To find the internal resistance and the currect sensitivity of the galvanometer.  Exercise 1. Set the potentiometer to 510 Ω. Connect the circuit as in the Figure 1.1 and keep the voltage source in minimum position such that voltage output from the voltage terminals  are 0V. 2. Increase the voltage supply and the galvanometer pointer will deflect towards right hand side or left hand side. You can replace the galvanometer with the DMM/Ammeter  in the Multisim. Assume R g is 1.2 Ω for the given galvanometer. Vary the voltage supply until the galvanom...

LAB OS 2

__________________________________________________ ** Before we start the lab, please Install and Launch Linux. ** __________________________________________________ Command retrieval and line editing 1. Type in all the commands below and press "Enter". a) route     - "route" is used for showing or update the IP/kernel routing table. b) uptime     - "uptime" is used to find out how long the system is active (running). c) ls     - "ls" is used to list files or directions in Linux and other Unix-based Operating Systems. d) date     - "date" is used to display the system date and time.      Output of all the commands above : 2. By pressing up arrow, the previous command will be shown.     Pressed up arrow 1 time :     Pressed up arrow 2 times :          Pressed up arrow 3 times :          Output after pressed up arrow 3 times : __________________________________...

Lab 3 : Blynk Application

--------------------------------------------------------------------------- Please ensure you have installed ESP32 properly in Arduino IDE software before proceeding. Click this link if you want to install Arduino IDE :  https://www.arduino.cc/en/software --------------------------------------------------------------------------- Please ensure you have installed and setup Blynk application before proceeding. (Take note that I am using the OLD VERSION of Blynk app in this lab.) Click this link if you want to install Blynk application :  https://blynk.io/ Click this link if you want to setup Blynk application :  https://microcontrollerslab.com/control-esp32-outputs-blynk-app-arduino-ide/ --------------------------------------------------------------------------- Part A : Blynk Application   Below are the circuit connections :  --------------------------------------------------------------------------- This is the Google Drive link of the coding for Lab Pract...