bash - konradmayer/knowledge-base GitHub Wiki

ssh

How to keep processes running after ending ssh session?

From https://askubuntu.com/a/222855

Option 1 - If know ahead:

nohup long-running-command &

logs stdout to nohup.log

To redirect output to a specific file use:

nohup long-running-command > logfile.out 2>&1 &

Option 2 - To detach an already running process:

ctrl+z
bg
disown -h

If you want to "background" already running tasks, then Ctrl+Z then run bg to put your most recent suspended task to background, allowing it to continue running. disown will keep the process running after you log out. The -h flag prevents hangup.

archives: tar, zip etc

peek into tar without extraction

https://askubuntu.com/a/392887

tar -tf filename.tar.gz

pipe to tree to see a tree view

displays

mirror screens from commandline

https://askubuntu.com/a/462084

query displays

xrandr --query

mirror (replace eDP-1 and DP-2 with the actual displays)

xrandr --output eDP-1 --same-as DP-2

sysadmin

List mountpoints

with type in human readable

df  -aTh

find big files

ncdu

clean up /tmp

https://www.redhat.com/sysadmin/manage-linux-tmp-directory

find files in /tmp of a user with age

find /tmp -type f \( ! -user kmayer \) -atime +2

add -delete to delete them

find /tmp -type f \( ! -user kmayer \) -atime +2 -delete

last user login

lastlog
lastlog -t 365 # user mit login innerhalb der letzten 365 Tage

check if process is running

ps -p <PID>

if just header is printed, the process is dead, otherwise PID, TTY, TIME, CMD is returned

remove files of size 0

https://stackoverflow.com/a/5475933

find . -size 0 -print -delete

convert softlinks to hardlinks

https://superuser.com/a/560610

go into dir and execute

find -type l -exec bash -c 'ln -f "$(readlink -m "$0")" "$0"' {} \;

graphics / documents

imagemagick

concatenate image

specify grid with argument tile (e.g. -tile 4x5)

montage -mode concatenate file1.jpg file2.jpg output.jpg

convenience

directory shortcuts

https://stackoverflow.com/a/39839346/10943838

added in .bashrc

shopt -s cdable_vars
export myFold=$HOME/Files/Scripts/Main

misc

env var from file

set env variables from key-value pairs within a file - from https://stackoverflow.com/a/20909045

# basic version
export $(cat .env | xargs)
# also ignore comments and handle values with spaces
export $(grep -v '^#' .env | xargs -d '\n')
⚠️ **GitHub.com Fallback** ⚠️