Linux Snippets

Coding Helpers

Create a Line Seperator


# function
CL () { WORDS=$@; termwidth="$(tput cols)"; padding="$(printf '%0.1s' ={1..500})"; printf '%*.*s %s %*.*s\n' 0 "$(((termwidth-2-${#WORDS})/2))" "$padding" "$WORDS" 0 "$(((termwidth-1-${#WORDS})/2))" "$padding"; }
# usage
CL test

Source: https://www.commandlinefu.com/commands/view/24626/line-separator-that-is-width-of-terminal

OS Basics

Terminal

Find open terminals and kill them

# Show open terminals
$ w
 10:23:27 up 44 days, 21:16,  5 users,  load average: 0.54, 1.05, 1.37
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    SomeLocation     06:28    1:21m  0.17s  0.03s -bash
root     pts/4    SomeLocation     08:25    1:36m  0.06s  0.04s -bash
root     pts/12   SomeLocation     10:21    0.00s  0.05s  0.00s w

# Find Process belonging to a terminal
$ ps -ft pts/0
UID        PID  PPID  C STIME TTY          TIME CMD
root      3684  3623  0 08:25 pts/10   00:00:00 -bash
root      3697  3684  0 08:25 pts/10   00:00:00 su - service
service   3698  3697  0 08:25 pts/10   00:00:00 -su
service   3750  3698  0 08:25 pts/10   00:00:00 vim some_file.sh

# Kill Parent Process
kill -9 3684

Retrieved from "$'"1"