Home › Linux command line: first steps › Step 5

Lesson 5: which, wc, lspci, gzip and tar

Step 5 of 5 in Linux command line: first steps · video 10:07

Can't see the video? Watch it on YouTube.

What you will learn

About this lesson

A mixed toolkit of everyday commands. which shows the full path of the program that runs when you type a command without its path, for example /usr/bin/cat for cat. wc counts lines, words and bytes in a file such as /etc/profile, with -l, -w, -c and -m for lines, words, bytes and characters. For hardware inventory, lspci lists PCI buses and devices (-v for detail, -m for machine-readable output), lsusb lists USB devices and lscpu describes the processor, including virtualisation support; the first two come from the pciutils and usbutils packages. The second half covers compression and archives. gzip compresses each named file into a .gz file and gunzip or gzip -d restores it; bzip2 and bunzip2 do the same with .bz2. tar packs many files into one archive, keeping ownership, timestamps, SELinux contexts and extended attributes, with c to create, r to append, t to list and x to extract, and it can compress while it archives.

Good to know: the package is pciutils (one word). On RHEL 8 and later dnf is the native package command and yum still works as an alias. tar does store empty directories, and tar czvf dir1.tar.gz dir1 archives and compresses in one step.

Check yourself

Answer in your head first, then open each question to see the answer.

1. How do you print only the number of lines in /etc/profile?

wc -l /etc/profile. Without options wc prints lines, words and bytes; -l limits the output to the line count, just as -w gives words, -c bytes and -m characters.

2. What happens when you run gzip file1.txt file2.txt, and how do you get the originals back?

gzip compresses each file separately, replacing them with file1.txt.gz and file2.txt.gz; it does not combine them into one archive. gunzip file1.txt.gz file2.txt.gz or gzip -d with the same names restores them.

3. On a minimal RHEL-family install, lspci returns command not found. How do you fix it?

Install the package that provides it: sudo dnf install pciutils (yum install pciutils still works, as yum points to dnf). lsusb is missing for the same reason and comes from usbutils.

4. What does tar tvf dir1.tar do?

It lists what is inside the archive without extracting it. t means list, v verbose (show details for each entry) and f names the archive file that follows; c would create an archive and x would extract it.

Go deeper

This lesson comes from the course below - with the full set of lessons, demonstrations and practice.

Administration of Red Hat Enterprise Linux

4.5★ · 10,209 students on Udemy

See the course on Udemy
← Lesson 4: date and hwclock - setting the hardware clockPath complete - back to Linux command line: first steps →

Video lesson by Vitalii Shumylo. The summary and the questions on this page were written from the lesson with AI help and checked against its transcript.