Command Line -- Lesson 3
2015-10-26 18:16
591 查看
In this lesson, I learned to use the bash profile to configure the environment.
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.
and exports an environment variable.
the name of the current user.
the command prompt.
the home directory. It is usually not customized.
a colon separated list of file paths. It is customized in advanced cases.
a list of environment variables.
$ nano hello.txt[/code]
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.
The command
the nano text editor.
a text string entered in nano through the cursor.
The menu of keyboard commands at the bottom of the window allow us to save changes to hello.txt and
exit nano. The
for the
a file. 'O' stands for output.
the nano program. 'X' stands for exit.
a help menu.
the terminal window, moving the command prompt to the top of the screen.
Please refer to
GNU nano for detailed information.
$ nano ~/.bash_profile[/code]
~/.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
the user's home directory.
The
a hidden file.
The name ~/.bash_profile is
important, since this is how the command line recognizes the bash profile.
The command
nano.
The text
string "Welcome, Jane Doe" when a terminal session begins.
The command
in ~/.bash_profile for
the current session. Instead of closing the terminal and needing to start a new session,
the changes available right away in the session we are in.
alias pd="pwd"[/code]
The
allows you to create keyboard shortcuts, or aliases, for commonly used commands.
Here
the
which is then saved in the bash profile. Each time you enter
the output will be the same as the
The command
in the current session.
alias hy="history"[/code]
set as alias for the
in the bash profile. The alias is then made available in the current session through
By typing
line outputs a history of commands that were entered in the current session.
alias ll="ls -la"[/code]
set as an alias for
made available in the current session through
By typing
line now outputs all contents and directories in long format, including all hidden files.
export USER="Jane Doe"[/code]
environment variables are
variables that can be used across commands and programs and hold information about the environment.
The line
The line
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.
At the command line, the command
always used when returning a variable's value. Here, the command
export PS1=">> "[/code]
a variable that defines the makeup and style of the command prompt.
the command prompt variable and exports the variable. Here we change the default command prompt from
After using the
the command line displays the new command prompt.
$ echo $HOME[/code]
The
is an environment variable that displays the path of the home directory. Here by typing
output.
$ echo $PATH
/home/ccuser/.gem/ruby/2.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin[/code]
an environment variable that stores a list of directories separated by a colon. Looking carefully,
/home/ccuser/.gem/ruby/2.0.0/bin
/usr/local/sbin
/usr/local/bin
/usr/bin
/usr/sbin
/sbin
/bin
Each directory contains scripts for the command line to execute. The
simply lists which directories contain scripts.
For example, many commands we've learned are scripts stored in the /bindirectory.
/bin/pwd[/code]
This is the script that is executed when you type the
/bin/ls[/code]
This is the script that is executed when you type the
env[/code]
The
stands for "environment", and returns a list of the environment variables for the current user. Here, the
returns a number of variables, including
and
env | grep PATH[/code]
"piped" to the
for the value of the variable
outputs it to the terminal.
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.
USERis
the name of the current user.
PS1is
the command prompt.
HOMEis
the home directory. It is usually not customized.
PATHreturns
a colon separated list of file paths. It is customized in advanced cases.
envreturns
a list of environment variables.
$ nano hello.txt[/code]
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.
The command
nano hello.txtopens a new text file named hello.txt in
the nano text editor.
"Hello, I am nano"is
a text string entered in nano through the cursor.
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
Ctrlkey.
Ctrl+
Osaves
a file. 'O' stands for output.
Ctrl+
Xexits
the nano program. 'X' stands for exit.
Ctrl+
Gopens
a help menu.
clearclears
the terminal window, moving the command prompt to the top of the screen.
Please refer to
GNU nano for detailed information.
$ nano ~/.bash_profile[/code]
~/.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_profileopens 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
echothe
string "Welcome, Jane Doe" when a terminal session begins.
The command
source ~/.bash_profileactivates the changes[/u]
in ~/.bash_profile for
the current session. Instead of closing the terminal and needing to start a new session,
sourcemakes
the changes available right away in the session we are in.
alias pd="pwd"[/code]
The
aliascommand
allows you to create keyboard shortcuts, or aliases, for commonly used commands.
Here
alias pd="pwd"creates the alias
pdfor
the
pwdcommand,
which is then saved in the bash profile. Each time you enter
pd,
the output will be the same as the
pwdcommand.
The command
source ~/.bash_profilemakes the alias
pdavailable
in the current session.
alias hy="history"[/code]
hyis
set as alias for the
historycommand
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.
alias ll="ls -la"[/code]
llis
set as an alias for
ls -laand
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.
export USER="Jane Doe"[/code]
environment variables are
variables that can be used across commands and programs and hold information about the environment.
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.
The line
exportmakes
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.
At the command line, the command
echo $USERreturns the value of the variable. Note that
$is
always used when returning a variable's value. Here, the command
echo $USERreturns the name set for the variable.
export PS1=">> "[/code]
PS1is
a variable that defines the makeup and style of the command prompt.
export PS1=">> "sets
the command prompt variable and exports the variable. Here we change the default command prompt from
$to
>>.
After using the
sourcecommand,
the command line displays the new command prompt.
$ echo $HOME[/code]
The
HOMEvariable
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.
$ echo $PATH
/home/ccuser/.gem/ruby/2.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin[/code]
PATHis
an environment variable that stores a list of directories separated by a colon. Looking carefully,
echo $PATHlists the following directories:
/home/ccuser/.gem/ruby/2.0.0/bin
/usr/local/sbin
/usr/local/bin
/usr/bin
/usr/sbin
/sbin
/bin
Each directory contains scripts for the command line to execute. The
PATHvariable
simply lists which directories contain scripts.
For example, many commands we've learned are scripts stored in the /bindirectory.
/bin/pwd[/code]
This is the script that is executed when you type the
pwdcommand.
/bin/ls[/code]
This is the script that is executed when you type the
lscommand.
env[/code]
The
envcommand
stands for "environment", and returns a list of the environment variables for the current user. Here, the
envcommand
returns a number of variables, including
PATH,
PWD,
PS1,
and
HOME.
env | grep PATH[/code]
env | grep PATHis a command that displays the value of a single environment variable. Here the standard output of
envis
"piped" to the
grepcommand.
grepsearches
for the value of the variable
PATHand
outputs it to the terminal.
相关文章推荐
- js重定向后跳转到当前页面锚点
- asp 必须为 MapPath 方法指定 Path 参数
- sql语句大全
- 初入运维职场的老男孩教育学员必须坚守的素质和态度!
- 前后端分离的思考与实践(六)
- Eclipse下Java+Scala混合编程的Maven项目
- 正则表达式速查
- MFC 中CMenu菜单的的使用
- MFC MDI去掉滚动条
- nagios监控windows主机
- Link
- Java for循环的几种用法分析
- EntityFramework6 Execute Storeprocedure
- 解决每次升级Xcode后三方插件失效问题
- java得到系统时区 +0800
- 在webView上添加手势
- C++模板
- sql 表连接 join
- iis中上传文件大小限制的修改方法
- java系统学习(十九) --------网络编程基础