1.
linux 软链接
[atguigu@hadoop102 ~]$ ln -s aaa bbb
[atguigu@hadoop102 ~]$ cd -P bbb
-P的理解 就是为了防止软链接问题 直接找到根目录
尝试在写一层 软链接
[atguigu@hadoop102 ~]$ ln -s bbb ccc
[atguigu@hadoop102 ~]$ cd -P ccc
直接到aaa
[atguigu@hadoop102 aaa]$ pwd
/home/atguigu/aaa
删除软链接比较安全的方式
[atguigu@hadoop102 ~]$ pwd
/home/atguigu
[atguigu@hadoop102 ~]$ unlink ccc
[atguigu@hadoop102 ~]$ ll
警告!!!
参考:
2.basename命令
[atguigu@hadoop102 ~]$ basename a.txt
a.txt
[atguigu@hadoop102 ~]$
[atguigu@hadoop102 ~]$ basename /home/atguigu/a.txt
a.txt
[atguigu@hadoop102 ~]$
3.总的图片信息
-p 的理解 如果文件夹存在就覆盖
4.102上同步一个 bin文件
102上 /home/atguigu
执行
xsync bin/
103和104都能看到同步的 bin
104
分发环境变量信息
[atguigu@hadoop102 ~]$ xsync /etc/profile.d/my_env.sh 错误吧
环境变量一般是root
[atguigu@hadoop102 ~]$ sudo ./bin/xsync /etc/profile.d/my_env.sh
检验103 和104
104
具体的脚本如下:
#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
echo Not Enough Arguement!
exit;
fi
#2. 遍历集群所有机器
for host in hadoop102 hadoop103 hadoop104
do
echo ==================== $host ====================
#3. 遍历所有目录,挨个发送
for file in $@
do
#4. 判断文件是否存在
if [ -e $file ]
then
#5. 获取父目录
pdir=$(cd -P $(dirname $file); pwd)
#6. 获取当前文件的名称
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
rsync -av $pdir/$fname $host:$pdir
else
echo $file does not exists!
fi
done
done