10 Using Linux
10.1 General Short Cuts
super+tab
switches between windowssuper+left/right arrow
fits active window to left or right of screenctrl+alt+t
opens a new terminal windowctrl+d
closes a terminal window
10.2 Terminal Short Cuts
tab
autocompletes from what you have started to typectrl+c
breaks out of a command or processctrl+d
logs out of current terminal- `ctrl+l clears screen
ctrl+a
moves cursor to beginnng of linectrl+e
moves cursor to the end of linectrl+u
clears the current linectrl+p
orup arrow
scrolls through previous commandsctrl_n
ordown arrow
scrolls forward through commandsctrl+shift+c
copies highlighted textctrl+shift+v
pastes copied text
10.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)
10.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
10.5 Quarto
10.6 Markdown
You will need to install pandoc to render markdown to pdf: sudo apt-get install pandoc texlive-latex-base texlive-fonts-recommended texlive-extra-utils texlive-latex-extra
.
Use pandoc [infile.md] -o [outfile.pdf]
to render infile.md to outfile.pdf.
Note also that the ReText app can render markdown to pdf (and html) as well if you don’t want to use the terminal.
10.7 Firefox
You can view an html file in firefox from terminal using firefox [filename]
10.8 Common Commands
wc, uniq, head, tail, |, >, >>, less, sort, grep, cat, man, help, –help, type, which, echo
ls -lSr
to 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 offind
andxargs
below if needed.cd -
changes tio previous directorymv
to 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 filerm
to remove file(s).rm -r
to remove non-empty directorycat filename_* > all_files.csv
to concatenate all files into one file.less
views file contents|
is pipe operatorwc
is word count.wc -l
counts lineschmod +x get_missing_jobs.sh
to change permissions on get_missing_jobs.sh to run it../get_missing_jobs.sh
to run it.find -maxdepth 1 -name "results_*.csv" | wc -l
will find results_*.csv in local folder (maxdepth 1) and pipe them into a word count that counts lines (-l)cat job_nums.csv | wc -l
reads contents ofjob_nums.csv
and pipes to a word count that counts lines (-l
)find -maxdepth 1 -name "results_*.csv" | ls -lSr
gets 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.
printf
to send formatted text to standard output or to a fileprintf "John is %s\n" "nice"
printf "John is %d years old" 54
printf "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.head
,tail
, andsort
work 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.
10.9 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 | less
to view contents of foo.txt without decompressing ittar cf playground.tar playground
make archive of playground directory. r rather than c to append rather than create new archive.tar czf playground.tgz playground
to archive and compress (could also name playground.tar.gz)tar xf playground2.tar
to extract files from archive- see linux book, chapter 18 for more details
10.10 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
,lpwd
are the three most useful commands - For remote
ls
,cd
,pwd
- Use
get foo.txt
to copy foo.txt from remote to local director - Use
put foo.txt
to copy foo.txt from local directory to remote directory exit
when done- Can set up a ssh key to log in without credentials to CHTC.
10.11 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.
10.12 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.