Extracting Data with Modifiers
Learn how to extract data with modifiers.
We'll cover the following
The :h
modifier
History expansion supports modifiers, which are suffixes we add to the command. For example, we saw that adding :p
to a history expansion prints the result of the change but doesn’t execute the altered command. But other modifiers let us alter the path of the results.
Here’s a trivial example to see how this works. We use the ls command to list the dpkg.log
file:
ls /var/log/dpkg.log
Next, we use echo
to print out the previous command’s first argument, but we then use the :h
modifier, which will extract the path up to the last segment:
echo !^:h
Use the terminal below to practice these commands.
Get hands-on with 1400+ tech skills courses.