Linux

Linux Tip#

Adding Storage#

  1. sudo fdisk -l or sudo lshw -C disk
  2. sudo fdisk /dev/sd<?>
  3. We want to add a new partition. Type “n” and press enter.
  4. 작성중

STD I/O#

#0 stdin -> PROCESS -> #1 stdout, #2 stderr

stdin: input information. Also, < define possible

stdout: normal output

stderr: error output

In python, print("message", file = sys.stderr) (default: stdout)

program 1> result.txt 2> error.txt

pipe run1 | run2 run2 receiving run1’s result.

awk#

awk ‘{print $0}’ infile

sed#

Usage: sed [OPTION]… {script-only-if-no-other-script} [input-file]…

-n, suppress automatic printing of pattern space

-e script, add the script to the commands to be executed

-f script-file, add the contents of script-file to the commands to be executed

-i[SUFFIX], edit files in place (makes backup if SUFFIX supplied)

-l N, specify the desired line-wrap length for the `l’ command

-E, -r, use extended regular expressions in the script

(for portability use POSIX -E).

-d, delete, i.e. 3d, 3rd row’s deleted.

sed -i -e 's/abc/\x0/g' /tmp/file.txt  # \x0?
sed -i '/abc/d; /XYZ/d' /tmp/file.txt  # /tmp/file.txt에서 abc와 XYZ를 찾아 삭제한다.

wc#

default printing $rows, $words, $characters

-l row

-w word

-c character

sort#

SVG to PNG#

ImageMagick has some issue. inkscape -w 1024 -h 1024 input.svg --export-filename output.png

ref - https://stackoverflow.com/a/14174624/10103236

Terminal Shortcut#

  1. Tab
  2. ^C: stop some progress
  3. ^Z: This shortcut will send a running program in the background.
  4. ^D: logout in ssh condition. exit in local condition.
  5. ^L: clear terminal screen
  6. ^A: This shortcut will move the cursor to the beginning of the line.
  7. ^E: This shortcut is sort of opposite to Ctrl+A.
  8. ^U: This shortcut erases everything from the current cursor position to the beginning of the line.
  9. ^K: it erases everything from the current cursor position to the end of the line.
  10. ^W: Using Ctrl+W shortcut, you can erase the word preceding to the cursor position.
  11. ^Y: This will paste the erased text that you saw with ^W, ^U and ^K shortcuts.
  12. ^P: You can use this shortcut to view the previous command.
  13. ^N: You can use this shortcut in conjugation with Ctrl+P. Ctrl+N displays the next command.
  14. ^R: search in command history

ssh#

ssh-keygen -p -f ~/.ssh/id_rsa passphrase를 변경할 수 있다.
ssh-copy-id <someonePC>~/.ssh/id_rsa.pub<someonePC>:~/.ssh/authorized_keys에 추가가 된다.

lsof#

login info#

uname#

-a: all information
-r: kernel release

#!/bin/bash

# Basic info
HOSTNAME=`uname -n`
ROOT1=`df -Ph | grep sdb1 | awk '{print $4}' | tr -d '\n'`
ROOT2=`df -Ph | grep sda1 | awk '{print $4}' | tr -d '\n'`
DATE=`date`

# System load
MEMORY1=`free -t -m | grep Total | awk '{print $3" MB";}'`
MEMORY2=`free -t -m | grep "Mem" | awk '{print $2" MB";}'`
LOAD1=`cat /proc/loadavg | awk {'print $1'}`
LOAD5=`cat /proc/loadavg | awk {'print $2'}`
LOAD15=`cat /proc/loadavg | awk {'print $3'}`


logo="
---
ABC
---
"
echo -e "\e[1;92m$logo\e[m"

echo -e "
\e[1;90m# info: ~ \e[0m"
echo "
=================================================
 - Hostname............: $HOSTNAME
 - Disk Space..........: $ROOT1 remaining (/home)
                         $ROOT2 remaining (/home2)
=================================================
 - CPU usage...........: $LOAD1, $LOAD5, $LOAD15 (1, 5, 15 min)
 - Memory used.........: $MEMORY1 / $MEMORY2
 - Swap in use.........: `free -m | tail -n 1 | awk '{print $3}'` MB
=================================================
              @ $DATE"

systemctl#

systemctl get-default

systemctl set-default [multi-user.target (runlevel 3)|graphical.target (runlevel 5)]

ldd#

ldd -v /path/to/program/executable

#

to show you the shared libraries required by any given program