Linux Column Command: The Text Formatter You Did not Know You Needed
Introduction
Have you ever tried to make sense of cluttered text output in your terminal? Perhaps you’ve found yourself squinting at disorganized data, wishing there was an easy way to transform it into neat, readable columns? Enter the column
command – one of Linux’s most underappreciated text-formatting utilities that can instantly transform messy text into beautifully aligned tabular displays.
While not as famous as commands like grep
or awk
, the column
command is a powerful tool that belongs in every Linux user’s toolkit. Whether you’re a system administrator parsing configuration files, a data analyst examining CSV exports, or just someone who appreciates well-organized information, column
can dramatically improve how you view and understand text data in the terminal.
In this guide, we’ll explore what the column
command is, its most practical use cases, and how it can make your command-line experience more efficient and visually pleasing. By the end, you’ll wonder how you ever lived without this simple yet powerful formatting tool.
What is the Column Command?
The column
command is a text processing utility that formats its input into multiple columns. Originally designed to format manual pages, it has evolved into a versatile text formatter that can handle various data formats including plain text, delimited data, and even JSON in some implementations.
At its core, column
does one thing extremely well: it takes lines of text and arranges them into aligned columns that are much easier to read. Think of it as an instant table maker for your terminal – transforming cluttered text into structured, scannable information with minimal effort.
The Top 3 Most Useful Column Command Applications
Let’s dive into the three most practical and powerful ways to use the column
command in your daily Linux work.
1. Formatting Delimited Data with -t
and -s
The most common and useful application of column
is formatting delimited data into tables. This is perfect for CSV files, configuration files, or any output that uses a consistent delimiter between fields.
# Basic usage with tab-delimited input
cat data.txt | column -t
# Specify a different delimiter (like comma for CSV files)
cat data.csv | column -t -s,
# Specify both input delimiter and output delimiter
cat data.csv | column -t -s, -o " | "
Example in Action:
Let’s say you have a CSV file containing information about Linux distributions:
Name,Version,Release Date,Desktop Environment
Ubuntu,22.04,2022-04-21,GNOME
Fedora,37,2022-11-15,GNOME
Debian,11,2021-08-14,Various
Arch Linux,Rolling,Continuous,Various
Linux Mint,21,2022-07-31,Cinnamon
When you view this file directly with cat
, it’s difficult to read:
$ cat distros.csv
Name,Version,Release Date,Desktop Environment
Ubuntu,22.04,2022-04-21,GNOME
Fedora,37,2022-11-15,GNOME
Debian,11,2021-08-14,Various
Arch Linux,Rolling,Continuous,Various
Linux Mint,21,2022-07-31,Cinnamon
But format it with column -t -s,
:
$ cat distros.csv | column -t -s,
Name Version Release Date Desktop Environment
Ubuntu 22.04 2022-04-21 GNOME
Fedora 37 2022-11-15 GNOME
Debian 11 2021-08-14 Various
Arch Linux Rolling Continuous Various
Linux Mint 21 2022-07-31 Cinnamon
The difference is striking! Your previously cluttered CSV data is now displayed as a clean, readable table with properly aligned columns. This makes it much easier to scan and understand the information at a glance.
The -t
flag tells column
to create a table, while -s,
specifies that commas are the field separators in the input. If you wanted to make the output even more visually distinct, you could add the -o
option to specify an output delimiter:
$ cat distros.csv | column -t -s, -o " | "
Name | Version | Release Date | Desktop Environment
Ubuntu | 22.04 | 2022-04-21 | GNOME
Fedora | 37 | 2022-11-15 | GNOME
Debian | 11 | 2021-08-14 | Various
Arch Linux | Rolling | Continuous | Various
Linux Mint | 21 | 2022-07-31 | Cinnamon
This makes the column
command especially useful for quickly examining data files or the output of other commands without having to open a spreadsheet application.
2. Creating Multi-Column Lists with Default Mode
The second most useful application of column
is its default behavior: transforming a long list into a multi-column display that efficiently uses terminal space.
# List files in multiple columns
ls | column
# Create a multi-column list from any command output
cat wordlist.txt | column
Example in Action:
Imagine you have a long list of package names:
$ cat packages.txt
nginx
postgresql
redis
mongodb
python3
nodejs
ruby
php
golang
rust
java
mysql
sqlite
apache2
git
docker
kubernetes
ansible
terraform
prometheus
Reading through this vertical list takes up a lot of space and requires scrolling. But when you pipe it through column
:
$ cat packages.txt | column
nginx postgresql redis mongodb python3
nodejs ruby php golang rust
java mysql sqlite apache2 git
docker kubernetes ansible terraform prometheus
The result is a compact, multi-column display that fits more information on screen at once. This is particularly useful for long lists of filenames, options, or any other data where you just need to scan through items quickly.
This default behavior is especially handy when combined with other commands:
$ dpkg --list | grep ^ii | awk '{print $2}' | column
adduser apparmor apt apt-utils
base-files base-passwd bash bsdutils
bzip2 coreutils dash debconf
debianutils diffutils dpkg e2fsprogs
fdisk findutils gcc-10-base gpgv
grep gzip hostname init-system-helpers
libacl1 libapt-pkg6.0 libattr1 libaudit-common
...
This outputs all installed packages in an easy-to-scan multi-column format, making much better use of your terminal space.
3. Working with Complex Output from System Commands
The third most powerful use case for column
is formatting the output of system commands that produce structured but hard-to-read information.
# Format mount information
mount | column -t
# Format network connection data
netstat -tuln | column -t
# Format disk usage information
df -h | column -t
Example in Action:
The mount
command is notoriously difficult to read in its raw output:
$ mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=8121732k,nr_inodes=2030433,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=1628440k,mode=755)
/dev/nvme0n1p2 on / type ext4 (rw,relatime,errors=remount-ro)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
...
But with column
, it becomes dramatically more legible:
$ mount | column -t
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=8121732k,nr_inodes=2030433,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=1628440k,mode=755)
/dev/nvme0n1p2 on / type ext4 (rw,relatime,errors=remount-ro)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
...
The aligned columns make it much easier to compare mount points, filesystem types, and options.
Similarly, the output of df
(disk free) command becomes more readable:
$ df -h | column -t
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 2.0M 1.6G 1% /run
/dev/nvme0n1p2 457G 298G 137G 69% /
tmpfs 7.8G 161M 7.6G 3% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/nvme0n1p1 511M 6.1M 505M 2% /boot/efi
tmpfs 1.6G 84K 1.6G 1% /run/user/1000
This clean formatting makes it much easier to quickly assess disk usage across different filesystems.
Advanced Column Command Features
Beyond the top three use cases, column
offers several advanced features worth knowing:
Table Headers with --table-header
Newer versions of column
can properly handle table headers:
# Specify the first line as a header row
cat data.csv | column -t -s, --table-header
This ensures the header row is treated specially and may be visually distinguished in some implementations.
JSON Output with -J
Some modern versions of column
(specifically the one from util-linux 2.36+) support JSON output:
# Output as JSON format
mount | column -J
This is useful for parsing the formatted data programmatically.
Custom Table Formatting with -x
and -c
You can control the way column
fills columns:
# Fill columns horizontally (default)
ls | column
# Fill columns vertically
ls | column -x
# Specify the number of columns
ls | column -c 3
Practical Column Command Applications in Daily Work
Here are some practical ways to incorporate column
into your daily Linux workflow:
Enhance Configuration File Readability
# Make /etc/fstab more readable
cat /etc/fstab | grep -v ^# | column -t
Format the Output of Database Queries
# Format PostgreSQL tabular output
psql -c "SELECT * FROM users LIMIT 10" | column -t
Create Better-Looking Command Outputs in Scripts
# In a shell script
echo -e "USER\tHOME\tSHELL" > report.txt
cat /etc/passwd | cut -d: -f1,6,7 | tr ':' '\t' >> report.txt
column -t -s $'\t' report.txt
Format Process Information
# Format process information for specific users
ps -u username -o pid,ppid,cmd,%cpu,%mem | column -t
Frequently Asked Questions
How do I install the column command?
The column
command is typically included in the util-linux
package, which is installed by default on most Linux distributions. If you need to install it:
On Debian/Ubuntu:
sudo apt install bsdmainutils
On CentOS/RHEL:
sudo yum install util-linux
Can column handle very large files?
column
reads the entire input into memory to calculate column widths, so it’s not ideal for extremely large files. For very large datasets, consider using alternative tools like awk
or processing the file in chunks.
How do I prevent column from interpreting certain characters?
If your data contains special characters that column
might interpret, you can use the -n
flag in some versions to disable this interpretation:
column -t -n file.txt
Can I use column with fixed-width input?
Yes, some versions of column
support the -c
option to specify column widths:
column -c 20,30,15 file.txt
However, this feature isn’t universally available across all implementations.
How can I format the output of the ls command properly?
While ls
already formats output in columns, you might want to combine it with other commands:
ls -la | awk 'NR>1 {print $1, $3, $4, $5, $9}' | column -t
This extracts specific fields from ls -la
output and formats them neatly.
Your Next Steps with Column Command
Now that you understand the power of the column
command, consider integrating it into your daily workflow:
- Create aliases for your most frequently used
column
commands - Add it to your scripts to make their output more readable
- Combine it with other text processing tools like
awk
,sed
, andgrep
for more powerful formatting - Explore advanced options in your specific version of
column
usingman column
The column
command may seem simple, but its ability to instantly transform messy text into structured, readable tables makes it an invaluable addition to your Linux command-line repertoire.
Ready to Level Up Your Terminal Text Formatting?
Have you tried using the column
command to improve the readability of your command-line output? Which formatting challenge will you tackle first? Share your experiences in the comments below or reach out with questions about using column
in specific scenarios.
Remember, good formatting isn’t just about aesthetics—it’s about making information more accessible and understandable. With column
in your toolkit, you’re well-equipped to transform cluttered data into clean, readable tables that help you work more efficiently in the Linux terminal.