Introduction To Terminal
Introduction To Terminal
MIT
I Say you want to delete all files in a directory that end with
.pyc
$ rm *.pyc
A file name usually has an extension (e.g. .pdf, .doc, .csv), but
these are just conventions.
What is a file?
A file name usually has an extension (e.g. .pdf, .doc, .csv), but
these are just conventions.
A file name usually has an extension (e.g. .pdf, .doc, .csv), but
these are just conventions.
Every file and directory has a unique location in the file system,
called a path.
I Absolute path:
/Users/jackiebaek/Dropbox/Documents/hello.txt
I Relative path (if my current working directory is
/Users/jackiebaek/Dropbox): Documents/hello.txt
Working with files
Working with files
mkdir directory name: create a new directory.
$ mkdir new directory
Working with files
mkdir directory name: create a new directory.
$ mkdir new directory
touch file: create an empty file.
rm file: delete a file (Careful! Can’t be undone!)
$ touch brand new file.txt
$ rm brand new file.txt
Working with files
mkdir directory name: create a new directory.
$ mkdir new directory
touch file: create an empty file.
rm file: delete a file (Careful! Can’t be undone!)
$ touch brand new file.txt
$ rm brand new file.txt
nano file: edit contents of a file (many other editors exist).
$ nano helloworld.txt
Working with files
mkdir directory name: create a new directory.
$ mkdir new directory
touch file: create an empty file.
rm file: delete a file (Careful! Can’t be undone!)
$ touch brand new file.txt
$ rm brand new file.txt
nano file: edit contents of a file (many other editors exist).
$ nano helloworld.txt
cat file: prints contents of a file.
$ cat helloworld.txt
Hello, World!
Working with files
mkdir directory name: create a new directory.
$ mkdir new directory
touch file: create an empty file.
rm file: delete a file (Careful! Can’t be undone!)
$ touch brand new file.txt
$ rm brand new file.txt
nano file: edit contents of a file (many other editors exist).
$ nano helloworld.txt
cat file: prints contents of a file.
$ cat helloworld.txt
Hello, World!
cp source target: copy.
mv source target: move/rename.
$ cp helloworld.txt helloworld_copy.txt
$ mv helloworld.txt goodbyeworld.txt
File path shortcuts
. is current directory.
.. is parent directory.
I ../file.txt references a file named file.txt in the parent
directory.
File path shortcuts
. is current directory.
.. is parent directory.
I ../file.txt references a file named file.txt in the parent
directory.
∼ is home.
I expands to /Users/<username> (or wherever home is on that
machine).
I ∼/Documents → /Users/jackiebaek/Documents
I The command cd (without any arguments) takes you to ∼.
Hidden Files
I Files that start with a dot (.) are called hidden files.
I Used for storing preferences, config, settings.
I Use ls -a to list all files.
$ ls
github_notes.md presentation scripts
$ ls -a
. .git github_notes.md scripts
.. .gitignore presentation
.bashrc / .bash profile
$ ssh [email protected]
Secure Shell (SSH)
I Sometimes we need to work on a remote machine.
I We need more computing power than just our local machine.
I We need to access data from a client’s server.
I Can use SSH to securely access the terminal for the remote
machine.
$ ssh [email protected]
Password:
Secure Shell (SSH)
I Sometimes we need to work on a remote machine.
I We need more computing power than just our local machine.
I We need to access data from a client’s server.
I Can use SSH to securely access the terminal for the remote
machine.
$ ssh [email protected]
Password:
baek@howe-and-ser-moving:~$
Can transfer files between local and remote machines using the scp
command on your local machine.
$ echo a*
a1.txt a2.pdf apple.txt
Simple Pattern Matching (Globbing)
I Match [multiple] filenames with wildcard characters.
I Similar to regular expressions, but slightly different syntax.
Example:
$ ls
a1.txt a2.pdf apple.txt bar.pdf
$ echo a*
a1.txt a2.pdf apple.txt
$ echo a[0-9]*
a1.txt a2.pdf
Simple Pattern Matching (Globbing)
I Match [multiple] filenames with wildcard characters.
I Similar to regular expressions, but slightly different syntax.
Example:
$ ls
a1.txt a2.pdf apple.txt bar.pdf
$ echo a*
a1.txt a2.pdf apple.txt
$ echo a[0-9]*
a1.txt a2.pdf
$ echo *.pdf
a2.pdf bar.pdf
Simple Pattern Matching (Globbing)
Copy all files that has ”dog” in its name to the animal/ directory.
$ cp *dog* animal/
How bash works
How bash works
$ echo $PATH
/Users/jackiebaek/.local/bin:/Users/jackiebaek/.cabal/bin:/
Applications/ghc-7.10.3.app/Contents/bin:/usr/local/bin:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin
NAME
mkdir -- make directories
SYNOPSIS
mkdir [-pv] [-m mode] directory_name ...
DESCRIPTION
The mkdir utility creates the directories named as operands
...
I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir
Key Takeaways
I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir
I Google is your friend.
Key Takeaways
I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir
I Google is your friend.
I So is tab for autocomplete, arrow keys for history.
Key Takeaways
I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir
I Google is your friend.
I So is tab for autocomplete, arrow keys for history.
I Be careful with rm.
Key Takeaways
I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir
I Google is your friend.
I So is tab for autocomplete, arrow keys for history.
I Be careful with rm.
I Getting comfortable with the terminal can be daunting at
first, but it has the potential to greatly boost your efficiency!
Thank you!