# install vm with vagrant(2.2.18) and virtualbox(6.1) & ubuntu basic command
vagrant --version
vboxmanage --version
* Adapter host only (virtualbox)

* Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "nginx" do |n|
n.vm.box = "ubuntu/bionic64"
n.vm.network "private_network", ip: "192.168.56.45"
n.vm.provision "shell", path: "./bootstrap.sh"
end
config.vm.provider "virtualbox" do |v|
v.memory = 512
v.cpus = 1
end
end
* vagrant up
* vagrant ssh

* uname -a
Show system and kernel
Linux ubuntu-bionic 4.15.0-151-generic #157-Ubuntu SMP Fri Jul 9 23:07:57 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
*head -n1 /etc/issue
Show distribution
Ubuntu 18.04.5 LTS \n \l
* mount
Show mounted filesystems
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=232988k,nr_inodes=58247,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=49264k,mode=755)
/dev/sda1 on / type ext4 (rw,relatime,data=ordered)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=25,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=11718)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/vagrant on /vagrant type vboxsf (rw,nodev,relatime,_netdev)
lxcfs on /var/lib/lxcfs type fuse.lxcfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other)
vagrant on /vagrant type vboxsf (rw,nodev,relatime,_netdev)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=49260k,mode=700,uid=1000,gid=1000)
* date
Show system date
Sun Aug 1 12:28:46 UTC 2021
* uptime
Show uptime
12:29:28 up 5 min, 1 user, load average: 0.00, 0.13, 0.08
* whoami
Show your username
vagrant
* man command
Show manual for command
for example: man sudo
* CTRL-c
Stop current command
* CTRL-z
Sleep program
* CTRL-a
Go to start of line
* CTRL-e
Go to end of line
* CTRL-u
Cut from start of line
* CTRL-k
Cut to end of line
* CTRL-r
Search history
* !!
Repeat last command
* !abc
Run last command starting with abc
for example : !man
* env
Show environment variables
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
LC_MEASUREMENT=C.UTF-8
SSH_CONNECTION=10.0.2.2 41982 10.0.2.15 22
LESSCLOSE=/usr/bin/lesspipe %s %s
LC_PAPER=C.UTF-8
LC_MONETARY=C.UTF-8
LANG=C.UTF-8
LC_NAME=C.UTF-8
XDG_SESSION_ID=3
USER=vagrant
PWD=/home/vagrant
HOME=/home/vagrant
SSH_CLIENT=10.0.2.2 41982 22
XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
LC_ADDRESS=C.UTF-8
LC_NUMERIC=C.UTF-8
SSH_TTY=/dev/pts/0
MAIL=/var/mail/vagrant
TERM=xterm-256color
SHELL=/bin/bash
SHLVL=1
LC_TELEPHONE=C.UTF-8
LOGNAME=vagrant
XDG_RUNTIME_DIR=/run/user/1000
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
LC_IDENTIFICATION=C.UTF-8
LESSOPEN=| /usr/bin/lesspipe %s
LC_TIME=C.UTF-8
_=/usr/bin/env
* echo $NAME
Output value of $NAME variable
* export NAME=value
Set $NAME to value
* $PATH
Executable search path
-bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin: No such file or directory
* $HOME
Home directory
-bash: /home/vagrant: Is a directory
* $SHELL
Current shell
* cmd < file
Input of cmd from file
* cmd1 <(cmd2)
Output of cmd2 as file input to cmd1
* cmd > file
Standard output (stdout) of cmd to file
* cmd > /dev/null
Discard stdout of cmd
* cmd >> file
Append stdout to file
* cmd 2> file
Error output (stderr) of cmd to file
* cmd 1>&2
stdout to same place as stderr
* cmd 2>&1
stderr to same place as stdout
* cmd &> file
Every output of cmd to file.
cmd refers to a command.
* cmd1 ; cmd2
Run cmd1 then cmd2
* cmd1 && cmd2
Run cmd2 if cmd1 is successful
* cmd1 || cmd2
Run cmd2 if cmd1 is not successful
* cmd &
Run cmd in a subshell
* pwd
Show current directory
/home/vagrant
* mkdir dir
Make directory dir
* cd dir
Change directory to dir
vagrant@ubuntu-bionic:~$ cd dir
vagrant@ubuntu-bionic:~/dir$
* cd ..
Go up a directory
vagrant@ubuntu-bionic:~$
* ls
List files
dir install.sh
* ls Options
-a
Show all (including hidden)
. .. .bash_history .bash_logout .bashrc .cache .gnupg .local .profile .ssh .vim .viminfo dir install.sh
-R
Recursive list
.:
dir install.sh
./dir:
-r
Reverse order
install.sh dir
-t
Sort by last modified
dir install.sh
-S
Sort by file size
install.sh dir
-l
Long listing format
total 12
drwxrwxr-x 2 vagrant vagrant 4096 Aug 1 12:44 dir
-rwxrwxr-x 1 vagrant vagrant 5206 Jul 27 06:06 install.sh
-1
One file per line
dir
install.sh
-m
Comma-separated output
dir, install.sh
-Q
Quoted output
"dir" "install.sh"
* Search Files
grep pattern files
Search for pattern in files
grep -i
Case insensitive search
grep -r
Recursive search
grep -v
Inverted search
grep -o
Show matched part of file only
find /dir/ -name name*
Find files starting with name in dir
find /dir/ -user name
Find files owned by name in dir
find /dir/ -mmin num
Find files modifed less than num minutes ago in dir
whereis command
Find binary / source / manual for command
locate file
Find file (quick search of system index)
* File Operations
touch file1
Create file1
cat file1 file2
Concatenate files and output
less file1
View and paginate file1
q to quit
file file1
Get type of file1
file1: empty
cp file1 file2
Copy file1 to file2
mv file1 file2
Move file1 to file2
rm file1
Delete file1
head file1
Show first 10 lines of file1
tail file1
Show last 10 lines of file1
tail -F file1
Output last lines of file1 as it changes
* Watch a Command
watch -n 5 'ntpq -p'
Issue the 'ntpq -p' command every 5 seconds and display output
* Process Management
ps
Show snapshot of processes
PID TTY TIME CMD
2191 pts/1 00:00:00 bash
2208 pts/1 00:00:00 ps
top
Show real time processes
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2209 vagrant 20 0 42140 3672 3112 R 0.3 0.7 0:00.04 top
1 root 20 0 159620 8836 6624 S 0.0 1.8 0:01.99 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H
5 root 20 0 0 0 0 I 0.0 0.0 0:00.05 kworker/u2:0
6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq
7 root 20 0 0 0 0 S 0.0 0.0 0:00.15 ksoftirqd/0
8 root 20 0 0 0 0 I 0.0 0.0 0:00.33 rcu_sched
9 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_bh
10 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
11 root rt 0 0 0 0 S 0.0 0.0 0:00.01 watchdog/0
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
14 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 netns
15 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_tasks_kthre
16 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kauditd
17 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khungtaskd
18 root 20 0 0 0 0 S 0.0 0.0 0:00.00 oom_reaper
19 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 writeback
20 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kcompactd0
21 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd
22 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 crypto
23 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kintegrityd
24 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kblockd
25 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 ata_sff
26 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 md
27 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 edac-poller
28 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 devfreq_wq
29 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 watchdogd
31 root 20 0 0 0 0 I 0.0 0.0 0:01.59 kworker/0:1
33 root 20 0 0 0 0 S 0.0 0.0 0:00.10 kswapd0
kill pid
Kill process with id pid
pkill name
Kill process with name name
killall name
Kill all processes with names beginning name
* Nano Shortcuts
Files
Ctrl-R
Read file
Ctrl-O
Save file
Ctrl-X
Close file
Cut and Paste
ALT-A
Start marking text
CTRL-K
Cut marked text or line
CTRL-U
Paste text
Navigate File
ALT-/
End of file
CTRL-A
Beginning of line
CTRL-E
End of line
CTRL-C
Show line number
CTRL-_
Go to line number
Search File
CTRL-W
Find
ALT-W
Find next
CTRL-\
Search and replace
More nano info at:
http://www.nano-editor.org/docs.php
* Screen Shortcuts
screen
Start a screen session.
screen -r
Resume a screen session.
screen -list
Show your current screen sessions.
CTRL-A
Activate commands for screen.
CTRL-A c
Create a new instance of terminal.
CTRL-A n
Go to the next instance of terminal.
CTRL-A p
Go to the previous instance of terminal.
CTRL-A "
Show current instances of terminals.
CTRL-A A
Rename the current instance.
More screen info at:
http://www.gnu.org/software/screen/
* File Permissions
chmod 775 file
Change mode of file to 775
chmod -R 600 folder
Recursively chmod folder to 600
chown user:group file
Change file owner to user and group to group
* File Permission Numbers
First digit is owner permission, second is group and third is everyone.
Calculate permission digits by adding numbers below.
4
read (r)
2
write (w)
1
execute (x)