Skip to content

VOL 00 / CH 02 / LESSON 06

2.6 Command Quick Reference Page ​

Type: Reference page, no required sequential reading

Scope: Bash/Zsh common interactive operations; examples prioritized for GNU/Linux validation, PowerShell syntax differs

Identity and Command Source ​

TargetCommandNote
Current userwhoamiOutput varies with the account
Current Shell processps -p $$ -o comm=$SHELL is typically the login Shell
Command type and all candidatestype -a nameCan view aliases, functions, and built-in commands
First callable commandcommand -v nameUsually more portable than which
Bash built-in helphelp cdApplies only to Bash built-in commands
GoalCommand
Current directorypwd
List entriesls
Include hidden entries and detailsls -la
Enter a directorycd path
Parent directorycd ..
Previous directorycd -
Home directorycd

~ typically expands to the home directory, and . is the current directory. Quote path variables: cd "$dir".

Files and Directories ​

GoalCommandNote
Temporary directoryworkdir=$(mktemp -d)Record and clean up after use
Create directorymkdir -p a/b-p also creates missing parent directories
Create empty file/update timetouch fileExisting content is not cleared
Write exactly one lineprintf '%s\n' text > file> will overwrite
Append a lineprintf '%s\n' text >> file>> appends
Copy a filecp -- src dst-- ends option parsing
Move or renamemv -- old newMay overwrite existing targets, depending on options
Delete a filerm -- fileTypically does not go to the trash
Delete an empty directoryrmdir dirRefuses if the directory is not empty
Recursive copycp -R -- src dstMetadata retention depends on options and platform

Environment and PATH ​

GoalCommand
Current shell variableNAME=value
Export to new sub-processesexport NAME
Print a variable literallyprintf '%s\n' "$NAME"
Temporarily add tool directoryPATH="$dir:$PATH"; export PATH
Delete variableunset NAME

The startup file varies depending on Bash/Zsh, login/interactive mode, and the system. Do not blindly overwrite or append ~/.bashrc, ~/.profile, and ~/.zshrc.

Wildcards and Quoting ​

SyntaxMeaning
*.logAny .log name
file-?.txt? matches one character
file-[13].txtMatches 1 or 3
"$path"Parameters remain a single parameter after expansion
-- "$path"Prevent paths starting with - from being treated as options

The behavior of unmatched wildcards varies depending on the shell and options. Preview the targets before a batch operation. Changing a file extension does not convert its format.

Standard Streams, Pipes, and Redirection ​

GoalSyntax
Redirect standard outputcommand >out.log
Append standard outputcommand >>out.log
Save standard error separatelycommand 2>err.log
Merge output and errorcommand >all.log 2>&1
Connect two programs`left
See failures in any part of a pipelineset -o pipefail

Redirection occurs from left to right, and 2>&1 >out.log is not equivalent to >out.log 2>&1. Pipes default to connecting standard output.

One Minute Before Deletion ​

bash
pwd
ls -ld -- "$target"
find "$target" -print

Set $target to the path you intend to inspect before using this read-only snippet. Before deletion, confirm that the variable is nonempty, the path is correct, and the scope is limited. Do not execute dangerous commands to test whether the system will protect you.

When Details Are Required ​

→ Open Isolated Exercise

Built with VitePress | Software Systems Atlas