版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/AXuan_K/article/details/79075541
1 服务管理
安装并运行samba:
sudo apt-get update
sudo apt-get install samba
sudo service samba restart
2 提取文本中的信息
用脚本提取给定文档中以png和jpg结尾的图片链接:
grep "http.*\.\(jpg\|png\)" $1
grep "http.*\.\ ( jpg \ | png \ )" $1
将 /etc 目录下所有内容中包含 shiyanlou 字符串的文件的完整路径都写入 /home/shiyanlou/output 文件中:
touch output
sudo grep -R "shiyanlou" /etc > output
请实现一个脚本获取指定端口上正在运行的程序的绝对路径,如果没有运行任何程序则打印 OK 字符串。
t=`lsof -i:$1|tail -1|awk '{print $1}'`
if [ -n "$t" ] ;then
which $t
else
echo "OK"
fi
5 证书配置
请为 shiyanlou 用户配置一个 SSH 证书,使 shiyanlou 用户 SSH 登陆本地实验环境的时候不需要输入密码。同时设置 SSH 服务禁止所有用户使用密码登陆。
#1 修改sshd配置
sudo vi /etc/ssh/sshd_config
#禁止密码登录
PasswordAuthentication no
#注释三行
#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
#重启让配置生效
sudo service ssh restart
#生成公钥写入文件
cd ~/.ssh
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cp id_dsa.pub authorized_keys
#不安全的设置,将不能使用RSA功能
chmod 600 ~/.ssh/authorized_keys
6 避免误删
(1)rm -f 命令删除的文件或文件夹都临时存入 /tmp/trash 文件夹,而不删除,例如使用 rm -f /home/shiyanlou/testfile 后,文件 testfile 会被移动到 /tmp/trash/testfile,如果 /tmp/trash 目录下已经有 testfile 重名文件则直接覆盖老的文件。
(2)rm 命令不加 -f 参数的时候执行流程不变,不需要移动到 /tmp/trash 文件夹。
sudo cp /bin/rm /bin/oldrm
sudo cp ~/rm.sh /bin/rm
#脚本内容
#!/bin/bash
if [ $# -eq 2 ] && [ "$1"=="-f" ]
then
mv $2 /tmp/trash
else
/bin/oldrm $1 $2
fi
(1)生成的密码字符串长度为12位
(2)密码中必须同时包含数字,大小写字母及至少1个特殊字符
(3)只允许使用这些特殊字符:><+-{}:.&;
arr1=(\> \< \+ \- \{ \} \: \. \& \;)
arr2=(a b c d e f g h i j k l m n o p q r s t u v w x y z)
arr3=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
t=${arr1[$[$RANDOM%10]]}
t=$t${arr2[$[$RANDOM%26]]}
t=$t${arr3[$[$RANDOM%26]]}
t=$t$[$RANDOM%10]
echo $t"abcdefgh"
拷贝指定目录下(包括子目录)所有大于4M文件
#!/bin/bash
function getdir(){
#目录一定要一致
if [ ! -d "/tmp"$1 ]; then
`mkdir "/tmp"$1`
fi
for element in `sudo ls $1 `
do
dir_or_file=$1"/"$element
if [ -d $dir_or_file ]
then
getdir $dir_or_file
continue
else
ss=`sudo ls -l $dir_or_file| awk '{print $5}'`
if [ $ss -gt 10240 ]; then
`cp $dir_or_file "/tmp"$1`
fi
fi
done
}
root_dir="/etc"
getdir $root_dir