This tutorial introduces the minimal set of command line concepts needed to use or develop Click-based command line interfaces (CLIs). It is written for beginners who may have little or no command line experience. All examples provide commands for both macOS/Linux (Bash) and Windows (PowerShell).
:depth: 2
:local:
Before using the command line, it's important to know which operating system and shell you are running. Different systems have slightly different commands, so this knowledge will help you follow tutorials and avoid errors.
macOS / Linux
uname -a # Display OS version and system informationWindows (PowerShell)
Get-ComputerInfo | Select-Object WindowsVersion, OsName, OsBuildNumberTip
Knowing your OS helps you troubleshoot problems more effectively.
Common mistake:
Trying to run a Linux command on Windows without an appropriate shell like WSL.
Command-line tools interact with files and directories:
- File: A piece of stored data (text, code, image, etc.).
- Directory (folder): A container for files or other directories.
- Path: A reference to a file or directory location, either relative or absolute.
macOS / Linux
pwd # Print working directory
ls # List files and directoriesWindows (PowerShell)
Get-Location
Get-ChildItemTip
Relative paths start from your current directory; absolute paths start from the root.
Common mistake:
Confusing relative and absolute paths, which can cause “file not found” errors.
You can move around directories using the cd command:
macOS / Linux
cd /tmp # Go to /tmp
cd ~ # Go to your home directory
cd .. # Go up one directory levelWindows (PowerShell)
cd C:\Temp
cd $HOME
cd ..Tip
Use
pwd(Linux/macOS) orGet-Location(Windows) to check your current directory.
Common mistake:
Forgetting that commands like
cdare case-sensitive on Linux/macOS.
To organize your files, create a directory using:
macOS / Linux
mkdir myproject # Make a new directory called myprojectWindows (PowerShell)
New-Item -ItemType Directory -Name myprojectTip
You can create nested directories with
mkdir -p myproject/subdiron Linux/macOS.
Common mistake:
Trying to create a directory that already exists will fail unless using the
-pflag.
Create an empty file inside a directory:
macOS / Linux
touch myproject/hello.txtWindows (PowerShell)
New-Item -ItemType File myproject/hello.txtTip
Files can be created in any directory you have write permissions for.
Common mistake:
Forgetting to specify the directory and ending up creating the file in the wrong place.
You can open and edit files with a text editor of your choice:
macOS / Linux
nano myproject/hello.txtWindows (PowerShell)
notepad myproject/hello.txtAdd the following line to the file:
Hello from the command line!
Tip
Try a simple editor like nano or notepad first; later you can use VS Code for larger projects.
Common mistake:
Forgetting to save the file before exiting the editor.
Check the contents of a file using these commands:
macOS / Linux
cat myproject/hello.txtWindows (PowerShell)
Get-Content myproject/hello.txtTip
Use these commands to quickly verify your edits.
Common mistake:
Using
caton very large files can flood the terminal; uselessinstead.
Search for specific text inside a file:
macOS / Linux
grep "Hello" myproject/hello.txtWindows (PowerShell)
Select-String -Pattern "Hello" -Path myproject/hello.txtTip
Use search to verify that text exists or to debug issues in configuration files.
Common mistake:
Forgetting to quote search patterns with spaces, which can break the command.
Click-based CLIs support the --help option, which lists commands and options:
mycli --help
If the CLI is implemented as a Python module:
python -m mycli --help