Linux format is converted to dos in batches, and linuxdos
Note: you only need the basic knowledge to write, but not to show off your skills. It is only to make it easier for others.
I. Script Function:
Batch Processing of file formats in directories and subdirectories allows you to easily convert the linux format to the dos format.
Ii. Significance of writing this blog:
1. In the spirit of open source, the purpose is to facilitate more people and not to spend too much time on such boring things.
2. There is no script for batch processing yet (at least I haven't found it), so someone really needs it.
3. If there are more sub-directories in the user directory, you can convert the directories by yourself. If there are more sub-directories, you will not be able to convert them.
III. The following describes how to use scripts:
1. This tutorial is accompanied by a script, which can be used according to the tutorial without having to know the internal code structure too much.
2. Explain the written scripts and learn by yourself. If you have any questions, add QQ: 2081795560 for communication and learning (it's better to have a sister ).
4. Introduction to using scripts:
Download link:
Address 1: http://files.cnblogs.com/files/wang-li/UnixChangeWindows.sh
Address 2: Click to download
The command required by the system:
1. unix2dos 2. If awk does not have this command, run the script after installation.
Instructions for use:
1. Copy the script to a linux machine and grant the corresponding permission (chmod 755 Script Name ).
2. Usage 1: Script Name relative path usage 2: Script Name absolute path usage 3: copy the script to the directory to be converted, and directly execute the script name without following the path
Explain the usage:
Assume that the directory to be converted from my script name UCW. sh is/home/Test/
Go to the directory where UCW. sh is located,
Grant permissions, chomd 755 UCW. sh
You can select one of the following operations for conversion.
Usage 1:./UCW. sh Test/This script should be executed under/home /.
Usage 2: absolute path./UCW. sh/home/Test/
Usage 3: cp UCW. sh/home/Test, and then run:/home/Test/UCW. sh
5. Explain the written scripts.
Because no function is written, the code is too repetitive in some places. Just explain it for a while. Due to your limited expression ability, if any of you can see the code below, please comment it out.
1 #! /Bin/bash 2 3 if [-z "$1"]; then # determine whether the command is followed by parameters, [-z] if it is null, true 4 5 FileName = $ (pwd) is returned) # Get the current directory 6 7 find $ PathName-ls | awk '{print $3 "" $11}' | grep' ^. * '> $ PathName/log.txt # Use the find command Jia awk to obtain the file attributes and the absolute file path 8 9 grep' ^-'$ PathName/log.txt | awk' {print $2} '> $ PathName/log2.txt # obtain the Object List with'-'as the object attribute, and get the absolute file path 10 11 which unix2dos 2> $ PathName/error. log # Check whether the user has the unx2dos command and input the error message to the file. In fact, you can also use $? To detect 12 if [-s $ PathName/error. log]; then # If the error message contains an error output, the user is prompted not to install this command and to exit this script 13 echo-e "Also need to install the following sofware: unix2dos "14 rm-rf $ PathName/error. log15 exit-1 # abnormal exit can be used $? To detect 16 fi17 18 cat $ PathName/log2.txt | while read line # read the list of accepted files and start to gradually detect 19 do20 echo "unix2dos: $ {line} "21 unix2dos $ line # In fact, the core of the entire script is here 22 done23 24 clear 25 echo" runing success "#26 else27 FilePath = $ (pwd) 28 29 if [[$1 =/*]; then # determines whether it is an absolute path. Also, I don't know what this [[] means. if anyone knows, please contact me. Thank you for your 30 PathName = $1; 31 32 if [-e $ PathName]; then # determine whether the directory 33 echo "" 34 else35 echo "unix2dos exists: cannot change $ PathName: No such directory "36 exit-1 # does not exist. Print the error message, 37 fi38 39 find $ PathName-ls | awk '{print $3 "" $11}' | grep '^. * '> $ PathName/log.txt 40 41 grep' ^-'$ PathName/log.txt | awk' {print $2} '> $ PathName/log2.txt42 43 which unix2dos 2> $ PathName/ error. log44 if [-s $ PathName/error. log]; then45 echo-e "Also need to install the following sofware: unix2dos" 46 rm-rf $ PathName/error. log47 exit-148 fi49 50 cat $ PathName/log2.txt | while read line51 do52 echo "unix2dos: $ {line} "53 unix2dos $ line54 done55 56 clear57 echo" runing success "58 59 else60 PathName = $ FilePath/$1 # because I think the path is, then you do not need to check 61 62 if [-e $ PathName]; then # determine whether the directory is a normal 63 echo "" 64 else65 echo "unix2dos: cannot change $ PathName: no such directory "66 exit-167 fi68 69 find $ PathName-ls | awk '{print $3" "$11}' | grep '^. * '> $ PathName/log.txt 70 71 grep' ^-'$ PathName/log.txt | awk' {print $2} '> $ PathName/log2.txt72 73 which unix2dos 2> $ PathName/ error. log74 if [-s $ PathName/error. log]; then75 echo-e "Also need to install the following sofware: unix2dos" 76 rm-rf $ PathName/error. log77 exit-178 fi79 80 cat $ PathName/log2.txt | while read line81 do82 echo "unix2dos: $ {line} "83 unix2dos $ line84 done85 86 clear87 echo" runing success "88 fi89 90 fi91 92 exit 0 # exit
The script has been introduced.
In that case, I am a little bit white. I just hope that this script can help you solve the problem.
Qingqing Riverside grass 10:21:11