Sometimes we need to copy a file in batches using linuxshell. The same principle applies to batch users. The knowledge used: test or [: can be used to compare the arithmetic comparison-equal eq-ne-gt greater than-ge is greater than or equal to-lt... news & n linux shell copy files in batches sometimes we need to copy a file a few minutes. The same principle applies to batch users. The knowledge used: test or [: can be used to compare the arithmetic comparison-equal eq-ne-gt greater than-ge is greater than or equal to-lt is less than-le is less than or equal! Test whether-d is Directory-f is set-group-id of file-g, whether the-r file is readable, and whether the file is blank file, if the file size is not zero, the result is true. -U file's set-user-id is set-w file can write-x file can be executed to get the parameters passed during runtime $1, $2 .... $ n: 1st, 2nd .... The nth parameter. (Excluding the file name) $ @ is extended to "$1" "$2 "... "$ n" $ # number of parameters if statement format: if conditionthen statementselse statementsfi while statement format: while conditiondo statementsdone let's look at the code directly. (Because arithmetic calculation is used. I am using bash shell. Run successfully in ubunut12.04 .) [Plain] #/bin/bash argc =$ # if [$ argc-lt 2] then echo "please input two parameters, for the files to be copied and the number of times "exit 0 fi file = $1 count = $2 left =$ {file %. *} # retrieve the file name. For example, the final result of a.tar.gz is a.tar right =$ {file ##*.} # to obtain the file suffix. For example, the result of a.tar.gz is gz I = 0 if [-f "$ file"] # to determine whether the file exists. Then while [$ I-le $ count] do cp $ file "$ left $ I. $ right "#" $ left $ I. $ right "combines the new file name let" I = $ I + 1 "# Add a done else echo to the I value" $ file is not exist \ n "fi source: http://blog.csdn.net/rentiansheng/article/details/8851684
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.