Skip to content

Encoding & Hashing

base64, md5sum, sha1sum, sha256sum, and file for encoding, integrity checking, and file type detection.


Encode or decode data in Base64 format.

base64 [OPTIONS] [FILE]
FlagDescription
-d, --decodeDecode Base64 input back to original data
-w NUM, --wrap=NUMWrap encoded output at NUM columns (default: 76, 0 = no wrap)

Returns a PsBash.TextOutput object with the encoded or decoded string as BashText.

Encode a string from the pipeline:

Terminal window
echo 'hello' | base64
aGVsbG8K

Decode a Base64 string:

Terminal window
echo 'aGVsbG8K' | base64 -d
hello

Encode a file:

Terminal window
base64 image.png

Encode without line wrapping:

Terminal window
echo 'a longer string that would normally wrap' | base64 -w 0

Decode a Base64 file:

Terminal window
base64 -d encoded.txt

Compute MD5 message digest for files or pipeline input.

md5sum [OPTIONS] [FILE...]
FlagDescription
-c, --checkRead checksums from file and verify them
-b, --binaryRead files in binary mode

Each result is a PsBash.TextOutput object:

PropertyTypeDescription
HashstringHex-encoded MD5 digest
FileNamestringPath to the hashed file, or - for pipeline input
AlgorithmstringMD5
BashTextstringFormatted hash filename output

Hash a file:

Terminal window
md5sum README.md
d41d8cd98f00b204e9800998ecf8427e README.md

Hash multiple files:

Terminal window
md5sum file1.txt file2.txt
098f6bcd4621d373cade4e832627b4f6 file1.txt
ad0234829205b9033196ba818f7a872b file2.txt

Hash pipeline input:

Terminal window
echo 'data' | md5sum
8d777f385d3dfec8815d20f7496026dc -

Access the hash property directly:

Terminal window
$result = md5sum README.md
$result.Hash # "d41d8cd98f00b204e9800998ecf8427e"
$result.Algorithm # "MD5"

Compute SHA-1 message digest for files or pipeline input. Same interface as md5sum.

sha1sum [OPTIONS] [FILE...]
FlagDescription
-c, --checkRead checksums from file and verify them
-b, --binaryRead files in binary mode

Each result is a PsBash.TextOutput object:

PropertyTypeDescription
HashstringHex-encoded SHA-1 digest
FileNamestringPath to the hashed file, or - for pipeline input
AlgorithmstringSHA1
BashTextstringFormatted hash filename output

Hash a file:

Terminal window
sha1sum README.md
da39a3ee5e6b4b0d3255bfef95601890afd80709 README.md

Hash from pipeline:

Terminal window
echo 'data' | sha1sum
a17c9aaa61e80a1bf71d0d850af4e5baa9800bbd -

Use the typed properties:

Terminal window
$result = sha1sum config.yml
$result.Hash # hex digest string
$result.FileName # "config.yml"

Compute SHA-256 message digest for files or pipeline input. Same interface as md5sum.

sha256sum [OPTIONS] [FILE...]
FlagDescription
-c, --checkRead checksums from file and verify them
-b, --binaryRead files in binary mode

Each result is a PsBash.TextOutput object:

PropertyTypeDescription
HashstringHex-encoded SHA-256 digest
FileNamestringPath to the hashed file, or - for pipeline input
AlgorithmstringSHA256
BashTextstringFormatted hash filename output

Hash a file:

Terminal window
sha256sum README.md
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 README.md

Hash pipeline input:

Terminal window
echo 'data' | sha256sum
b8e2f6eb2098b6d0fcbabf2db0b3b5e24bfe7b6eab9a573ae322e4f0a7c17e3c -

Compare checksums programmatically:

Terminal window
$expected = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
$actual = (sha256sum README.md).Hash
$expected -eq $actual # True

Determine the type of a file by inspecting its contents (magic bytes).

file [OPTIONS] FILE...
FlagDescription
-b, --briefOmit the filename prefix from output
-i, --mimeOutput MIME type instead of human-readable description
-L, --dereferenceFollow symbolic links (accepted for compatibility)
TypeMagic BytesDescriptionMIME Type
PNG89 50 4E 47PNG image dataimage/png
JPEGFF D8JPEG image dataimage/jpeg
PDF25 50 44 46PDF documentapplication/pdf
ZIP50 4B 03 04Zip archive dataapplication/zip
ELF7F 45 4C 46ELF executableapplication/x-executable
GIF47 49 46 38GIF image dataimage/gif
RIFF52 49 46 46RIFF dataapplication/octet-stream
Text(no binary bytes)ASCII texttext/plain

Files that match no magic signature and contain binary bytes are reported as data with MIME type application/octet-stream.

Each result is a PsBash.TextOutput object:

PropertyTypeDescription
FileNamestringPath to the inspected file
FileTypestringHuman-readable type description
MimeTypestringMIME type string
BashTextstringFormatted output string

Detect file type:

Terminal window
file image.png
image.png: PNG image data

Brief output (no filename):

Terminal window
file -b image.png
PNG image data

MIME type output:

Terminal window
file -i document.pdf
document.pdf: application/pdf

Combine brief and MIME:

Terminal window
file -bi archive.zip
application/zip

Check multiple files:

Terminal window
file script.ps1 photo.jpg data.bin
script.ps1: ASCII text
photo.jpg: JPEG image data
data.bin: data

Access typed properties:

Terminal window
$info = file image.png
$info.FileType # "PNG image data"
$info.MimeType # "image/png"