Trap Ctrl-C in a Bash script
How to trap Ctrl-C in a Bash script?
The piece of code:
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT
function ctrl_c() {
echo
echo "Ctrl-C by user"
# do the jobs
exit
}
How to trap Ctrl-C in a Bash script?
The piece of code:
# trap ctrl-c and call ctrl_c()
trap ctrl_c INT
function ctrl_c() {
echo
echo "Ctrl-C by user"
# do the jobs
exit
}
A file may be splitted to many chunks and replications stored on many datanodes in HDFS. Now, the question is how to find the DataNodes that actually store a file in HDFS? You may use the dfsadmin -fsck tool from the Hadoop hdfs util. Here is an example: $ hadoop fsck /user/aaa/file.name -files -locations -blocks…
How to find and change a user’s UID on Linux? Find the UID of a user: id -u $USER_NAME Change a user’s UID: # usermod -u $NEW_UID $USER_NAME Read more: How to move all the files under Users for a user to another drive on Windows? How to allow non-root users on Linux to mount…
How to get the directory path and file name from a absolute path in Bash on Linux? For example, with “/foo/bar/baz.txt”, it will produce: “/foo/bar/” and “baz.txt”. You also have the basename and dirname commands besides of the basename and dirname C API in Linux: [zma@laptop:~]$ p=”/foo/bar/baz.txt” [zma@laptop:~]$ dirname $p /foo/bar [zma@laptop:~]$ basename $p baz.txt…
How to get the mtime of a file on Linux from the file’s path? You can use stat to get the file status including the mtime: %y time of last modification, human-readable %Y time of last modification, seconds since Epoch As an example, $ stat -c %y ./file 2017-06-26 13:33:06.764042064 +0800 $ stat -c %Y…
There are good ssh clients on Windows and, needless to mention, Linux. But which ssh client on iOS for iPhone/iPad works the best for socks? You may try vSSH. It is the best SSH client app I found on iOS. vSSH supports tunneling/port forwarding: you can setup port tunneling in the “Port forwarding” section of…
In Golang, how to convert a string to unicode rune array and do the reverse way? Convert string s to a rune array: runes := []rune(s) Convert a rune array runes to string: str := string(runes) Read more: In Golang, how to print string to STDERR? How to get all the keys in an associative…