Skip to main content

Calculate file and directory sizes from the command line.

Project description

filesize CLI

PyPI - Version GitLab Release PyPI - Downloads GitLab Last Commit GitLab Stars

filesize CLI is a simple yet useful command-line tool written in Python. Using the filesize command, you can see the size of a file or directory right in your CLI (e.g., 12.4 MB). It works for singular and multiple files and directories. filesize CLI can be installed easily on Windows, macOS, and Linux via Homebrew, pip (in a virtual environment), or pipx`.

Table of Contents

[TOC]

✨ Features

  • Multi-Unit Support: Display file sizes in Bytes (B), Kilobytes (KB), Megabytes (MB), Gigabytes (GB), or Terabytes (TB).
  • Customizable Conversion Rate: Specify a custom conversion rate (default is 1000).
  • Pretty Print Option: Toggle between plain output and formatted output with unit labels.
  • Cross-Platform Compatibility: Works seamlessly on Windows, macOS, and Linux.
  • Easy Installation: Install globally using pip for universal access.

🔧 Requirements

  1. Python 3.6 or above

🛠️ Installation

For all installation methods, make sure you have Python 3.6 or above running. Check this in your CLI with python --version. If you don't have Python, follow the steps under "Get Python".

Using pip in Virtual Environments (Recommended)

This method is recommended if you use a Python virtual environment.

  1. Create your virtual Python environment (e.g., python -m venv venv)
  2. Activate it by entering source venv/bin/activate
  3. Install pip install -r requirements.txt.

The command filesize is now available in your environment.

Using pipx for system-wide installations (only macOS)

If you use macOS and want to use filesize CLI globally, you must install pipx via Homebrew.

  1. Download and install Homebrew (if not done)
  2. Run pipx install filesize-cli

That's it!

Build from Source

If you prefer to install filesize CLI from the source repository, follow these steps:

  1. Clone the Repository

    git clone https://gitlab.com/thaikolja/filesize-cli.git
    cd filesize-cli
    
  2. Install the Package

    pip install -r requirements.txt
    
  3. Verify Installation (optional)

    filesize --help
    

🚀 Usage

The filesize command allows you to view the size of a specified file in your desired unit. Below are the options and examples to help you get started.

Options

  • -u, --unit: string (Optional) Unit to display the file size in. Default: auto
    1. b: Bytes
    2. kb: Kilobytes
    3. mb: Megabytes
    4. gb: Gigabytes
    5. tb: Terabytes
    6. auto: Determines the unit automatically based on its size
  • -r, --rate: int (Optional) Conversion rate of the file size. Default: 1000
    1. e.g., 1024
  • -q, --quiet: string Description: If enabled, only the filesize will be returned without size units. Default: Deactivated

Examples

1. Show File Size with Auto Unit Detection

filesize examples/image.jpg

Output:

191.50 KB

2. Display Size in Kilobytes

filesize --unit mb examples/image.jpg

Output:

0.19 MB

3. Display Size in Bytes Without Size Unit

filesize --unit b --quiet examples/base64.txt

Output:

65

4. Use a Custom Conversion Rate

filesize --unit mb --rate 1024 examples/video.mp4

Output:

0.18 MB

🐍 Get Python

In case you don't have Python, follow these steps.

  • Windows:

    • Download and install Python from the official website.
    • Ensure that Python is added to your system's PATH during installation.
  • macOS:

    • Python 3 is pre-installed on newer versions. If not, install it via Homebrew:

      brew install python
      
  • Linux:

    • Python 3 can be installed via your distribution's package manager, but should be pre-installed for most distributions. For example, on Ubuntu:

      sudo apt update
      sudo apt install python3 python3-pip
      

🧪 Testing

Ensuring the reliability and correctness of filesize-cli is paramount. The project includes a comprehensive test suite using pytest.

Running Tests

  1. Clone the Repository (if not already done)

    git clone https://gitlab.com/thaikolja/filesize-cli.git
    cd filesize-cli
    
  2. Create and Activate a Virtual Environment

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install Dependencies

    pip install -r requirements.txt
    pip install .
    
  4. Run Tests

    pytest
    

Test Structure

Tests are located in the tests/ directory and cover various scenarios. Run them with pytest tests/test_*.py

🤝 Contributing

Contributions are welcome! Whether it's reporting a bug, suggesting a feature, or submitting a pull request, your input helps improve filesize CLI.

Steps to Contribute

  1. Fork the Repository

    Click the "Fork" button on the GitLab repository to create your own copy.

  2. Clone Your Fork

    git clone https://gitlab.com/thaikolja/filesize-cli.git
    cd filesize-cli
    
  3. Create a New Branch

    git checkout -b feature/YourFeatureName
    
  4. Make Your Changes

    Implement your feature or fix bugs.

  5. Commit Your Changes

    git commit -m "Add feature: YourFeatureName"
    
  6. Push to Your Fork

    git push origin feature/YourFeatureName
    
  7. Submit a Merge Request

    Go to the original repository and create a merge request from your fork.

🧑‍💻 Authors and Contributors

  1. Kolja Nolte (kolja.nolte@gmail.com )

📜 License

This project is licensed under the MIT License.

📅 Changelog

See CHANGELOG.md for detailed information about changes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

filesize_cli-1.1.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

filesize_cli-1.1.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file filesize_cli-1.1.1.tar.gz.

File metadata

  • Download URL: filesize_cli-1.1.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.2

File hashes

Hashes for filesize_cli-1.1.1.tar.gz
Algorithm Hash digest
SHA256 2cc9cf72b48bd40e721fe52bf76064df13bb2a899cf60c7d145e92339773e0a7
MD5 f6f18a7018f57991f941e87e7674fa9f
BLAKE2b-256 31b27279301e60e2d56f12703b98e6f1d97db096adc22b893f7d6f2b1cf1146e

See more details on using hashes here.

File details

Details for the file filesize_cli-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: filesize_cli-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.2

File hashes

Hashes for filesize_cli-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6cde4dbd9517d2c026c79226522976056fd37e07df6d0297c37e26919f992457
MD5 f7335105160eeedbdd790f048245239e
BLAKE2b-256 fcab4f8bfdddf8ab274bcc470844abd91daf5fb94bbaee9520aa8c65efd867c8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page