file-size

File size script that works on many operating systems

https://github.com/sixarm/file-size

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.8%) to scientific vocabulary
Last synced: 8 months ago · JSON representation ·

Repository

File size script that works on many operating systems

Basic Info
  • Host: GitHub
  • Owner: SixArm
  • Language: Shell
  • Default Branch: main
  • Size: 10.7 KB
Statistics
  • Stars: 7
  • Watchers: 3
  • Forks: 3
  • Open Issues: 0
  • Releases: 0
Created over 8 years ago · Last pushed about 1 year ago
Metadata Files
Readme Code of conduct Citation Codeowners

README.md

file-size:
show file size in bytes, using the apparent size

Syntax:

file-size <file>

Example:

file-size example.txt
123

Exit

Exit codes:

  • 0 is success
  • Anything else is an error.

Strategies

This script has a goal to be cross-platform, so this script tries these strategies in order:

  • $FILE_SIZE

    • Any command you want.
  • du --apparent-size

    • Standard on current Linux.
  • gdu --apparent-size

    • Available in current GNU coreutils.
  • find -printf

    • Standard on current Linux, and likely on many others.
  • gfind -printf

    • Available in GNU fileutils.
  • stat --printf

    • Not standard on macOS, OSX, or Solaris.
  • stat -f%z

    • Standard on macOS, OSX, maybe BSD, and others.
  • wc -c

    • Fast on some systems, but very slow on others.

Environment variables

This script has a goal to be customizable at runtime, so this script accepts envirnment variables for commands:

  • FILE_SIZE

    • Any command you want; it must print the size first.
  • DU

    • du command (disk usage)
    • Example: DU=/usr/bin/du
  • GDU

    • gdu command (GNU disk usage)
    • Example: GDU=/usr/local/bin/gdu
  • FIND

    • find command (find files and print sizes)
    • Example: FIND=/usr/bin/find
  • GFIND

    • gfind command (GNU find files and print sizes)
    • Example: GFIND=/usr/local/bin/gfind
  • STAT

    • stat command (file statistics)
    • Example: STAT=/usr/bin/stat
  • WC

    • wc command (word count of characters a.k.a. bytes.)
    • Example: WC=/usr/bin/wc

Example to provide a custom du command path:

DU="/foo/du" file-size example.txt

Example to export a custom du command path:

export DU="/foo/du"
file-size example.txt

We typically set our command variables in our /etc/environment file, and similar startup files such as our ~/.bashrc file and ~/.zshrc file, so our command variables are available for all of our shell scripts.

Environment variables for optimization

Using an environment variable can boost the speed of this script, because it able to use the correct command first, rather than probing.

For example, suppose your system command wc is very fast.

You can use it this way:

export FILE_SIZE="wc -c"

Now the script will prefer your system command.

For OSX users

If your system is a typical OSX system, a way to get the GNU commands is by using the brew package manager and installing GNU packages:

brew install coreutils findutil

If you want to use the GNU commands without a g prefix, instead of your default system commands, one way is this:

brew install --default-names coreutils findutil

Another way is to add the GNU commands to your PATH, such as:

export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH

Tracking

  • Program: file-size
  • Version: 3.0.1
  • Created: 2014-12-02
  • Updated: 2019-06-20
  • License: GPL
  • Contact: Joel Parker Henderson (joel@joelparkerhenderson.com)

Owner

  • Name: SixArm
  • Login: SixArm
  • Kind: organization
  • Email: sixarm@sixarm.com
  • Location: San Francisco

SixArm Software

Citation (CITATION.cff)

cff-version: 1.2.0
title: file-size:<br>show file size in bytes, using the apparent size
message: >-
  If you use this work and you want to cite it,
  then you can use the metadata from this file.
type: software
authors:
  - given-names: Joel Parker
    family-names: Henderson
    email: joel@joelparkerhenderson.com
    affiliation: joelparkerhenderson.com
    orcid: 'https://orcid.org/0009-0000-4681-282X'
identifiers:
  - type: url
    value: 'https://github.com/SixArm/file-size/'
    description: file-size:<br>show file size in bytes, using the apparent size
repository-code: 'https://github.com/SixArm/file-size/'
abstract: >-
  file-size:<br>show file size in bytes, using the apparent size
license: See license file

GitHub Events

Total
  • Push event: 1
Last Year
  • Push event: 1

Committers

Last synced: 12 months ago

All Time
  • Total Commits: 14
  • Total Committers: 2
  • Avg Commits per committer: 7.0
  • Development Distribution Score (DDS): 0.071
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Joel Parker Henderson j****l@j****m 13
Daniel Thalhuber d****v@u****i 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 0
  • Total pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: about 2 hours
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 2.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • danielthalhuber (1)
Top Labels
Issue Labels
Pull Request Labels