Full width home advertisement

Post Page Advertisement [Top]













USING THE TERIMAL/COMMAND LINE

PART 1 The .bashrc file

The .bashrc file is useful and it can help us to save time. You definitely don't want to enter these every time we start a new shell. The .bashrc file can store your settings. 

1) Enter those command as shown below:- 

cat .bashrc

After you enter the command, you will see all of your configuration file.


This is my own .bashrc file.

These are the description of the lines.
1. # symbol is comment a line.
2. export tag is to create a variable.
3. alias tag is to create an alias (if you don't know what is alias, check out my Lab 2 Blog)
4. if clause is for allows control statements.
5. After modifying your .bashrc file, remember to source it using the dot operator as follows:
    . .bashrc

Next I will show how to modifying your .bashrc file.
2) Enter those command as shown below:- 

nano .bashrc

3) In the .bashrc file, add on aliases in your bashrc file. You can enter the command as below:-

alias cls="tput clear"

*tput clear is to clear my screen


4) After that Press CTRL+X and it will ask whether you want to save or not, just press Y to save it. Next enter the command as belows:-

. .bashrc

Try it out your new variable by typing cls.


PART 2 Dealing with blanks and special characters in filenames 

1) Create 3 Textfile in a folder named as 'test 1.txt', 'test1>.txt', '-test1.txt'

2) Run ls -la test 1.txt
You will noticed out there some error in this command.

How to correct it??
3)    Try this out this command, it will work properly now.
       ls -la "test 1.txt" 

4)    Next, try this command, you will probably get error too
       ls -la test1>.txt


5)    Try this command now, you will noticed the command can work properly now.
        ls -la "test1>.txt"


6)     Next, try out this command, properly get error too
        ls -la -test1.txt


7)     You can correct it with  this command
        ls -la ./-test1.txt


As you can see, this can also be a problem if special characters have been used in the filename. If the file starts with a dash '-', use the ./ operator. It means to refer to the file in the current directory.


PART 3 Understanding the $? variable
1) Run this command:
ping -c 1 packt.com
echo $?


You should able to get the output as 0.


2) Try run it again with this command:
    ping -c 1 phooey
    echo $?

You should be get the output a non-zero number.

In general, a return of zero means success. A non-zero return means an error has occurred, and in many cases the code returned indicates what the error was.

PART 4 Redirection and piping
1)  Enter the command as below, you probably won't see any output because the output went into the         file.
     ifconfig > file1.txt

2)  Next enter the command below to run the output:
    cat file1.txt


3) To sort the output, try the command below:-
    sort < file1.txt
    OR
    sort < file1.txt > output-file.txt
    cat output-file.txt


The output is sort out complete.

Furthermore, you can also send the output to another command using the pipe operator. For example, run route | grep link-local. 

The above command would display only the lines from route that contain the phrase link-local.

If I want some program in C a long time ago, have several versions, and want to find the latest one. I could run locate to find them all:

locate crc.c

This might return quite a few lines. By run ls on each file, you can find the latest one. Piping the output into the xargs command and then ls:

locate crc.c | xargs ls -la

This command show you the time and date of each file.



PART 5 Sending Output from one terminal to another
By doing this, you need to open two terminals.

1) In the first terminal run this command:-

tty


The output should be something like this.

2) In second terminal, run this command:-
route
You will be seeing the output similar to this:-


3)Type this command again:-
route > /dev/pts/0

You will find it surprise that the output goes to the other terminal




PART 6 Using the Screen Program
Screen is a full-screen window manager that shares a physical terminal with other processes. It is normally used when no other manager or desktop is available, such as on a server. It has a scroll-back history buffer and also allows for copy and paste of text between windows.


Try this out!
Step1:In a terminal run this command:-
screen -L
The output should be blank terminal.

Step2: Next press Ctrl+A and then press C. This will create another window.
Step3: Do this two more times.

Step4: Now press Ctrl+A+O
Step5: Last, press Ctrl+A+3

How this works?
Step 1 will create a new window, window 0. If you are running inside a window manager you may notice the title change showing which window it is.

Step 2 will create another window. After step 3,you will have 4 windows in total.

When you perform the actions in step 4, you should be in window 0. Typing Ctrl+a+3 will take you window 3.


LAB 3 END


LET'S MAKE A LITTLE BIT PROGRESS EVERY DAY AND YOU SEE 
THE POWER OF SMALL CHANGES

No comments:

Post a Comment

Bottom Ad [Post Page]

| Designed by Colorlib