unexpand command in Linux with Examples Last Updated : 15 Oct, 2024 Comments Improve Suggest changes Like Article Like Report To convert the leading spaces and tabs into tabs, there exists a command line utility called unexpand command. The unexpand command by default converts each space into tabs writing the produced output to the standard output. Syntax $unexpand [OPTION]... [FILE]...where, OPTION: Represents the various options or flags available for modifying the behavior of unexpand.FILE: Refers to the name of the file on which the command operates.Using unexpand commandTo convert all the space characters into tab characters in the file kt.txt, use unexpand as: $cat -vet kt.txthave a nice day$always try harder$to achieve better$/* In the below output $ refers to the new line feed and ^I refers to the tab */$unexpand kt.txthave^Ia^Inice^Iday$always^Itry^Iharder$to^Iachieve^Ibetter$In order to save the produced output by unexpand command in another file let's say dv.txt use the below syntax: /* Saving output in file, dv.txt */$unexpand kt.txt>dv.txt$cat -vet dv.txthave^Ia^Inice^Iday$always^Itry^Iharder$to^Iachieve^Ibetter$Key Options for the unexpand command1. -a, - -all option This option is used to convert all blanks, instead of just initial blanks (which is by default). /* This converts all the blanks also into tabs */$unexpand -a kt.txt>dv.txt2. --first-only option This is used to convert only leading sequences of blanks (overrides -a option). /* This converts only the leading sequences of blanks */$unexpand --first-only kt.txt>dv.txt3. -t, - -tabs=N option This set tabs N characters apart instead of the default of 8 (enables -a option). /* the -t option with numerical value 2 forces to change the spaces into tabs of only 2 characters */$unexpand -t2 kt.txt>dv.txtOther available OptionsOptionDescription-t, --tabs=LISTUses a comma-separated list of tab positions, enabling the -a option to convert all spaces to tabs.--helpDisplays a help message with usage information and exits.--versionDisplays version information of the unexpand command and exits.Also see: expand command ConclusionThe unexpand command in Linux is a simple yet powerful tool for converting spaces to tabs in text files. With its various options, such as -a for converting all spaces, -t for custom tab widths, and --first-only for restricting changes to leading spaces, it offers flexibility in managing text file formatting. Comment More infoAdvertise with us D Dimpy Varshni Follow Improve Article Tags : Misc Linux-Unix linux-command Linux-text-processing-commands Practice Tags : Misc Similar Reads How to Monitor System Activity in Linux | top Command top command is used to show the Linux processes. It provides a dynamic real-time view of the running system. Usually, this command shows the summary information of the system and the list of processes or threads which are currently managed by the Linux Kernel. As soon as you will run this command it 10 min read How to Create an Empty File in Linux | Touch Command The touch command is a standard command used in the UNIX/Linux operating system which is used to create, change and modify the timestamps of a file. Basically, there are two different commands to create a file in the Linux system which are as follows: touch command: It is used to create a file witho 7 min read tr command in Unix/Linux with examples The tr command is a UNIX command-line utility for translating or deleting characters. It supports a range of transformations including uppercase to lowercase, squeezing repeating characters, deleting specific characters, and basic find and replace. It can be used with UNIX pipes to support more comp 4 min read tracepath command in Linux with Examples The 'tracepath' command in Linux is a network diagnostic tool used to trace the path packets take to reach a destination, discovering the Maximum Transmission Unit (MTU) along the way. It operates similarly to the traceroute command but does not require superuser privileges and offers a simpler set 2 min read Traceroute Command in Linux with Examples In networking, understanding the path that data packets take from one point to another is crucial for diagnosing and troubleshooting connectivity issues. One of the most valuable tools for this purpose is the traceroute command in Linux. Traceroute is a command-line tool used in Linux or other opera 8 min read tree Command in Linux with Examples The tree command in Linux is a powerful, user-friendly tool that visually maps directory structures in a hierarchical, tree-like format. Unlike the basic ls command, which lists files and folders linearly, tree reveals the nested relationships between directories and their contents, making it easier 7 min read tty Command in Linux with Examples In the Linux operating system, everything is represented within a file system, including hardware devices and terminal interfaces. Among these, the terminal is also treated as a file, allowing users to interact with the system by sending inputs and receiving outputs. One essential command related to 3 min read type command in Linux with Examples The type command in Linux is a useful utility for identifying how the shell will interpret a given command. It provides information on whether a command is a shell built-in, external binary, function, or alias, helping users understand the source of the command and its behavior. The command is parti 3 min read uname command in Linux with Examples Linux, renowned for its open-source flexibility and powerful performance, offers a range of commands that reveal the inner workings of your system. Among these, the 'uname' command stands out as a versatile tool that provides key details about your Linux machine. Here, we will learn the basics of th 4 min read unexpand command in Linux with Examples To convert the leading spaces and tabs into tabs, there exists a command line utility called unexpand command. The unexpand command by default converts each space into tabs writing the produced output to the standard output. Syntax $unexpand [OPTION]... [FILE]...where, OPTION: Represents the various 3 min read Like