These notes move from basic commands to more advanced command composition. The goal is to understand how simple commands combine to form powerful pipelines.
Represents the current working directory.
Used to pass optional parameters (flags) to commands to modify their behavior.
Example: ls -R
Pipe operator.
Used to chain commands together.
The output of the command on the left becomes the input of the command on the right.
Wildcard character.
Matches any number of characters in filenames.
Example: rm *.cpp
Takes the output from the left side of a pipe and passes it as arguments to the command on the right, one by one.
Output redirection.
Sends the standard output of a command into a file.
Overwrites the file if it already exists.
Output redirection (append).
Appends output to a file if it exists.
Creates the file if it does not exist.
Escape character.
Forces the shell to treat the next character literally.
Command separator.
Marks the end of one command and begins another.
Example: mkdir test; cd test
Placeholder used with the -exec option of the find command.
Represents the currently matched file.
Must be followed by \;
Lists files and directories in the current working directory.
Lists files and directories inside the specified folder.
Lists files and directories recursively (includes subdirectories).
Lists only directories inside the current directory (recursively).
Does not list files.
Filters input and prints lines containing the given string.
Used mostly with pipes.
Finds all files in the current directory (recursively)
that:
- are regular files (
-type f) - have extension
.cpp
Prints the content of a file to the terminal.
Step-by-step logic:
findgets all.cppfilesxargspasses each file tocatcatprints their content
This is the first example of command chaining.
Building further:
- Find all
.cppfiles - Print their content
- Filter only lines containing the word "int"
This shows how commands combine progressively.
Sorts input lexicographically (alphabetical order).
Sorts lines based on the third column (field).
Removes duplicate consecutive lines.
Best used after sort.
Skips the first three fields and checks uniqueness starting from the fourth field.
Creates a directory in the specified path.
Copies files or directories from source to destination.
Step-by-step logic:
findlocates.cppfiles-execruns a command on each file{}represents the current filersync -Rcopies files while preserving directory structure\;marks the end of the exec command
This is a more advanced way to operate on matched files.
Removes all files ending with .cpp in the current directory.
Uses wildcard *.
Be careful — deletion is permanent.
Linux becomes powerful when you combine small, simple commands:
find → pipe → process → filter → sort → unique → redirect
Understanding composition is more important than memorizing commands.