五周第四次课(4月23日)
8.6 管道符和作業控制
| 管道符,把前面命令輸出的結果交給后面的命令
[root@aiker02 ~]# cat ls.txt | wc -l 6 [root@aiker02 ~]# ls | wc -l 13ctrl z 暫停一個任務
[root@aiker02 ~]# top top - 23:15:20 up 5 days, 9:23, 2 users, load average: 0.00, 0.01, 0.05 Tasks: 70 total, 2 running, 68 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 1883724 total, 478788 free, 72408 used, 1332528 buff/cache KiB Swap: 0 total, 0 free, 0 used. 1612380 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 993 root 20 0 130716 13372 8364 S 0.3 0.7 14:49.25 AliYunDun 1 root 20 0 125140 3648 2440 S 0.0 0.2 1:26.27 systemd [1]+ Stopped topjobs 查看后臺的任務
[root@aiker02 ~]# jobs
[1]+ Stopped top
bg[id] 把任務調到后臺
[root@aiker02 ~]# bg 1<br/>[1]+ top &
fg[id] 把任務調到前臺
fg 1
sleep 5 暫停5s
命令后面加& 直接丟到后臺
[root@aiker02 ~]# top &<br/>[1] 13841
8.7/8.8 shell變量
PATH,HOME,PWD,LOGNAME
env命令
[root@aiker02 ~]# env XDG_SESSION_ID=54517 HOSTNAME=aiker02 TERM=linux SHELL=/bin/bash HISTSIZE=1000set命令多了很多變量,并且包括用戶自定義的變量
[root@aiker02 ~]# set
自定義變量a=1
[root@aiker02 ~]# a=1<br/>[root@aiker02 ~]# echo $a<br/>1
注意,變量名和等號之間不能有空格,這可能和你熟悉的所有編程語言都不一樣。同時,變量名的命名須遵循如下規則:
命名只能使用英文字母,數字和下劃線,首個字符不能以數字開頭。
中間不能有空格,可以使用下劃線(_)。
不能使用標點符號。
不能使用bash里的關鍵字(可用help命令查看保留關鍵字)。
變量類型
運行shell時,會同時存在三種變量:
1) 局部變量 局部變量在腳本或命令中定義,僅在當前shell實例中有效,其他shell啟動的程序不能訪問局部變量。
2) 環境變量 所有的程序,包括shell啟動的程序,都能訪問環境變量,有些程序需要環境變量來保證其正常運行。必要的時候shell腳本也可以定義環境變量。
3) shell變量 shell變量是由shell程序設置的特殊變量。shell變量中有一部分是環境變量,有一部分是局部變量,這些變量保證了shell的正常運行
全局變量export b=2 全局變量有繼承屬性,但上級shell不生效,子shell和下級shell生效
8.9 環境變量配置文件
/etc/profile 用戶環境變量,交互,登錄才執行
/etc/bashrc 用戶不用登錄,執行shell就生效
~/.bashrc 自定義
~/.bash_profile 用戶下
~/.bash_history 命令行歷史
~/.bash_logout 登出執行
修改后如果想立即生效,使用. file 或者 source file**
PS1='[\033[01;32m]\u@\h[\033[00m]:[\033[01;36m]\w[\033[00m]\$ ' 修改命令行提示符格式
bash_profile和bashrc區別
【.bash_profile 與 .bashrc 的區別】
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
【login shell 與 non-login shell 的區別】
1、當你直接在機器login界面登陸、使用ssh登陸或者su切換用戶登陸時,.bash_profile 會被調用來初始化shell環境
Note:.bash_profile文件默認調用.bashrc文件
.bash_profile中有如下內容
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
2、當你不登陸系統而使用ssh直接在遠端執行命令,.bashrc 會被調用
3、當你已經登陸系統后,每打開一個新的Terminal時,.bashrc 都會被再次調用。
【故】若要配置環境變量之類,最保險是寫在 .bashrc 文件中。因為不管是登陸還是不登陸,該文件總會被調用!
Linux 系統添加操作記錄審計
Linux系統自帶的history命令用戶有自行刪除權限,那怎么設置可以讓用戶的操作記錄實時記錄,并保證普通用戶無權刪除呢?本文教你一招
1.建立文件夾
mkdir -p /usr/local/shellrecord/records/ chmod 777 /usr/local/shellrecord/records/ chmod +t /usr/local/shellrecord/records/2.vim /etc/profile 在最后添加下面的代碼
[root@aiker02 ~]# vim /etc/profile
轉載于:https://blog.51cto.com/235571/2104210
總結
以上是生活随笔為你收集整理的五周第四次课(4月23日)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【深度学习】数据降维方法总结
- 下一篇: 学习新 api 的思考过程 4.18