Basic Linux Tools ================== Information about System Programs ------------------------------------ * man * whereis * whatis * mandb * which .. code-block:: bash # program man man bash man python3 man hosts # /etc/hosts config file man man sshd # deamon man man -k syslog # search man pages with "syslog" apropos ssh # same as man -k whatis bash whatis node whereis python3 # locate the sources, bins and mans of a prog Working with Directories ------------------------- * pwd * cd * ls * mkdir * rmdir .. code-block:: bash # users home directory cd ~ # parent directory cd .. # return to previous directory, and alternate between two Directories cd - # cd can be used in a subshell, as part of a pipeline. echo $(cd /var/log && tail dmesg) # or echo $(cd /var/log; tail dmesg) # this is especially useful with the tar utility, which relies on current shell pwd ( cd /bits/stage/; tar -c docs -f docs.tar; mv docs.tar ~; cd - ) Working with files ------------------ * ``file``: Determine Filetype * ``touch``: update file timestamp * ``rm``: Remove file or directory * ``mv``: Move File or Directory * ``cp``: Copy file or Directory * ``rename``: rename many file with regex * ``cat``: concatenate files and print to stdout * ``tac``: reverse of cat - concatenate and print files in reverse * ``strings``: display string within binary files. * ``xxd``: make a hexdump or do the reverse * ``base64``: make a base64 dump or do the reverse * ``man hier``: distro's file system hierarchy .. code-block:: bash # the s flag is for special file types typically found under dev file /dev/* # touch is to update or set timestamp of a file touch ~/.bashrc # cat can be used to concatenate multiple files. Like how we do with SSL certs cat *.crt *.ca-bundle >> chain.crt # to display ASCII text embedded within binary files strings /bin/python3 string /bin/node .. code-block:: bash # human reasable hex dump with xxd echo "I love Bash, C, Python and Javascript" | xxd -ps # continueous hexdump echo "I love Bash, C, Python and Javascript" | xxd -ps # hex encode and decode pipeline with the -r reverse flag echo "I love Bash, C, Python and Javascript" | xxd -ps | xxd -r -ps # with cat and outiouput redirection mkdir /tmp/mk; cat /var/log/dmesg | xxd -ps > /tmp/mk/dmesg.hex tail /tmp/mk/dmesg.hex # encode to base64 and back echo "I love Bash, C, Python and Javascript" | base64 | base64 -d The Linux Filesystem and conf ----------------------------- /etc/init.d/ Startup and Management scripts for system daemons and services. ``less /etc/init.d/postgresql`` /dev/ The /dev in-memory directory is populated with files as the kernel is recognising hardware. ``file -s /dev/*`` /proc/ It is actually a view of the kernel, or better, what the kernel manages, and is a means to interact with it directly ``cat /proc/cpuinfo`` /etc/sysctl.conf Runtime Kernel parameters. see also the ``sysctl`` command Linux Processes ---------------- * ``ps`` snapshop of the current processes * ``top`` and ``htop`` display linux process * ``jobs`` * ``time`` command to display real, sys and user time .. code-block:: bash time ls -lh | sort -k5n | less time sudo ufw status