~ /reference /commands
Reference · Commands

Every command, one search away.

The Linux commands used in this project for setup, compiling, running, monitoring and version control. Type in the filter to narrow the list, and use the copy button on any block.

bashgccps · top · htopgit

System#

Kernel & OS#

Identify the kernel, architecture and Ubuntu release.

uname -a              # full system information
uname -s              # kernel name
uname -m              # architecture
lsb_release -a        # Ubuntu version
cat /etc/os-release   # OS details

Memory, CPU & disk#

Check the resources available to the VM.

free -h               # memory usage
lscpu                 # CPU details
df -h                 # disk usage
cat /proc/meminfo     # detailed memory info

Packages (APT)#

Install and maintain software.

sudo apt update
sudo apt upgrade
sudo apt install build-essential
sudo apt install nano htop git
sudo apt remove package-name
sudo apt autoremove
sudo apt clean

Logs & status#

Inspect the kernel log, journal, uptime and time.

dmesg | tail -50
journalctl -xe
last
uptime
date
timedatectl

Files & editing#

Move around and copy, move or delete files.

ls -la
mkdir project-name
cd /path/to/directory
cd ~
cp source.txt destination.txt
cp -r source_dir/ destination_dir/
mv oldname.txt newname.txt
rm filename.txt
rm -r directory_name/

Read files#

Print whole files or just the start or end.

cat filename.txt
head -20 filename.txt
tail -15 filename.txt
less filename.c

Edit with nano#

Open a file, then use the shortcuts listed below.

nano filename.c
# Ctrl+O  save      Ctrl+X  exit
# Ctrl+K  cut line  Ctrl+U  paste
# Ctrl+W  search    Ctrl+\  replace

Build & run#

GCC flags#

Common ways to compile C.

gcc program.c -o program
gcc -Wall program.c -o program   # warnings
gcc -g program.c -o program      # debug info
gcc -O2 program.c -o program     # optimize
gcc program.c -o program -lm     # link math
gcc main.c utils.c -o program    # multiple files

Run programs#

Execute, time and redirect output.

./program
chmod +x program
time ./program
./program > output.txt
./program 2> error.txt
./program > output.txt 2>&1
./program &

matrix_fork.c#

Build and run the Phase I program.

gcc -Wall matrix_fork.c -o matrix_fork
./matrix_fork
gcc -Wall matrix_fork.c -o matrix_fork && ./matrix_fork

Repeat runs#

Loops used to collect several timings.

for i in {1..3}; do echo "Run $i:"; ./matrix_fork; done
for i in {1..5}; do echo "Run $i:"; time ./matrix_fork; done

Full build–run cycle#

Edit, compile, run and watch.

cd ~/os-project/src
nano matrix_fork.c
gcc -Wall matrix_fork.c -o matrix_fork
./matrix_fork
htop

Java (Phase II)#

Compile and run the multithreaded benchmark.

javac ArraySum.java Summer.java
java ArraySum

Processes#

Inspect processes#

List and find running processes.

ps
ps aux
ps -ef
pstree
ps -u $USER
pgrep program_name
ps aux | grep program_name

Signals & termination#

Stop, pause or resume a process.

kill -SIGINT process_id
kill process_id
kill -TERM process_id
kill -9 process_id
pkill program_name
killall program_name
kill -STOP process_id
kill -CONT process_id

Jobs#

Background and foreground control.

./program &
jobs
fg %1
bg %1
disown

Performance monitoring#

Watch CPU, I/O and memory live.

top
htop
mpstat
iostat
vmstat 1
top -p process_id

Git & virtualization#

Git workflow#

Clone, commit, push and branch. See the Git workflow guide for the full walkthrough.

git clone https://github.com/Shoug-Alomran/CS330-Parallel-Performance-Evaluation-in-Linux-Project.git
git status
git add .
git commit -m "Description of changes"
git push origin main
git pull origin main
git log --oneline --graph
git checkout -b feature-branch

VM diagnostics#

Check the virtualization layer.

ps aux | grep -i utm
systemctl status libvirtd
virt-host-validate
kvm-ok

Shell#

Keyboard shortcuts#

Terminal editing and control.

Ctrl+C   interrupt process      Ctrl+A   start of line
Ctrl+Z   suspend process        Ctrl+E   end of line
Ctrl+D   exit shell             Ctrl+U   clear before cursor
Ctrl+L   clear screen           Ctrl+K   clear after cursor
Ctrl+R   search history         Tab      autocomplete

Operators#

Chain commands and redirect output.

command1 && command2   # run 2 only if 1 succeeds
command1 ; command2    # run both
command1 | command2    # pipe
command 2>&1           # merge stderr into stdout
command | wc -l        # count lines
command | grep pattern # filter
No commands match that filter.