pstree command usage example

$pidof systemd
1461 1059
$pstree 1461
systemd─┬─(sd-pam)
        ├─at-spi-bus-laun─┬─dbus-daemon
        │                 └─3*[{at-spi-bus-laun}]
        ├─at-spi2-registr───2*[{at-spi2-registr}]
        ├─dbus-daemon
        ├─dconf-service───2*[{dconf-service}]
        ├─evolution-addre─┬─evolution-addre───5*[{evolution-addre}]
        │                 └─4*[{evolution-addre}]
        ├─evolution-calen─┬─evolution-calen───9*[{evolution-calen}]
        │                 └─4*[{evolution-calen}]
        ├─evolution-sourc───3*[{evolution-sourc}]
        ├─gnome-shell-cal───5*[{gnome-shell-cal}]
        ├─gnome-terminal-─┬─bash───pstree
        │                 └─3*[{gnome-terminal-}]
        ├─goa-daemon───4*[{goa-daemon}]
        ├─goa-identity-se───3*[{goa-identity-se}]
        ├─gvfs-afc-volume───3*[{gvfs-afc-volume}]
        ├─gvfs-goa-volume───2*[{gvfs-goa-volume}]
        ├─gvfs-gphoto2-vo───2*[{gvfs-gphoto2-vo}]
        ├─gvfs-mtp-volume───2*[{gvfs-mtp-volume}]
        ├─gvfs-udisks2-vo───2*[{gvfs-udisks2-vo}]
        ├─gvfsd───2*[{gvfsd}]
        ├─gvfsd-fuse───5*[{gvfsd-fuse}]
        ├─gvfsd-metadata───2*[{gvfsd-metadata}]
        ├─mission-control───3*[{mission-control}]
        ├─pulseaudio───2*[{pulseaudio}]
        └─tracker-store───7*[{tracker-store}]
$pstree 1059
systemd─┬─(sd-pam)
        ├─at-spi-bus-laun─┬─dbus-daemon
        │                 └─3*[{at-spi-bus-laun}]
        ├─at-spi2-registr───2*[{at-spi2-registr}]
        ├─dbus-daemon
        └─pulseaudio───2*[{pulseaudio}]
$

$pstree `pidof systemd | awk '{print $2}'`
systemd─┬─(sd-pam)
        ├─at-spi-bus-laun─┬─dbus-daemon
        │                 └─3*[{at-spi-bus-laun}]
        ├─at-spi2-registr───2*[{at-spi2-registr}]
        ├─dbus-daemon
        └─pulseaudio───2*[{pulseaudio}]
$

Search for a pattern at the beginning of a line using grep

$ps -e "kworker$"
error: unknown sort specifier

Usage:
 ps [options]

 Try 'ps --help '
  or 'ps --help '
 for additional help text.

For more details see ps(1).
$ps -ef | grep "^daemon"
daemon     639     1  0 May04 ?        00:00:00 /usr/sbin/atd -f
$ps -ef | grep "^rtkit"
rtkit     1245     1  0 May04 ?        00:00:00 /usr/lib/rtkit/rtkit-daemon
$ps -ef | grep "^systemd+"
systemd+   522     1  0 May04 ?        00:00:00 /lib/systemd/systemd-timesyncd
$

tinkering with trap and exit commands

$echo $?
0
$echo $?
0
$exit 10 | tee solve.txt
$cat solve.txt 
$rm solve.txt 
$exit 10 | echo $?
0
$exit -1 | echo $?
0
$exit -1 | echo $?
0
$false | true
$echo $?
0
$false
$echo $?
1
$true
$echo $?
0
$exit 5 | tee var=$?
$file var\=0 
var=0: empty
$type var
bash: type: var: not found
$file var\=0 
var=0: empty
$

$trap $? > solve.txt exit 10
$cat solve.txt 
Display all 296 possibilities? (y or n)
$cat solve.txt 
$trap echo $? > solve.txt exit 10
$cat solve.txt 
$trap `echo $? > solve.txt` exit 10
$cat solve.txt 
0
$

$bash -c 'exit 7'; echo $?
7
$bash -c `exit 7`; echo $?
bash: -c: option requires an argument
2
$bash -c 'exit 7'; echo $?
7
$trap 'echo $? > solve.txt' exit 10
$cat solve.txt 
0
$cat solve.txt 
0
$bash -c 'exit 11'; echo $?
11
$


Indicate how each name would be interpreted if used as a command name

$type -a locate
locate is /usr/bin/locate
$type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls
$type -t ls
alias
$type -t locate
file
$type -t /dev/urandom
$type -t /dev/sda1
$type -t urandom
$type -t sda1
$type -t type
builtin
$type -t shuf
file
$type -t bash
file
$type -t proc
$type -t debugfs
$sudo type -t debugfs
[sudo] password for jeffrin: 
sudo: type: command not found
$sudo type -t debugfs
sudo: type: command not found
$