Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to copy files to a specified directory in a recursive function in shell

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the shell recursive function how to circularly copy files to the designated directory, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

Code:

#! / bin/shrecursive () {for file in $1 do subfile= `ls $2 $3 then rm $file` for subsubfile in $subfile do # echo $subsubfile if ["$subsubfile" = = "$2 $3/$file"] then rm-rf $3/$file mv $subsubfile $3/$file else recursive `ls $2 $3Compact $file` $2 $3/$file Fi done done} cd / tmpmkdir update;tar-zxvf update.tgz-C update;chmod-R 755 / tmp/update/*;rootdir= "/ tmp/update" filelist= `ls / tmp/update/ `for file in $filelistdo subfile= `ls $rootdir/$ file`for subsubfile in $subfile do if ["$subsubfile"! = "$rootdir/$file"] then $(recursive `ls $rootdir/$ file` $rootdir/$file) # rm-rf / $file/$subfile # mv $rootdir/$file/$subsubfile / $file break 1 Else kill-9 `ps | grep $file` rm-f / usr/bin/$file mv $rootdir/$file / usr/bin fi donedone#reboot

The following are new additions

Create soft links to all files in the folder, and linked files can be specified to be saved to other directories

When you assign a filelist, you can specify the source path

In the following sentence "ln-s $file arm-linux-" $lastwd ", you can specify the directory of the linked file, for example, the source path is the current path, and the destination path is also the current path.

# / bin/bash

Filelist= `ls. / `

For file in $filelist

Do

Firstwd=$file | cut-d "-"-F1

# if ["$firstwd" = = "arm"]

# then

Lastwd= `echo "$file" | sed's Unip. Sed-[] $/\ 1Unip'`

Echo $lastwd

Ln-s $file arm-linux- "$lastwd"

# fi

Done

Thank you for reading this article carefully. I hope the article "how to circularly copy files to a specified directory in shell" shared by the editor is helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report