Resource: Command line crash course
Basic built-in terminal commands
- Navigate computer’s file system:
- Move around your directory(folder) structure:
cd - Create directories:
mkdir - Create files (and modify their metadata):
touch - Copy files or directories:
cp - Move files or directories:
mv - Delete files or directories:
rm
- Move around your directory(folder) structure:
- Download files found at specific URLs:
curl - Search for fragments of text inside larger bodies of text:
grep - View a file’s contents page by page:
less,cat - Manipulate and transform streams of text (for example changing all the instances of
<div>s in an HTML file to<article>):awk,tr,sed
1. Navigation on the command line cd pwd ls
pwdcan print the current directory(folder)lscan list the contents in the current directory- The
cdcommand lets you Change Directory
cd desktop- To move back up to the previous directory, you can use
cd ..- Can also type entire path
cd Desktop/project/srcNote:
cleancan clean the terminal
2. Open content open
open can open the folder, website ecc.
open downloads
open https://traversymedia.com3. Command Options
Most terminal commands have options — these are modifiers that you add onto the end of a command, which make it behave in a slightly different way.
ls -lTo find out exactly what options each command has available, you can look at its man page. This is done by typing the
mancommand, followed by the name of the command you want to look up, for exampleman ls.
4. Creating, copying, moving, removing
mkdir— this creates a new directory inside the current directory you are inrmdir— removes the named directory, but only if it’s empty.touch— creates a new empty file, inside the current directory.mv— moves a file from the first specified file location to the second specified file locationcp— similar in usage tomv,cpcreates a copy of the file in the first location specified, in the second location specified.rm— removes the specified file.
5. Connecting commands together with pipes |
if we wanted to quickly count the number of files and directories inside the current directory.
There is another Unix tool available called wc. This counts the number of words, lines, characters, or bytes of whatever is inputted into it.
wc -l myfile.txtSince ls prints each file or directory on its own line, that effectively gives us a directory and file count.
ls | wc -l