I'm taking MIT's The Missing Semester of Your CS Education and these are my notes.
Lecture 1: The Shell
Simply put, the shell is a program that takes commands from the keyboard and gives them to the operating system to perform.
~ from Linux Command
Vocabulary 📚
- shell prompt: where you type commands, in my case:
-
environment variable: variables set usually during the installation; they contain info necessary for the system shell when executing commands; one example:
$PATH
stores a list of paths on our machine where bash will be looking for a program to execute -
absolute paths: full paths determining the location of the file in relation to the root directory (in MacOS it's
/
) - relative paths: paths in relation to a given file
-
arguments: what you write after a command with a space, for instance: in
echo Hello
,echo
is a command andWorld
is an argument -
options: are optional arguments you can add to a command, they are are often preceded by a single dash, e.g.
ls
will list (ls
command) all files andls -a
will also include those whose names begin with a dot (.
) -
flags: boolean-type options given to commands, they are invoked with two dashes
--
Command lookup 🔍
-
pwd
— print working directory -
cd
— change directory -
ls
- list files -
mv
- move files, takes two paths as arguments (old path and new path), which also allows you to rename the file if you just change the name or to move a file to another directory -
cp
- copy, also takes two paths (from and to) -
rm
- remove -
rmdir
- remove directory if it’s empty -
mkdir
— creates a new directory; it takes an argument of the directory name; notemkdir My Photos
will create two directories ("My" and "Photos") so you'd need to call itmkdir My\Photos
,mkdir “My Photos”
ormkdir my-photos
man -> for manual pass an arg of the program -
cat
- print out the contents of the file, takes an arg of a file path -
man
- print manual page for the given command; it takes an argument of the command, e.g.man echo
-
tail -n1
- prints the last n lines of the input -
tee test.md
-echo
es the input but also saves it to the file -
echo hello > hello.txt
- overwrite the hello.txt with the hello input -
cat < hello.txt
- take hello.txt and populatecat
method with it -
cat < hello.txt > hello2.txt
- take hello.txt and overwrite it into cat and then populate it into hello2.txt -
>>
- append, not overwrite -
|
- take the output of the program to the left and make it an input to the program to the right -
sudo
— "do as a su (superuser)", meaning execute a command as the root user (see below) -
chmod
- change file modes or Access Control Lists -
grep
- search for a substring in files
ROOT USER 🔥
- special user -- it can access (read, write, execute) any file
- its id is 0
- if you're operating as su, your prompt will start with
#
and not$
- you can execute commands as root by running the
sudo
command - since has access to all the files, if you are using sudo, you’re acting as the operating system
- generally not the best idea to use
sudo
too often cause you can mess up your computer
KERNEL 🌽
- core of your computer
- in Linux, you access it through
ls/sys
, which gives you an output of all the kernels in your computer browsable as files so you can use the programs at hand to manipulate them (cool demonstration)
Photo by Polina Tankilevitch from Pexels