A cornucopia of Linux commands

Contents

From the “moreutils” RPM

  • chronic - runs a command quietly unless it fails (intended for use by cron)
  • combine - combine sets of lines from two files using boolean operations
  • errno - look up errno names and descriptions
  • ifdata - get network interface info without parsing ifconfig output
  • ifne - Run command if the standard input is not empty
  • isutf8 - check whether files are valid UTF-8
  • lckdo - run a program with a lock held
  • mispipe - pipe two commands, returning the exit status of the first
  • pee - tee standard input to pipes
  • sponge - soak up standard input and write to a file [after all data have been collected]
  • ts - timestamp input (up to now I’ve done this using perl)
  • vidir - edit directory (akin to my mvmp3 command)
  • vipe - edit pipe (edit pipeline data before sending it to the next command)
  • zrun - automatically uncompress arguments to command

“bat” - a cat(1) clone with syntax highlighting and Git integration

bat on GitHub

“bat” combines the functionality of cat with a pager like less and syntax highlighting. For example, to view my DateTime.pl program with syntax highlighting:

bat ~/bin/DateTime.pl

However, that expands tabs on 8 columns, not the 4 that I prefer. This helps:

expand -t4 ~/bin/DateTime.pl | bat -l perl

Instead of passing the language directly, one could extract it from the file name and pass it that way:

function jbat {
    local L="$(echo "$1"|egrep -o '\.[[:alnum:]]+$')"
    expand -t4 $1 | /usr/bin/bat --language ${L:1}
}
jbat ~/bin/DateTime.pl

“xsv” - a fast CSV command line toolkit written in Rust

xsv on GitHub

XSV subcommands:

  • cat - Concatenate CSV files by row or by column.
  • count - Count the rows in a CSV file. (Instantaneous with an index.)
  • fixlengths - Force a CSV file to have same-length records by either padding or truncating them.
  • flatten - A flattened view of CSV records. Useful for viewing one record at a time.
    e.g., xsv slice -i 5 data.csv | xsv flatten.
  • fmt - Reformat CSV data with different delimiters, record terminators or quoting rules. (Supports ASCII delimited data.)
  • frequency - Build frequency tables of each column in CSV data. (Uses parallelism to go faster if an index is present.)
  • headers - Show the headers of CSV data. Or show the intersection of all headers between many CSV files.
  • index - Create an index for a CSV file. This is very quick and provides constant time indexing into the CSV file.
  • input - Read CSV data with exotic quoting/escaping rules.
  • join - Inner, outer and cross joins. Uses a simple hash index to make it fast.
  • partition - Partition CSV data based on a column value.
  • sample - Randomly draw rows from CSV data using reservoir sampling (i.e., use memory proportional to the size of the sample).
  • reverse - Reverse order of rows in CSV data.
  • search - Run a regex over CSV data. Applies the regex to each field individually and shows only matching rows.
  • select - Select or re-order columns from CSV data.
  • slice - Slice rows from any part of a CSV file. When an index is present, this only has to parse the rows in the slice (instead of all rows leading up to the start of the slice).
  • sort - Sort CSV data.
  • split - Split one CSV file into many CSV files of N chunks.
  • stats - Show basic types and statistics of each column in the CSV file. (i.e., mean, standard deviation, median, range, etc.)
  • table - Show aligned output of any CSV data using elastic tabstops.