Saturday, April 9, 2016

Command Line_Lesson_Enviroment

1.Environment
Each time we launch the terminal application, it creates a new session. The session immediately loads settings and preferences that make up the command line environment.
We can configure the environment to support the commands and programs we create. This enables us to customize greetings and command aliases, and create variables to share across commands and programs.
We'll begin by learning to use a simple, command line text editor called nano.
In the terminal, type

nano hello.txt
This will open the nano text editor.
In nano, at the top of the window, type

"Hello, I am nano."
Using the menu at the bottom of the terminal for reference, type Ctrl + O (the letter, not the number) to save the file. This is the letter "O", not the number zero.
Press Enter, when prompted about the filename to write.
Then type Ctrl + X to exit nano.
Finally, type clear to clear the terminal window. The command prompt should now be at the top of the window.
2.nano
nano is a command line text editor. It works just like a desktop text editor like TextEdit or Notepad, except that it is accessible from the command line and only accepts keyboard input.
  1. The command nano hello.txt opens a new text file named hello.txt in the nano text editor.
  2. "Hello, I am nano" is a text string entered in nano through the cursor.
  3. The menu of keyboard commands at the bottom of the window allow us to save changes to hello.txt and exit nano. The ^ stands for the Ctrl key.
  4. Ctrl + O saves a file. 'O' stands for output.
  5. Ctrl + X exits the nano program. 'X' stands for exit.
  6. Ctrl + G opens a help menu.
  7. clear clears the terminal window, moving the command prompt to the top of the screen.
learn more about nano here.
2.1.Create a file to store environment settings.
In the terminal, type
nano ~/.bash_profile
This opens up a new file in nano.
2.2.In ~/.bash_profile, at the top of the file, type

echo "Welcome, Jane Doe"
You can use your name in place of "Jane Doe".
Type Ctrl + O to save the file.
Press Enter to write the filename.
Type Ctrl + X to exit.
Finally, type clear to clear the terminal window.
2.3.see the greeting you entered.
$ source ~/.bash_profile                                                                         
Welcome, Becky 3.Bash Profile
~/.bash_profile is the name of file used to store environment settings. It is commonly called the "bash profile". When a session starts, it will load the contents of the bash profile before executing commands.
  • The ~ represents the user's home directory.
  • The . indicates a hidden file.
  • The name ~/.bash_profile is important, since this is how the command line recognizes the bash profile.
  • The command nano ~/.bash_profile opens up ~/.bash_profile in nano.
  • The text echo "Welcome, Jane Doe" creates a greeting in the bash profile, which is saved. It tells the command line to echo the string "Welcome, Jane Doe" when a terminal session begins.
  • The command source ~/.bash_profile activates the changes in ~/.bash_profile for the current session. Instead of closing the terminal and needing to start a new session, source makes the changes available right away in the session we are in.
1.Now that we know what bash profile is, let's continue configuring the environment by adding command aliases. Open ~/.bash_profile in nano.$ nano ~/.bash_profile

2.In ~/.bash_profile, beneath the greeting you created, type

alias pd="pwd"
Save the file.
CTRL+O
Press Enter to write the filename
Exit nano.
CTRL+X
Clear the terminal window.
clear

3.In the command line, use the source command to activate the changes in the current session.

source ~/.bash_profile

4.Let's try out the alias. Type

pd
You should see the same output as you would by typing the pwd command.
$ pd                                                                                        
/home/ccuser/workspace/music4.Aliases I
The alias command allows you to create keyboard shortcuts, or aliases, for commonly used commands.
  1. Here alias pd="pwd" creates the alias pd for the pwd command, which is then saved in the bash profile. Each time you enter pd, the output will be the same as the pwd command.
  2. The command source ~/.bash_profile makes the alias pd available in the current session.
Each time we open up the terminal, we can use the pd alias.
4.1.Open ~/.bash_profile in nano.

4.2.In the bash profile, beneath the previous alias, add

alias hy="history"
Save the file.
Press Enter to write the filename.

4.3.Add another alias

alias ll="ls -la"
Save the file.
Press Enter to write the filename.
Exit nano
Clear the terminal window.

4.4.In the command line, use source to activate the changes to the bash profile for the current session.
$ source ~/.bash_profile  

4.5.Let's try out the aliases. In the command line, type

hy
1  nano ~/.bash_profile                                                                      

    2  clear                                                                                     
    3  nano ~/.bash_profile                                                                      
    4  clear                                                                                     
    5  source ~/.bash_profile                                                                    
    6  hy  


4.6.Now type

ll
1  nano ~/.bash_profile                                                                      

    2  clear                                                                                     
    3  nano ~/.bash_profile                                                                      
    4  clear                                                                                     
    5  source ~/.bash_profile                                                                    
    6  hy  
