CS Basics: Command Line Interface (CLI)
An introduction to the core commands used in the Command Line Interface - a text-based way to interact with your computer and servers efficiently.
Originally written by Carl Mills · December 2017
What Is the CLI?
The Command Line Interface (CLI) is an alternative to the graphical user interface (GUI). Before we could point and click, users interacted with computers by typing commands. Today, developers still use the CLI to work faster, automate tasks, and communicate with servers and tools.
General CLI Commands
cd - Change Directory
Moves the working directory to a specified folder.
cd /Users/carlmills/Documents
ls - List Files
Lists all files in the current directory. Add parameters for extra detail:
-l detailed list, -S sort by size, -t sort by date, -r reverse order.
ls -lTr
rm - Remove Files
Deletes files or directories. Use with care - there's no undo.
rm filename.txt
rm * # remove all files in directory
rm -rf foldername # recursive, force delete
touch - Create File
Creates a new blank file.
touch newfile.txt
mv - Move or Rename File
Moves or renames a file or folder.
mv file.txt samefile.txt
mv file.txt ~/Documents/samefile.txt
cp - Copy File
Copies a file or directory.
cp john.txt john2.txt
mkdir - Make Directory
Creates a new folder in the current directory.
mkdir newFolder
rmdir - Remove Directory
Removes an empty folder. For non-empty folders, use rm -R.
rmdir oldFolder
chmod - Change Permissions
Adjusts file access permissions (read, write, execute).
chmod u+w file.txt # allow user to write
chmod u-r file.txt # remove read access
pwd - Print Working Directory
Displays the full path of your current directory.
pwd
open - Open Files in GUI
Opens a file using the system's default application, equivalent to double-clicking it.
open ~/Documents/file.txt
Next Steps
These core commands form the foundation of CLI navigation and file management. In future posts, we'll cover application-specific commands for GitHub, Node.js, Gulp, and Grunt.
Continue to GitHub Commands →