based on boot.dev
resources (redhat blog, ibm docs, digitalocean community)
echo "Hello world"
Historically a terminal was "physical terminal", a device to type commands (a keyboard and a screen). Today means "terminal emulator". This one lets you type commands into a window on your computer (responsible of drawing text on screen, process keystrockes).
Shell mainly do the magic (Read, Eval, Print, Loop). optimized for running other programs, writing small scripts.
ex: expr 123456 + 7890
name="Lane" $ echo Hello $name Hello Lane
history clear
. : working dir (pwd) .. : parent dir (pwd) / : fs root ~ : home (/home/user)
cd ls
cat file1.txt file2.txt
head -n 10 file1.txt tail -n 10 file1.txt
less -N 2023.csv # show numbers
command1 ; command2 command1 && command2 # if first success, second run
touch file.txt
mkdir my_directory mv rm -rf cp -R
grep "hello" words.txt grep -r "hello" . --exclude-dir="backups" # recursive
find some_directory -name hello.txt find some_directory -name "*chad*" # wildcards
ex: curl -L https://github.com/bootdotdev/worldbanc/archive/refs/heads/main.zip -o worldbanc.zip
unzip worldbanc.zip
rm worldbanc.zip
mv worldbanc-main worldbanc
sudo chown -R $(whoami) worldbanc
sudo chmod -R 755 worldbanc
drwxrwxrwx - : file d : dir
(owner, group, others) (read, write, exec)
rwx: All permissions
rw-: Read and write, but not execute
r-x: Read and execute, but not write
ex: -rwxrwxrwx: A file where everyone can do everything
-rwxr-xr-x: Everyone can read and execute, but only owner can write
drwx------: Only owner can read, write and execute
chmod -R u=rwx,g=,o= DIRECTORY chmod u+x program.sh # or -x
sudo chown -R root DIRECTORY
mydir/program.sh # unless ./
compiled, interpreted programs
which sh cat /bin/sh
#! interpreter [optional-arg] #!/usr/bin/python3
env # environment variables
WARN_MESSAGE="this works too" ./warn.sh # local
export NAME="Lane"
echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin export PATH="$PATH:/path/to/new" source ~/.bashrc
man man --help -h help
ex: wc -c
exit-status 0: success 1: general error # another is error
echo $? # 0 # non-zero (depends on your OS)
unset ENV_VAR_NAME export ENV_VAR_NAME=""
data-streams (stdout, stderr) > # redirect to file 2>
stdin read VAR
echo "Have you heard the tragedy of Darth Plagueis the Wise?" | wc -w
ctrl+c: SIGINT # interrupt
ps aux | grep malicious.sh kill PID top (M sort by ram)
Unix Philosophy (write programs that) do one thing and do it well work together handle text streams (universal interface)
webi is an anti-package manager (install cli tools from web).