Posts

Showing posts from 2019

Linux: Using screen and screen under su

Linux: Using screen and screen under su    If you need to run something and let is run after you close the session, you can use screen. Install the screen package and just run screen. You can de-attach from the screen shell, using the "CTRL+A" keyboard shortcut.   To list the screen sessions, you can run "screen -ls" command: debian:~# screen -ls There are screens on:         14573.pts-1.debian       (03/27/2019 06:59:01 PM)        (Attached)         14546.pts-1.debian       (03/27/2019 06:58:55 PM)        (Detached) To re-attach to a screen session you can run "screen -r {session name}":  debian:~# screen -r 14573.pts-1.debian In order to attach to the same screen session from different shells, you need to use the "-xr" arguments, enabling multi-display mode.  debian:~# screen -xr 14573.pts-1.debian When you need to run it under su, you'll face the issue below:  debian:~# sudo su - silviu silviu@debian:~$ screen Cannot o

Linux: Working with sed

Working with sed (a stream editor)   At some point I had to modify the configuration of multiple nginx configuration files, replacing on all of them a specific string with another one, commenting some strings, deleting some other strings, on one of my CentOS machines.   If I would go to edit manually file by file, it would take a few hours, at least.   So, I choose to use sed and to edit all files at the same time and in order to explain, I creates 100 files containing the same string, I'm using "tee" command: johnyc20@centos:~$ echo "fastcgi_pass 127.0.0.1:9501;"  | tee site-name-{1..100}.conf   Now I have 100 files containg the "fastcgi_pass 127.0.0.1:9501;": johnyc20@centos:~$ cat site-name-* fastcgi_pass          127.0.0.1:9501;   Now I will explain: How to replace content How to comment lines How to insert lines  How to delete lines Short summary of sed options How to replace content The first thing, I am replacing t