linux 笔记 shell
来源:互联网 发布:怎么延长电池寿命 知乎 编辑:程序博客网 时间:2024/06/13 16:52
#man bash#shell 首选 /bin/bash 类似C语言chsh -l[root@station198 桌面]# echo $SHELL/bin/bash[root@station198 桌面]# chsh -l/bin/sh/bin/bash/sbin/nologin/bin/tcsh/bin/csh[root@station198 桌面]# set#变量:#环境变量 : 全局export 例如:export var = 2#本地变量 : 局部 :var = 2#特殊变量 : shell特有[root@station198 桌面]# ps aux | grep bashroot 1711 0.0 0.0 108192 776 ? S 09:35 0:00 /bin/bash /usr/sbin/ksmtunedroot 2810 0.0 0.0 108324 1704 pts/0 Ss+ 09:36 0:00 /bin/bash -lroot 3172 0.0 0.0 108324 1840 pts/3 Ss 09:47 0:00 /bin/bash -lroot 3276 0.0 0.0 103248 864 pts/3 S+ 09:54 0:00 grep bash[root@station198 桌面]# ps -o pid,ppid,comm : 查看进程ID PID PPID COMMAND 3172 2808 bash 3296 3172 bash 3314 3296 ps#ppid:父进程#父子shell-rw-r--r--. 1 root root 56 12月 18 10:07 1.sh[root@station198 shell]# ./1.shbash: ./1.sh: 权限不够[root@station198 shell]# chmod u+x 1.sh[root@station198 shell]# ls1.sh[root@station198 shell]# ls -l总用量 4-rwxr--r--. 1 root root 56 12月 18 10:07 1.sh[root@station198 shell]# ./1.sh & #后台执行[1] 3524[root@station198 shell]# kill -9 3524[root@station198 shell]# jobs[1]+ 已杀死 ./1.sh#./(子进程)#source [root@station198 shell]# source 1.sh [root@station198 shell]# echo $var100[root@station198 shell]# which sh/bin/sh#set -X : 调试时使用[root@station198 ftp]# set -o nounset#man bash #/PS1 然后使用【n】 找到初始定义位置#初始化[root@station198 sysconfig]# vim /etc/rc.sysinit(系统初始化) [root@station198 sysconfig]# vim /etc/profile(PATH)[root@station198 sysconfig]# vim /etc/bashrc(PS1)特殊变量:Special Parameters$0 $1 $2 $3 .... $255【ESC】进入命令行->【YY】->【P】 复制 【U】:撤销ls /etc/tt # $? 只记录最近一次调用的命令$# 表示参数个数$* = "$1 $2 $3 $..... $254"$@ = "$1" "$2" "$3" "$4" ....$ : 当前进程对应pid --当前执行脚本的pid #ps -o pid,comm | grep bash防止 进程竞争 yum install if*$! : 后台进程对应pid [root@station198 bak]# find /etc/ -name "*.conf" -exec cp {} /shell/bak \;语句:if [ -f /etc/vsftpd/vsftpd.conf ]; thenelsefips axo pid,comm | grep ftp[root@station198 bak]#id test