LAB 2 | BASIC LINUX COMMANDS





PART 1 


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


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

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



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


First time:





Second time:





  1. 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.



  1. Run the history command.


  1. Look for a command you would like to run again, but instead of typing the command, type an exclamation point (!) and then the number next to the command as shown in the history listing, and press Enter.

  2. That command will run again.


PART 3



  1. Change to your home directory, in my case it's:






  1. Create a directory using the following command:





  1. Change to it Linuxbook using the following command: cd Linuxbook

ls > file2.txt ls > file3.txt ls > file4.txt

ls > unique1.txt





  1. Now let's create some dummy files; run using the following command: ls > file1.txt





















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

  2. Now type ls -al file and press Tab. Nothing will happen, and your console may beep. Press Tab again. Now all 4 filenames will appear.


First time:


Second time:



















  1. Add a 4, press Tab again, and then Enter. The command ls -la file4 will run.






























PART 4



WHAT IS PS1?




When you open the terminal the first thing that came the shows pi@raspberry:~$ 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.



  1. 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.








  1. 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"






  1. 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


  1. An export can be removed by setting it to nothing: export EDITOR=



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


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

Environment variables are written in uppercase so that it will differentiate them from the normal user variable.For more info on it,you can google on it.



**************************************************







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.








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

INPUT COMMAND alias cls="tput clear"




This command will set cls to clear the screen.




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.

  1. 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 la="ls -la"



Now you can see the la command we created does the work.This is how we create our own command in linux.

  1. To show a long listing with the most current files last enter '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 comamnd 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:


  1. mkdir /home/pi/linuxbook




I created a foldername linuxbook in my home directory.


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





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


  1. 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/pi/linuxbook"


  1. alias lbook="cd $LBOOK"


  1. lbook




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


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


  1. Now when I enter lbook command in the terminal it will the run the LBOOK command. The LBOOK will will run the cd/home/pi/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.



**************************************************


THE END OF LAB 2


**************************************************

Comments