tty, wc, uniq, split, join, cut, paste and more
LPIC-1LINUX


Different ways to “go home”
cd
cd ~
cd $HOME
cd /home/username
tty
show which is your virtual terminal:
tty
Go to virtual terminal 1:
Ctrl + Alt + F1
Go to virtual terminal 2 or return to GUI:
Ctrl + Alt + F2 to go to tty2
To go to tty 3, and so on.
F3 to go to tty3, and so on.
You can go from a virtual terminal (tty) to a new graphical session by typing:
sudo startx
help
Help provides information on commands built into the Bash shell.
Up Arrow key; press Enter
Execute the last command.
cat .bash_history
It won't display the same as the history command because part of this is in memory.
wc
Lines count, word count, bytes count in a file.
wc /etc/passwd
36 89 2283 /etc/passwd
uniq
Only repeated lines that are next to each other.
nl
Number lines (it doesn't number a blank line):
md5sum, sha256sum, sha512sum
Check if a particular file is corrupted:
split
It is used to break a file into smaller pieces. The -l switch specifies that the split should happen after every designated number of lines.
join
It is used to join lines of two files based on a common field (like a database join). It requires that both input files be sorted on the join field before execution. join matches lines from two files based on a shared field — usually the first field by default.
Example
file1 (id and name):
1 apple
2 banana
3 cherry
file2 (id and color):
1 red
2 yellow
3 dark_red
Both files share field 1 (the id: 1, 2, 3) — that's the common field.
join file1 file2
Output:
1 apple red
2 banana yellow
3 cherry dark_red
If your files aren't sorted, sort them first:
sort file1 -o file1
sort file2 -o file2
join file1 file2
Example with a delimiter, similar to something you might see combining /etc/passwd fields with another file:
join -t: -1 1 -2 1 file_a.txt file_b.txt
Let's extend the same example with unmatched lines, since that's the trickier part.
file1:
1 apple
2 banana
4 date
file2:
1 red
2 yellow
3 dark_red
Notice: 4 date only exists in file1, and 3 dark_red only exists in file2.
Plain join (default = inner join)
join file1 file2
Output:
1 apple red
2 banana yellow
Only the matching keys (1 and 2) show up. The unmatched lines (3 and 4) are silently dropped.
-a to keep unmatched lines
-a 1 says "also include unpaired lines from file1":
join -a 1 file1 file2
Output:
1 apple red
2 banana yellow
4 date
cut
Extract a certain field using the delimiter ':' for the file /etc/passwd
cut -d : -f 7 /etc/passwd
extract the first 10 characters of the file /etc/passwd
cut -c1-10 /etc/passwd
paste
To join 2 files side by side.
Contact
hello@unixtips.eu
© 2025. All rights reserved.
NEW! Join the community at https://www.skool.com/linux-and-unix-command-line-6976/about