Three popular command line file conversion tools under Linux

Three popular command line file conversion tools under Linux

【51CTO.com Quick Translation】Recently, a friend naively asked me how many file formats there are in the computer world. I responded half-seriously and half-jokingly, "The total number of sand grains in a soup bowl filled with beach sand is the total number of file formats in the world."

[[173962]]

Well, there aren't that many file formats (https://en.wikipedia.org/wiki/List_of_file_formats). Even so, you've probably never heard of as many common file formats as the ones listed on Wikipedia. The reality is that you'll never see and never use that many file types. However, if you want or need to convert between file formats, there are quite a few tools out there for that purpose.

Next, let’s learn three popular command line file type conversion tools on the Linux platform.

Pandoc

Everyone I know who uses markup languages ​​says Pandoc (http://pandoc.org/) is the tool they use most often to convert between those languages. And there's a good reason for that: Pandoc not only supports some very nice conversions, it does it very quickly.

Do you have a Markdown document that you want to convert to a LibreOffice Writer document? Or a LaTeX document that you want to turn into an EPUB document? Or maybe you have an HTML document that you want to turn into a slideshow. Pandoc can do all of these tasks, and more.

Here is an example of using Pandoc to perform a simple file format conversion (in this case, converting from HTML format to reStructuredText format):

pandoc -t rst myFile.html -o myFile.rst

In fact, you are not limited to direct conversion. For example, you can also add a table of contents, printed references, custom headers, syntax highlighting, etc. to the generated file. For details, please refer to the Pandoc reference documentation (http://pandoc.org/MANUAL.html#options).

However, it is important to note that Pandoc can only process text-based files. What happens if you have a binary file, such as a word processor document file? When running from the command line, it will display a prompt saying that the user provided an unexpected file source.

LibreOffice

You might be thinking, "Stop! LibreOffice (http://libreoffice.org/) is a GUI application. Yes, it is. However, what many people don't know is that you can also run LibreOffice from the command line to quickly convert one or more files.

So, how do you use LibreOffice? For example, if you want to use LibreOffice to convert a set of slides to PDF, you can use the following command line content:

soffice --headless --convert-to pdf mySlides.odp

Here, you just need to replace the pdf extension with the extension of any file format you want to convert. As for the --headless option, its function is to prevent an empty LibreOffice window from opening on your desktop when running the above command.

Using LibreOffice on the command line to convert a single file is a bit of an overkill. However, it is a great way to convert multiple files at once. For example, if you want to convert all of the Microsoft Word documents in a folder to the LibreOffice Writer file format, you can use the following command:

soffice --headless --convert-to odt *.docx

This command-line conversion takes far less time than opening all those files in LibreOffice Writer and converting them manually.

FFmpeg

If Pandoc is the Swiss Army knife for converting between markup languages, then FFmpeg is the "Swiss Army knife" of Pandoc in the field of audio and video format file conversion.

FFmpeg is a collection of libraries and executable files. With this tool, you can convert files in almost any format.

The following is an example of using FFmpeg to convert an AVI video file to an Ogg video file:

ffmpeg -i myVideo.avi myvideo.ogg

Actually, FFmpeg is much more capable than that. For example, you can set the frame rate of the video and add subtitles to it, change the aspect ratio, alter the audio, and much more.

If you choose to use multiple control options, the command line can get quite crowded. Especially when you use only a few of FFmpeg's options like the ones above, it's easy to forget about other options. I recommend that you always read the help file for this tool at https://ffmpeg.org/ffmpeg.html.

Do you have your own favorite command line file conversion tool? We hope you can share it with us.

[Translated by 51CTO. Please indicate the original translator and source as 51CTO.com when reprinting on partner sites]

<<:  Dive into the implementation details of Messenger

>>:  Android unit testing - several important issues

Recommend

What should I pay attention to when using someone else’s bidding account?

In the process of Baidu bidding account promotion...

The "fluffiest planet ever" looks like cotton candy!

Marshmallow planet on a cat dwarf: a quirky and a...

APP promotion: What is it like to operate a bad product?

Someone invited me to answer a question on Zhihu....

Musk warms up: Tesla Autopilot price will increase by $1,000 from November

Recently, Tesla CEO Elon Musk said on Twitter tha...

What is the secret behind TikTok’s explosive user growth?

Think first: How do you measure user growth ? Wha...

Tips for K12 & Preschool Education Advertising!

As homogeneous competition in the industry become...

Do you want to have sex as soon as you start dating? What's wrong?

Expert of this article: Wang Li, deputy chief phy...

From online to offline, advertising budgets continue to decline!

Well-known self-media complained in the circle of...