5.Aliases II
hy is set as alias for the history command in the bash profile. The alias is then made available in the current session through source. By typing hy, the command line outputs a history of commands that were entered in the current session.
ll is set as an alias for ls -la and made available in the current session through source. By typing ll, the command line now outputs all contents and directories in long format, including all hidden files.
5.1.Setting environment variables.
Open ~/.bash_profile in nano.

5.2.In the bash profile, beneath the aliases, on a new line, type

export USER="Jane Doe"
Feel free to use your own name.
Save the file.
Press Enter to write the filename.
Exit nano.
Finally, clear the terminal.

5.3.In the command line, use source to activate the changes in the bash profile for the current session.
$ source ~/.bash_profile     
5.4.Type

echo $USER
Becky
This should return the value of the variable that you set. 6.Environment Variables
environment variables are variables that can be used across commands and programs and hold information about the environment.
  1. The line USER="Jane Doe" sets the environment variable USER to a name "Jane Doe". Usually the USER variable is set to the name of the computer's owner.
  2. The line export makes the variable to be available to all child sessions initiated from the session you are in. This is a way to make the variable persist across programs.
  3. At the command line, the command echo $USER returns the value of the variable. Note that $ is always used when returning a variable's value. Here, the command echo $USER returns the name set for the variable.
1.Let's learn a few more environment variables, starting with the variable for the command prompt.
Open ~/.bash_profile in nano.
$ nano ~/.bahs_profile

2.On a new line, beneath the last entry, type

export PS1=">> "
Save the file.
Press Enter to write the filename.
Exit nano
Finally, clear the terminal window.

3.In the command line, use source to activate the changes in the bash profile for the current shell session.
$ source ~/.bash_profile                                                                         
>> 

4.Let's try out the new command prompt. In the terminal type

>>echo "hello"
>>hello

5.Now type

>>ls -alt

total 16                                                                                         
-rw-r--r-- 1 ccuser ccuser  362 Apr  9 22:28 .test.bats                                          
drwxr-xr-x 3 ccuser ccuser 4096 Apr  9 22:14 .                                                   
drwxr-xr-x 3 ccuser ccuser 4096 Apr  9 22:13 ..                                                  
drwxr-xr-x 2 ccuser ccuser 4096 Aug  1  2015 artists
the prompt has changed from $ to >>.
7.PS1
PS1 is a variable that defines the makeup and style of the command prompt.
  1. export PS1=">> " sets the command prompt variable and exports the variable. Here we change the default command prompt from $ to >>.
  2. After using the source command, the command line displays the new command prompt.

In the command line, type
echo $HOME
/home/ccuser
This returns the value of the HOME variable.

8.HOME
The HOME variable is an environment variable that displays the path of the home directory. Here by typing echo $HOME, the terminal displays the path /home/ccuser as output.
You can customize the HOME variable if needed, but in most cases this is not necessary.


8.1.In the command line, type

$ echo $PATH                                                                                     
/home/ccuser/.gem/ruby/2.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 
8.2.Type

$ /bin/pwd                                                                                       
/home/ccuser/workspace/music 

8.3.Type

$ /bin/ls                                                                                        
artists  hello.txt
9.PATH

PATH is an environment variable that stores a list of directories separated by a colon. Looking carefully, echo $PATH lists the following directories:
  1. /home/ccuser/.gem/ruby/2.0.0/bin
  2. /usr/local/sbin
  3. /usr/local/bin
  4. /usr/bin
  5. /usr/sbin
  6. /sbin
  7. /bin
Each directory contains scripts for the command line to execute. The PATH variable simply lists which directories contain scripts.
For example, many commands we've learned are scripts stored in the /bin directory.
/bin/pwd
This is the script that is executed when you type the pwd command.
/bin/ls
This is the script that is executed when you type the ls command.
In advanced cases, you can customize the PATH variable when adding scripts of your own.
9.1.In the command line type

$ env                                                                                            
GEM_HOME=/home/ccuser/.gem/ruby/2.0.0                                                            
TERM=linux                                                                                       
LC_ALL=C.UTF-8                                                                                   
PATH=/home/ccuser/.gem/ruby/2.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:
/usr/sbin:/sbin:/bin                                                                                                
PWD=/home/ccuser/workspace/music                                                                 
LANG=C.UTF-8                                                                                     
PS1=$                                                                                            
HOME=/home/ccuser                                                                                
SHLVL=1                                                                                          
UPSTART_INSTANCE=                                                                                
UPSTART_JOB=godex                                                                                
_=/usr/bin/env         
9.2.Then type
$ env | grep PATH                                                                                
PATH=/home/ccuser/.gem/ruby/2.0.0/bin:/usr/local/sbin:/usr/local/bin:
/usr/bin:/usr/sbin:/sbin:/bin
10.env
The env command stands for "environment", and returns a list of the environment variables for the current user. Here, the env command returns a number of variables, including PATH, PWD, PS1, and HOME.
env | grep PATH is a command that displays the value of a single environment variable. Here the standard output of env is "piped" to the grep command. grep searches for the value of the variable PATH and outputs it to the terminal. 
11.Generalizations
  • The environment refers to the preferences and settings of the current user.
  • The nano editor is a command line text editor used to configure the environment.
  • ~/.bash_profile is where environment settings are stored. You can edit this file with nano.
  • environment variables are variables that can be used across commands and programs and hold information about the environment.
    • export VARIABLE="Value" sets and exports an environment variable.
    • USER is the name of the current user.
    • PS1 is the command prompt.
    • HOME is the home directory. It is usually not customized.
    • PATH returns a colon separated list of file paths. It is customized in advanced cases.
    • env returns a list of environment variables.
