13 Using Linux
13.1 General Short Cuts
super+tabswitches between windowssuper+left/right arrowfits active window to left or right of screenctrl+alt+topens a new terminal windowctrl+shift+topens a new tab in terminal windowalt-numberswitches between tabs in terminal windowctrl+dcloses a terminal window
13.2 Terminal Short Cuts
tabautocompletes from what you have started to typectrl+cbreaks out of a command or processctrl+dlogs out of current terminalcclears screen (my alias)ctrl+amoves cursor to begining of linectrl+emoves cursor to the end of linectrl+uclears the current linectrl+porup arrowscrolls through previous commandsctrl_nordown arrowscrolls forward through commandsctrl+shift+ccopies highlighted textctrl+shift+vpastes copied textalt-tabswitches between open windows within an appsuper-tabswitches between apps
13.3 Control processes
- command & to launch program in background of terminal
 - fg %1 to move program to foreground
 - bg %1 to move to background
 - kill %1 (see chap 10 in linux book)
 
13.4 Pdf manipulation
We use evince [filename.pdf] to view pdfs
we use qpdf --empty --pages infile.pdf 1-5 -- outfile.pdf to extract pages from a pdf
See [docs]https://qpdf.readthedocs.io/en/stable/cli.html#page-ranges) for options on listing page ranges in qpdf
- no spaces
 - 1-2,5-6 for pages 1-2 and 5-6
 - 3-z for all pages except 1-2
 - 1-z,x3-4 for all pages except 3-4
 
13.5 Browsers
chrome [filename]s opens a file in chrome. You can view an html file in firefox from terminal using firefox [filename]
13.6 Common Commands
wc, uniq, head, tail, |, >, >>, less, sort, grep, cat, man, help, –help, type, which, echo, history
ls -lSrto list files sorted by size (with larger sizes later:r). Useful to find the non-zero error files. Can have issues when applied to large numbers of files (> 60K). See use offindandxargsbelow if needed.cd -changes to previous directorymvto move files between directories. can use..as target to move file to home directory. e.g.,mv results_* ..>redirect standard output to a new file (creates file if does not exist; writes over file contents if it does exist).>>redirect standard output to append to a filermto remove file(s).rm -rto remove non-empty directorycat filename_* > all_files.csvto concatenate all files into one file.lessviews file contents|is pipe operatorwcis word count.wc -lcounts lineschmod +x get_missing_jobs.shto change permissions on get_missing_jobs.sh to run it../get_missing_jobs.shto run it.find -maxdepth 1 -name "results_*.csv" | wc -lwill find results_*.csv in local folder (maxdepth 1) and pipe them into a word count that counts lines (-l)cat job_nums.csv | wc -lreads contents ofjob_nums.csvand pipes to a word count that counts lines (-l)find -maxdepth 1 -name "results_*.csv" | ls -lSrgets around the too many arguments issue. Find searches recursively by default (override with maxdepth if needed), whereas ls searches just.or the specified directory (e.g.,./results)See tutorial on awk to understand its use for simple programming. See a tutorial on the use of xargs.
printfto send formatted text to standard output or to a fileprintf "John is %s\n" "nice"printf "John is %d years old" 54printf "hello world\nIt is John!" > out.txt)
man [command]to open manual for commandsdiff file1 file2- Compare two files side by side.vimdiff file1 file2- Highlight the differences between two files in the vim editor.tar [-] c|x|t f tarfile [pattern]- Create, extract or list contents of a tar archive using pattern, if supplied.du -h- Display sizes in human readable format. For example, 1.2M, 3.7G, etc.du -shc- Display size of directory and its subdirectories
head,tail, andsortwork as expected. Remember to use -n with sort if you want to do a numeric (rather than text) sort. Sort also takes -r for reverse. Use pipe to pipe in a vector of numbers or text. Use -1 with head or tail to get the first (or last) value in series.cd-switches back to previous directorycolumn -s , -t < test.csvwill display contents of .test.csv in columns using built in function. default without -s , is space delimited
13.7 Compressing and archiving files
- `gzip foo.txt - Compress foo.txt. The resulting compressed file is named file.txt.gz. -r to compress subdirectories when compressing a directory rather than file.
 gunzip foo.txt- Uncompress foo.txt.gz (no need to append .gz).gunzip foo.txt -c | lessto view contents of foo.txt without decompressing ittar cf playground.tar playgroundmake archive of playground directory. r rather than c to append rather than create new archive.tar czf playground.tgz playgroundto archive and compress (could also name playground.tar.gz)tar xf playground2.tarto extract files from archive- see linux book, chapter 18 for more details
 
13.8 FTP
- use sftp at command line. e.g., 
sftp submit-1.chtc.wisc.edu - can use command line to review local and remote computers.
 - For local 
lls,lcd,lpwdare the three most useful commands - For remote 
ls,cd,pwd - Use 
get foo.txtto copy foo.txt from remote to local director - Use 
put foo.txtto copy foo.txt from local directory to remote directory exitwhen done- Can set up a ssh key to log in without credentials to CHTC.
 
13.9 SSH
- use ssh at command line. e.g., 
ssh submit-1.chtc.wisc.edu - Can set up a ssh key to log in without credentials to CHTC, Github, etc.
 
13.10 Kill a frozen app
Press Alt + F2 . Type xkill and hit Enter. The cursor will turn into a small ‘x’. Left click any window to kill the process associated with that window.