🍎🐧 Mac and Linux
Getting Started
Mac → You can boot up a new command line by searching up 'Terminal' in Launchpad
Linux → You can press CTRL+ALT+T
to open a new Terminal
Basic commands
Navigating folders
cd
→ is short for 'change directory'. If you were to compare it back to the graphical interface, its much like navigating and clicking through folders through your file explorer.When specifying a directory to change to, you can use either absolute or relative path names. The absolute or full path starts from the system root
/
, and relative path starts from your current directory.Usually when you start a new Terminal, you are in the
home
directory, commonly denoted as~
You can navigate into folders by doing
cd name-of-folder
, and even nested folders by doingcd name-of-folder/nested-folder
You can go back one level of folders by doing
cd ..
and multiple levels by doingcd ../..
Still confused? No worries! There are lots of resources that give you lots of information about
cd
. Here are a few:ls
→ is short for 'list'. This command tells you what files are in your current working directory. If you are in the home directory, the output will look something like this:→ ls Applications Desktop Downloads Library Music Files Documents Movies Pictures
Copying, moving, and deleting files and folders
cp
→ is short for 'copy'. This command lets you copy files and folders from one location to another. You can copy single files from A to B by doingcp A B
. For example, if you want to copy a file from your Downloads into your home folder, it would look something like# copy a file from Downloads into the Home directory cp ~/Downloads/example.txt ~
If you need to copy an entire folder, you can add the
-r
flag.# copy a folder inside Downloads to the current folder # you can reference current location using `.` cp -r ~/Downloads/example_folder .
mv
→ is short for 'move'. The commands follow the same format ascp
rm
→ is short for 'remove'. The commands follow the same format asmv
andcp
Creating files and folders
touch
→ creates new, empty files. For example,touch example.txt
will create a new empty file with the nameexample.txt
in the current directory.mkdir
→ is short for 'make directory' and makes a new folder. For example,mkdir folder-name
will create an empty folder with the namefolder-name
in the current directory.Viewing file contents
cat
→ is short for 'concatenate' but really we just use it to print out file contents. Say you had a file calledREADME.md
and you wanted to quickly view what the contents of it were, you could docat README.md
and it would print out its contents into the terminal. If it's too long, you can docat README.md | less
so that it scrolls.Editing file contents
nano
→ a simple text editor in the terminal. If you want to quickly edit the contents of a README, a Python script, or anything really, you can donano file-name
to edit it. When you're finished, pressCTRL+X
and save if you'd like.
Package Managers
Hate downloading installers? Wish you could just download and install stuff just from your command line? Package managers may be for you!
apt
(Linux)apt
is a package manager that comes pre-installed with Linux. It makes it super easy to install packages and other stuff. You can install a new package by doingsudo apt install <package_name>
. For example, if you wanted to installpip
, a Python package manager for Python 3, you can just dosudo apt install python3-pip
. To uninstall, you can just dosudo apt purge python3-pip
.You can find more info here: https://itsfoss.com/apt-command-guide/
brew
(Mac) Homebrew is the "missing package manager for macOS". Basically, it lets you manage, install, and remove software super easily through the command line. To install it, paste this into your terminal
Then, installing pa is as easy as# install homebrew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install python
. To uninstall, it's as easy asbrew uninstall python
.
You can read more here: https://brew.sh/