Project:
1.Type the less command, with the filename javanese.txt. After you do this, type q to quit.
The less command is similar to cat, but is better adapted to handling larger files since files to the terminal, one page at a time.
less javanese.txt 
2.The less command is a special command that we can configure in the bash profile through the LESS environment variable.
Open the bash profile, and create and export a new environment variable called LESS, setting it equal to the option "-N". The -N option adds line numbers to the file.
Save the bash profile, exit nano, and clear the terminal window.
export LESS="-N"
3.Type the less command again now, with the filename javanese.txt. The file should appear, along with line numbers. Press q to quit.
4.return the value for the environment variable for LESS.
>> env | grep LESS                                                                               
LESS=-N 




16 comments :

  1. Health Is God is the main finish wellbeing and health site that you may portray as it yours. We made a site that presents the accumulation of wellbeing and way of life data bolstered by solid substance suppliers and certifiable client surveys. This is a true exertion on our part to deliver a client encounter which is drawing in, moving, and intuitive.

    ReplyDelete
  2. Great Post! You Shared Everything About The Topic. Thanks Again! Times For Education - Everyday News Portal Of Education. We Regularly Update Education's News From All Over The Worlds. Our Mission Not Only Provide Education's News But Also People Get Become Educated. Visit also this website: https://timesforeducation.com/

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Nice Post Share……Keep Shareing!!               
    https://care2fit.com

    ReplyDelete
  5. Absolutely love your creative idea! Can I share your post on my facebook page?
    Keto BodyTone

    ReplyDelete
  6. Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too.
    Morgan @ Gowell Health Tips

    ReplyDelete
  7. Thenutritionsclinic So it's not hard to see that the development of blood all through our bodies is totally critical for our reality and on the off chance that we experience the ill effects of poor blood course it can have desperate repercussions whenever left untreated. A portion of the basic indications of poor blood course may incorporate; shivering sensation or deadness of either the hands or feet (also called Neuropathy); a brevity of breath; absence of vitality; sporadic heart pulsates; poor memory; and an absence of stamina.
    https://thenutritionsclinic.com/

    ReplyDelete
  8. Great post. If they are familiar with each other, it should make for an interesting game.
    health tips "write for us"

    ReplyDelete
  9. Massive Male Plus This male enhancement product is made up of safe natural substances, which integrate with the evidently taking place human increase hormone in the body to reinforce and improve the various muscle agencies inside the penile vicinity and reenforce the male organ to carry out with a more potent and fortified vigor. Dr. Daniel stein, m. D has reviewed the product and added his very own components, which incorporates dhea, a seasoned hormone that increases the testosterone stages required to boost the male libido.
    https://thenutritionsclinic.com/massive-male-plus/

    ReplyDelete
  10. Ultraskillpills Do not lead them to too difficult, you want them to conceivable. However do not lead them to too smooth either. Make a brand new habit being lazy is a addiction. And behavior are tough to interrupt, but no longer impossible. The extra you exercise, the less difficult it receives and starts offevolved turning into a habit.
    https://ultraskillpills.com/

    ReplyDelete
  11. ketogenicpedia We need to find out the basis cause of this problem if we begin to experience it. It can be the genetics i just mentioned our lifestyle or maybe by means of medicines that we may take for other fitness issues that could have an effect on us. Whatever the reason is, hair loss is a critical challenge for which a variety of human beings search for treatments.
    https://ketogenicpedia.com/

    ReplyDelete
  12. Pretty adequate post. I merely stumbled aloft your web log and basic to say that I acquire extremely enjoyed annual your web log posts.
    Natural Health "Write for Us"

    ReplyDelete
  13. Hello, I am Prithvika malhotra thank you for this informative post. That is a great job. Wish you more success.Thank you so much and for you all the best. Takes Down
    https://thiscruelwar.tech

    ReplyDelete

  14. both of which we all need! Also like to Logo design admire the time and effort
    Fitness "write for us"

    ReplyDelete
  15. What an excellent blog entry. Thanks for sharing it with me.
    wings2fashion

    ReplyDelete