Forrest logo
back to the unexpand tool

unexpand:tldr:2fbdd

unexpand: Convert blanks to tabs, reading from standard output.
$ unexpand
try on your machine

The unexpand command is a Unix/Linux command-line utility used to convert spaces to tabs in a file or standard input. It is the opposite of the expand command.

Here is the syntax of the unexpand command:

unexpand [OPTION]... [FILE]...

The OPTION argument is optional and can be used to modify the behavior of the command. Some commonly used options include:

  • -a or --all: Convert all spaces to tabs, including leading ones.
  • -t N or --tabs=N: Set the number of spaces per tab. The default is 8 spaces.
  • -i or --initial: Convert only leading sequences of spaces to tabs.

The FILE argument specifies the file(s) on which the unexpand command should operate. If no file is provided, it reads from the standard input.

When using the unexpand command, it scans through the input file or standard input and replaces spaces with tabs using the specified options. It does not change any existing tabs in the file.

Here's an example to demonstrate the usage of the unexpand command:

$ cat input.txt
Hello         world!
    This is an indented line.
$ unexpand -a -t 4 input.txt
Hello   world!
    This is an indented line.

In the above example, the unexpand command reads the input.txt file and converts multiple spaces to tabs (with 4 spaces per tab) using the -a and -t options. The output shows the modified text with tabs in place of the spaces.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the unexpand tool