
ls -l|awk '{print $9}'|xargs -I{} mv {} {}.bak
[root@ test]# touch a b c
[root@ test]# ls -l
total 0
-rw-r--r-- 1 root root 0 Apr 27 21:50 a
-rw-r--r-- 1 root root 0 Apr 27 21:50 b
-rw-r--r-- 1 root root 0 Apr 27 21:50 c
[root@ test]# ls -l|awk '{print $9}'|xargs -I{} mv {} {}.bak
[root@ test]# ls -l
total 0
-rw-r--r-- 1 root root 0 Apr 27 21:50 a.bak
-rw-r--r-- 1 root root 0 Apr 27 21:50 b.bak
-rw-r--r-- 1 root root 0 Apr 27 21:50 c.bak
[root@localhost
~]#
cat
test.sh
#!/bin/bash
a="test.sh
mem01.txt
.txt"
echo
${a/mem01.txt/mem01}
#将变量a中定义的mem01.txt替换为mem01
echo
${a/%.txt}
#将变量a中.txt结尾的内容删除,%表示以
什么什么
结尾
[root@localhost
~]#
sh
test.sh
test.sh
mem01
.txt
test.sh
mem01.txt
希赛
里又很多这种Linux资料的。
使用for循环,find命令,mv命令实现此功能,代码如下:
for f in $(find /tmp -name "*.c")do mv "$f" "${f%.c}.cpp"done
如果需要: shell编程列举/tmp目录下的所有文件并显示其是否是普通文件,是否可读,是否可写
可以用以下代码完成
#!/bin/bash
for file in /tmp/*
do
if [ -f $file ]then
echo "$file is a normal file."
if [ -r $file ]then
echo "$file is readable."
else
echo "$file is not readable."
fi
if [ -w $file ]then
echo "$file is writable."
else
echo "$file is not writable."
fi
fi
done
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)