How to use the terminal.
- Linux and commandline programs
- Git
- Installation
- Convert
- Node JS
- Bash scripting
- Network
- Raspberry Pi
- Nginx
- MongoDB
- MySQL
- Email and Calendar
- i3 view manager
- netcat nc
- cli translate
- Create alias'es in terminal:
sudo nano ~/.bashrc
e.g:alias cdjava='cd path/to/java/projects'
- Logout another user from the system
who
will show all logged in userssudo pkill -KILL -u <username>
logs out the user by that username.
- Change permissions
sudo chmod -R 755 <folder>
recursively change permision on the folder and all sub folders.
- Delete folder with content
rm -rf <foldername>
- Print folder structure to console:
tree
ortree <path/to/folder>
installed with - Create an alias. Open file
~/.bashrc
and find section with aliases. Write something ala:alias pip=pip3
- Show active processes:
htop
- from:
sudo apt-get install htop
now usehtop
- from:
- Show all running processes:
ps -A | less
pipe the process list through less for pagination. pressq
to exit.- pipe through grep:
ps -A | grep firefox
- find the process id:
pgrep firefox
- Show processes on ports
lsof -i:3000
- Kill process running on port:
kill $(lsof -t -i:3000)
orkill -9 $(lsof -t -i:3000)
for hard kill (but probably not necessary)
- Turn on palm detection to avoid accidental pointer jumps.
xinput set-prop 11 "Synaptics Palm Dimensions" 5, 5
and maybe alsoxinput set-prop 11 "Synaptics Palm Detection" 1
- Turn on/off nautilus desktop items:
gsettings set org.gnome.desktop.background show-desktop-icons <false/true>
- Turn on/off nemo desktop items:
gsettings set org.nemo.desktop show-desktop-icons true/false
: additional info if not enough: - Show file preview in nemo file manager: source
sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install gloobus-preview
sudo apt-get install nemo-gloobus-sushi
- publish markdown:
README.md
file locally with grip (was installed withpip install grip
since pip is written in python).- go to the folder containing the README.md file and enter:
grip
remove colors from the terminal when listing files and direcotories:
unalias ls
: See reference here
- Open the ConpizConfig Settings Manager (launcher -> ccsm)
- Go to window management and click the Application Switcher (or static application switcher) and set the alt+tab for the next ...
- show location bar: ctrl + l
- rename system folders
sudo nano /home/thomas/.config/user-dirs.dirs
- I used this to rename the desktop folder and pictures, videos etc.
- Using curl
curl http://example.com -o my.file -s
- Downloads the html file into the my.file file (-o is --output and -s is --silent)
- Using wget
- Using svn (subversion)
- From github this is the only way to download a sub directory
- svn checkout https://github.com/datsoftlyngby/dat2sem2017Fall/trunk/evalueringer
- Above the github url was changed so that 'trunk' now replaces 'tree/master' then it works
- Split a pdf file into many one page files:
pdftk largepdfile.pdf burst
The ubuntu package manager dpkg is derived from Debian linux
- To see if a package (pandoc in this case) is installed:
dpkg -l | grep pandoc
sudo wget https://github.com/jgm/pandoc/releases/download/1.15.1/pandoc-1.15.1-1-amd64.deb
followed bysudo dpkg -i pandoc-1.15.1-1-amd64.deb
vssudo apt-get install pandoc
vscabal install pandoc
vssudo dpkg -i pandoc-2.3-1-amd64.deb
when the deb is downloaded and terminal runs in download folder vs.- Or just double click the .deb file and it will open Ubuntu software GUI where install button is an option.
tar xvzf $TGZ --strip-components 1 -C pandoc-2.3-linux.tar.gz
when the tar is downloaded and terminal runs from same folder WHAT ARE THE PROS AND CONS?
pandoc test1.md -f markdown -t html -s -o test1.html
convert test1.md from -f markdown -t to html into the file: test1.htmlpandoc test.docx -f docx -t markdown -s -o test.md
To push to a different github repo.
git remote set-url origin [email protected]:USERNAME/REPOSITORY.git
To find out what is the remote:
git remote show origin
Set default credentials for remote to github with https:
- in home folder ~/ create file .netrc
- inside enter:
machine github.com
login Thomas-Hartmann
password Ho3el123
git reset --soft HEAD~1
Now the files are staged but not commited.
git reset HEAD -- .
removes everything in the current folder recursively from staged area.
- first do
git fetch --all
- then do
git reset --hard origin/master
or whatever branch.
- remove from repo so they will no longer be added if they were escaped in the .gitignore file
git rm -r --cached **/*.jar
git fetch
This will take the commits from remote and add them to git but not to the working tree
git diff master origin/master
This will compare what is in git repo for origin/master with what is in the working tree for branch: master.
forever start script.js
Run Express server script as a Daemon in the backgroundforever start -l forever.log -o out.log -e err.log script.js
log the output and errors to 2 log files
Loop through all .docx files in current folder
#!/bin/bash
FILES=./*.docx
echo "start script ............."
for f in $FILES
do
echo "Processing $f file..."
# Use pandoc on each .docx file to change it to .md file and change filename to not include .docx
pandoc $f -f docx -t markdown -s -o ${f%.*}.md
done
10.0.0.4:/volume1/files /home/pi/share nfs nouser,atime,auto,rw,dev,exec,suid 0 0
Mounting from NAS server Synology to raspberry folder:share
. In raspberry/etc/fstab
:
10.0.0.4:/volume1/files /home/pi/Share nfs nouser,atime,auto,rw,dev,exec,suid 0 0
10.0.0.4:/volume1/videos /home/pi/Videos nfs nouser,atime,auto,rw,dev,exec,suid 0 0
10.0.0.4:/volume1/music /home/pi/Music nfs nouser,atime,auto,rw,dev,exec,suid 0 0
Then in sudo nano /etc/samba/smb.conf
[Pi Share]
comment = Pi shared folder
path = /home/pi/Share
browseable = yes
writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
public = yes
guest ok = yes
[Pi Video]
comment = Pi shared folder
path = /home/pi/Video
browseable = yes
writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
public = yes
guest ok = yes
[Pi Music]
comment = Pi shared folder
path = /home/pi/Music
browseable = yes
writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
public = yes
guest ok = yes
Then sudo /etc/init.d/samba restart
Then in the file manager: smb://10.0.0.3
Raspberry pi specific operations here
- Overall configuration:
sudo raspi-config
- Start node red on reboot
sudo systemctl enable nodered.service
- Where are the host files
/etc/nginx/sites-enabled
and/etc/nginx/sites-available
For all sites both active and 'dormant'- create a symbolic link from sites-available to sites-enabled. This means that the symbolic link can just be removed from sites-enabled when we wish to disable the site temporarily. And to re-enable it just create a new symbolic link:
sudo ln -s /etc/nginx/sites-available/example_file /etc/nginx/sites-enabled/
- Where are the default web folder
/var/www/html/
- See what are the default server
grep -R default_server /etc/nginx/sites-enabled/
- check nginx config before restart
sudo nginx -t
- restart nginx
sudo systemctl restart nginx
- Configure nginx: /etc/nginx/sites-enabled/
upstream tomcat {
server 127.0.0.1:8080 fail_timeout=0;
}
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.jsp;
server_name www.bugelhartmann.dk bugelhartmann.dk;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
# proxy_pass http://127.0.0.1:8080;
include proxy_params;
proxy_pass http://tomcat/;
}
location /nodeapps/ {
proxy_pass http://127.0.0.1:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
- Install: Small tutorial
- Connect from terminal
mongo -u admin -p --authenticationDatabase admin
; - Config
sudo nano /lib/systemd/system/mongod.service
- restart
sudo systemctl daemon-reload
andsudo service mongod restart
- Stop mysql:
sudo service mysql stop
- First I had to go to BIOS and allow virtualmachine (Just the once)
- Then I had to stop Mysql server:
sudo service mysql stop
because it was taking up the port 3306 that vagrant file was forwarding. - Starting vagrant from folder that contains Vagrantfile:
vagrant up
- Current vagrant repos:
- edudata:
~/projects/kotlinProjects/Edutor/edutor/edudata
- edudata:
- Now I could run the Example of a vagrant file:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.box_check_update = false
# connect on port 13306
config.vm.network :forwarded_port, guest: 3306, host: 3306
config.vm.provision :shell, :path => "install.sh"
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777", "fmode=666"]
config.vm.network "private_network", ip: "10.19.17.12"
config.vm.hostname = "edudata"
end
Best solution was calDav:
- Installed caldav from Here downloaded the .deb file dubbleclicked it and install.
- Followed this instruction
- To remove annoying icon in system tray:
alt+right click icon
moved it to different workspace. - Password manager to insert the password: edit -> preferences -> security -> passwords -> saved passwords.
- Automatic update to ubuntu updated Thunerbird and then the lightning add-on no longer worked. Solution:
- Shut down thunderbird
sudo apt install xul-ext-lightning
- Start thunderbird and now the calendar is back.
- Extend screen to HDMI:
- xrandr --output HDMI-2 --same-as eDP-1 --auto
netcat article nc command is the "Swiss-army knife for TCP/IP". A 'power version' of telnet. It can:
- create socket servers to listen for incoming connections on ports
- transfer files from the terminal etc
- Use as telnet:
nc -v google.com 80
thenGET index.html HTTP/1.1
and click 'enter' TWICE! - As socket server:
nc -l -v 1234
netcat listen verbose on port 1234. - socket client (e.g. from another terminal):
telnet localhost 1234
- create an echo server:
nc -lp 1234
and from another node on network:nc <node name or ip> 1234
- Simple translate (auto detects the input language)
trans <word>
autodetects the language and translates to englishtrans :fr <phrase>
translates to french (:da for danish, :es for spanish)trans zh: <phrase>
to tell google translate that this is chinese (zh=chinese)trans fr:da 'cést la vie come sa'
put phrase or sentence in single-quotetrans -b :fr "Saluton, Mondo"
-b is for brief mode (less verbose)trans :en word
use as dictionary when source and target-language are the same.trans -d fr: mot
the -d flag to use dictionary mode what ever language.- read from input file
trans -b -i input.txt :fr
use the -i flag - read fro std in
echo "Saluton, Mondo" | trans -b -o output.txt :fr
it writes to an output file in this example.