base64 Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

In the world of Linux, we regularly encounter a variety of commands with diverse functions. Among them, the base64 command in Linux plays a significant role in the realm of data encoding. The base64 command in Linux is used to encode or decode file data. It's a binary-to-text encoding schemes technique that represents binary data in an ASCII string format. This article aims to provide a deep dive into the base64 command in Linux, explaining its syntax, options, common and advanced usages.

Syntax of base64 Command in Linux

The basic syntax of the base64 command in Linux is as follows:

Where:

  • base64: This is the actual command used to initiate the encoding or decoding process.
  • [OPTION]...: These are the options or flags which can be used with the base64 command. Examples include -d or --decode to decode data.
  • [FILE]: This is the specific file that you want to encode or decode. If no file is specified, base64 will use standard input.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Options in base64 Command in Linux

  1. -d, --decode: This option is used to decode data.

    For example -

    Output:

    This command is taking a base64 encoded string and decoding it back into its original form.

  2. -i, --ignore-garbage: When decoding, ignore non-alphabet characters.

    For example -

    Output:

    This command ignores the non-alphabet character (=) during decoding.

  3. -w, --wrap: Wrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping.

    For example -

    Output:

    This command encodes the file input.txt into a single, unwrapped line.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Basic usage of the base64 command in Linux to encode data.:

    Output:

    Explanation: This command encodes the string 'Hello World' into a base64 format.

  • Decoding base64 data back to its original form.:

    Output:

    Explanation: This command takes the base64 encoded string and decodes it back into its original format.

Tips

  • Remember that base64 encoding does not encrypt or secure your data in any way. It is a form of representation, not a security feature.

  • When decoding, if you encounter data corruption or unknown characters, try using the --ignore-garbage (-i) flag to bypass them.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of base64 Command in Linux

  • Encode a file and save the output to another file.:

    Output:

    Explanation: This command encodes the contents of input.txt and saves the base64 output to a new file named output.txt.

  • Decode a file and save the decoded content to another file.:

    Output:

    Explanation: This command decodes the contents of a base64 file named input.txt and saves the decoded output to output.txt.

  • Use base64 command with gzip to compress, then encode data.:

    Output:

    Explanation: This command first compresses the 'Hello World' string using gzip and then encodes the compressed data using base64.

Conclusion

  • The base64 command in Linux is a versatile tool for encoding and decoding files or standard input in base64 format.

  • While it doesn't offer data protection, it can be beneficial for representing binary data, especially when that data needs to be stored and transferred over media designed to deal with text.

  • Advanced usage can be combined with other commands, such as gzip, to compress and then encode data.