__________________________________________________
** 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
Post a Comment