1 Tricks and Hacks
Create QR Code:
qrencode -s 15 -d 700 -o labWebsite.png "https://onkyo.u-aizu.ac.jp/#/"
Download videos from Terminal:
yt-dlp 'url'
yt-dlp --extract-audio 'url'
Specs of a Ubuntu system
sc
lshw | less
Beamer presentation with second screen and timer:
python3 -m pympress pdf_file
Finding creation/access/modify and change date of a file
stat -x foo
Finding metadata of a file
mdls
Change the contents of a column in a list of files within the same directory (in this case, 5th column ‘z’ by ‘m’)
for f in *; do
awk -v OFS='\t' -F"\t" '{gsub("z","x",$5)}1' $f > 'o'$f
mv 'o'$f $f
awk -v OFS='\t' -F"\t" '{gsub("m","z",$5)}1' $f > 'o'$f
mv 'o'$f $f
awk -v OFS='\t' -F"\t" '{gsub("x","m",$5)}1' $f > 'o'$f
mv 'o'$f $f
done
Extract text from all powerpoint files using Terminal in MacOS
Move to the directory where the pptx files are and run this:
mkdir unzipped
rm bla.txt
for f in session*.pptx;
do
rm -r unzipped;
mkdir unzipped
unzip "$f" -d unzipped;
grep -hoe "<a:t>[/%&–\'\".()-: 1-9A-Za-z]*</a:t>" unzipped/ppt/slides/slide*.xml| sed 's/<a:t>//g'| sed 's/<\/a:t>//g' >>bla.txt;
done
tar zip a file:
tar -zcvf output.tar.gz path_to_directory/
Find a string within a file in a directory:
grep -ril "string" dir
Rename files:
for f in *; do ext=""; [[ $f =~ \. ]] && ext="."${f#*.}; mv "$f" "${f%%.*}"_NO$ext; done
or
ls -1 *_bla_* | awk -F"_" -v old="bla" -v new="newBla" '$2==old{print "mv "$0 " "$1"_"new"_"$3}' | sh
Move inner files to outer directory
find . -maxdepth 2 -type f -exec mv {} .. \;
copy files in a list (in a textile) from the same directory to a directory
cat file.csv | xargs -I % cp % PATH_TO_OTHER_DIR
replace a word in all files within a directory
sed -i '.old' 's/phonation/vowels/g' *.textgrid
delete part of the name of a file:
for file in *_auto.TextGrid ; do mv "$file" "${file%_auto.TextGrid}.TextGrid" ; done
Delete the first n characters of a filename
for f in *; do mv "$f" "${f#??}"; done
Add extensions to files in a directory
find . -type f -exec mv '{}' '{}'.wav \;
change the extension of a list of files
for file in *.textgrid; do mv "$file" "${file%.textgrid}.TextGrid"; done
Copy files with the same name but different extension from a folder to a subfolder:
for f in ./DuanStimuliForSubjectiveExperiment/*;
do
cp `basename ${f%.*}.TextGrid` ./DuanStimuliForSubjectiveExperiment/;
done
Change the encoding of a set of files
for f in ./*;
do
iconv -f SHIFT-JIS -t UTF-8 $f > ./UTF8/$f
done
Convert PDF files to PS
for f in *.pdf; do gs -sDEVICE=ps2write -dNOPAUSE -dBATCH -sOutputFile=./psFigures/$f.ps $f; done
Convert a batch of PDFs into jpegs
for i in *.pdf; do gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=jpeg -r144 -sOutputFile=./converted/$(basename $i .pdf).jpg $i; done
Trim the white space around a graphic
for i in *.jpg; do convert $i -trim $i; done
select N random lines from a file:
brew install coreutils
gsort -R input | head -n 100 >output
Merge and compress PDFs in a directory:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sPAPERSIZE=a4 -dFIXEDMEDIA -dPDFFitPage -sOutputFile=out.pdf *.pdf
Make a smaller file:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed.pdf input.pdf
Make the pdf even smaller at 150 DPI:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/ebook -sOutputFile=compressed.pdf input.pdf
Add something to the path:
echo $PATH
export PATH=$PATH:/usr/local/include/faust
Tricks with Sox
Normalize audio files:
for i in *.wav; do /Applications/sox/sox --norm=-.1 $i ./normalized/$i ; done
for i in *.wav; do /Applications/sox/sox $i equalLengthRecordings/$i trim 0 0.5275; done
for i in *.wav; do /Applications/sox/sox
$i ~/Desktop/$i fade 0 0.5275 0.01; done
for i in *.wav; do /Applications/sox/soxi -s $i; done
for i in *.wav; do /Applications/sox/sox $i ~/Desktop/$i rate 44100; done
Tricks with ffmpeg
for j in *.m4a; do /Applications/ffmpeg -i "$j" -acodec libmp3lame -ab 320k ../mp3/"$j".mp3 ; done
for file in *.m4a.mp3 ; do mv "$file" "${file%.m4a.mp3}.mp3" ; done
Search LaTeX Documentation:
texdoc library_name
Find the bounding box of a ps/pdf
gs -sDEVICE=bbox -dNOPAUSE -dBATCH file
Reset the key for SSH connections when the key has changed:
ssh-keygen -R <host>
$ scp foobar.txt your_username@remotehost.edu:/some/remote/directory
copy from remote
scp userbounding@server:/path/to/remotefile.zip /Local/Target/Destination
rsync -avW -e ssh user@server:/PATH/
scp file user@linsv.u-aizu.ac.jp:/PATH/
https://streamsv.u-aizu.ac.jp/PATH/file
Replacement for finger:
pinky -l
python3 -m venv path/to/venv
source path/to/venv/bin/activate
python3 -m pip install xyz
space in disk:
sudo df -h
sapply(seq(1, length(numbers), by = 2), function(i) { paste(numbers[i], numbers[i + 1], sep = ".")
debug Python MacVIM
import pdb
...
pdb.set_trace()
1 Execute the next statement… with “n” (next)
2 Repeating the last debugging command... with ENTER
3 Quitting it all... with “q” (quit)
4 Printing the value of variables… with “p” (print)
a) p a
5 Turning off the (Pdb) prompt… with “c” (continue)
6 Seeing where you are… with “l” (list)
7 Stepping into subroutines... with “s” (step into)
8 Continuing... but just to the end of the current subroutine... with “r” (return)
9 Assign a new value
a) !b = "B"
10 Set a breakpoint
a) break linenumber
b) break functionname
c) break filename:linenumber
11 Temporary breakpoint
a) tbreak linenumber
12 Conditional breakpoint
a) break linenumber, condition