Technical skill

Linux: basic commands

Type a command and see what it does

A terminal is a text window where you can type instructions. A shell is the program that reads those instructions, expands some words, and starts commands. For example, pwd prints the folder the shell is currently using, while cd path changes to that folder. A path describes where a file or folder is. A relative path starts from the current folder; an absolute path begins at /. The ls command prints names. A command can be a shell builtin or a separate program such as grep; learning the difference helps explain where a command comes from.

This short exercise creates and reads files in a practice folder under your home directory:

mkdir -p ~/cli-practice
cd ~/cli-practice
printf 'first line\nsecond line\n' > notes.txt
grep -n 'second' notes.txt
cp notes.txt copy.txt
ls -l

mkdir -p creates missing parent folders, cp copies a path, and mv renames or moves one. The shell's > redirection creates or empties the destination before writing. >> adds text to the end instead. rm removes directory entries and normally does not put them in a recoverable trash folder. Check the target before recursive removal, especially when a wildcard is involved.

Find files and read their contents

Use ls -la to include hidden entries in the current folder. man command opens the local manual page for a command; command --help often gives a shorter option summary. To find the word “timeout” in a configuration file, grep -n 'timeout' app.conf prints matching lines with their numbers. less app.conf lets you move through a long file. cat prints or joins file contents, which is handy for short files and pipelines but gives no scrolling controls.

Quote paths that contain spaces or shell metacharacters, as in less 'project notes/final draft.txt'. Without quotes, the shell may split one filename into several arguments or expand wildcard characters. For a filename beginning with a dash, use a path such as ./-draft or the utility's documented end-of-options marker.

Connect commands and check their results

A pipeline sends one command's standard output to the next command's standard input. For example, grep 'ERROR' app.log | less lets you page through matching lines. Programs also return an exit status. Zero commonly means success; a nonzero status can mean an error or an ordinary result, such as no matches. GNU grep, for example, returns status 1 when it finds no matching lines.

In Bash, cd and pwd are builtins, so they run inside the shell. grep is an executable the shell finds through its command search path. GNU and BSD utilities share many basic options but have different extensions, so check the local manual when portability matters. Before a command changes data, inspect the paths it will affect and keep a recoverable copy when the data matters.

Interactive exercises

Skillsets
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Skyeng Senior Backend Developer preview
image descriptionSkyeng Senior Backend Developer
by Artem Naumenko (slack2)
39 users
Skillset Linux for backend developer preview
image descriptionLinux for backend developer
by Artem Naumenko (fb)
16 users
Skillset Skyeng QA Automation Hard Skillset v09.21 preview
image descriptionSkyeng QA Automation Hard Skillset v09.21
by Aleksandra Kulikova
16 users
Skillset Skyeng SRE preview
image descriptionSkyeng SRE
by Yuliya Marochkina
12 users
Show more
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful