Use the command line to manipulate the local filesystem.
- Familiarize yourself with the command line.
- Obtain access to a personal computer with either Windows or Mac OS.
See the following operating system-specific guides in separate files, below.
Use the command line to manipulate the local filesystem.
See the following operating system-specific guides in separate files, below.
Open the Terminal application.
Print the current user's name.
whoami
Print the current/present working directory.
pwd
List files in the current working directory.
ls
ls -al # for a different display
Change directories (specifying absolute file path).
cd ~/Desktop
Make a new directory.
mkdir my_folder
Remove a directory.
rm my_folder # triggers an error
rm -rf my_folder # recursively (-r) forces (-f) removal
Change directories (using relative file path).
cd my_folder # first re-create this directory if it doesn't exist, else this will trigger an error
Create a file.
touch README.md
touch index.html
touch my_data.csv
touch my_message.txt
Remove a file.
rm index.html
Edit and save a file, using a text editor like notepad.
Print file contents.
cat my_message.txt
Move a file.
mv ~/Desktop/my_folder/my_message.txt ~/Desktop
Copy a file.
cp ~/Desktop/my_message.txt ~/Desktop/my_folder
Copy contents of a file into the clipboard for pasting.
pbcopy < ~/Desktop/my_folder/my_message.txt
# ... then just paste as you normally would after copying some text
There are many other utilities to use from the command-line.
Make your computer speak:
say "Hello, I am your computer. Let's be friends."
Trace the route traveled by a network request:
traceroute google.com
# ... stop after a few seconds if necessary by pressing: control + c
Time the duration of a network request:
ping google.com
# ... stop after a few seconds if necessary by pressing: control + c
Request the contents of a webpage:
curl google.com
curl http://www.google.com
curl http://hypem.com/playlist/popular/3day/json/1/data.js
curl https://raw.githubusercontent.com/debate-watch/twenty_sixteen/master/lib/twenty_sixteen/candidates.json
Open the Command Prompt application.
Print the current user's name.
whoami
Print the current/present working directory.
cd
List files in the current working directory.
dir
Change directories (specifying absolute file path).
cd C:\Users\YOUR_USERNAME\Desktop\ # where YOUR_USERNAME is the name of the user currently operating your local machine
Make a new directory.
mkdir my_folder
Remove a directory.
rmdir my_folder
Change directories (using relative file path).
cd my_folder # first re-create this directory if it doesn't exist, else this will trigger an error
Create a file.
type nul > README.md
type nul > index.html
type nul > my_data.csv
type nul > my_message.txt
Remove/delete a file.
del index.html
Edit and save a file, using a text editor like notepad or notepad++.
Print file contents.
type my_message.txt
Move a file to target location.
move C:\Users\YOUR_USERNAME\Desktop\my_folder\my_message.txt C:\Users\YOUR_USERNAME\Desktop
Copy a file.
xcopy C:\Users\YOUR_USERNAME\Desktop\my_message.txt C:\Users\YOUR_USERNAME\Desktop\my_folder
Copy contents of a file into the clipboard for pasting.
type C:\Users\YOUR_USERNAME\Desktop\my_folder\my_message.txt | clip
# ... then just paste as you normally would after copying some text
Trace the route traveled by a network request:
tracert google.com # stop after a few seconds if necessary by pressing: control + c
Time the duration of a network request:
ping google.com # stop after a few seconds if necessary by pressing: control + c