Linux
Linux是一种操作系统,对比与熟悉的windows操作系统
Linux基本操作对比熟悉的Windows操作
新建文件夹 新建文件 查看文件 删除文件等一些操作类似
ls tree mkdir touch rm mv cat less tail | 文件操作 |
---|---|
chmod sudo useradd password | 权限操作 |
tar gzip | 压缩解压 |
find grep | 筛选 |
date cal | 日期 |
以上是一些Linux命令,具体使用可baidu.com
转换思维,Linux与Windows,像是安卓和苹果手机
Shell
说到Linux就离不开shell,就像手机和系统设置一样
shell简单一些当成一门语言来看待,就如同Java,python。它是连接Linux内核的
一门语言基础,首先变量,运算符,数组,逻辑判断,循环语句,函数,大概都是一样的套路,只是语法不同
#变量
a=100
echo $a
#运算符
#算数运算符 + - * / % == !=
echo `expr 1 + 2`
echo `expr 1 - 2`
echo `expr 1 \* 2`
echo `expr 1 / 2`
if [ 1 == 2 ]
then
echo "1等于2"
else
echo "1不等于2"
fi
if [ 1 != 2 ]
then
echo "1不等于2"
else
echo "1等于2"
fi
#逻辑判断 if if--else if--elif--else case--esac
if [ 1 == 1 ]
then echo "true"
fi
if [ 1 == 1 ]
then echo "true"
else echo "false"
fi
a=10
if [ $a == 10 ]
then echo "true"
elif [ $a != 10 ]
then echo "false"
else echo "这不是一个数字"
fi
a=2
case $a in
1) echo "1号"
;;
2) echo "2号"
;;
3) echo "3号"
;;
esac
#关系运算符 大于(-gt) 小于(-lt) 大于等于(-ge) 小于等于(-le) 等于(-eq) 不等于(-ne)
if [ 1 -eq 1 ]
then echo "true"
else echo "false"
fi
if [ 1 -ne 1 ]
then echo "true"
else echo "false"
fi
if [ 1 -lt 2 ]
then echo "true"
else echo "false"
fi
if [ 1 -gt 2 ]
then echo "true"
else echo "false"
fi
if [ 1 -ge 1 ]
then echo "true"
else echo "false"
fi
if [ 1 -le 1 ]
then echo "true"
else echo "false"
fi
#布尔运算符 -a(与) -o(或) !(非)
if [ 1 != 2 ]
then echo "1!=2"
fi
if [ 1 -lt 2 -a 1 != 2 ]
then echo "1小于2,并且不等于2"
fi
if [ 1 -lt 2 -o 1 -gt 2 ]
then echo "1<2或者1>2"
fi
#逻辑判断 && ||
if [[ 1 -gt 2 && 1 -ne 2 ]]
then echo "true"
else echo "false"
fi
if [[ 1 -gt 2 || 1 -ne 2 ]]
then echo "true"
else echo "false"
fi
#循环 for while until
for i in 1 2 3 4 5
do
echo "当前i为$i"
done
i=1
while (($i < 5))
do
echo "当前i为$i"
i=`expr $i + 1`
done
i=7
until [ $i == 10 ]
do
echo "i=$i"
i=`expr $i + 1`
done
#函数
createFile(){
touch add.txt
}
echo "执行函数"
createFile
echo "执行完毕"
a=1
b=2
addNum(){
return `expr $a + $b`
}
addNum
echo $?
#重定向
touch log.log
ls > log.log #重定向
ls -la >> log.log #追加