How to split a string by string in Bash?

Posted on

How to split a string by string in Bash? For example, “a string separated by space” => [“a”, “string”, “separated”, “by”, “space”] and “a,string,separated,by,comma” => [“a”, “string”, “separated”, “by”, “comma”] You can convert a string to an array using the grammar like inarr=(${a}) If the delimiter is not space and delimiter is a single character
Read more

Getting Hostname in Bash in Linux in 3 Ways

Posted on

Getting the hostname of the node running a program can be useful in various scenarios, such as creating logs with the hostname, identifying which node a script is running on, or configuring a distributed system with different nodes. In Bash, there are several ways to retrieve the hostname of the machine, as mentioned in the
Read more

How to get the epoch timestamp in Go lang?

Posted on

In Go lang, how to get the epoch timestamp, the number of seconds passed since the epoch? In Go, you can use the time.Now() func to get current time and its Unix() func to convert it into an epoch timestamp: import(“time”) func getEpochTime() int64 { return time.Now().Unix() } If you would convert a time string
Read more

Any good Go REPL implementation / tool?

Posted on

Go lang is fast to compile and can be used as a script by go run prog.go. However, a REPL is more convenient for testing/trying some small pieces of code. Any good Go REPL implementation / tool? Try gore https://github.com/motemen/gore Get gore $ go get -u github.com/motemen/gore An example $ gore gore version 0.2.6 :help
Read more

How to read the whole file content into a string in Go?

Posted on

How to read the whole file content into a string in Go? You can use the ReadFile() func from the io/ioutil package in Go to read the whole file content: func ReadFile(filename string) ([]byte, error) For example, read file filepath content and check the error: if bytes, err := ioutil.ReadFile(filepath); err != nil { log.Fatal(“Failed
Read more

How to install encfs on CentOS 6?

Posted on

I noticed your answer on configuring encfs on CentOS 6. I had difficulties installing encfs on CentOS 6. How did you install it? Thanks. For CentOS 6, I used a slightly old version (version 1.7.4) using an RPM built for by PUIAS: For x86-64 version: # yum install http://puias.princeton.edu/data/puias/6/x86_64/os/Addons/fuse-encfs-1.7.4-1.puias6.x86_64.rpm For i686 version: # yum install
Read more

encfs on CentOS 6 can’t mount as normal user

Posted on

On CentOS 7, using a normal user, encfs works just well. On CentOS 6, using the root user, encfs works. However, the problem is, on CentOS 6, using a normal user account, encfs does not work as on CentOS 7. $ encfs -s ~/t/.enc ~/t/enc EncFS Password: fuse: failed to exec fusermount: Permission denied fuse
Read more

How to remove the bottom panel in gnome 3 classic?

Posted on

The gnome 3 classic’s bottom panel looks not useful to me. I do not use it. How to remove the bottom panel in gnome 3 classic? That bottom panel is from the “Window List” plugin. The gnome 3 classic package depends on that plugin package on CentOS 7 as far as I checked. And Gnome
Read more

How to redirect non-www domain to www domain in .htaccess?

Posted on

I have a website. But I would like use the www.example.com instead of example.com. How to redirect non-www domain to www domain on my server? I am using apache2 (httpd). You can add a piece of code into the top .htaccess in your site: Specific method: redirect example.com domain to www.example.com domain RewriteEngine On RewriteBase
Read more

How to make tee catch the stderr only in Linux?

Posted on

I would like to make tee catch the stderr and log it into a file. A brute force method by let tee listen on both stderr and stdout is okay like cmd 2>&1 | tee -a log But how to make tee catch the stderr only? You can make use of “process substitution” (>(…)) to
Read more