To download this repository
wget https://github.com/eliranwong/wsl2/archive/master.zip
To install:
sudo apt install mlocate
To create database:
sudo /etc/cron.daily/mlocate
To manually update the database:
sudo updatedb
To run:
locate
or
mlocate
To split a single text file into multiple ones, with maximum of 500 lines each, e.g.:
split -d -l 500 [filename] [optional_prefix_name]
To sort TAB-delimited text file by first 3 columns:
sort -b -n -t "[TAB HERE]" -k 1,3 test.txt > test2.txt
To add line numbers to text file, starting from number 1:
nl -nln -v 1 -s "[TAB HERE]" test.txt > test2.txt
[Remarks: -v 1 -s "[TAB HERE]" is implemented by default, could be omitted.]
To change file extensions of multiple files:
for file in *.html; do mv "$file" "${file%.html}.txt"; done
To add an empty line at the end of a file:
echo "" >> test.txt
To add an empty line in multiple files:
for file in *.txt; do echo "" >> $file; done
To combine multiple files in a single file:
cat *.txt > combined.txt
Tutorial on string manipulation:
https://www.tldp.org/LDP/abs/html/string-manipulation.html
More at: http://www.tldp.org/LDP/abs/html/
- Simple tasks with sed:
sed -E -i.bak 's/[search]/[replace]/g' [file]
e.g. an example of back references:
echo "test testing" | sed -E 's/(t)(e)s\1/\2/g'
e.g. executing multiple commands
echo "test testing" | sed -E -e 's/(t)(e)s\1/\2/g;s/i/I/g'
sed -E -i.bak -f myScript.sed inputFile.txt
e.g. remove file extension:
echo "test.txt.html" | sed s/\.[^\\.]*$//
e.g. open Thunar from Windows Explorer:
- Simple tasks with awk / gawk:
echo "My_name_is_Wong" | awk -F '_' '{surname=$4; $4="Eliran"; print $4 " " surname; print $0 " " surname}'
echo "My_name_is_Wong" | awk -F '_' '{gsub($4,"Eliran_Wong",$0); print$0}'
e.g. append text before file extension
echo "test.text.txt.html" | awk -F '.' '{gsub(
$(NF-1), $ (NF-1)"_new", $0); print$0}'
e.g. open Windows Explorer from Thunar:
https://github.com/eliranwong/wsl2/blob/master/file_manager/thunar.md#by-right-clicking-a-folder
echo '<img src="data:image/png;base64,'$(base64 test.png)'">' > test.html
https://github.com/eliranwong/bible-verse-parser/blob/master/RegexSearch.py
Read usage & examples at:
https://github.com/eliranwong/wsl2/blob/master/cli_tools/resr.md
To list files in a rar file, e.g. file.rar:
unrar l file.rar
To extract a rar file, e.g. file.rar:
unrar e file.rar
To pack a folder, e.g. myFolder, into a rar file, e.g. file.rar:
rar a file.rar myFolder
Import a TAB-delimited text file into a table:
sqlite3 FILE.sqlite
.separator "\t"
.import DATA.csv TABLENAME
VACUUM;
.quit
To export without header:
sqlite3 -separator "[TAB HERE]" FILE.sqlite "SELECT * FROM TABLENAME;" > output_filename.csv
To export with header:
sqlite3 -header -separator "[TAB HERE]" FILE.sqlite "SELECT * FROM TABLENAME;" > output_filename.csv
To delete all records in a table:
sqlite3 FILE.sqlite "DELETE FROM TABLENAME; VACUUM;"
To delete a table:
sqlite3 Bible_Promises.book "DROP TABLE TABLENAME;"
Remarks: To enter a TAB character on terminal:
Ctrl + v + TAB
Convert traditional Chinese to simplified Chinese:
opencc -i [inputFile] -o [outputFile] -c t2s.json
Convert simplified Chinese to traditional Chinese:
opencc -i [inputFile] -o [outputFile] -c s2t.json
https://github.com/eliranwong/wsl2/blob/master/multimedia/youtube-dl.md
https://github.com/eliranwong/wsl2/blob/master/multimedia/ffmpeg.md
To add / update configurations:
nano ~/.Xresources
[Edit ~/.Xresources]
xrdb -merge ~/.Xresources
To replace / remove configurations:
xrdb -query -all > ~/.Xresources
[Edit ~/.Xresources]
xrdb ~/.Xresources
- check cpu
lscpu
- check storage
df -h
- check size of current directory
du -sh
- check memory
free -h
- Display File(s) in Tree
For example:
tree -L 1 /
Make use of "aux ps" to locate a process and "kill" to quit.
Alternatively, use "pkill"
To Install a downloaded .deb file:
sudo dpkg -i packagename.deb
OR
sudo apt install ./packagename.deb
OR
Use chrome os "Files" app, right-click a .deb file and select "Install with Linux"
To Remove an installed package:
sudo dpkg -r packagename
Alternatively, open chrome os "Files" app (Alt+Shift+m), right click a *.deb file and select "Install with Linux"
tar xvfz [package].tar.gz
cd [unpacked folder]
./configure
make
make install
-
Use "mlocate" to find full path of the missing file:
mlocate [missing file] -
Use "dpkg -S" to find the package(s) owning file(s):
dpkg -S [full file path] -
re-install the package, indicated in step in the result of step (2)
For example, https://community.rstudio.com/t/installation-error-cannot-find-libsmime3-so/30646
Use "sudo apt dist-upgrade" instead of "sudo apt upgrade"
sudo apt clean
sudo apt autoremove --purge
e.g. To launch leafpad through terminal:
geany &
[Closing the terminal closes leafpad too.]
OR
geany & disown
[Leafpad keeps running even the terminal is closed.]
ZZ - Save and exit
:q! - discard all changes, since the last save, and exit
:w - save file but don't exit
:wq - again, save and exit
SPACE = next page
b = previous page
q = quit