No description
  • C 26.2%
  • HTML 24.7%
  • Go 15%
  • Python 11.8%
  • Perl 11.7%
  • Other 10.6%
Find a file
Mike Marion 501a8a3cf2 Move histogram bars to the right of percent/count/data columns
Reorder histogram output from [bar] percent count data
to percent count data [bar], so the data column is always
visible without scrolling past the bar.  The data column is
now padded to a fixed width (longest key) so bars align.
Update README with revised option description and example.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 18:01:41 -07:00
debian Add GNU info manual and integrate into RPM and Debian packaging 2026-05-17 17:53:07 -07:00
.gitignore Add .gitignore to exclude compiled binaries 2026-05-17 18:24:38 -07:00
go.mod Port --min/--max/--fullperc/--ignore/--verbose to C and Go; update README 2026-05-16 10:36:12 -07:00
port-comparison.html Update port-comparison.html: psort_c now fastest after O(n²) fix 2026-05-17 11:44:19 -07:00
psort.1 Add --histogram / -H option to all four ports 2026-05-17 18:21:45 -07:00
psort.c Move histogram bars to the right of percent/count/data columns 2026-05-18 18:01:41 -07:00
psort.go Move histogram bars to the right of percent/count/data columns 2026-05-18 18:01:41 -07:00
psort.info Add --histogram / -H option to all four ports 2026-05-17 18:21:45 -07:00
psort.pl Fix histogram line wrapping: account for key length in bar width 2026-05-17 18:32:29 -07:00
psort.py Move histogram bars to the right of percent/count/data columns 2026-05-18 18:01:41 -07:00
psort.spec Add GNU info manual and integrate into RPM and Debian packaging 2026-05-17 17:53:07 -07:00
psort.texi Add --histogram / -H option to all four ports 2026-05-17 18:21:45 -07:00
README.md Move histogram bars to the right of percent/count/data columns 2026-05-18 18:01:41 -07:00
scaling_mem.png Update scaling charts with fixed psort_c (all four variants, single subplot) 2026-05-17 11:33:58 -07:00
scaling_real.png Update scaling charts with fixed psort_c (all four variants, single subplot) 2026-05-17 11:33:58 -07:00
scaling_sys.png Update scaling charts with fixed psort_c (all four variants, single subplot) 2026-05-17 11:33:58 -07:00
scaling_user.png Update scaling charts with fixed psort_c (all four variants, single subplot) 2026-05-17 11:33:58 -07:00

psort

Originally a Perl script that combines sort | uniq -c | sort -n into one command, with percentages, aligned columns, and filtering options.

 find Movies -type f -name \*.mp4 -o -name \*.m4v | awk -F\. '{print $NF}' | psort
 2.8649%    42 mp4
97.1351%  1424 m4v
  Total:  1466

Implementations

Four implementations are provided, all supporting identical options:

Binary Language Notes
psort_c C Fastest; default psort symlink
psort_go Go
psort.py Python 3
psort.pl Perl Original implementation

When installed via the RPM or Debian package, /usr/bin/psort is a symlink managed by update-alternatives pointing to psort_c by default. Switch with:

update-alternatives --config psort

Usage

Usage: psort [options] [file ...]
    --csv, -c     : Output as CSV (percentage%,count,value)
    --csvall, -a  : CSV output, also replacing whitespace in values with commas
    --decimal, -d : Decimal places for percentages (default 4)
    --numeric     : Sort by numeric value of input instead of by count
    --min, -m     : Exclude entries with count below N
                     (percentages recomputed from remaining; see --fullperc)
    --max, -x     : Exclude entries with count above N
    --fullperc, -f: With --min/--max, compute % from the full original total
    --ignore, -i  : With --min/--max, suppress the [excluded] summary line
    --verbose, -v : With --min/--max, print key/count totals before and after
    --reverse, -r : Reverse sort order (highest count/value first)
    --histogram,-H: Show a bar histogram; columns are percent, count, value,
                     then a bar scaled to the remaining terminal width
    --help, -h    : Output this help info

Synopsis: Takes input and essentially does the equivalent of `sort | uniq -c | sort -n`
with added percentages and total info, default output is nicely formatted for humans to read.

Examples

Top 5 most common file extensions, highest first:

find /path -type f | sed 's/.*\.//' | psort -r | head -5

HTTP status code distribution, CSV output:

awk '{print $9}' access.log | psort -c

Word frequencies, minimum 10 occurrences, full-total percentages:

tr -cs 'A-Za-z' '\n' < doc.txt | tr 'A-Z' 'a-z' | psort --min 10 --fullperc

Histogram — percent, count, and value columns appear first; the bar fills the remaining terminal width:

 cut -d: -f7 /etc/passwd | psort -H
 2.4390%   1 /bin/bash         [#                                            ]
 2.4390%   1 /bin/sync         [#                                            ]
 2.4390%   1 /usr/bin/bash     [#                                            ]
 4.8780%   2 /usr/sbin/nologin [##                                           ]
88.0000%  36 /sbin/nologin     [###########################################  ]
  Total:  41

Installation

RPM (Fedora / RHEL / CentOS)

Build and install from the included spec:

# Create a source tarball from the repo
git archive --prefix=psort-1.0.0/ HEAD | gzip > ~/rpmbuild/SOURCES/psort-1.0.0.tar.gz

# Build the RPM
rpmbuild -ba psort.spec

# Install
rpm -i ~/rpmbuild/RPMS/$(uname -m)/psort-1.0.0-1.*.rpm

Debian / Ubuntu

Build and install from the included packaging:

dpkg-buildpackage -us -uc -b
sudo dpkg -i ../psort_1.0.0-1_$(dpkg --print-architecture).deb

Manual

Copy the binaries you want to /usr/local/bin (or anywhere on your PATH). A man page is in psort.1:

sudo install -m755 psort_c psort_go psort.py psort.pl /usr/local/bin/
sudo install -m644 psort.1 /usr/local/share/man/man1/

Man Page

A man page covering all options and examples is included as psort.1.

man ./psort.1