Quick take: The paste command merges lines from files side by side into columns. paste a.txt b.txt joins them with a tab; -d sets a custom delimiter, and -s joins all lines of a file into one.
Introduction
The paste command is the column-wise counterpart to cat: instead of stacking files end to end, it places their lines side by side. This makes it ideal for building tables from separate lists, combining columns, or flattening a file into a single line.
Syntax
The basic syntax of the paste command is:
paste [OPTIONS] FILE...Common Options and Parameters
The most useful options and parameters for the paste command:
| Option | Description |
|---|---|
| (default) | Merge lines side by side, separated by a tab. |
| -d DELIM | Use a custom delimiter instead of tab. |
| -s | Serial — join all lines of each file into one line. |
| - | Read from standard input (can be used multiple times). |
Practical Examples
Real paste commands you can run today:
# Merge two files into columns
paste names.txt emails.txt
# Use a comma delimiter (make a CSV)
paste -d ',' names.txt emails.txt
# Join all lines of a file into one
paste -s -d ',' list.txt
# Combine three columns
paste col1.txt col2.txt col3.txt
# Turn command output into a single comma line
ls | paste -s -d ','Tips and Best Practices
paste -s -d ','flattens a multi-line list into a single comma-separated line — handy for building arguments.- Use
-dwith a delimiter to produce CSV or TSV directly from separate column files. - paste matches lines by position, so the files should have the same number of lines for clean columns.
Final Thoughts
paste joins files column-wise, turning separate lists into tables or flattening a file into a single line with -s. Pair it with -d to produce CSV output and with cut to slice columns back out. Where cat stacks vertically, paste combines horizontally — a small but handy distinction.
FAQ: paste Command in Linux
What does the paste command do?+
paste merges lines from files side by side into columns, separated by a tab by default. It is the horizontal counterpart to cat, which stacks files vertically.
How do I merge two files into columns?+
Run paste file1 file2. Each output line contains the matching line from both files separated by a tab. Use -d ',' to separate with a comma instead.
How do I join all lines of a file into one?+
Use -s: paste -s -d ',' file.txt joins every line into a single comma-separated line, which is useful for building argument lists.
How do I create a CSV with paste?+
Use a comma delimiter: paste -d ',' col1.txt col2.txt col3.txt combines the column files into comma-separated rows.
What is the difference between paste and cat?+
cat concatenates files end to end (vertically), while paste combines them side by side (horizontally) into columns. Use cat to stack and paste to merge into rows.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support