←  cshw: The C Shell for Windows

Chapter 3

Your First Five Minutes at the Prompt

In This Chapter

A shell is a place you live. The way you stay comfortable in any place you live is by learning where the most-used things are: the light switches, the coffee mug, the spare batteries. This chapter is the where-things-are tour for cshw. By the end of it you'll have a working vocabulary of about a dozen commands — enough to get real work done.

We're going to type a lot. Each command in this chapter has a "Try It" suggestion that takes maybe ten seconds. Do them. Reading about a shell is like reading about swimming: it works up to a point, and then you have to get in the water.


The Prompt, Up Close

Open cshw. You see something like this:

C Shell for Windows
Copyright (C) 2024-2026 Tropibyte, Inc.  All rights reserved.
CSHW C:\Users\YourName >

That last line is the prompt. The shell is telling you three things:

The prompt is configurable, and Chapter 7 covers the language for customizing it. The good news for anyone migrating from cmd.exe: cshw's prompt syntax is the same one Windows has used for decades. $P is the path, $G is the >, $T is the time, $D is the date, $_ is a newline, and so on. The default cshw prompt is $J$S$P$S$G — which renders as "CSHW", a space, the path, a space, and a greater-than sign. If you've ever set PROMPT in cmd.exe, you already know how this works.

REMEMBER

The current working directory is one of the most important pieces of state in a shell. Half the bugs you'll have as a beginner come from being in a different directory than you thought you were. When something doesn't work, your first move should be: "Where am I?"


Where Am I? (pwd)

pwd stands for Print Working Directory. It prints the current working directory:

CSHW C:\Users\YourName >pwd
C:\Users\YourName

Yes, the prompt already shows it. pwd is still useful — when you're inside a script, when you've changed the prompt to something minimal, or when you want to capture the path into a variable. It also has the virtue of being the first command you should reach for whenever you're lost.

TRY IT

Type pwd and press Enter. You're somewhere.


Getting Around (cd)

cd (Change Directory) moves you to a different folder. It's the workhorse of any shell.

cd Documents
cd C:\Tools
cd ..
cd \
cd

Walking through those:

TIP

cshw ships with cd.., cd., and cd\ as built-in aliases — that is, the missing space is forgiven. You can type cd.. and it works. Old DOS habits die hard, and cshw is fine with that.

REMEMBER

