step by step.
目录
——只是把需要深入理解的放进来了。
第三章
echo
ls
-a:(all)包含隐藏文件
cd pwd ~ ../..
[root@localhost ~]# cd /root --同cd ~
[root@localhost ~]# pwd --查看当前路径
/root
[root@localhost ~]# cd /etc --绝对路径
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd yum --相对路径
[root@localhost yum]# pwd
/etc/yum
[root@localhost yum]# cd ~
[root@localhost ~]# pwd
/root
[root@localhost ~]# useradd test
[root@localhost ~]# su test
[test@localhost root]$ pwd
/root
[test@localhost root]$ cd ~
[test@localhost ~]$ pwd
/home/test --普通用户(test)主目录在/home中,而root主目录在root中。
[root@localhost ~]# cd /etc
[root@localhost etc]# cd yum
[root@localhost yum]# pwd
/etc/yum
[root@localhost yum]# cd .. --该目录的父目录
[root@localhost etc]# cd yum
[root@localhost yum]# cd ../.. --父目录的父目录
[root@localhost /]# cd /etc/yum
[root@localhost yum]# cd . --自己
mkdir rmdir rm
不存在父目录则会提示。-p:自动创建父目录
[root@localhost ~]# mkdir dir/dir2
mkdir: cannot create directory ‘dir/dir2’: No such file or directory --没有dir
[root@localhost ~]# mkdir dir --需先创建dir再创建dir内子目录
[root@localhost ~]# mkdir dir/dir2
[root@localhost ~]# mkdir dir/dir2
mkdir: cannot create directory ‘dir/dir2’: No such file or directory
[root@localhost ~]# mkdir -p dir/dir2 --‘-p’:自动创建中间目录
[root@localhost ~]# rmdir dir/dir2 --只能删除空目录
[root@localhost ~]# rmdir dir
[root@localhost ~]# mkdir -p dir/dir2
[root@localhost ~]# rmdir dir --不能直接删除dir(非空)
rmdir: failed to remove ‘dir’: Directory not empty
[root@localhost ~]# rmdir -p dir/dir2
[root@localhost ~]# mkdir -p dir/dir2/dirr
[root@localhost ~]# rm dir/dir2/dirr
rm: cannot remove ‘dir/dir2/dirr’: Is a directory
[root@localhost ~]# rm -r dir/dir2/dirr --递归删除子目录内容
rm: descend into directory ‘dir/dir2/dirr’? y
rm: remove regular file ‘dir/dir2/dirr/dir.txt’? y
rm: remove directory ‘dir/dir2/dirr’? y
[root@localhost ~]# ls dir
dir2 --只剩dir2了
head tail
[root@localhost ~]# head -n 5 /etc/passwd --仅显示前5行(同效于下一条)
head 5 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[root@localhost ~]# tail -5 /etc/passwd --仅显示后5行(同效于下一条)
tail -n 5 /etc/passwd
pengyu:x:1000:1000:LinuxSystemVM:/home/pengyu:/bin/bash
a201925320219:x:1025:1025::/home/a201925320219:/bin/bash
exm:x:1026:1026::/home/exm:/bin/bash
a2022:x:1027:1027::/home/a2022:/bin/bash
test:x:1028:1028::/home/test:/bin/bash
cp
[root@localhost ~]# cp dir/dir2 -r /tmp --包括子目录递归复制
[root@localhost ~]# ls /tmp
dir2
mv
[root@localhost ~]# mv dir/dir2 tmp/dir2
[root@localhost ~]# ls tmp/dir2
dir2 dirr
第四章
用户类型
[root@localhost ~]# cat /etc/passwd | grep root --查看root相关用户
root:x:0:0:root:/root:/bin/bash --root的userid是0
operator:x:11:0:operator:/root:/sbin/nologin
ln 软链接 硬链接
awk
第五章
wc
[root@localhost ~]# cat /etc/passwd | wc -l
48
[root@localhost ~]# wc -l /etc/passwd
48 /etc/passwd
which where
[root@localhost ~]# which useradd
/usr/sbin/useradd
[root@localhost ~]# whereis useradd
useradd: /usr/sbin/useradd /usr/share/man/man8/useradd.8.gz
第九章 shell
$#
#!/bin/bash
echo There are $# parameters.
echo "The parameters are *${*}*"
echo "The parameters are *$@*"
echo "The script $0 is now running."
echo "The first parameter was *$1*"
echo "The second parameter was *$2*"
echo "The third parameter was *$3*"
[root@localhost ~]# sh ./5.sh 1 2 3 4 5 6
There are 6 parameters.
The parameters are *1 2 3 4 5 6*
The parameters are *1 2 3 4 5 6*
The script ./5.sh is now running.
The first parameter was *1*
The second parameter was *2*
The third parameter was *3*
简单数学表达式
expr
[root@localhost ~]# s=`expr 2+3`
[root@localhost ~]# expr $s\*4
2+3*4
[root@localhost ~]# s=`expr $s\*4`
[root@localhost ~]# echo $s
2+3*4
let
[root@localhost ~]# let s=(2+3)*4
[root@localhost ~]# echo $s
20
条件判断
0:真
1:假
逻辑运算
-a:与
-o:或
!: 非
第十章
进程启动
[root@localhost ~]# jobs&
[1] 3896
[1]+ Done jobs
[root@localhost ~]# ping www.baidu.com > out.txt &
[1] 3911
[root@localhost ~]# jobs 1
[1]+ Running ping www.baidu.com > out.txt &
第十一章
makefile
main:main.o mytool1.o mytool2.o
gcc main.o mytool1.o mytool2.o -o main
main.o:main.c
gcc -c main.c -o main.o -Itool1 -Itool2
mytool1.o:tool1/mytool1.c
gcc -c tool1/mytool1.c -o mytool1.o -Itool1
mytool2.o:tool2/mytool2.c
gcc -c tool2/mytool2.c -o mytool2.o -Itool2
clean:
rm -f *.o
rm -f main
main:a.o main.o b.o
gcc a.o main.o b.o -o main
a.o:f1/a.c
gcc -c f1/a.c -o a.o -If1
b.o:f2/b.c
gcc -c f2/b.c -o b.o -If2
main.o:main.c
gcc -c main.c -o -I f1 f2