Linux

Bash: How to Insert One White Space before and after English Words in Japanese

Consider to insert one white space before and after English word in Japanese. Run the following script by changing a string 'YOUR_FILENAME'. The script copy the original file as YOUR_FILENAME.org and overwrite and replace the original file by inserting one white space before and after an English word. It is useful multi-byte language such as CJK (Chinese, Japanese and Korean).

続きを読む

DevOps: What You Should Know

1. Adjust the time amongst the server in your system

ntpdate time.apple.com

2. Check and monitor your disk space

  • Your service may stop after one year from the beginning of your service release date because the log files occupies a server disk space.
  • Use logrotate to truncate the log files (even if you are practicing that, the logs will overflow at the server).
  • Monitor the remaining disk space by using df command.
df -h
続きを読む

Linux: How to Add a User to a Group

There are a couple of options to add a user to group(s) in Linux. The commands are gpasswd, usermod and adduser.

I recommend to use gpasswd to add a user to group, which is no harm.

gpasswd -a <USERNAME> <GROUPNAME>

You must use usermod command as follows:

usermod -aG <GROUPNAME> <USERNAME>
続きを読む

Docker: How to Change Image Name

Use a 'tag' command on docker.

docker tag <image_id> <repository_name>:<tag>

Note: You can omit the part '<tag>' and only write '<repository_name>'. The meaning of the <tag> string after colon (:) of the repository name is that you can put a different version image by changing the date or versions.

docker tag <image_id> <repository_name>
続きを読む

How to Run Linux cron Job at the End of Every Month

Edit /etc/crontab

vi /etc/crontab

Every end of the month

H 23 28-31 * * /usr/bin/test $( date -d '+1 day' +%d ) -eq 1 && <COMMAND>

Every last Friday of the month

0 0 * * 5 /usr/bin/test $( date +%m ) -ne $( date --date '7 day' +%m ) && <COMMAND>

These will be useful in Jenkins.

/usr/bin/test $( date -d '+1 day' +%d ) -eq 1

or

/usr/bin/test $( date +%m ) -ne $( date --date '7 day' +%m )
続きを読む

Bash: How to Show Escape Sequence Colors

Create the following script and run:

vi color.sh
chmod +x color.sh
./color.sh

The bash script:

#!/bin/bash

export txtrst='\x1b[00m'      # Reset

echo
for i in {0..255} ; do
  printf "\x1b[00;${i}m ${i}${txtrst}"
done
echo

echo
for i in {0..255} ; do
  printf "\x1b[38;05;%03dm 38;05;%03d " ${i} ${i}
  if [ $(( ${i} % 8 )) -eq 7 ] ; then
    echo
  fi
done
echo

Once you figure out the escape sequence color number, you can use as follows:

続きを読む

Linux: How to Change the Timezone

To adjust timezone on your Linux to Pacific Standard Time (PST/PDT), type the following on command line.

sudo mv /etc/localtime /etc/localtime.org; sudo ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

To adjust timezone on your Linux to Japanese Standard Time (JST), type the following on command line.

sudo mv /etc/localtime /etc/localtime.org; sudo ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
続きを読む
Subscribe to Linux