How-to bash

Put files and directory rights to default values

find ../492A-5B6E/ \( -type f -execdir chmod 644 {} \; \) -o \( -type d -execdir chmod 755 {} \; \)
find where_to_search/ -name name_directory -type d

Look (grep) for utf8 characters in files

grep --color='auto' -P -n "[\x80-\xFF]" file

Rename files (extensions)

rename 's/\.cxx$/.cpp/' *.cxx

Idem inside the text (like “includes” in C++)

grep -rl '\.cxx' ./ | xargs sed -i 's/\.cxx/\.cpp/g'

Find top directories with a size above a given threshold (e.g. 1Gb)

du -h -d1 --threshold=1G * | sort -h

Copy with a progression bar (and more)

rsync -av --delete-after --stats --progress to_save/ rep_where_to_save/

The options are:

Vim command to search and replace in several files

vim
:args *.cpp *.h
:bufdo %s/pattern/replace/g | update
vim
:args *.cpp *.h
:bufdo execute "normal! gg" | :call Myfunction() | execute "normal! gg=G" | execute "normal! gg" | w

Generate public and private ssh keys

ssh-keygen -t rsa

Give a name like “id_rsa_foo” and you get two files:

Then copy the public key on the remote machine:

scp id_rsa_foo.pub username@remotemachine:/home/username/.ssh/

Add the key to the authorized host file:

cat id_rsa_foo.pub >> authorized_hosts

Make a config file for ssh

In .ssh/, create a file named “config” and add a profile to make it easy to connect via ssh.

Host remMach
	HostName remoteMachineName
	User username
	IdentityFile ~/.ssh/id_rsa_foo
	ProxyCommand ssh remoteMachineName nc %h %p

Or even simpler depending on the case:

Host remMach
	HostName remoteMachineName.institute.edu
	User username
	PubkeyAuthentication no

Then to connect instead of:

ssh username@remoteMachineName.institute.edu
scp -r username@remoteMachineName.institute.edu:/mnt/home/username/dir/ .

one can use:

ssh username@remMach
scp -r username@remMach:/mnt/home/username/dir/ .

Create a torrent file

transmission-create -o ~/torrent_name.torrent -t udp://open.demonii.com:1337 -t udp://9.rarbg.com:2710/announce -t udp://tracker.openbittorrent.com:80/announce -p -c "comment" rep_to_share.zip

Different tracker addresses can be used, but beware what you share.

Download a website

wget -r -l5 -k -E "http://www.l_adresse_du_site.a_recuperer.com"

Add the option -c to restart an incomplete download, or the option -np to avoid going up the directory tree to download a single page.

Open a Jupyter notebook on MacOS

Install Jupyter using Homebrew, then:

jupyter notebook [location] &