Working with Files in Terminal
File operations for copying, describing, validating, and analyzing local or remote files.
Available Commands
Section titled “Available Commands”The fairspec file command provides utilities for working with files:
copy- Copy local or remote filesdescribe- Get file statistics and metadatavalidate- Validate file integrityinfer-format- Detect file format automatically
Copy Files
Section titled “Copy Files”Copy files from local or remote sources to a local destination:
# Copy a local filefairspec file copy data.csv --to-path output.csv
# Copy a remote filefairspec file copy https://example.com/data.csv --to-path local-data.csv
# Copy from a dataset resourcefairspec file copy --from-dataset dataset.json --from-resource users --to-path users.csvOptions
Section titled “Options”--to-path <path>(required) - Local output path--from-dataset <path>- Load file from dataset descriptor--from-resource <name>- Specify resource name from dataset--silent- Suppress output messages--debug- Show debug information--json- Output as JSON
Describe Files
Section titled “Describe Files”Get detailed information about a file including size, type, and checksums:
# Describe a local filefairspec file describe data.csv
# Describe with specific hash typefairspec file describe data.csv --hash-type sha256
# Describe a remote filefairspec file describe https://example.com/data.csv
# Describe from a datasetfairspec file describe --from-dataset dataset.json --from-resource usersOutput
Section titled “Output”The describe command returns:
bytes- File size in bytestextual- Whether the file is text-basedintegrity- Hash value and type
Options
Section titled “Options”--hash-type <type>- Hash algorithm to use- Choices:
md5,sha1,sha256(default),sha512
- Choices:
--from-dataset <path>- Load file from dataset descriptor--from-resource <name>- Specify resource name from dataset--silent- Suppress output messages--debug- Show debug information--json- Output as JSON
Example Output
Section titled “Example Output”{ "bytes": 1024, "textual": true, "integrity": { "type": "sha256", "hash": "a1b2c3d4e5f6..." }}Validate Files
Section titled “Validate Files”Validate file integrity using checksums:
# Validate with expected hashfairspec file validate data.csv --hash a1b2c3d4e5f6 --hash-type sha256
# Validate using MD5fairspec file validate data.csv --hash 098f6bcd4621 --hash-type md5
# Output as JSON for automationfairspec file validate data.csv --hash a1b2c3d4 --jsonOptions
Section titled “Options”--hash <hash>- Expected file hash--hash-type <type>- Hash algorithm to use (default:md5)- Choices:
md5,sha1,sha256,sha512
- Choices:
--silent- Suppress output messages--debug- Show debug information--json- Output as JSON
Validation Report
Section titled “Validation Report”Returns a validation report with:
valid- Boolean indicating if validation passederrors- Array of validation errors (if any)
Example error:
{ "valid": false, "errors": [ { "type": "file/integrity", "hashType": "sha256", "expectedHash": "a1b2c3d4e5f6...", "actualHash": "different..." } ]}Infer Format
Section titled “Infer Format”Automatically detect the format of a file:
# Infer format from filefairspec file infer-format data.csv
# Infer from remote filefairspec file infer-format https://example.com/data.json
# Output as JSONfairspec file infer-format data.xlsx --jsonOptions
Section titled “Options”--silent- Suppress output messages--debug- Show debug information--json- Output as JSON
Supported Formats
Section titled “Supported Formats”The command can detect:
- CSV/TSV files
- JSON/JSONL files
- Excel files (.xlsx, .xls)
- OpenDocument Spreadsheet (.ods)
- Parquet files
- Arrow/Feather files
- SQLite databases
Working with Datasets
Section titled “Working with Datasets”All file commands support loading files from dataset descriptors:
# Describe a resource from a datasetfairspec file describe --from-dataset dataset.json --from-resource sales-data
# Copy a resource from a datasetfairspec file copy --from-dataset dataset.json --from-resource users --to-path users.csv
# Validate a resource from a datasetfairspec file validate --from-dataset dataset.json --from-resource products --hash abc123Output Formats
Section titled “Output Formats”Text Output (default)
Section titled “Text Output (default)”Human-readable output with colors and formatting:
fairspec file describe data.csvJSON Output
Section titled “JSON Output”Machine-readable JSON for automation and scripting:
fairspec file describe data.csv --jsonSilent Mode
Section titled “Silent Mode”Suppress all output except errors:
fairspec file copy data.csv --to-path output.csv --silentExamples
Section titled “Examples”Copy and Validate
Section titled “Copy and Validate”# Copy a file and get its hashfairspec file copy remote-data.csv --to-path local-data.csvfairspec file describe local-data.csv --hash-type sha256
# Validate the copied filefairspec file validate local-data.csv --hash <hash-from-describe> --hash-type sha256Process Dataset Resources
Section titled “Process Dataset Resources”# Describe all details of a dataset resourcefairspec file describe --from-dataset dataset.json --from-resource sales
# Copy the resource locallyfairspec file copy --from-dataset dataset.json --from-resource sales --to-path sales.csv
# Infer its formatfairspec file infer-format sales.csvAutomation with JSON
Section titled “Automation with JSON”# Get file info as JSON for scriptingINFO=$(fairspec file describe data.csv --json)HASH=$(echo $INFO | jq -r '.integrity.hash')
# Use in validationfairspec file validate data.csv --hash $HASH --hash-type sha256