Restores content and packages that are found on a default Ubuntu in order to make it more suitable for interactive and learning use
Running multiple shell sessions in a single terminal window.
Basic tmux:
- Start new tabbed window: Press Ctrl+b, release and then press c
- Start new window horizontally: Press Ctrl+b, release and press "
- Start new window vertically: Press Ctrl+b, release and press %
- Switch between tabbed window: Press Ctrl+b, release and press p or n
- Switch between horizontal or vertical window: Press Ctrl+b, release and then press ;
- Kill a window: Press Ctrl+b, release and then press x
- Rename a tabbed window: Press Ctrl+b, release and then press ,
- Scroll through window console output: Press Ctrl+b, release and then use arrows to move
apt is a package manager **to manage packages in **Ubuntu Linux.
Update the packages repository
apt update
Upgrade packages in bulk
apt
Search for a package named htop
apt search htop
Show information about a package
apt show htop
Install a package named htop
apt install htop
Remove a package named htop
apt remove htop
Install multiple packages
apt install htop less
apt-file is a program to search for packages containing files. Very helpful if you do not remember the name of the package, but you know the command.
Install apt-file using apt
apt install apt-file
Update the apt-file cache
apt-file update
Search for a package that provides postgres command
apt-file search bin/psql
cd /home
cd -
cd ..
pwd
uname -a
uname -r
uptime
hostname
hostname -I
last reboot
date
cal
w
whoami
id
###Display CPU information
cat /proc/cpuinfo
nproc
cat /proc/meminfo
cat /proc/1/environ
free -h
##System Monitoring, Statistics, Debugging
top
###Install and use a friendly interactive process viewer (alternative to top)
apt install htop
htop
mpstat 1
vmstat 1
iostat 1
lsof
lsof -u USER
###List files opened by a certain process with PID (e.g: 1)
lsof -p PIS
du -sh
watch -n1 df -h
List all files (including hidden) in a long listing human-readable format in the current directory (specifying . is optional).
ls -hal
###Display the present working directory
pwd
touch file1 file2
mkdir dir1
mkdir -p dir1/dir2/dir3
tree dir1
cp -v file1 dir1/file1-copy
cp -vr dir1 dir1-copy
mv -v file1 file1-rename
mv -v file1-rename dir1
rm file1
rm -vr dir1
ln -s file1 file1-link
echo "hello, world!" > hello.txt
cat hello.txt
less hello.txt
head -n 20 hello.txt
tail -n 20 hello.txt
tail -f hello.txt
A process is a running instance of a program.
ps
ps auxf
ps uf -C processname
top
htop
pgrep nginx
kill PID
kill -s SIGNAL_NUMBER pid
kill -l
pkill nginx
(sleep 30; echo "woke up after 30 seconds") &
jobs
bg
fg
fg N
kill %N
# Create a file
touch file1
# Set permission using either of the method
chmod 750 file1
chmod u=rwx,g=rx,o= file1
# List the file permission
ls -lh file1
chown user:group file1
ip addr
ip addr show eth0
ip route
ping google.com
ping 8.8.8.8
whois medium.com
dig medium.com A # IPv4 addresses
dig medium.com AAAA # IPv6 addresses
dig medium.com NX # Nameservers
host medium.com # IPv4 addresse
hostname
hostname -i
wget [http://ipv4.download.thinkbroadband.com/5MB.zip](http://ipv4.download.thinkbroadband.com/5MB.zip)
curl --output 5MB.zip [http://ipv4.download.thinkbroadband.com/5MB.zip](http://ipv4.download.thinkbroadband.com/5MB.zip)
netstat -plunt
lsof -i
lsof -i tcp # only TCP ports
grep pattern file
# For example:
grep root /etc/passwd
grep -R "/bin/bash" /etc
grep -B 5 root /etc/passwd
grep -A 3 root /etc/passwd
find /etc -iname 'passwd'
find /etc -iname 'pass*' # glob pattern
###Find files based on filesize
find / -size +1M # larger than 1MB
find / -size -1M # smaller than 1MB
##Disk Usage
df -h
du -sh /var/log
du -h 5MB.zip
ncdu
echo "hello" > hello.stdout.txt
echo "world" > hello.stdout.txt
cat somefile 2> cat.stderr.txt
ps auxf >& processes.txt
echo "hello" >> hello2.stdout.txt
echo "world!" >> hello2.stdout.txt
cat some-unknown-file 2>> cat2.stderr.txt
ps auxf &>> processes.txt
The shell pipe **is a way to **communicate between commands.
mkdir pipes-example
cd pipes-example
touch {1..10}.txt
ls -1 *.txt | sort -n # sorts the output in ASC order
ls -1 *.txt | sort -nr # sorts the output in DESC order
ls -1 *.txt | sort -n | head -n 5 # show the first 5 lines
ls -1 *.txt | sort -n | tail -n 5 # show the last 5 lines
cat /etc/passwd | grep root # show lines containing string 'root'
env
echo $HOME
echo $SHELL
export PORT=80
export PLATFORM=medium.com
unset PORT
PATH is one of the common and important environment variables. What do you think will happen if you unset it?
echo $PATH
unset PATH