How much time needed to transfer a file

I need to estimate the time required to transfer a file, here below:

The file is 1000M and the transfer rate is 100MB/S,

Amount to transfer / transfer rate = time to transfer, so 1000/100 = 10

The time needed is 10 secondes.

Posted in General | Leave a comment

Git: Recover a deleted file


To get a deleted file from git (whatever the reason could be), there the command:

git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"


Posted in General | Leave a comment

Postgresql-Get the number of rows affected

You will find a way below to get the number of rows affected by an UPDATE or a DELETE statement.

CREATE FUNCTION update_foobar(id INT, field1 VARCHAR(40))
LANGUAGE plpgsql
AS $$
    -- some variables declarations
    -- then 
    RETURN ru;
$$ ;
Posted in General | Leave a comment

Setup sftp server on debian8 (chroot)

Let’s start by:

su -
groupadd sftp_users
usermod -G sftp_users my_username


emacs /etc/ssh/sshd_config
# Search the line below and replace it
Subsystem sftp /usr/lib/openssh/sftp-server
# by this one
Subsystem sftp internal-sftp
# Now each time that a user connects from the sftp group, 
# we are gonna apply theses rules:
Match Group sftp_users
 X11Forwarding no
 AllowTcpForwarding no
 ChrootDirectory /home
 ForceCommand internal-sftp


systemctl restart ssh

Edit: If you need to remove a user from a group:

gpasswd -d user group

or debian includes a tool:

deluser user group

Posted in Server, SFTP | Leave a comment

Interesting link 1

Posted in General | Leave a comment

iterate over files in directory

To do not forget:

for f in $FILES
     echo $filename

More informations:

Posted in Shell | Leave a comment

shell variable to execute a command

To do not forget:

=> variable=$(my_commands)
json_files=$(find . -name "*.json")
echo $json_file
Posted in Shell | Leave a comment

SQL – From timestamptz A to timestamptz B

For PostgreSQL (tested on 9.4)

CREATE TABLE tests(id serial not null, created_on timestamptz);
INSERT INTO tests (created_on) VALUES (now());
2016-02-16 19:26:13.823126-05

I guess you have configured your timezone in your postgresql.conf file. I have for information ‘America/Toronto’.

SELECT created_on  AT TIME ZONE ‘Europe/Paris’ FROM tests;
2016-02-17 01:26:13.823126

Posted in Database, SQL | Leave a comment

shell – code de retour par une commande

Comment lire le code de retour d’une commande comme pwd ?

chaque commande executée vous renverra un code d’erreur situé entre 0 et 255. 0 pour opération réussie, sinon toute autre chiffre signifiera qu’une erreur s’est déroulée lors de l’exécution.

Le code de retour est disponible dans cette variable:


Pour exemple

~ pwd toto
pwd: too many arguments
~ echo $?
~ 1

~ pwd
~ /home/user
~ echo $?
~ 0

Stay tuned

Posted in General | Leave a comment

shell – La commande read

La commande read lit l’entrée standard et affecte à la variable passé en paramètre la valeur:

~ read variable_1
~ echo $variable_1
~ foobar

Si vous voulez que le premier mot soit stocké dans la variable_1 et que le reste soit accessible à travers la variable nommée variable_2

~ read variable_1 variable_2

Le premier mot sera stocké dans la variable variable_1 et tout le reste de la chaine de caractère sera dans variable_2. Vous pouvez continuer ainsi de suite …

Autre découverte: rajouté l’option -s et vous pourrez cacher la saisie. Intéréssant pour saisir un mot de passe.

read -s mot_de_passe

Stay tuned

Posted in Shell, Terminal | Leave a comment