linux整理
2016-07-12 00:00
197 查看
工作中常用整理:
开启: chkconfig iptables on 关闭: chkconfig iptables off
ps -ef|grep tomcat
username -a
env|grep java
unzip xxx.zip -d /usr/local/xxx
查找常用: find / -iname "*tomcat*"
看文件:less -n xx文件 还是比较实用的
一:
1.启动过程
系统-》boot->init->运行级别-》/etc/init.d-》loginshell
2.各种目录
a.设备也是目录。
3.密码忘记怎么办?
重启,单用户登录后重置root密码。
4.如何远程登录LInux
用putty等安全秘钥设置后登录。
5.文件权限
属于自己的文件,同组的权限,不同组权限。用户是按组划分的,1个用户可能属于多个组。
6.改变权限
a.更改属性,chgrp,chown,chmod,还有符号方式。
7.显示当前目录
pwd
8.持续监听文档变化,如日志编码
cat -nf /etc/test.log
9.用户管理
a.useradd
b.userdel
10.用户组管理
a.groupadd
b.groupdelll
c.初创用户默认是属于和自己同名的组。
11.用户也可以进行批量的添加操作,最终的文件都不变。
12.磁盘空间
a.df,总体文件系统
b.du,每个文件列表大小
c.fdisk,查看分区
d.mount/unmount
12.vi
13.yum是一组自动的控制功能。
二:shell脚本
1.多数关注bourne again shell.直接执行./test.sh,/bin/sh test.sh.
2.shell我的测试脚本》
#shell测试脚本start
#!/bin/bash
echo "hello world!"
your_name="gxl"
echo $your_name
your_name="gxl2"
echo ${your_name}
arg2="gxl22222"
unset arg2
arg3="hello3${your_name}finish.."
echo ${arg3}"len is:" ${#arg3}
echo `expr index "$arg3" fin`
array_name=(
v1
v2
v3
)
echo ${array_name[@]}
#this is comment
echo 'arraylenis:'${#array_name[0]}
#shell测试脚本end
3.sell参数传递测试
echo "shell arguments test..."
echo "file name:$0"
echo "arg1:$1"
echo "arg2:$2"
echo "args num: $#"
echo "total args :$*"
echo "current process:$$"
echo "shell set info :$-"
for i in "$*";do
echo $i
done
for i in "$@";do
echo $i
done
4.关于数组只支持1维数组,上面的实例已集成。
5.shell运算符
a.基本
b.算数
c.关系
d.布尔
e.逻辑
f.字符串
g.文件测试
6.echo
a.原样输出用'',不执行命令。
b.使用read读入
7.print/test命令
8.shell流程控制
a.for语句
b.while
c.case
d.break/continue
9.shell function 定义调用
10.shell输入输出重定向
a./dev./nulll可以禁止输出
12.文件包含引用
总体测试脚本:
#!/bin/bash
echo "hello world!"
your_name="gxl"
echo $your_name
your_name="gxl2"
echo ${your_name}
arg2="gxl22222"
unset arg2
arg3="hello3${your_name}finish.."
echo ${arg3}"len is:" ${#arg3}
echo `expr index "$arg3" fin`
array_name=(
v1
v2
v3
)
echo ${array_name[@]}
#this is comment
echo 'arraylenis:'${#array_name[0]}
echo "shell arguments test..."
echo "file name:$0"
echo "arg1:$1"
echo "arg2:$2"
echo "args num: $#"
echo "total args :$*"
echo "current process:$$"
echo "shell set info :$-"
for i in "$*";do
echo $i
done
for i in "$@";do
echo $i
done
a=10
b=20
val=`expr $a+$b`
echo "a+b:$val"
val=`expr $a-$b`
echo "a-b:$val"
val=`expr $a \* $b`
echo "a*b:$val"
val=`expr $a / $b`
echo "a /:$val"
val=`expr $b % $a`
echo "b % a : $val"
file="/home/gxl/test.sh"
if [ -r $file ]
then
echo "file can read"
else
echo "file can not read"
fi
read name
echo "$name is ok"
echo "file info test" > myfile
echo '$name\"'
echo `date`
if [ $a == $b ]
then
echo "a equals b"
elif [ $a -gt $b ]
then
echo "a bigger than b"
elif [ $a -lt $b ]
then
echo "a littl than b"
else
echo "not match condition"
fi
num1=$[2*3]
num2=$[1+5]
if test $[num1] -eq $[num2]
then
echo "number is equal"
else
echo "number is not equal"
fi
for var in it1 it2 it3
do echo "info is $var"
done
for str in 'this is a string test'
do
echo $str
done
int=1
while(( $int<=5 ))
do
echo $int
let "int++"
done
echo -n 'input your like file name:'
while read FILM
do
echo "yes! your like $FILM is a good film"
done
x=1
until (( x>=100))
do
echo "until test $x"
let "x++"
done
echo 'input your num'
read ynum
case $ynum in 1) echo 'choise 1'
;;
2) echo 'choiose 2'
;;
3) echo 'choise 3'
;;
*) echo 'others'
;;
esac
while :
do
echo -n "input number between 1 and 5:"
read ynum
case $ynum in 1|2|3|4|5)
echo "your num is $ynum!"
;;
*) echo "your num is over the top"
break
echo "game over";;
esac
done
demoFun(){
echo "this is a funtest"
}
echo "---funteststart"
demoFun
echo "---funend"
funWithReturn(){
echo "input your number 1"
read aNum
echo "input your number 2"
read aNum2
echo "two num is $aNum and $aNum2"
echo "total args is :$*"
return $(($aNum+$aNum2))
}
funWithReturn 'arg1' 'arg2'
echo "two num sum is:$?"
二:整理linux2
1.操作系统-/boot-init进程-运行级别-/ect/init.d-用户登录-loginshell
2./bin:常用命令;/boot启动核心文件;/dev外部设备和访问文件方式相同;/etc系统管理所需的配置文件;/home用户目录;/lib类型dll,应用程序用;/lost+found非法关机存放的文件;/media linux自动识别设备,u盘光驱;/mnu临时挂载;/opt主机额外安装软件;/proc内存映射;/root系统管理员主目录;/sbin系统管理员程序;/selinux防火墙安全;/srv服务启动后数据;/sys内核文件;/tmp临时文件;/usr用户多应用程序;/usr/bin系统用户应用程序;/usr/sbin超级用户使用的高级的程序;/usr/src内核源码;/var各种日志变量
3.d目录;-文件;/连接件;b可随机存储设备;c串行
文件类型 属主权限 属组权限 其他用户
d rwx rwx rwe
0 123 456 789
user gorup(users) 属用户 属同组 其他用户s
4.r(4)w(2)x(1)
5.ls -l 查看详细的文件信息:http://blog.sina.com.cn/s/blog_406127500101dgl8.html
6.用户是可以批量添加的。默认添加的用户数目同名的用户组。
7.df -ah ;du -h
开启: chkconfig iptables on 关闭: chkconfig iptables off
ps -ef|grep tomcat
username -a
env|grep java
unzip xxx.zip -d /usr/local/xxx
查找常用: find / -iname "*tomcat*"
看文件:less -n xx文件 还是比较实用的
一:
1.启动过程
系统-》boot->init->运行级别-》/etc/init.d-》loginshell
2.各种目录
a.设备也是目录。
3.密码忘记怎么办?
重启,单用户登录后重置root密码。
4.如何远程登录LInux
用putty等安全秘钥设置后登录。
5.文件权限
属于自己的文件,同组的权限,不同组权限。用户是按组划分的,1个用户可能属于多个组。
6.改变权限
a.更改属性,chgrp,chown,chmod,还有符号方式。
7.显示当前目录
pwd
8.持续监听文档变化,如日志编码
cat -nf /etc/test.log
9.用户管理
a.useradd
b.userdel
10.用户组管理
a.groupadd
b.groupdelll
c.初创用户默认是属于和自己同名的组。
11.用户也可以进行批量的添加操作,最终的文件都不变。
12.磁盘空间
a.df,总体文件系统
b.du,每个文件列表大小
c.fdisk,查看分区
d.mount/unmount
12.vi
13.yum是一组自动的控制功能。
二:shell脚本
1.多数关注bourne again shell.直接执行./test.sh,/bin/sh test.sh.
2.shell我的测试脚本》
#shell测试脚本start
#!/bin/bash
echo "hello world!"
your_name="gxl"
echo $your_name
your_name="gxl2"
echo ${your_name}
arg2="gxl22222"
unset arg2
arg3="hello3${your_name}finish.."
echo ${arg3}"len is:" ${#arg3}
echo `expr index "$arg3" fin`
array_name=(
v1
v2
v3
)
echo ${array_name[@]}
#this is comment
echo 'arraylenis:'${#array_name[0]}
#shell测试脚本end
3.sell参数传递测试
echo "shell arguments test..."
echo "file name:$0"
echo "arg1:$1"
echo "arg2:$2"
echo "args num: $#"
echo "total args :$*"
echo "current process:$$"
echo "shell set info :$-"
for i in "$*";do
echo $i
done
for i in "$@";do
echo $i
done
4.关于数组只支持1维数组,上面的实例已集成。
5.shell运算符
a.基本
b.算数
c.关系
d.布尔
e.逻辑
f.字符串
g.文件测试
6.echo
a.原样输出用'',不执行命令。
b.使用read读入
7.print/test命令
8.shell流程控制
a.for语句
b.while
c.case
d.break/continue
9.shell function 定义调用
10.shell输入输出重定向
a./dev./nulll可以禁止输出
12.文件包含引用
总体测试脚本:
#!/bin/bash
echo "hello world!"
your_name="gxl"
echo $your_name
your_name="gxl2"
echo ${your_name}
arg2="gxl22222"
unset arg2
arg3="hello3${your_name}finish.."
echo ${arg3}"len is:" ${#arg3}
echo `expr index "$arg3" fin`
array_name=(
v1
v2
v3
)
echo ${array_name[@]}
#this is comment
echo 'arraylenis:'${#array_name[0]}
echo "shell arguments test..."
echo "file name:$0"
echo "arg1:$1"
echo "arg2:$2"
echo "args num: $#"
echo "total args :$*"
echo "current process:$$"
echo "shell set info :$-"
for i in "$*";do
echo $i
done
for i in "$@";do
echo $i
done
a=10
b=20
val=`expr $a+$b`
echo "a+b:$val"
val=`expr $a-$b`
echo "a-b:$val"
val=`expr $a \* $b`
echo "a*b:$val"
val=`expr $a / $b`
echo "a /:$val"
val=`expr $b % $a`
echo "b % a : $val"
file="/home/gxl/test.sh"
if [ -r $file ]
then
echo "file can read"
else
echo "file can not read"
fi
read name
echo "$name is ok"
echo "file info test" > myfile
echo '$name\"'
echo `date`
if [ $a == $b ]
then
echo "a equals b"
elif [ $a -gt $b ]
then
echo "a bigger than b"
elif [ $a -lt $b ]
then
echo "a littl than b"
else
echo "not match condition"
fi
num1=$[2*3]
num2=$[1+5]
if test $[num1] -eq $[num2]
then
echo "number is equal"
else
echo "number is not equal"
fi
for var in it1 it2 it3
do echo "info is $var"
done
for str in 'this is a string test'
do
echo $str
done
int=1
while(( $int<=5 ))
do
echo $int
let "int++"
done
echo -n 'input your like file name:'
while read FILM
do
echo "yes! your like $FILM is a good film"
done
x=1
until (( x>=100))
do
echo "until test $x"
let "x++"
done
echo 'input your num'
read ynum
case $ynum in 1) echo 'choise 1'
;;
2) echo 'choiose 2'
;;
3) echo 'choise 3'
;;
*) echo 'others'
;;
esac
while :
do
echo -n "input number between 1 and 5:"
read ynum
case $ynum in 1|2|3|4|5)
echo "your num is $ynum!"
;;
*) echo "your num is over the top"
break
echo "game over";;
esac
done
demoFun(){
echo "this is a funtest"
}
echo "---funteststart"
demoFun
echo "---funend"
funWithReturn(){
echo "input your number 1"
read aNum
echo "input your number 2"
read aNum2
echo "two num is $aNum and $aNum2"
echo "total args is :$*"
return $(($aNum+$aNum2))
}
funWithReturn 'arg1' 'arg2'
echo "two num sum is:$?"
二:整理linux2
1.操作系统-/boot-init进程-运行级别-/ect/init.d-用户登录-loginshell
2./bin:常用命令;/boot启动核心文件;/dev外部设备和访问文件方式相同;/etc系统管理所需的配置文件;/home用户目录;/lib类型dll,应用程序用;/lost+found非法关机存放的文件;/media linux自动识别设备,u盘光驱;/mnu临时挂载;/opt主机额外安装软件;/proc内存映射;/root系统管理员主目录;/sbin系统管理员程序;/selinux防火墙安全;/srv服务启动后数据;/sys内核文件;/tmp临时文件;/usr用户多应用程序;/usr/bin系统用户应用程序;/usr/sbin超级用户使用的高级的程序;/usr/src内核源码;/var各种日志变量
3.d目录;-文件;/连接件;b可随机存储设备;c串行
文件类型 属主权限 属组权限 其他用户
d rwx rwx rwe
0 123 456 789
user gorup(users) 属用户 属同组 其他用户s
4.r(4)w(2)x(1)
5.ls -l 查看详细的文件信息:http://blog.sina.com.cn/s/blog_406127500101dgl8.html
6.用户是可以批量添加的。默认添加的用户数目同名的用户组。
7.df -ah ;du -h
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