try 在GNU/Linux上解码base64文件时,我得到"base64:无效输入".

$ base64 test.zip | base64 -d > test2.zip
base64: invalid input
$ ll test*
-rw-r--r-- 1 user grp 152 19 11:41 test.zip
-rw-r--r-- 1 user grp  57 19 11:42 test2.zip

我try 了dos2unix命令,但没用.

我的base64版本:

$ base64 --version
base64 (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Simon Josefsson.

推荐答案

该版本不会(默认情况下)使用分隔符对行进行解码,但编码器默认会这样做.(新版本没有这个问题.)

一个解决方案:

base64 -w 0 foo.zip | base64 -d > foo2.zip

备选方案:

base64 foo.zip | base64 -di > foo2.zip

-i选项代表(来自man页):

-i, --ignore-garbage
       When decoding, ignore non-alphabet characters.
[...]
Decoding require compliant input by default, use --ignore-garbage to
attempt to recover from non-alphabet characters (such as newlines)

Linux相关问答推荐

如何注释掉SLURM中的延迟调度命令?

为什么在Linux上STD::SLEEP_FOR(STD::Chrono::Hors::Max())会立即返回?

Ansible-删除两个注释之间的代码块(包括注释本身)

如何在充满 csv 的目录中获得不同的值计数

使用 AWK 过滤 Linux 输出

我需要 -D_REENTRANT 和 -pthreads 吗?

具体来说,fork() 如何处理 Linux 中 malloc() 动态分配的内存?

KDE 桌面效果中的 OpenGL 和 XRender 有什么区别?

未定义的引用 'shm_open',已在此处添加 -lrt 标志

让 Tk 看起来像一个原生 Linux 应用程序

并行运行 shell 脚本

`是什么意思! -d` 在这个 Bash 命令中?

从核心转储中获取堆栈跟踪

ctrl-x 在终端中使用时会发送哪个信号?

bash中变量名后的2个逗号是什么意思?

JAVA_HOME 和 PATH 已设置,但 java -version 仍显示旧版本

`cd //` 中的双斜杠 // 在 Linux 中是什么意思?

带有日期和时间的 Linux 命令历史记录

构建窗口管理器

如何在我的终端中编辑文本文件