Check your session type – wayland or X11

With both wayland and X11 in mainstream, its pretty easy to forget if you are running in Wayland or in X11. To check this here are the commands:

loginctl list-sessions
# The above command will show you all the sessions. Note the session number for your session

loginctl show-session <session number> -p Type

copy /proc folder

Other day, I was trying to copy the proc folder with following command:

tar cvzf /tmp/proc.tgz /proc

and I found out that all the files in tar were empty. Strange it may seem but lot of people are facing this as /proc is not a regular filesystem, so I wrote a quick script to copy the proc folder. Here is the script:

cd /
mkdir /tmp/proc
[[ -z $1 ]] && exit -1
find /proc/$1/ -not -name pagemap | while read F ; do
    D=/tmp/$F
    if [[ -d $F ]]
    then
        echo "$(ls -ld $F) => Directory"
        mkdir -p $D
    fi
    if [[ -L $F ]]
    then
        echo "$(ls -ld $F) => copied"
        cp -P $F /tmp/$F
        
    elif [[ -f $F ]]
    then
        echo "$(ls -ld $F) => Cat"
        cat $F > /tmp/$F
    else
        echo "Dont know $F"
    fi
done

cool sed/grep magic to convert output to csv format

I generallly keep doing this a lot, so thought will share with you. Lets assume we are capturing free ouput every min/hour/or whatever. The output looks like this:

Time: Mon Jan 21 23:59:10 AEDT 2019
——————-

total        used        free      shared  buff/cache   available
Mem:          32014        8656        1735        1697       21621       21308
Swap: 51195 75 51120

then we can use some grep and sed to convert this to something like this:

Mon Jan 21 23:59:10 AEDT 2019,32014,8656,1735,1697,21621,21308

This is the code that I used for this:

zgrep -E '^(Time|Mem):' free.20190121.gz |sed -E '/Mem/ s/\s+/,/g'|sed -E 's/^(Time|Mem):\s*//' |sed   ':a;$!N;s/\n//;P'
Explanation:

use zgrep to get the line starting with time or mem
use sed to convert multiple spaces to single space
use sed again to get only the line containing Memory or time
use sed the last time to merge the 2 lines