编写一个bash脚本程序,用for循环实现将当前目录所有的·c文件移到指定的目录

编写一个bash脚本程序,用for循环实现将当前目录所有的·c文件移到指定的目录,第1张

#!/bin/bash

for i in `ls *.c`

do

cp $i /path

done

顺便提一下,直接用

cp *.c /path/ 一样可以把让链侍.c文件拷到指定坦吵目唤侍录,for循环并不是必要的

#第一个

#!/bin/bash

Dir_path=$1

[ ! -d $Dir_path ] &&

echo "Error: this is not a directory!" &&

exit 1

find $Dir_path -name ".*" -type f -print # 第二个

#! /bin/bash

Dir_path=$1

: ${Dir_path:=$PWD}

[ ! -d $Dir_path ] &&

echo "Error: this is not a directory!" &&

exit 1

file_list=`ls $Dir_path | grep "txt$"`

Empty_file=0

for i in $file_list

do

        count=`wc -c $i | awk '{print $1}'`

   敬喊兆     if [ $count -eq 0 ] then

          渗答      ((Empty_file++))

                rm -rf $Dir_path/$i

                [ $? -ne 0 ] &&

                echo "Warning, cannot remove $Dir_paht/$i."

        fi

done

echo "$Dir_path has $Empty_file empty txt file." #第三个

#! /bin/bash

# para1: max limit number

Max_limit=$1

: ${Max_limit:=1000}

touch empty_file

awk -v limit=$Max_limit 'BEGIN{i=0\

        while(i<limit) {

                if ((i % 7)  && index(i, "7") == 0 )

           亮租             print i

                i++

        }

}' empty_file

rm empty_file

第四个可以用cat file1 file2 >file3的形式加上文件是否存在的判断

[ -e file]

实现目的


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8215124.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存