Operations notes

Reverse lines in a file

tac /path/to/file

In vim, you can select the lines you need to reverse and issue :'<,'>!tac.

Source: https://stackoverflow.com/a/742485/526189

Compare two files and get only the difference

# Using the `diff` tool
diff -a --suppress-common-lines -y a.txt b.txt > c.txt

# Using the `comm` tool
comm -2 -3 <(sort a.txt) <(sort b.txt)

Source: https://stackoverflow.com/questions/4544709.

Prepend data to a file

sed -i -e "1i <your data goes here>" FILE_NAME

Have rsync print timestamps

Use the --out-format option. For example:

rsync --out-format='%t %f' -avzu ~/myfolder/ user@1.1.1.1:/home/user/myfolder

Source: https://askubuntu.com/a/652532/118883

Upload folder to S3

# 1. Create a profile (optional, but recommended)
aws configure --profile <profile-name>

# 2. Upload folder to bucket
aws s3 cp --profile <profile-name> /path/to/folder/ s3://my.bucket.name/ --recursive

# 3. Custom endpoint (e.g., if you're uploading to Wasabi or other S3 compatible service)
aws s3 cp --profile <profile-name> /path/to/folder/ s3://my.bucket.name/ --recursive --endpoint-url=https://s3.us-west-1.wasabisys.com 

NOTE: S3 is a global service, but Wasabi is not, make sure you include the region in the endpoint.

Supervisor: keep process running

Supervisor is a tool that helps us keep processes running.

Installation (Debian/Ubuntu/*)

sudo apt install supervisor

Let’s say you want to have a program/script running all the time on your system, you can create the following config file /etc/supervisor/conf.d/app.conf:

[program:app]
numprocs=1
directory=/home/user/projects/app/
command=scripts/server.sh
autostart=true
autorestart=true
stderr_logfile=/home/user/projects/app/logs/app.err.log
stdout_logfile=/home/user/projects/app/logs/app.out.log

Enable and start supervisor

sudo systemctl enable supervisor
sudo systemctl start supervisor

Check Supervisor status

$ sudo supervisorctl  status
app                              RUNNING   pid 16188, uptime 0:13:48

MySQL: Loading local data is disabled

SET GLOBAL local_infile=1;

Source: https://stackoverflow.com/q/59993844/526189


Posted

in

,

by

Tags: