Operations notes

Reverse lines in a file

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
tac /path/to/file
tac /path/to/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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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)
# 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)
# 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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sed -i -e "1i <your data goes here>" FILE_NAME
sed -i -e "1i <your data goes here>" FILE_NAME
sed -i -e "1i <your data goes here>" FILE_NAME

Have rsync print timestamps

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
rsync --out-format='%t %f' -avzu ~/myfolder/ user@1.1.1.1:/home/user/myfolder
rsync --out-format='%t %f' -avzu ~/myfolder/ user@1.1.1.1:/home/user/myfolder
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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# 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
# 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
# 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/*)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo apt install supervisor
sudo apt install supervisor
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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[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
[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
[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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sudo systemctl enable supervisor
sudo systemctl start supervisor
sudo systemctl enable supervisor sudo systemctl start supervisor
sudo systemctl enable supervisor
sudo systemctl start supervisor

Check Supervisor status

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ sudo supervisorctl status
app RUNNING pid 16188, uptime 0:13:48
$ sudo supervisorctl status app RUNNING pid 16188, uptime 0:13:48
$ sudo supervisorctl  status
app                              RUNNING   pid 16188, uptime 0:13:48

MySQL: Loading local data is disabled

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SET GLOBAL local_infile=1;
SET GLOBAL local_infile=1;
SET GLOBAL local_infile=1;

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


Posted

in

,

by

Tags: