顯示具有 command 標籤的文章。 顯示所有文章
顯示具有 command 標籤的文章。 顯示所有文章

2020年5月21日 星期四

[Linux & cli] Useful Linux command

Details
The following are some useful commands which usually made use and always being forgotten when needed, here is a note down.
  • Edit /etc/fstab to mount new drives (files system, mount point, type, options, dump, pass)
    • /dev/sdb1   /home/jacky/Documents/2tb-hdd   ext4   defaults  0   0
    • mount -av (run from root, show the mount point)
  • Run command and pipe all output to file
    • do_something 2>&1 | tee -a some_file (2>&1 is to direct all stderr to stdout)
  • Clear all text in a text file
    • > someTxtFile.txt
  • Kill process occupied by a known port (e.g. 32769)
    • sudo kill -9 $(sudo lsof -t -i:32769)
References

2020年3月22日 星期日

Useful bash command sytax (keep updating...)

Below are the useful syntax / tricks of bash commands that are easily forgot but handy. Keep them noted here

General Bash Command

1. Assignment of the value of variable word to parameter if and only if it is null
${parameter:=word}

2. Text processing using AWK example 1
echo $CODEBUILD_BUILD_ID | awk -F":" '{print $2}'

Output and pipe the string of variable CODEBUILD_BUILD_ID to awk as input, use ":" as separator and output the second element of the separated words

3. Cut out a range of characters for further processing
echo abcde | cut -c 1-2

cut accepts standard input and file as the reading source, cut -c 1-2 "xxx"  is not allowed

4. Find row of string existence and replace the whole line
SOME_VER=v1.0 && sed -i "/LINE TO FIND/c\VER=$SOME_VER" ./dir/to/file

Variable "SOME_VER" is defined, and then search for the line contains words "ROW TO FIND" and substitute with VER=v1.0 (variable substituted)

Note: The double quote "", single quote cannot perform variable substitution, single quote does not interpolate anything

"c\SomeText" is to replace the selected line with SomeText

Docker command
1. Close all running containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

2. Show docker entrypoint command without truncate
docker ps --no-trunc --format '{{.Command}}'

2019年11月16日 星期六

[Docker] Console Log Problem

Background
Making a docker application through docker compose, the log terminal does not return any of the console logging returned from my node server


Cause & Solution
Turn out the problem comes from my mistakes on making a "command substitution" in entrypoint of the dockerFile. Here is my entrypoint command

ENTRYPOINT /bin/bash -c "npm install && if [ $NODE_ENV == '"development"' ]; then \
$(nodemon --ignore node_modules/ mongoEngine.js); else $(node mongoEngine.js); fi"

Outputting in command substitution mode will not be captured. Remove the $(...) quoting solves the problem

References



2015年1月6日 星期二

[CMD] List of Common Commands Used in APs

This post will mark down all the necessary or common commands which often use and always forget.

  1. wifi detect > wireless
    • Generate the default config

This post will keep up-to-date.