Trap bash exit signal
Answer:
To trap your script before exit, you can use the trap in bash, e.g.
#!/bin/bash
set -eu
function bye {
echo "Good bye"
}
trap bye EXIT
sleep 1000
# Quit the script by pressing Ctrl+C
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Trap bash exit signal
Answer:
To trap your script before exit, you can use the trap in bash, e.g.
#!/bin/bash
set -eu
function bye {
echo "Good bye"
}
trap bye EXIT
sleep 1000
# Quit the script by pressing Ctrl+C
How to tail a remote file over ssh
Answer:
If you want to tail a remote file over ssh, you can use
# ssh -t remote-server "tail -f /var/log/log.txt"
Writing more robust shell script
Answer:
You should always start your bash shell script with the line set -eu
The meaning is:
How to find files and tar them together
Answer:
You can use the following command to find files and tar them together
# find . -type f -print0 | tar -czvf backup.tgz --null -T -
Move forward or backward by a word in bash shell
Answer:
To move more efficiently in bash shell, you can use the following short cuts
Meta + f (move forward by a word)
Meta + b (move backward by a word)
The Meta key is the Alt key under most systems, on Mac, you would need to enable "use option as meta key" in the Terminal's Preference.