Computing Cheat Sheets
Computing Cheat Sheets
1 Download the most recent Long-Term Support (LTS) version of Ubuntu (from ubuntu.com)
To Install Linux on a Desktop Machine:
Use Rufus (from rufus.ie) on Windows or Startup Disk Creator utility on Ubuntu to create
2
a bootable flash drive from the downloaded ‘.iso’ file.
3 Use the bootable flash drive to install Ubuntu on the system.
To Install Linux as a Virtual Machine:
2 Download Virtual Box (from virtualbox.org) and install on system.
3 Using Virtual Box and the downloaded ‘.iso’ file, create new virtual machine.
To Install/Remove Packages
sudo1 apt install 〈𝑝𝑘𝑔1 〉 … 〈𝑝𝑘𝑔𝑛 〉
sudo dpkg -i 〈𝑑𝑒𝑏𝑖𝑎𝑛 𝑝𝑎𝑐𝑘𝑎𝑔𝑒〉
To Update Packages
1 sudo apt update
2 sudo apt upgrade
1
‘sudo’ enables administrative permissions.
2
for OS-agnostic environment export, use –-no-builds or --from-history.
1
Other Useful Stuff
1 PATH=$PATH:〈𝑑𝑖𝑟𝑐_𝑝𝑎𝑡ℎ〉
2 echo3 $PATH
To Permanently Add to Path:
uname -n lspci
Operating System and
Node Name
Kernel Release uname -r lstopo9
uname -v
Hardware
Kernel Version
Hardware Name uname -m free -h
CPU Type uname -p
Hardware Platform uname -i df -h
Operating System uname -o
3
‘echo’ prints the following string or value.
4
Can be used instead of adding to path; e.g.: ln -s 〈𝑝𝑎𝑡ℎ 𝑡𝑜 𝑚𝑎𝑡𝑙𝑎𝑏〉 /usr/local/bin/matlab
5
e.g. lpd://printserver.ece.unm.edu/ece313-bw.
6
To exclude certain file types, include the following flag --exclude-ext=〈𝑡𝑦𝑝𝑒1 〉, 〈𝑡𝑦𝑝𝑒2 〉, …
7
On Windows PowerShell, do: $fn=git ls-files; cloc $fn
8
More complete information can be read from the file: /proc/cpuinfo
9
Requires hwloc package.
10
This will output informations in the same order as above.
2
Most Used Commands of ‘bash’ Shell in Linux11
11
To get help for any command, do: 〈𝑐𝑜𝑚𝑚𝑎𝑛𝑑_𝑛𝑎𝑚𝑒 〉 ‘--help’
12
Command ‘cd’ without any arguments returns to user’s ‘home’ directory.
13
Command ‘ls’ without any arguments lists the content of the current directory. The flag ‘-l’ lists content of
the directory in Long Listing Format. The flag ‘-a’ will include hidden files and folders (the names of hidden
files and folders always start with a dot ‘.’ ; The same can be achieved in graphical mode using: ctrl+H). The
flag ‘-t’ sorts the listing according to the date modified. Single letter flags can be lumped together; e.g.: ls -la
or ls -lat. To get long format information about specific files, do: ls -l 〈𝑓𝑖𝑙𝑒𝑛𝑎𝑚𝑒1 〉 … 〈𝑓𝑖𝑙𝑒𝑛𝑎𝑚𝑒𝑛 〉.
14
To exclude files from the archive, add the following flag: --exclude=〈𝑝𝑎𝑡𝑡𝑒𝑟𝑛 〉. To remove files after
archiving, add the following flag: --remove-files.
15
An example of piping the output of ‘watch’: watch -n 1 ‘qstat | tail -n 10’
16
Full Path to a file can be used as its name.
17
Some Important Environment Variables are: HOME, PATH, PWD, SHELL, USER, USERNAME, LD_LIBRARY_PATH.
18
Shell Script files are given the extension ‘.sh’.
19
A pipe is a form of redirection that is used to send the output of one command/program/process to another
command/program/process for further processing.
3
‘vim’ Basic Commands
4
Remote Access to HPC System
ssh 〈𝑢𝑠𝑒𝑟𝑛𝑎𝑚𝑒〉@〈𝑟𝑒𝑚𝑜𝑡𝑒_𝑚𝑎𝑐ℎ𝑖𝑛𝑒_𝑎𝑑𝑑𝑟𝑒𝑠𝑠〉21
20
For resizing of windows to take effect do: eval $(resize)
21
e.g. username@xena.alliance.unm.edu or username@wheeler.alliance.unm.edu.
22
X11, Port Forwarding, Preferred Authentication and Identity File are optional.
23
On windows ‘ssh-copy-id’ doesn’t exist; for the second step, the content of the ‘id_rsa.pub’ must be
manually copied to the host’s ‘authorized_keys’ file.
24
Typical values for Tensorflow applications: LocalForward 16006 localhost:6006
5
7-3- Manage User’s Processes on Remote Machine using ‘top’
top -u 〈𝑢𝑠𝑒𝑟𝑛𝑎𝑚𝑒〉
To View Processes for all Users press ‘u’
top
To View Processes for a Specific User press ‘o’25 and enter USER=〈𝑢𝑠𝑒𝑟𝑛𝑎𝑚𝑒〉
To Go Back to Processes for All Users press ‘=’
1 From the login node, ‘ssh’ onto the node that is running the job
2 ‘nvidia-smi’
3 Username associated with the Job ID can be obtained using ‘top’ command
25
This defines a Filter.
6
7-6- Resource Manager / Job Scheduler: ‘torque’ / ‘pbs’
qstat -q
26
‘-X’ flag is used to enable X11. Its optional.
7
7-7- Resource Manager / Job Scheduler: ‘slurm’
sinfo -N -l
CD TO DIRECTORY THE
cd $SLURM_SUBMIT_DIR # SHELL SCRIPT WAS
SUBMITTED FROM
8
Version Control using ‘git’
27
Another Option is GitHub (github.com)
9
Performance Monitoring Tools
9-1- Perf
To get overall count of events:
perf stat -e < 𝑒𝑣𝑒𝑛𝑡1 > ⋯ < 𝑒𝑣𝑒𝑛𝑡𝑛 > < 𝑐𝑜𝑚𝑚𝑎𝑛𝑑 >
CPPFLAGS : -DLIKWID_PERFMON
LDLIB : -likwid
# include <likwid.h>
# include <likwid-marker.h>
…
LIKWID_MARKER_INIT; // Must be called from serial region
…
#pragma omp parallel
{
LIKWID_MARKER_THREADINIT; // Only required if measuring multiple threads
}
…
LIKWID_MARKER_START(“Compute”);
…
LIKWID_MARKER_STOP(“Compute”);
…
LIKWID_MARKER_CLOSE; // Must be called from serial region
likwid-perfctr -C < 𝑝𝑟𝑜𝑐𝑒𝑠𝑠𝑜𝑟𝑠 > -g < 𝑝𝑒𝑟𝑓𝑜𝑟𝑚𝑎𝑛𝑐𝑒 𝑔𝑟𝑜𝑢𝑝𝑠 > -m < 𝑐𝑜𝑚𝑚𝑎𝑛𝑑 >
10
Migrating To Windows
10-1- PowerShell
Update PowerShell:
(1) Check the current version using the ‘$PSVersionTable’ environment variable.
(2) Search for the latest version of PowerShell:
winget search Microsoft.PowerShell
(3) Install PowerShell:
winget install --id Microsoft.Powershell --source winget
Keyboard Shortcuts:
11
10-3- Miniconda
As an alternative to the Miniconda (and Windows version of packages), WSL lets developers
run a Linux environment.
To install:
wsl --install
To Run:
wsl --cd ~/
To Uninstall:
wsl --unregister
10-5- Rclone
rclone mount "< 𝑟𝑐𝑙𝑜𝑛𝑒 𝑝𝑟𝑜𝑓𝑖𝑙𝑒 >" "< 𝑝𝑎𝑡ℎ 𝑡𝑜 𝑚𝑜𝑢𝑛𝑡 >"28 --cache-dir
"< 𝑝𝑎𝑡ℎ 𝑡𝑜 𝑐𝑎𝑐ℎ𝑒 >" --vfs-cache-mode full
(5) To unmount:
Ctrl+C
28
Must end with the name of a non-existent directory. rclone will create it and mount the drive in it.
12
10-6- Maintaining and Consuming a Video/Music Library
(1) Make sure none of the files in the directory have spaces in their names. cd into the
directory and use the following command in PowerShell to replace spaces with
underlines:
Get-ChildItem -File | Rename-Item -NewName { $_.Name -replace ' ','_'}
(2) Maintain a list of file names (relative paths) from a desired location:
29
mpv's command line options can also be put in a configurations file: in mpv’s directory, create a directory named
‘portable_config’. Inside ‘portable_config’, create a file named ‘mpv.conf’. Put the options in
‘mpv.conf’.
13
Appendix I: make’s Built-in Rules and Variables
% : %.cc
$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@
IMPLICIT
RULES
%.o: %.cc
$(COMPILE.cc) $(OUTPUT_OPTION) $<
(%): %
$(AR) $(ARFLAGS) $@ $<
CXX = g++
VARIABLES
AUTOMATIC
OUTPUT_OPTION = -o $@
AR = ar
ARFLAGS = rv
COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
LINK.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
CXXFLAGS
USER DEFINED
CPPFLAGS
VARIABLES
LDFLAGS
LOADLIBES30
LDLIBS
30
Deprecated
14
Appendix II: C/C++ Debugging using ‘gdb’
To Set a Break Point break < 𝑓𝑖𝑙𝑒𝑛𝑎𝑚𝑒 > : < 𝑙𝑖𝑛𝑒_𝑛𝑢𝑚𝑏𝑒𝑟 >
To See the List of all Break Points info b
To Disable a Break Point disable < 𝑏𝑟𝑒𝑎𝑘_𝑛𝑢𝑚 >
To Enable a Break Point enable < 𝑏𝑟𝑒𝑎𝑘_𝑛𝑢𝑚 >
To Delete Break Points delete < 𝑏𝑟𝑒𝑎𝑘_𝑛𝑢𝑚1 > ⋯ < 𝑏𝑟𝑒𝑎𝑘_𝑛𝑢𝑚𝑛 >
To Delete all Break Points delete
15
Appendix III: List of Packages
On Windows, if portable version of software is not provided by the vendor, search portableapps.com.
31
At the time of writing of this document, Install libgsl23/libgslcblas0 (Installed by default on Ubuntu).
32
Install package linux-tools-< 𝑘𝑒𝑟𝑛𝑒𝑙_𝑟𝑒𝑙𝑒𝑎𝑠𝑒 >.
16