- Forward Communications
- Linux Enthusiast
- Programmer
+ Rust, Python, Go
user@host:~$
user@host:~$ sudo -i
[sudo] password for user:
root@host:~#
Windows Key (App Search)
Ctrl+Alt+Up OR Ctrl+Alt+Down (Change "Workspace")
user@host:~$ ping -c 3 www.google.com
PING www.google.com (XXX.XXX.XXX.XXX) 56(84) bytes of data.
64 bytes from foo-bar-baz.net (XXX.XXX.XXX.XXX): icmp_seq=1 ttl=55 time=8.60 ms
64 bytes from foo-bar-baz.net (XXX.XXX.XXX.XXX): icmp_seq=2 ttl=55 time=4.59 ms
64 bytes from foo-bar-baz.net (XXX.XXX.XXX.XXX): icmp_seq=3 ttl=55 time=5.66 ms
--- www.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 4.591/6.286/8.604/1.698 ms
Go to https://remarkableapp.github.io/
Markdown is a plain text syntax that allows code formating and highlighting and rendering
# Title
## Sub Title
### etc. etc. etc.
Comments about `commands`
List:
* **bold**
* *italics*
* ++underline++
* ~~strikethrough~~
* ==Highlight==
Even [hyper-links](www.someurl.com)
user@host:~$ sudo dd if=/dev/nvme0n1 count=1 bs=512 | od -v -x
1+0 records in
1+0 records out
512 bytes copied, 1.9505e-05 s, 26.2 MB/s
0000000 0000 0000 0000 0000 0000 0000 0000 0000
0000020 0000 0000 0000 0000 0000 0000 0000 0000
0000040 0000 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000
0000100 0000 0000 0000 0000 0000 0000 0000 0000
0000120 0000 0000 0000 0000 0000 0000 0000 0000
0000140 0000 0000 0000 0000 0000 0000 0000 0000
0000160 0000 0000 0000 0000 0000 0000 0000 0000
0000200 0000 0000 0000 0000 0000 0000 0000 0000
0000220 0000 0000 0000 0000 0000 0000 0000 0000
0000240 0000 0000 0000 0000 0000 0000 0000 0000
0000260 0000 0000 0000 0000 0000 0000 0000 0000
0000300 0000 0000 0000 0000 0000 0000 0000 0000
0000320 0000 0000 0000 0000 0000 0000 0000 0000
0000340 0000 0000 0000 0000 0000 0000 0000 0000
0000360 0000 0000 0000 0000 0000 0000 0000 0000
0000400 0000 0000 0000 0000 0000 0000 0000 0000
0000420 0000 0000 0000 0000 0000 0000 0000 0000
0000440 0000 0000 0000 0000 0000 0000 0000 0000
0000460 0000 0000 0000 0000 0000 0000 0000 0000
0000500 0000 0000 0000 0000 0000 0000 0000 0000
0000520 0000 0000 0000 0000 0000 0000 0000 0000
0000540 0000 0000 0000 0000 0000 0000 0000 0000
0000560 0000 0000 0000 0000 0000 0000 0000 0000
0000600 0000 0000 0000 0000 0000 0000 0000 0000
0000620 0000 0000 0000 0000 0000 0000 0000 0000
0000640 0000 0000 0000 0000 0000 0000 0000 0000
0000660 0000 0000 0000 0000 0000 0000 0000 0000
0000700 0001 feee ffff 0001 0000 6daf 7470 0000
0000720 0000 0000 0000 0000 0000 0000 0000 0000
0000740 0000 0000 0000 0000 0000 0000 0000 0000
0000760 0000 0000 0000 0000 0000 0000 0000 aa55
pwd | ps | mount |
lsof | ss | jobs |
uname | ls | free |
env | whoami | users |
groups |
user@host:~$ command information "more information"
user@host:~$ command --flag -F -xod
user@host:~$ command --option=value -O value
user@host:~$ command information "more information"
Examples
user@host:~$ command --flag -F --ohter-flag -xod
Examples
Will Error -->
user@host:~$ command -oval -o val -o=val
user@host:~$ command --option val --option=val
user@host:~$ command1 | command2 | command3
user@host:~$ cat testfile.txt
Hello! I'm some
file that
needs to be
counted!
user@host:~$ cat testfile.txt | wc
4 9 47
user@host:~$ echo "Send me to a file" > file.txt
user@host:~$ echo < file.txt
Send me to a file
Most people in the terminal
Command | Action |
---|---|
apt update | Updates the list of known versions (synchronizes) |
apt upgrade | Upgrade installed packages |
apt search <name> | Search for software |
apt install <name> | Install software |
apt remove <name> | Uninstall software |
Command | Function |
---|---|
ls | List Files |
cd | Change Directory |
pwd | Print Working Directory |
tree | Lists contents of directory tree |
Install -->
╭─student@student01 /home/student
╰─$ ls
Desktop Documents Downloads Music Pictures Videos test.txt
╭─student@student01 /home/student
╰─$ ls -l
total 16
drwxr-xr-x 2 student student 6 Dec 7 11:27 Desktop
drwxr-xr-x 2 student student 6 Dec 7 11:27 Documents
drwxr-xr-x 3 student student 288 Jan 10 14:15 Downloads
-rw-r--r-- 1 student student 8980 Dec 7 11:21 test.txt
drwxr-xr-x 2 student student 6 Dec 7 11:27 Music
╭─student@student01 /home/student
╰─$ ls ./D*
./Desktop:
./Documents:
./Downloads:
google-chrome-stable_current_amd64.deb keybase_amd64.deb
haroopad-v0.13.1-x64.deb
Flag | Function |
---|---|
ls -l | Long Listing |
ls -a | Show hidden files and directories |
ls -h | Show human readable sizes |
ls -F | Show a trailing / for directories |
ls -d | Do not list directory contents |
ls -G | Disable group display (only used with -l) |
╭─student@student01 /home/student
╰─$ cd Downloads/
╭─student@student01 /home/student/Downloads
╰─$ cd ../Desktop
╭─student@student01 /home/student/Desktop
╰─$ cd /etc
╭─student@student01 /etc
╰─$
$ cd Downloads/
$ pwd
/home/student/Downloads
$ cd ../Desktop
$ pwd
/home/student/Desktop
$ cd /etc
$ pwd
/etc
╭─student@student01 /home/student
╰─$ tree Pictures
Pictures
├── 01.png
└── 02.png
0 directories, 2 files
Flag / Option | Function |
---|---|
tree -L# | Only go # levels deep |
tree -a | Show hidden files/directories |
tree -P <pattern> | Only show files which match <pattern> |
tree -I <pattern> | Ignore files which match <pattern> |
Command | Function |
---|---|
mv | Move a file |
cp | Copy a file |
rm | Delete (remove) a file |
mkdir | Make a Directory |
rmdir | Remove a Directory |
cat | Show file contents |
touch | Create a blank file |
wc | Count components of a file |
╭─student@student01 /home/student
╰─$ ls
Desktop Documents Downloads test.txt Videos
╭─student@student01 /home/student
╰─$ mv test.txt Downlods/
╭─student@student01 /home/student
╰─$ ls
Desktop Documents Downloads Videos
╭─student@student01 /home/student
╰─$ ls Downloads/
test.txt
Flag | Function |
---|---|
mv -v <old> <new> | Display the renames that happen (useful later) |
╭─student@student01 /home/student
╰─$ ls
Desktop Documents Downloads test.txt Videos
╭─student@student01 /home/student
╰─$ cp test.txt Downlods/
╭─student@student01 /home/student
╰─$ ls
Desktop Documents Downloads test.txt Videos
╭─student@student01 /home/student
╰─$ ls Downloads/
test.txt
Flag | Function |
---|---|
cp -R <from> <to> | Recursive copy (all subdirectories, etc) |
╭─student@student01 /home/student
╰─$ ls
Desktop Documents Downloads test.txt Videos
╭─student@student01 /home/student
╰─$ rm test.txt
╭─student@student01 /home/student
╰─$ ls
Desktop Documents Downloads Videos
Flag / Option | Function |
---|---|
rm -r | Recursive delete (allows deleting directories) |
rm -f | Force. Be. Careful. |
rm -i | Interactive (confirm before deleting) |
╭─student@student01 /home/student
╰─$ cat some_file.txt
Hello! I'm a file
╭─student@student01 /home/student
╰─$ cat some_file.txt | wc -l
1
╭─student@student01 /home/student
╰─$ touch some_file.txt
╭─student@student01 /home/student
╰─$ cat some_file.txt
╭─student@student01 /home/student
╰─$ wc some_file.txt
1 8 42 some_file.txt
Flag / Option | Function |
---|---|
wc -m | Count characters |
wc -l | Count lines |
wc -w | Count words |
╭─student@student01 /home/student
╰─$ mkdir some_dir
Flag / Option | Function |
---|---|
mkdir -p <path> | Makes any missing directories in all of <path> |
╭─student@student01 /home/student
╰─$ rmdir some_dir
Command | Function |
---|---|
man <command> | View the "manpage" or extended help |
whatis <command> | Basic description |
which <command> | Where is the binary located |
<comamnd> --help | Help (not all commands support) |
<comamnd> -h | Short Help (not all commands support) |
whereis <command> | Where is the command and associated files |
╭─student@student01 /home/student
╰─$ cat some_file.txt > other_file.txt
╭─student@student01 /home/student
╰─$ cat < some_file.txt
╭─student@student01 /home/student
╰─$ cat some_file.txt 2> err_file.txt
# Redirect stderr to 'err_file.txt'
╭─student@student01 /home/student
╰─$ cat some_file.txt 2>&1
# Redirect stderr to stdout (stdout still goes to screen)
╭─student@student01 /home/student
╰─$ cat some_file.txt 2>&1 > out.txt
# Redirect stderr to stdout, then stdout to 'out.txt' file
╭─student@student01 /home/student
╰─$ cat some_file.txt &> some_file.txt
# Redirect stderr AND stdout to a file
╭─student@student01 /home/student
╰─$ touch file
╭─student@student01 /home/student
╰─$ ls -l file
-rw-rw-r-- 1 student student 0 Jan 16 13:58 file
╭─student@student01 /home/student
╰─$ chmod o+x file
╭─student@student01 /home/student
╰─$ ls -l file
-rw-rw-r-x 1 student student 0 Jan 16 13:58 file
╭─student@student01 /home/student
╰─$ touch file
╭─student@student01 /home/student
╰─$ ls -l file
-rw-rw-r-- 1 student student 0 Jan 16 13:58 file
╭─student@student01 /home/student
╰─$ sudo chown root:student file
╭─student@student01 /home/student
╰─$ ls -l file
-rw-rw-r-- 1 root student 0 Jan 16 13:58 file
╭─student@student01 /home/student
╰─$ touch file
╭─student@student01 /home/student
╰─$ ls -l file
-rw-rw-r-- 1 student student 0 Jan 16 13:58 file
╭─student@student01 /home/student
╰─$ sudo chown root:student file
╭─student@student01 /home/student
╰─$ ls -l file
-rw-rw-r-- 1 root student 0 Jan 16 13:58 file
╭─student@student01 /home/student
╰─$ ls -l file
-rw-rw-r-- 1 student student 0 Jan 16 13:58 file
╭─student@student01 /home/student
╰─$ chmod o+x file
╭─student@student01 /home/student
╰─$ ls -l file
-rw-rw-r-x 1 student student 0 Jan 16 13:58 file
alias ls='ls -H --color=always'
$ ANIMAL=cat
$ echo $ANIMAL
cat
$ ls -l
total 264896
-rw-r--r-- 1 kevin kevin 15400455 Jan 17 10:33 09b25a9a5c720.tar.gz
-rw-rw-r-- 1 kevin kevin 43487904 Dec 7 13:00 code_1.18.1-1510857349_amd64.deb
-rw-rw-r-- 1 kevin kevin 27765264 Dec 7 13:01 encryptr_2.0.0-1_amd64.deb
-rw-rw-r-- 1 kevin kevin 1407463 Jan 10 14:14 FEL-r22.pdf
-rw-rw-r-- 1 kevin kevin 397750 Jan 10 14:14 FEL.tar.gz
-rw-rw-r-- 1 kevin kevin 42004318 Dec 7 13:01 haroopad-v0.13.1-x64.deb
-rw-rw-r-- 1 kevin kevin 79941824 Dec 7 13:04 keybase_amd64.deb
$ ls -l *.deb
total 264896
-rw-rw-r-- 1 kevin kevin 43487904 Dec 7 13:00 code_1.18.1-1510857349_amd64.deb
-rw-rw-r-- 1 kevin kevin 27765264 Dec 7 13:01 encryptr_2.0.0-1_amd64.deb
-rw-rw-r-- 1 kevin kevin 42004318 Dec 7 13:01 haroopad-v0.13.1-x64.deb
-rw-rw-r-- 1 kevin kevin 79941824 Dec 7 13:04 keybase_amd64.deb
$ echo {one,two,three}
one two three
$ ls -l {*.deb,0*}
-rw-r--r-- 1 kevin kevin 15400455 Jan 17 10:33 09b2af7a5c720.tar.gz
-rw-rw-r-- 1 kevin kevin 43487904 Dec 7 13:00 code_1.18.1-1510857349_amd64.deb
-rw-rw-r-- 1 kevin kevin 27765264 Dec 7 13:01 encryptr_2.0.0-1_amd64.deb
-rw-rw-r-- 1 kevin kevin 49035482 Dec 19 15:23 google-chrome-stable_current_amd64.deb
-rw-rw-r-- 1 kevin kevin 42004318 Dec 7 13:01 haroopad-v0.13.1-x64.deb
-rw-rw-r-- 1 kevin kevin 79941824 Dec 7 13:04 keybase_amd64.deb
$ echo {A..Z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
$ ls $(echo "-l")
total 264896
-rw-r--r-- 1 student student 15400455 Jan 17 10:33 09b2afa5c720.tar.gz
-rw-rw-r-- 1 student student 43487904 Dec 7 13:00 code_1.18.1-1510857349_amd64.deb
-rw-rw-r-- 1 student student 27765264 Dec 7 13:01 encryptr_2.0.0-1_amd64.deb
$ ls -l
total 264896
-rw-r--r-- 1 student student 15400455 Jan 17 10:33 09b2afa5c720.tar.gz
-rw-rw-r-- 1 student student 43487904 Dec 7 13:00 code_1.18.1-1510857349_amd64.deb
-rw-rw-r-- 1 student student 27765264 Dec 7 13:01 encryptr_2.0.0-1_amd64.deb
$ ANIMAL=cat
$ echo ${ANIMAL}
cat
$ echo ${ANIMAL}s
cats
$ echo $ANIMALs
$ ANIMAL=cat
$ echo ${ANIMAL/at/ow}
cow
$ CAT=tabby
$ ANIMAL=CAT
$ echo ${!ANIMAL}
tabby
$ echo ${ANIMAL}
CAT
$ echo ${#ANIMAL}
3
$ diff <(ls -l) <(ls -al)
1c1,3
< total 264896
---
> total 264904
> drwxr-xr-x 3 student student 4096 Jan 17 11:11 .
> drwxr-xr-x 35 student student 4096 Jan 17 12:34 ..
$ diff $(ls -l) $(ls -al)
diff: invalid option -- '-'
diff: Try 'diff --help' for more information.
student@student01: ~
➜ ls <up_arrow>
Flag / Option | Function |
---|---|
head -n <num> | Show <num> lines of output |
tail -n <num> | Show <num> lines of output |
tail -F | Constantly show new lines as they appear |
Flag / Option | Function |
---|---|
grep -v | Invert searches (show lines not matching <pattern>) |
grep -A <num> | Show <num> lines of output after found <pattern> |
grep -B <num> | Show <num> lines of output before found <pattern> |
grep -C <num> | Show <num> lines before and after found <pattern> |
grep -e '<expr>' | Search for <expr> instead of a pattern (allows Regex) |
grep -r <path> | Search recursively through all files starting at <path> |
grep -o | Only show matching portions of found <pattern> |
grep -i | Case insensitive |
student@student01: ~
➜ find / -type f -name "*stud*"
# Find all FILES starting from ROOT that include "stud" in the filename
student@student01: ~
➜ find /home -type d -empty
# Find all EMPTY DIRECTORIES starting from /HOME
student@student01: ~
➜ find / -type f -name "*stud*" -exec wc -l {} \;
# Find all files
# execute wc -l on every file
student@student01: ~
➜ find / -type f -name "*stud*" -print0 2>/dev/null | xargs -0 -I{} wc -l {} | grep -e '^[0-9][0-9] '
student@student01: ~
➜ ls /mnt/etern
student@student01: ~
➜ mount /dev/nvme0n1p1 /mnt/extern
student@student01: ~
➜ ls /mnt/extern
file_a file_b file_c dir_1/ dir_2/
student@student01: ~
➜ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop10 7:10 0 405.1M 1 loop /snap/intellij-idea-community/22
nvme0n1 259:0 0 931.5G 0 disk
└─nvme0n1p1 259:1 0 931.5G 0 part /mnt/extern
nvme1n1 259:2 0 477G 0 disk
├─nvme1n1p1 259:3 0 417.3G 0 part /
└─nvme1n1p3 259:4 0 59.6G 0 part [SWAP]
student@student01: ~
➜ umount /mnt/extern
student@student01: ~
➜ ls /mnt/extern
Flag / Option | Function |
---|---|
bs=<SIZE> | Sets the "byte size" or how many bytes to copy |
count=<num> | How man of "byte size" to copy |
conv=<OPTS> | Can use options like: * noerror: stop copying on errors * sync: sync up after copying |
progress=<LEVEL> | Show progress (changes by version), try "verb" |
student@student01: ~
➜ dd if=/dev/random count=2 bs=8 | od -t x1
2+0 records in
2+0 records out
16 bytes copied, 2.1937e-05 s, 729 kB/s
0000000 d9 a4 0c 31 5f 43 6c 55 63 02 fd ec 41 6c 99 9c
0000020
student@student01: ~
➜ dd if=/dev/random count=2 bs=8 | od -t x1
2+0 records in
2+0 records out
16 bytes copied, 5.8776e-05 s, 272 kB/s
0000000 bb 28 7d 99 d9 88 67 a7 fb e9 1f 57 e7 a3 42 6e
0000020
student@student01: ~
➜ lsmod
Module Size Used by
xt_nat 16384 1
ebtable_filter 16384 0
ebtables 32768 1 ebtable_filter
ip6table_nat 16384 0
nf_conntrack_ipv6 20480 1
nf_defrag_ipv6 36864 1 nf_conntrack_ipv6
nf_nat_ipv6 16384 1 ip6table_nat
ip6table_filter 16384 0
ip6_tables 28672 2 ip6table_filter,ip6table_nat
ipt_MASQUERADE 16384 1
nf_nat_masquerade_ipv4 16384 1 ipt_MASQUERADE
Flag / Option | Function |
---|---|
journalctl -b | Only show messages from current boot (also allows things like -b -1 for boot before current) |
journalctl -k | Kernel messages |
journalctl -u <service> | Only messages pertaining to <service> |
journalctl -f | Live logging (show messages as they appear) |
journalctl -S <time> | Only messages after <time> (Since) |
journalctl -U <time> | Only messages before <time> (Until) |
student@student01: ~
➜ dmesg -H
[ +0.000000] KERNEL supported cpus:
[ +0.000000] Intel GenuineIntel
[ +0.000000] AMD AuthenticAMD
[ +0.000000] Centaur CentaurHauls
[ +0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[ +0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[ +0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[ +0.000000] x86/fpu: Supporting XSAVE feature 0x008: 'MPX bounds registers'
[ +0.000000] x86/fpu: Supporting XSAVE feature 0x010: 'MPX CSR'
[ +0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ +0.000000] x86/fpu: xstate_offset[3]: 832, xstate_sizes[3]: 64
[ +0.000000] x86/fpu: xstate_offset[4]: 896, xstate_sizes[4]: 64
[ +0.000000] x86/fpu: Enabled xstate features 0x1f, context size is 960 bytes, using 'compacted' format.
[ +0.000000] e820: BIOS-provided physical RAM map:
[ +0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009dbff] usable
[ +0.000000] BIOS-e820: [mem 0x000000000009dc00-0x000000000009ffff] reserved
[ +0.000000] BIOS-e820: [mem 0x00000000000e0000-0x00000000000fffff] reserved
[ +0.000000] BIOS-e820: [mem 0x0000000000100000-0x000000006dab2fff] usable
[ +0.000000] BIOS-e820: [mem 0x000000006dab3000-0x000000006f528fff] ACPI data
student@student01: ~
➜ sudo chsh -s fish student
WARNING!
student@student01: ~
➜ sudo chsh -s $(which fish) student
#!/bin/bash
echo "Hello world!"
student@student01: ~
➜ ./.local/bin/script_01.sh
zsh: permission denied: ./.local/bin/script_01.sh
Denied!
student@student01: ~
➜ ls -l .local/bin
total 4
-rw-rw-r-- 1 student student 33 Jan 29 10:46 script_01.sh
student@student01: ~
➜ chmod u+x .local/bin/script_01.sh
student@student01: ~
➜ ls -l .local/bin
-rwxrw-r-- 1 student student 33 Jan 29 10:46 script_01.sh
student@student01: ~
➜ ./.local/bin/script_01.sh
Hello world!
student@student01: ~
➜ export PATH=$PATH:$HOME/.local/bin
student@student01: ~
➜ script_01.sh
Hello world!
student@student01: ~
➜ for NUM in $(seq 1 10); do echo "Hello World! x$NUM"; done
Hello World! x1
Hello World! x2
Hello World! x3
Hello World! x4
Hello World! x5
Hello World! x6
Hello World! x7
Hello World! x8
Hello World! x9
Hello World! x10
for <VAR> in <SET>;
do
<CMDS>
done
for NUM in $(seq 1 10);
do
echo "Hello $NUM times:"
for _ in $(seq 1 $NUM);
do
echo -e "\tHello"
done
done
We can even nest loops
if [ <CONDITION> ];
then
<command if true>
else
<command if NOT true>
fi
#!/bin/bash
LINES=$(tput lines)
COLUMNS=$(tput cols)
declare -A snowflakes
declare -A lastflakes
clear
function move_flake() {
i="$1"
if [ "${snowflakes[$i]}" = "" ] || [ "${snowflakes[$i]}" = "$LINES" ]; then
snowflakes[$i]=0
else
if [ "${lastflakes[$i]}" != "" ]; then
printf "\033[%s;%sH \033[1;1H " ${lastflakes[$i]} $i
fi
fi
printf "\033[%s;%sH*\033[1;1H" ${snowflakes[$i]} $i
lastflakes[$i]=${snowflakes[$i]}
snowflakes[$i]=$((${snowflakes[$i]}+1))
}
while :
do
i=$(($RANDOM % $COLUMNS))
move_flake $i
for x in "${!lastflakes[@]}"
do
move_flake "$x"
done
sleep 0.1
done
Command | Function |
---|---|
systemctl start | Starts a service for current boot only |
systemctl stop | Stops a service |
systemctl restart | Stops and then starts a service for current boot only |
systemctl reload | Reloads a service configuration file without restarting |
systemctl enable | Sets a service to start at bootup |
systemctl status | See the status of a service |
[Section]
Directive1=value
Directive2=value
[Section2]
Directive3=value
...
Command | Function |
---|---|
top | Process Monitoring |
memtop | Memory Monitoring (Not installed by default) |
vtop | All in One monitoring (Not installed by default) |
ptop | Power Monitoring (Not installed by default) |
sntop | Host Monitoring (Not installed by default) |
student@student01: ~
➜ ps aux | head
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 220552 8972 ? Ss Jan10 0:38 /sbin/init splash
root 2 0.0 0.0 0 0 ? S Jan10 0:00 [kthreadd]
root 6 0.0 0.0 0 0 ? S< Jan10 0:00 [mm_percpu_wq]
root 7 0.0 0.0 0 0 ? S Jan10 0:00 [ksoftirqd/0]
root 8 0.0 0.0 0 0 ? S Jan10 3:19 [rcu_sched]
root 9 0.0 0.0 0 0 ? S Jan10 0:00 [rcu_bh]
root 10 0.0 0.0 0 0 ? S Jan10 0:00 [migration/0]
root 11 0.0 0.0 0 0 ? S Jan10 0:01 [watchdog/0]
root 12 0.0 0.0 0 0 ? S Jan10 0:00 [cpuhp/0]
student@student01: ~
➜ watch -n 1 ps aux
Every 1.0s: ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 220552 8972 ? Ss Jan10 0:38 /sbin/init splash
root 2 0.0 0.0 0 0 ? S Jan10 0:00 [kthreadd]
root 6 0.0 0.0 0 0 ? S< Jan10 0:00 [mm_percpu_wq]
root 7 0.0 0.0 0 0 ? S Jan10 0:00 [ksoftirqd/0]
root 8 0.0 0.0 0 0 ? S Jan10 3:19 [rcu_sched]
root 9 0.0 0.0 0 0 ? S Jan10 0:00 [rcu_bh]
root 10 0.0 0.0 0 0 ? S Jan10 0:00 [migration/0]
root 11 0.0 0.0 0 0 ? S Jan10 0:01 [watchdog/0]
root 12 0.0 0.0 0 0 ? S Jan10 0:00 [cpuhp/0]
root 13 0.0 0.0 0 0 ? S Jan10 0:00 [cpuhp/1]
student@student01: ~
➜ ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 28:f1:0e:1a:89:f0 brd ff:ff:ff:ff:ff:ff
inet 10.17.150.252/24 brd 10.17.150.255 scope global dynamic enp0s31f6
valid_lft 62598sec preferred_lft 62598sec
inet6 xxxx::xxxx::xxxx::xxxx::xxxx/64 scope link
valid_lft forever preferred_lft forever
3: lxdbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
inet 10.243.178.1/24 scope global lxdbr0
valid_lft forever preferred_lft forever
inet6 xxxx::xxxx::xxxx::xxxx::xxxx/64 scope link
valid_lft forever preferred_lft forever
student@student01: ~
➜ ping -c 3 www.google.com
PING www.google.com (172.16.1.1) 56(84) bytes of data.
64 bytes from iad23s57-in-f4.1e100.net (172.16.1.1): icmp_seq=1 ttl=54 time=35.7 ms
64 bytes from iad23s57-in-f4.1e100.net (172.16.1.1): icmp_seq=2 ttl=54 time=46.1 ms
64 bytes from iad23s57-in-f4.1e100.net (172.16.1.1): icmp_seq=3 ttl=54 time=30.0 ms
--- www.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 30.079/37.305/46.132/6.652 ms
student@student01: ~
➜ nslookup google.com
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: google.com
Address: 172.16.1.14
student@student01: ~
➜ traceroute www.google.com
traceroute to www.google.com (172.217.7.164), 64 hops max
1 10.1.1.1 1.425ms 0.868ms 1.340ms
2 172.16.1.254 270.868ms 149.332ms 187.508ms
3 10.2.1.1 8.302ms 8.083ms 8.066ms
4 * * *
5 * * *
student@student01: ~
➜ netstat -ptuna
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:5355 0.0.0.0:* LISTEN -
tcp 0 0 10.2.1.1:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN -
tcp 0 0 10.1.1.252:55846 52.4.87.2:443 ESTABLISHED 6593/kbfsfuse
tcp 0 0 10.1.1.252:40098 23.23.209.213:443 ESTABLISHED 3534/firefox
tcp 0 0 10.1.1.252:45328 52.206.36.233:443 ESTABLISHED 6593/kbfsfuse
tcp 0 0 10.1.1.252:40838 35.161.114.234:443 ESTABLISHED 3534/firefox
tcp 0 0 10.1.1.252:55828 52.4.87.2:443 ESTABLISHED 6593/kbfsfuse
tcp 0 0 10.1.1.252:52530 52.84.34.228:443 ESTABLISHED 3534/firefox
Command | Function |
---|---|
lsof -i | Show open networking files (can also add 'tcp' or 'udp' to be specific) |
lsof -i -a | All |
lsof -i -a -c <chars> | Only list processes that start with characters <chars> |
lsof -i -a -p <PID> | Only list processes with a PID of <PID> |
lsof -i :<port> | Only show files open for ports <PORT> |
student@student01: ~
➜ lsof -i -a
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
firefox 3534 student 111u IPv4 41734554 0t0 TCP student01:40838->ec2.us.compute.com:https (ESTABLISHED)
firefox 3534 student 200u IPv4 41979422 0t0 TCP student01:40386->slid.es:https (ESTABLISHED)
keybase 6590 student 16u IPv4 40646863 0t0 TCP student01:54808->ec2.compute-1.com:https (ESTABLISHED)
kbfsfuse 6593 student 11u IPv4 40658534 0t0 TCP student01:55828->ec2.compute-1.com:https (ESTABLISHED)
kbfsfuse 6593 student 32u IPv4 40673896 0t0 TCP student01:55846->ec2.compute-1.com:https (ESTABLISHED)
kbfsfuse 6593 student 33u IPv4 40732025 0t0 TCP student01:45328->ec2.compute-1.com:https (ESTABLISHED)
chrome 27947 student 98u IPv4 37653361 0t0 UDP *:mdns
chrome 27947 student 101u IPv6 37653362 0t0 UDP *:mdns
chrome 27947 student 122u IPv4 40670442 0t0 TCP student01:57600->qb-in-f188.1e100.net:5228 (ESTABLISHED)
chrome 27947 student 138u IPv4 41988911 0t0 TCP student01:55586->iad30s09-.1e100.net:https (ESTABLISHED)
Command | Function |
---|---|
tcpdump -D | List available interfaces (You'll need this before anything else) |
tcpdump -i <IFACE> | Dump packets from the <IFACE> interface |
tcpdump -nn | Don't resolve IP->Hostnames or Port numbers->Names |
tcpdump -t | Use human readable time stamps |
root@student01: ~
➜ tcpdump -nntc3 -i any tcp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes
IP 10.1.1.252.54808 > 52.200.75.29.443: Flags [P.], seq 35118:3503178, ack 55969, win 293, options [nop,nop,TS val 278801 ecr 6312], length 60
IP 52.200.75.29.443 > 10.1.1.252.54808: Flags [P.], seq 1:42, ack 60, win 114, options [nop,nop,TS val 63511515 ecr 2781761801], length 41
IP 10.1.1.252.54808 > 52.200.75.29.443: Flags [.], ack 42, win 293, options [nop,nop,TS val 2781761814 ecr 63511515], length 0
3 packets captured
3 packets received by filter
0 packets dropped by kernel
Command | Function |
---|---|
iptables -A <CHAIN> | "Append" a rule at the bottom of <CHAIN> |
tcpdump -I <CHAIN> <NUM> | Insert a rule on <CHAIN> and rule number <NUM> |
iptables -D <CHAIN> <NUM> | Delete rule number <NUM> from <CHAIN> |
Option / Flag | Function |
---|---|
-j <ACTION> | What to do with the packet. Normally: * ACCEPT * LOG * DROP * MASQUERADE |
-p [!] <PROTO> | Match a particular protocol like 'tcp' or 'udp' |
-i <IFACE> | Match only on input interface <IFACE>. If '!' is included it reverses the rule |
-d [!] <IP>[/cidr] | Destination IP/network. If '!' is included it reverses the rule |
-s [!] <IP> | Source IP/network. If '!' is included it reverses the rule |
-o <IFACE> | Only match output interface <IFACE> |
-m <NAME> | Performs a "match" matches can be thought of as "modules" and enable other "matching options/flags" More on this later... |
--dport <NUM> | Destination port |
--sport <NUM> | Source port |
Common Rule options/switches
Option / Flag | Function |
---|---|
-m conntrack | Adds a --ctstate <STATE> flag where you can match connection states * ESTABLISHED * RELATED * NEW * INVALID Can be comma separated like ESTABLISHED,RELATED Also adds --ctproto |
-m comment | Allows adding comments with --comment "some comment" |
-m multiport | Allows matching on more than one port with --dports <port1,port2> |
-m iprange | Allows --src-range and --dst-range for a range of IPs |
-m log | Adds --log-level <#> to only log at specified logging levels |
-m udp OR -m tcp | Adds --sport and --dport that will match only TCP or UDP ports |
List of all extensions: http://ipset.netfilter.org/iptables-extensions.man.html
iptables -A INPUT -i lo -p all -j ACCEPT
iptables -A OUTPUT -o lo -p all -j ACCEPT
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
iptables -A INPUT -p tcp --dport www -j ACCEPT
iptables -I INPUT -p tcp --dport 22 -i eth0 -m conntrack --ctstate NEW -m recent --set
iptables -I INPUT -p tcp --dport 22 -i eth0 -m conntrack --ctstate NEW -m recent --update \
--seconds 900 --hitcount 3 -j DROP
iptables -P INPUT DROP
student@student01: ~
➜ ssh instructor@instructor01
instructor password:
instructor@instructor01: ~
➜
student@student01: ~
➜ scp some.txt student@remote:/home/student/
student@student01: ~
➜ scp student@remote:/home/student/some.txt some.txt
student@remote: ~
➜ netcat -l 2201 < file.txt
student@local: ~
➜ netcat -p 2201 > file.txt
Command | Function |
---|---|
netcat -l <NUM> | Listen on port <NUM> |
netcat -L <NUM> | Listen on port <NUM> but DO NOT close connection after first connection |
netcat -p <NUM> | Connect to port <NUM> |
student@local: ~
➜ md5sum file.txt
d41d8cd98f00b204e9800998ecf8427e file.txt
student@local: ~
➜ scp file.txt student@remote:/home/student
student@local: ~
➜ ssh student@remote
student@remote: ~
➜ md5sum file.txt
d41d8cd98f00b204e9800998ecf8427e file.txt
Your Shell
apt-add-repository ppa:fish-shell/release-3
apt-get update
apt-get install fish