Nils Werner, Lorenz Schmidt
nils.werner@audiolabs-erlangen.com
International Audio Laboratories Erlangen
Linux is extremely versatile and popular:
udev
GRUB
)linux
)initramfs
)/
)systemd
)journald
)udev
)/etc/fstab
)gdm@tty1.service
)getty@tty2.service
)sshd.service
)nginx.service
)/
: The root node/home
: Everybody's home directories/etc
: Custom config files/dev
: Devices/usr
: Programs, Libraries, Headers, Default Configs/var
: Logfiles etc.uname -r
: Get current kernel versiondmesg
: Kernel messages, when hardware failsmount
: List currently mounted drivessystemctl
: Inspect and restart servicesjournalctl
: Inspect logfilesuname -r
sudo dmesg
mount
systemctl
systemctl status
systemctl status sshd.service
journalctl
journalctl -u sshd
journalctl -fu sshd
systemctl status
)systemctl list-timers
)systemctl --user status
)systemctl --user list-timers
)Loaded in increasing order of importance
/usr/lib/bla.cfg
: Package config/usr/lib/bla.d/setting.cfg
: Package partial config, these get merged/etc/bla.cfg
: Custom config/etc/bla.d/setting.cfg
: Custom partial config, these get merged# /usr/lib/server.cfg, provided by package server
[Service]
root = /var/bla
timeout = 1
# /usr/lib/server.d/database.cfg, provided by package database
[Service]
timeout = 10
# /etc/server.d/my-timeout.cfg, provided by administrator
[Service]
timeout = 100
env
: Print environment variablesecho $PATH
: Print variablepwd
: Print current working directorywhoami
: Print current usernameenv
echo $PATH
pwd
whoami
cd
, ls
, mkdir
, touch
, ps
, grep
, cat
...
vim
, ssh
, git
, wc
, history
... there are too many to list them all!
clear
to clear outputexit
to log outpwd
)$PATH
(check which
)bash script.sh
: Run script in bash
./script.sh
: Run script in whatever shell it wants (e.g. #!/usr/bin/env bash
). script.sh
: Run script in this shellsource script.sh
: Run script in this shellcat script.sh
bash script.sh
./script.sh
. script.sh
source script.sh
echo *.txt
echo $PATH
echo {train,test}.txt
echo {1..3}
echo *.txt
echo '*.txt'
echo "*.txt"
pwd
: Print working directorycd
: Change working directoryls
: List directory contentsmkdir
: Make directorytouch
: Make filecp
: Copy file/directorymv
: Move file/directoryrm
: Remove file/directoryln
: Create linkpushd
: Change into directory, remembering stack of directoriespopd
: Change back to previous directory in stackpwd
mkdir test
cd test/
pwd
cd -
pwd
rm -r test
pwd
mkdir test
pushd test/
pwd
popd
pwd
rm -r test
touch hello
ln hello you
echo "bla" > hello
cat hello
cat you
command > file
: Put output into filecommand >> file
: Append output into filecommand < file
: Read intput from filecommand < file > file2
: Combine the twocommand | command2
: Pass output from command into second commandcommand <(command2)
: Pass output from command as file into second commandecho "Lorem Ipsum Dolor Sit Amet" > lipsum.txt
echo "consectetur adipiscing elit" >> lipsum.txt
echo "Lorem Ipsum Dolor Sit Amet" | wc
wc
cat lipsum.txt > wc
wc < lipsum.txt
echo <(echo "foo")
mail -s "test" nils.werner@audiolabs-erlangen.de
mail -s "lipsum" nils.werner@audiolabs-erlangen.de < lipsum.txt
ping -c 5 www.google.de | mail -s "ping" nils.werner@audiolabs-erlangen.de
true
: Always succeedsfalse
: Always fails$?
: Return value of last commandcommand1 && command2
: Run second command if first succeededcommand1 || command2
: Run second command if first failedcommand1 ; command2
: Run both commandstrue
false
echo $?
true && echo "run this"
false && echo "dont run this"
true || echo "dont run this"
false || echo "run this"
false ; echo "always run this"
false && echo "you can" || echo "combine them"
cat
: Concatenate datadd
: Dump datagrep
: Filter datased
: Transform dataawk
: Transform dataless
: Paginate and search in outputtar
: Bundle filesgz
: Compress databsdtar
: Compress datazstd
: Compress datacat lipsum.txt lipsum.txt
dd if=lipsum.txt count=10 bs=1
ping www.google.de | grep 3
ping www.google.de | grep -v 3
ping www.google.de | sed 's/3/AAAAAAAAAAAAA/'
man sudo | less
tar cvf * | zstd > everything.tar.zstd
wget
: Download data from the webcurl
: Download data from the webrsync
: Upload/Download datacurl https://www.audiolabs-erlangen.de/
curl -s https://www.githubstatus.com/api/v2/status.json
curl -s https://www.githubstatus.com/api/v2/status.json | jq '.page.updated_at'
wget https://data.deepai.org/mnist.zip
curl -O https://data.deepai.org/mnist.zip
curl https://data.deepai.org/mnist.zip | bsdtar -xvf - -C .
rsync lipsum.txt work:
rsync --progress=eta work:data .
touch test.txt bla.txt test.wav bla.wav
grep e *.txt
find . -name "*.txt" -exec grep e {} \;
find . -name "*.txt" -exec grep -l e {} \;
ls *.txt | xargs -n 1 python process.py
ls *.txt | xargs -n 1 echo python process.py
ls *.wav | xargs -n 1 -I {} echo sox {} -r 22050 low_{}
find . -name "*.wav" -exec echo sox {} -r 22050 low_{} \;
ls *.txt | parallel echo python process.py
find . -name "*.txt" | parallel echo python process.py
parallel echo python process.py {1} ::: ls *.txt
parallel echo python process.py {1} {2} {3} ::: ls *.txt ::: 1 2 3 ::: a b c
id
: Display user identitychmod
: Change a file's modeumask
: Set the default file permissions for the current sessionsu
: Run a shell as another user (ask for password of that user)sudo
: Execute a command as another user (ask for your password)chown
: Change a file's ownerchgrp
: Change a file's group ownershippasswd
: Change a user's passwordsetcap
/getcap
: Set/get capabilities of executablesetfacl
/getfacl
: Set/get Access Control List of file/dirmkdir bla; touch test.txt
ls -l
cat test.txt
chmod -r test.txt
cat test.txt
chmod -x bla
cd bla
ls -l
cd bla
chmod g+s .
chgrp wheel .
mkdir blubb
touch foooo
ps
: Report a snapshot of current processestop
/htop
: Display tasksjobs
: List active jobsbg
: Continue job in the backgroundfg
: Continue job in the foregroundkill
: Send a signal to a processkillall
: Kill processes by nameshutdown
: Shutdown or reboot the systemcommand &
: Send command immediately to backgroundps
ps aux
kill 123
kill -9 123
killall python
ping www.google.de # Ctrl Z
jobs
fg
bg
/dev/zero
: Zeros/dev/urandom
: Random characters/dev/null
: "Black hole"dd if=/dev/urandom count=1 bs=10
dd if=/dev/zero of=zeros.bin count=100 bs=1M
dd bs=4M count=1000 if=/dev/zero | zstd > zeros.zstd
dd bs=4M count=100 if=/dev/urandom | zstd > urandom.zstd
ping -c 1 www.google.de &> /dev/null && echo "yes" || echo "no"
virtualenv
: Create virtualenvsource activate
: Activate virtualenvdeactivate
: Deactivate virtualenvconda create
: Create Conda envconda activate
: Activate Conda envvirtualenv .env
env
source .env/bin/activate
env
deactivate
env
alias ac="source .env/bin/activate"
alias de="deactivate"
alias qgit="git"
man
: "Manual pages" documentation for all commands and C interfacesman bash
man ls
man sudo
man urandom
man tar
ssh -A
: SSH Key Forwarding.ssh/config
: Simplify SSH commandsssh-copy-id
: Copy your SSH key to a servertmux
upon loginExample .ssh/config
Host work lin git devel notebooks pascal tesla cmm nwmac data
Hostname %h.audiolabs.uni-erlangen.de
ForwardAgent yes
Match Host work.audiolabs.uni-erlangen.de
User nils
Match Host *.audiolabs.uni-erlangen.de
User nwerner
ProxyJump dialog
Host dialog
Hostname dialog.rrze.uni-erlangen.de
User snniwern
https://missing.csail.mit.edu/2020/course-shell/
https://wiki.archlinux.org/
https://linuxcommand.org/tlcl.php
nils.werner@audiolabs-erlangen.com
@nlswrnr
https://www.audiolabs-erlangen.de/fau/assistant/werner