LAB 2

 Name: Muhammad Danial Bin Zainal Azlan                                            Matric Number:192020173

PART 1 

1.    Type in the command route and press the Enter key.


2.    Do the same for uptime, ls, date, and sync, pressing Enter after each command.


3.    Now press the up arrow key one time. You should see the following command: sync.


4. Now press the up arrow two more times. You should see date and ls.

First time:

Second time:


5. Press Enter. The ls command will run again. Pressing Enter will always run the command shown.


PART 2

1. Run a few commands such as route, uptime, date, and sync.




2. Create a directory  and change to it Linuxbook using the following command:


4.Now let's create some dummy files; run using the following command:


5. Now type ls -la u and then press Tab. The rest of the filename "unique1.txt" will appear. Press Enter. 

PART 4

WHAT IS PS1? 


When i open the terminal the first thing that came to show kali@kali is the PS1. We use the export PS1 command to modify how the PS1 should look like in the terminal.




INPUT COMMAND: export PS1="\u \h \w \$ "



It's the format string for your prompt

\u = user
\h = hostname
\W = working directory
\$=the symbol that represents each command in the terminal

TO UNDERSTAND THIS MUCH BETTER SIMPLY PLAY AROUND WITH THE COMMAND

1.export PS1="\u \h \w "


Now you can see the $ symbol is gone because we removed the $ symbol in the command.

2.export PS1="\u \h "


Now when you remove /w in the command it brings back you to the home directory.Since we are using this command in the home directory there is no change.

3.export PS1="\u  "


When we only use \u it only shows the username of the pc in the PS1

ABOVE STEPS ARE JUST FOR YOUR KNOWLEDGE .NOW WE DO THE LAB QUESTIONS FOR PART 4.


1.Before getting into this,you should not what is PATH.


WHAT IS PATH?

PATH= It shows and sets the directories where programs are searched for



1. Prepending a dot to the PATH means the program will be looked for in the current directory first, before searching the rest of the path. This is very useful during the code development for example. Do this by running:

export PATH=".:$PATH"




2.The EDITOR variable can be set to your favorite text editor. Most people use vi (or vim); however, you can point it to the one you want. If you change this, be sure to   use the full path. To change the EDITOR variable do this:

Before i use export EDITOR=/lewis/bin64/kw My current EDITOR is set to nothing.To check that pls type echo $EDITOR



After i use export EDITOR=/lewis/bin64/kw My current EDITOR is set to kw. To check you can type echo $EDITOR


3. An export can be removed byu setting it to nothing: export EDITOR =


As you can see when i use export EDITOR= , my editor is removed.

4.By convention, environment variables are usually written in uppercase. View the man pages
and/or search Google for more information on these variables.

PART 5 ( CREATING SIMPLE COMMAND)

Wouldn't it be nice if you could easily create a simple command without having to make a script out of it? Well, there is a way. This is done using aliases.

1.Type tput clear and press Enter. Your screen should have cleared.\



2. Now enter alias cls="tput clear". Now when you run cls it will do the same thing. 
INPUT COMMAND alias cls="tput clear"

INPUT COMMAND : cls


As you can see in the video the the cls command has cleared the screen. This is very useful if you have too many commands in the terminal.

3. Let's create some more. To show a long directory listing enter alias la="ls =la". Enter 'la' to run the alias.

When you enter the ls = la in the terminal ,it will list all the directories.



Now you understand what ls -la does. Now we wanna create our own command line that does the same work using 'alias lt="ls -latr"'.


The ls -latr command will list the current files list. Now we have created the our own command line "lt" which does the same function as "ls -latr"


EXTRA:

TO UNDO YOUR ALIAS OR THE COMMAND YOU CREATED SIMPLE USE unalias "command name given" .For example , unalias lt.


As you can see, when I use unalias lt, the lt command I created is deleted.


PART 6:(ALIAS CONTINUATION)

You can also use aliases to move around the filesystem efficiently. This is very handy and will save you an incredible amount of typing. Here are some examples:



I created a foldername linuxbook in my home directory.

1. alias lbook="cd /home/kali/linuxbook"


Now I created lbook command to open the linuxbook folder when I enter the lbook.

2. lbook



Now you can see, when I use lbook it opens the linuxbook folder.


PART 7(USING EXPORT TO CREATE ALIAS)

You will now be taken to that directory. Here is something I make frequent use of on my systems:


1. export LBOOK="/home/kali/linuxbook"

2. alias lbook="cd $LBOOK"

3. lbook



1.As you can see, I have craeted own envronment variable which is LBOOK and make it to open the linuxbook folder.

2.And then I created own lbook command using alias to call the LBOOK command.

3.Now when I enter lbook command in the terminal it will the run the LBOOK command. The LBOOK will will run the cd/home/kali/Linuxbook.


PART 8

As you can see, running lbook will take you to the directory as shown above. However, you can also use the LBOOK variable to copy files to that directory:

1. cd /tmp
2. touch f1.txt
3. cp f1.txt $LBOOK



1.I entered the /tmp which is temporary directory .
2.I created a file which is f1.txt.
3.Now i copy and paste the file into the linuxbook file .When you go into the linuxbook file the f1.txt is copied into the folder.

EXTRA:To remove the lbook command use the unalias lbook command.












































 




 







Post a Comment

0 Comments