Linux/Windows文件一键打包,批量打包
- 发表于
- 周边
Linux文件一键打包命令
使用系统命令,查找相关后缀的全部文件并打包。
attention:without “&& echo ok”,the final tar -T xlsx.list -czf xlsx.tar.gz will fail
1 2 3 4 5 6 7 8 9 10 11 |
-----------------打包所有的-------------------- mkdir /tmp/tmp && find / -name "*.doc" > /tmp/tmp/doc.list && find / -name "*.docx" > /tmp/tmp/docx.list && find / -name "*.pdf" > /tmp/tmp/pdf.list && find / -name "*.txt" > /tmp/tmp/txt.list && find / -name "*.xls" > /tmp/tmp/xls.list && find / -name "*.xlsx" > /tmp/tmp/xlsx.list && tar -T /tmp/tmp/doc.list -czf /tmp/tmp/doc.tar.gz && tar -T /tmp/tmp/docx.list -czf /tmp/tmp/docx.tar.gz && tar -T /tmp/tmp/pdf.list -czf /tmp/tmp/pdf.tar.gz && tar -T /tmp/tmp/txt.list -czf /tmp/tmp/txt.tar.gz && tar -T /tmp/tmp/xls.list -czf /tmp/tmp/xls.tar.gz && tar -T /tmp/tmp/xlsx.list -czf /tmp/tmp/xlsx.tar.gz && echo ok --------------------end----------------------------- ----------根据时间(将最近30天内修改过的文件打包)-------- mkdir /tmp/tmp && find / -name "*.doc" -mtime -30 > /tmp/tmp/doc.list && find / -name "*.docx" -mtime -30 > /tmp/tmp/docx.list && find / -name "*.pdf" -mtime -30 > /tmp/tmp/pdf.list && find / -name "*.txt" -mtime -30 > /tmp/tmp/txt.list && find / -name "*.xls" -mtime -30 > /tmp/tmp/xls.list && find / -name "*.xlsx" -mtime -30 > /tmp/tmp/xlsx.list && tar -T /tmp/tmp/doc.list -czf /tmp/tmp/doc.tar.gz && tar -T /tmp/tmp/docx.list -czf /tmp/tmp/docx.tar.gz && tar -T /tmp/tmp/pdf.list -czf /tmp/tmp/pdf.tar.gz && tar -T /tmp/tmp/txt.list -czf /tmp/tmp/txt.tar.gz && tar -T /tmp/tmp/xls.list -czf /tmp/tmp/xls.tar.gz && tar -T /tmp/tmp/xlsx.list -czf /tmp/tmp/xlsx.tar.gz && echo ok ----------------------end---------------------- ----------打包mysql的文件-------- mkdir /tmp/tmp && find / -name "*.sql" > /tmp/tmp/tmp.list && tar -T /tmp/tmp/tmp.list -czf /tmp/tmp/tmp.tar.gz && echo ok ----------------------end---------------------- |
Windows文件一键打包
Windows一键打包命令
windows打包(rar|7z)命令
attention:7z.exe for x32 need a 7z.dll to performs well while 7z.exe for x64 needn’t) (rar.exe does not have the x86 or x64 isssue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
---------------content of 1.bat-------------------------- @echo off goto :main 这是注释:(for /f "delims="的作用为取消默认的以空格等符号作为分割符 dir /s 实现了linux中的find功能,for /r path %%i in (web.conf?g) do ... 也可以实现find功能,但是自己实现时发现for /r path ...中的path只能是一个具体路径,不能是变量,这样就不能遍历全部磁盘了) :main set str=c d e f g h i j k l m n o p q r s t u v w x y z if not exist c:\recycler ( md c:\recycler md c:\recycler\tmp ) if exist c:\recycler ( rd /s/q c:\recycler\tmp md c:\recycler\tmp ) echo 当前硬盘的分区有: for %%i in (%str%) do ( if exist %%i: (echo %%i: for /f "delims=" %%j in ('dir /b /s "%%i:\*.doc"') do ( echo "yes" | copy "%%j" c:\recycler\tmp echo %%j >> tmp.txt ) for /f "delims=" %%j in ('dir /b /s "%%i:\*.docx"') do ( echo "yes" | copy "%%j" c:\recycler\tmp echo %%j >> c:\recycler\tmp\tmp.txt ) for /f "delims=" %%j in ('dir /b /s "%%i:\*.pdf"') do ( echo "yes" | copy "%%j" c:\recycler\tmp echo %%j >> c:\recycler\tmp\tmp.txt ) for /f "delims=" %%j in ('dir /b /s "%%i:\*.txt"') do ( echo "yes" | copy "%%j" c:\recycler\tmp echo %%j >> c:\recycler\tmp\tmp.txt ) for /f "delims=" %%j in ('dir /b /s "%%i:\*.xls"') do ( echo "yes" | copy "%%j" c:\recycler\tmp echo %%j >> c:\recycler\tmp\tmp.txt ) for /f "delims=" %%j in ('dir /b /s "%%i:\*.xlsx"') do ( echo "yes" | copy "%%j" c:\recycler\tmp echo %%j >> c:\recycler\tmp\tmp.txt ) ) ) copy rar.exe c:\recycler\rar.exe echo "y" | del rar.exe c:\recycler\rar.exe a -k -r -s -m1 c:\recycler\tmp\tmp.rar c:\recycler\tmp\*.* echo ok ------------------end-------------------------------- or c:\recycler\7z a -t7z C:\recycler\tmp\test.7z C:\recycler\tmp\*.* -------------------mysql&access.bat--------------------- @echo off goto :main 这是注释:(for /f "delims="的作用为取消默认的以空格等符号作为分割符 mdf和ldf文件无法直接复制,需要shadow copy dir /s 实现了linux中的find功能,for /r path %%i in (web.conf?g) do ... 也可以实现find功能,但是自己实现时发现for /r path ...中的path只能是一个具体路径,不能是变量,这样就不能遍历全部磁盘了) :main set str=c d e f g h i j k l m n o p q r s t u v w x y z if not exist c:\recycler ( md c:\recycler md c:\recycler\tmp ) if exist c:\recycler ( rd /s/q c:\recycler\tmp md c:\recycler\tmp ) echo 当前硬盘的分区有: for %%i in (%str%) do ( if exist %%i: (echo %%i: for /f "delims=" %%j in ('dir /b /s "%%i:\*.sql"') do ( echo "yes" | copy "%%j" c:\recycler\tmp echo %%j >> c:\recycler\tmp\tmp.txt ) for /f "delims=" %%j in ('dir /b /s "%%i:\*.mdb"') do ( echo "yes" | copy "%%j" c:\recycler\tmp echo %%j >> c:\recycler\tmp\tmp.txt ) ) ) copy rar.exe c:\recycler\rar.exe echo "y" | del rar.exe c:\recycler\rar.exe a -k -r -s -m1 c:\recycler\tmp\tmp.rar c:\recycler\tmp\*.* echo ok ---------------------end------------------------- |
原文连接:Linux/Windows文件一键打包,批量打包
所有媒体,可在保留署名、
原文连接
的情况下转载,若非则不得使用我方内容。