Chapter 21
In This Chapter
You've made it through nineteen chapters. You've seen hundreds of commands. Most of them you'll use occasionally; some maybe once a year; a few never. But there's a small core that you'll touch every single shell session — the muscle-memory commands that turn the shell from "thing you fight with" into "thing you live in."
This is that list. Ten commands, in roughly the order you'll reach for them over the course of a working day, with the flags that actually matter and an example or two each. By the time you're done with this chapter, you should be able to predict what each example does without running it. That is when the shell starts to feel transparent.
ls (or dir) — List FilesThe first command you run after cd. cshw accepts both names; pick whichever your fingers prefer (ls if you came from Unix, dir if you came from Windows).
ls # list current directory
ls -l # long form (mode, owner, size, date)
ls -la # include hidden files
ls -lR # recursive
ls *.cpp # glob — only matching files
The most useful flags:
-l — long format. Without it you just get filenames; with it you get sizes, dates, and attributes. Most users default to -l.-a — include hidden files (dotfiles on Unix; system/hidden on Windows).-R — recursive into subdirectories.-S — sort by size (biggest first).-t — sort by modification time (newest first).TIP
ls -lSh (or dir /OS) is the answer to "what's eating my disk?" Lists by size, biggest at top, with human-readable units. Run it at the root of your project once a quarter; you'll be surprised what shows up.
cd — Change DirectoryYou navigate the filesystem dozens of times a day. cd is the verb.
cd C:\Projects\cshw # absolute path
cd src # relative — go into 'src' from here
cd .. # up one level
cd ..\.. # up two
cd - # back to where you just came from
cd # to your home directory
The two clever forms worth knowing:
cd - flips you back to the previous directory. Hop between two working folders with no typing.cd with no argument goes home, regardless of where you are.For more navigation power, see pushd and popd (Chapter 4) — they keep a stack of directories so you can jump around and come back precisely. Worth using for tasks that bounce you across three or four folders.
grep — Search Text in FilesThe text-search workhorse. Quote what you're searching for; pass files (or use a pipe).
grep "TODO" *.cpp # find TODOs in C++ files
grep -i "error" log.txt # case-insensitive
grep -r "main" src/ # recursive into subdirectories
grep -n "panic" *.go # show line numbers
grep -v "DEBUG" log.txt # invert: lines NOT matching DEBUG
grep -E "error|warning" log.txt # extended regex with alternation
The flags that matter:
-i — case-insensitive-r — recursive-n — show line numbers (extremely useful for "where exactly is this?")-v — invert (everything except the matches)-E — extended regex (alternation with |, quantifiers, groups)-l — only print filenames containing matches, not the matching lines-c — count matches per file instead of printing themTIP
Combine grep -l (list files only) with command substitution to operate on the matching files: $(grep -l "deprecated" src/*.py) gives you a list you can feed to another command. "Edit every file containing 'deprecated'" becomes one line.
find — Locate FilesWhere grep searches inside files, find searches for files — by name pattern. Daily essential when "I know I had a file called something like..." strikes.
find accepts two operand orders, and tells them apart by whether the first operand is a directory that exists. The Unix order is the one your fingers already know:
find . -name "*.log" # everything under here -- recursive
find C:\Projects -name "main.cpp" # explicit search root
find . -type f -name "*.log" # files only
find . -name "*.tmp" -size +10M # larger than 10 MB
find . -maxdepth 2 -name "*.exe" # cap the recursion depth
find src # a lone directory: list all of it
cshw's own order puts the pattern first, and does not recurse unless you ask:
find "*.log" # in the current directory only
find "*.log" . /s # and every subdirectory -- /s recurses
find "main.cpp" C:\Projects /s # explicit search root
find "*.tmp" . /s -mtime +30 # last modified more than 30 days ago
find "*" . /s -type d # directories only
The rule is simply: a path operand means the Unix reading, and turns recursion on. find . -name "*.log" walks the tree because . is a directory; find "*.log" stays put because *.log is not. Earlier versions of cshw supported only the second form, so the first one — the shape in Chapter 4, in every Unix script, and in find's own man page — failed with '*.log': No such file or directory. It works now.
-print is accepted too. cshw's find always prints, so it does nothing; it is there so a GNU-shaped command line does not have to be edited before it will run.
The filters, all of which are real:
/s — recurse into subdirectories. Only needed in the pattern-first order; a path operand already implies it.-type f|d — regular files only, or directories only.-size +N — larger than N, with c/k/M/G suffixes. -N is smaller-than, bare N is exactly.-mtime +N — modified more than N days ago. -N is within the last N days.-maxdepth N / -mindepth N — bound the recursion, counted GNU-style: the directory you start in is depth 0, so the files sitting directly in it are depth 1. -maxdepth 1 is "here only, don't descend"; -mindepth 2 skips the top level. Combine them to take exactly one slice: -mindepth 2 -maxdepth 2.-name/-iname — supply the pattern. On Windows these are the same thing: filename matching is case-insensitive, so -iname is accepted as a synonym rather than as a separate mode.-delete — remove each match.Anything else is rejected with an error rather than ignored, so a filter that cshw does not implement cannot silently give you the answer to a different question.
⚠️
-deleteis real, and it deletes. Earlier printings of this chapter said it was deliberately omitted. It is not:find "*.tmp" . /s -deleteremoves every match. It now printsdeleted: <path>for each one so the output cannot be mistaken for a plain listing, but there is no confirmation prompt and no undo. Run the command without-deletefirst and read the list.
TIP
If you want the deletion to be explicit in your script rather than a flag, the loop form still works and puts the verb where you can see it: foreach f (`find "*.tmp" . /s -type f`) … rm "$f" … end
cat / type + head / tail — Read FilesFor "show me the contents of this file":
cat file.txt # show whole file
type file.txt # same (Windows-style name)
head file.txt # first 10 lines
head -n 50 file.txt # first 50 lines
tail file.txt # last 10 lines
tail -n 100 log.txt # last 100 lines (debugging logs)
tail -f app.log # follow mode -- print new lines as they appear
For ongoing log debugging, tail -f is the canonical pattern: cshw keeps the file open and prints new lines as they're appended. Combine it with grep to alert only on lines that matter — tail -f app.log | grep -i error is the "wake me when something breaks" idiom. Ctrl+C to stop following.
TIP
head and tail compose with pipes. ls -lt | head -n 20 shows the 20 most-recently-modified files. processlist /s memory | head -n 10 shows the top 10 memory hogs.
history — Recall Past CommandsYou typed it ten minutes ago; you don't remember it now. history is the answer.
history # show recent commands (numbered)
history 20 # last 20 only
Up-arrow walks back through history one command at a time — interactive recall when you just need the last thing or two. For older entries, history N gives you a numbered list; copy the command you want and paste it back at the prompt.
TIP
cshw persists history across sessions. Closing the shell, opening a new one, your history is still there. This is the one feature that changes how it feels to use a Windows shell — cmd.exe famously forgets everything the moment you close the window.
set — VariablesSetting variables is shell automation 101. You do this constantly — to remember a path, to compose a pipeline, to parameterize a script.
set project = "C:\Projects\cshw"
echo "Working in $project"
cd $project
set listing = `ls *.txt` # capture command output (backticks)
echo "Found: $listing"
set # show all variables
unset project # remove one
Backtick command substitution (cshw's csh-style alternative to $(...)) is the secret weapon. It turns "I'd like to use the result of this command as the value of that variable" into a one-liner.
TIP
For variables you want available to child processes (programs you launch), use setenv instead of set. set is for the shell's own use; setenv exports into the environment. Most tools you run will look at environment variables (PATH, EDITOR, etc.), so setenv is what you want for configuring them.
source (or .) — Load a ScriptWhen you write a .cshw file with procedures or variable definitions you want available in your current shell, source is how you load it:
source helpers.cshw # run in current shell -- changes persist
. helpers.cshw # same thing, shorter
Compare with just running helpers.cshw as a command — that runs in a child shell, and any variables or procedures it defines disappear when it exits. source runs in the current shell, so the side effects stick.
This is the mechanism for "every shell session, load my personal toolbox." Put your aliases, your procedures, your shortcuts in ~/.cshrc (or your equivalent), and they're available the moment you open a shell.
# Inside ~/.cshrc
alias ll "ls -la"
alias gst "git status"
proc deploy
fetch -X POST -d "deploy=now" https://my.deploy.host/deploy
endproc
After that, every new shell session has ll, gst, and deploy immediately. Personal productivity multiplier.
fetch — Talk to the WebThe shell's web client. Every day you'll use it for something: testing an API, downloading a file, scraping a quick page, checking a service is up.
fetch https://example.com # body to stdout
fetch -o data.json https://api.example.com/data # save to file
fetch -I https://example.com # headers only
fetch -X POST -d "name=alice" https://api.example.com/users
# Pipe into other tools
fetch -q https://api.weather.gov/atlanta | grep "temperature"
Most days you'll just be checking if a thing is up (fetch -I URL), pulling some JSON from an API to inspect, or grabbing a file from a release page. For everything more involved (auth flows, multi-step interactions, file uploads), reach for a real HTTP library; but for ad-hoc use, fetch is right there at the prompt.
TIP
fetch | genai ask "..." is the pattern that earns its keep. "Fetch this and ask the AI about it" replaces a startling amount of "open the page, scan it, decide what's relevant" — see the next entry.
genai ask — Ask the AIOnce you've registered a provider (Chapter 17), genai ask becomes part of the daily toolkit. Most people use it for:
genai ask "How do I format a date in PowerShell?"
# Quick code reference
genai ask "git command to undo the last commit without losing changes"
# Analysis of piped input
type error.log | genai ask "What is causing these errors?"
# Inline transformation
echo "alice,bob,charlie" | genai ask "Convert to JSON array, just the JSON"
It replaces "open browser, search Stack Overflow, read the top answer." The same time it would take you to switch to a browser window, you've already got a focused answer in your shell.
The killer feature: piped input. genai ask accepts whatever the previous command sends and answers in that context. So "summarize this," "find errors in this," "is this normal?" — all become pipelines.
TIP
For commands where you want exactly one value back (a number, a yes/no, a name), tell the model explicitly: "Just the number, nothing else." "Answer with only Y or N." This is the difference between "the model gives you a useful sentence" and "the model gives you something you can use programmatically."
If we got to twenty, the next ten would be:
wc — count lines/words/chars (great for "is this file what I expect?")sort / uniq — the classic text-processing pairawk — when the data has columnssed — when you need to transform text in a pipelinekill — for processes that won't go awayprocesslist (ps) — when you need to find the process to killalias — to shorten the commands you type ten times a dayecho — surprisingly often, just to assemble strings or test outputtime — to find out how long something actually takesexit — eventuallyAll of them earn their place; they just don't fire quite as often as the top ten.
A typical working session, using nothing but the ten:
cd Projects\my_service # navigate
ls -lt | head # see what I touched recently
grep -rn "TODO" src/ # find what I haven't finished
type src/handler.cs | head -n 50 # remind myself of the structure
set out = $(fetch -q https://my.service/status)
echo $out | genai ask "Anything alarming in this status output?"
history # what did I just do? Save the good parts.
Seven commands, five minutes, a real working flow. The shell's job — making this feel weightless. After enough days, it does.
The next chapter takes a different angle. Ten Things cshw Does That cmd.exe Doesn't — the bragging-rights chapter, where we line up some of cshw's features against the shell Windows ships with by default and let the comparison speak for itself.
After that comes Chapter 23 (Ten Tricks for When You're Stuck — the debugging and recovery toolkit) and the Appendix Cheat Sheet. The book wraps up with the kinds of references you'll want close at hand for the rest of your time using the shell.