diff --git a/org/_posts/2024-02-24-command_line_tricks_globbing.org b/org/_posts/2024-02-24-command_line_tricks_globbing.org new file mode 100644 index 0000000..8fc7835 --- /dev/null +++ b/org/_posts/2024-02-24-command_line_tricks_globbing.org @@ -0,0 +1,424 @@ +#+OPTIONS: toc:nil num:nil +#+STARTUP: showall indent +#+STARTUP: hidestars +#+BEGIN_EXPORT html +--- +layout: blogpost +title: Command line tricks: Globbing basics +tags: cli linux macosx automation +--- +#+END_EXPORT + +When working with files in the command line, you don't always want to write full file names. Maybe you are working on a group of files that has file names with a given patterns, like log files (e.g, log_011023.txt)? Or maybe you want to filter out files that don't fit a given pattern? Or maybe your use case is just picking out shell scripts that starts with the letter P? In this article we will look at globbing, which can be thought of as wildcards we use in place of explicitly writing full filenames. Read on to see several examples on how they can be used to solve various command line tasks! + + +If it is not clear from the introductions: globs can be thought of as wildcards. That way we can make patterns to match files instead of explicitly writing full filenames. We will also use bash here, so there might be minor differences in other Unix style shells like Fish or Zsh. (I use zsh, so there is one note about that below!). + + + +* Glob patterns +There are a lot of different patterns we could cover, and many of them would be very esoteric. Instead, the basic and most useful patterns will be covered here. If you are curious on different ones from the ones covered, you can skip to the further reading section for a suggested place to read more. + + +To make the explanations a bit more fun, they will be very example heavy. + + + +#+BEGIN_EXPORT html +
cat *.html" (to print contents of all html files directly to the command line). +
cat 404.html about.html index.html privacypolicy.html" directly. Before cat is being run, bash will replace the glob pattern with those exact file matches. +