Windows paths use backslashes (C:\Users\You). Unix paths use forward slashes (/home/you). cshw understands both, so cd C:/Users/You works exactly like cd C:\Users\You. Use whichever you find easier to type. (Forward slashes don't need escaping inside double-quoted strings, which makes them a little nicer for scripting.)

TRY IT

Type cd \, then pwd. You should see something like C:\. Now type cd Users, then pwd. You moved one level deep. Type cd .., then pwd. You're back at the root.

Switching Drives

On Windows, drives are a thing. To change to a different drive, just type the drive letter followed by a colon, or use cd with a full path:

D:
cd D:\Projects

The first form is short and has been working since DOS. The second is more flexible because it sets your working directory on D: to a specific folder.


What's Here? (ls and dir)

To see what's in the current directory, use ls (Unix-style) or dir (DOS-style). They do similar things with slightly different output:

ls
dir

Both list files and folders. ls is more compact, dir shows file sizes and timestamps by default. The most useful flags:

ls -l          # long format: mode, owner, size, date, name
ls -a          # show hidden files (names starting with .)
ls -la         # both
ls -lh         # sizes as 4.2K rather than 4321
ls -lt         # newest first
ls -ld folder  # about the FOLDER, not its contents
ls *.txt       # only files matching a pattern
ls Projects    # contents of a specific folder

ls -l reads the same way it does on any Unix system:

-rw-r--r-- 1 tarie tarie 4321 Aug  1 21:24 notes.txt
drwxr-xr-x 1 tarie tarie    0 Aug  1 21:24 Projects

The first character is the type — - a file, d a directory, l a link. The nine after it are the permission bits. Windows has no owner/group/other triad, so those are synthesized from the attributes it does have: a read-only file loses its w, and anything Windows would run gets an x.

TECHNICAL STUFF

In a Unix shell, the shell itself expands *.txt into the matching filenames before ls ever sees them. cshw does the same — globbing is a shell-level feature, not a command feature. That's why ls *.txt, cp *.txt backup\, and rm *.tmp all work consistently. There's also a glob command if you want to see exactly what a pattern expands to without running anything.

TRY IT

cd to your Documents folder, then run ls -l. You'll see your files with sizes and dates. Now run ls *.docx (if you have any Word docs). The shell filtered the list down to just those.

Hidden Files

Files starting with a dot (.cshrc, .gitignore) are hidden by Unix convention. cshw respects that — ls won't show them unless you ask with -a. Files marked hidden by Windows itself (the H attribute) are also suppressed by default.


Reading Files (type)

To dump a text file to the screen, use type:

type README.md
type C:\Windows\System32\drivers\etc\hosts

It prints the entire contents. For long files you'll want pagination — pipe the output through a pager or use head for the start and tail for the end:

head README.md         # first 10 lines
head -n 5 README.md    # first 5 lines
tail README.md         # last 10 lines
tail -n 20 log.txt     # last 20 lines

TIP

type is the command's primary name in cshw, but a cat alias is the kind of thing many users add to their .cshrc for muscle memory. We'll do that in Chapter 5 when we cover aliases.

WARNING

type will happily dump binary files to your terminal, which produces beeping, garbled output, and occasionally a wedged terminal. If you don't know whether something is text, run file <filename> first. cshw's file command identifies file types by magic bytes — much more reliable than trusting the extension.

TRY IT

Run type C:\Windows\System32\drivers\etc\hosts. That's the Windows hosts file. Tiny, mostly comments. A safe target for exploring.


Telling the System About Itself (say)

say is one of cshw's nicest pieces of design: a single command that knows about a couple of dozen system facts, asked for by topic.

say os           # Windows version
say uptime       # how long since boot
say user         # who am I
say hostname     # what's this machine called
say cwd          # current working directory (same as pwd)
say version      # cshw version
say cpucore      # number of logical CPU cores
say mem_free     # available RAM
say memsize      # total RAM
say disk_free    # free space on the current drive
say processor    # current CPU usage as a percentage
say sysstats     # composite snapshot of all the above

It's also the easiest way to get a formatted timestamp without writing a script:

say time                    # default: HH:MM:SS.cs
say date                    # default: MM/DD/YYYY
say datetime                # default: YYYY-MM-DD HH:MM:SS
say time /fmt:"%I:%M %p"    # 12-hour clock with AM/PM
say date /fmt:"%A, %B %d"   # Wednesday, May 06

The /fmt: codes follow standard wcsftime conventions — %H for 24-hour hour, %I for 12-hour, %M for minute, %S for second, %Y for year, %m for month, %d for day, %A for weekday name, %p for AM/PM, and so on. If you've ever used strftime in another language, this will feel familiar.

TIP

say stores its result in the special variable $result, which means you can capture it. We'll see that in Chapter 5, but here's a preview: set t = `say time` puts the current time into $t.

TRY IT

Run say sysstats for the grand tour of your machine. Then try say time /fmt:"%A %I:%M %p" for a nicely formatted timestamp.


Asking for Help

You will forget commands. Everyone does. cshw has three layers of help, in increasing order of detail.

help — list every built-in command with a one-line description:

help

That's a long list (245 commands as of 1.0.8.4). Pipe it through grep to find what you want:

help | grep -i archive
help | grep -i hash

help <command> — usage for a specific command:

help cd
help say
help genai

You'll get the synopsis, the options, and usually a few examples. This is the fastest way to remind yourself what a flag does.

man <command> — the full manual page, if one is available:

man ls
man genai

Manual pages are longer and better organized than the inline help — they include description, options, examples, environment variables, and "see also" references. Not every command has one yet (cshw is a young project, and writing good man pages is real work), but the most-used commands do.

To find a man page when you don't remember the command name, search by keyword:

man -k archive    # finds tar, etc.
man -k network    # finds fetch, ftpfetch, tcpclient...

REMEMBER

Three layers of help, increasing in depth: help (everything, one line each), help <cmd> (one command, usage), man <cmd> (one command, full manual). When in doubt, start with help <cmd> — it's almost always enough.


Recalling What You Just Typed (history)

The shell remembers what you've typed. Press the up-arrow key to walk back through previous commands; down-arrow to walk forward. Edit any recalled command by moving the cursor and retyping.

To see the full list:

history

You'll get a numbered list of recent commands, oldest at the top. cshw saves history to disk between sessions — typically at %APPDATA%\cshw\history — so the up-arrow tomorrow morning will recall what you typed last night.

TIP

On Windows, the F7 key sometimes pops up a console-managed history list. That's a console feature, not a shell feature, and it runs alongside cshw's own history. If something looks odd, prefer cshw's history command and the up/down arrows — they're under the shell's control.


When Things Go Wrong

You will mistype things. Here's what cshw tells you:

CSHW C:\Users\You >foo
ERROR: 'foo' is not recognized as an internal or external command, operable program, CSHW script or batch file.

That message means: cshw checked its built-in commands (no match), checked your PATH for a program called foo.exe or foo.bat or similar (no match), checked for a .cshw script (no match), and gave up. The fix is usually a typo, a missing path, or a command that needs to be installed first.

Some other common errors and what they mean:

TIP

Every command sets the special variable $? to its exit code. Zero means success, non-zero means failure. After a command, type echo $? to see what happened. You'll use this constantly when scripting.


A Five-Minute Tour, Pulled Together

Let's run a session that touches everything from this chapter. Type along:

say os
pwd
cd \
ls
cd Users
ls
cd %USERNAME%
pwd
say sysstats
history
help cd

That's the whole vocabulary of basic shell life:

That's enough to be productive in a shell. Everything else in this book builds on those seven verbs.


Onward

You've got the basics. The next chapter — Chapter 4 — turns these primitives into a working file-management toolkit: copying, moving, deleting, finding, archiving, and the surprising number of useful things cshw can do to a file. Bring your text editor; we're going to start producing files worth managing.