================== Linux and Linux API ================== Linux ===== Linux is one of the most popular operating systems for servers and cloud-based infrastructures. It gives access to a robust CLI (Command Line Interface), a scripting environment, essential tools and utilities, strong security features, and powerful diagnostic tools for troubleshooting. In order to master the art of delivering high-quality software and infrastructure, it is required for a DevOps Engineer to master Linux. The REPL: Read iput, Evaluate command, Print input, Loop back to read input. Opening Terminal (macOS): .. code-block:: python :caption: ``pwd - print working directory`` $ pwd /Users/TeslaPython .. code-block:: python :caption: ``ls - list`` $ ls Applications Desktop Documents Downloads library Movies Music Music Pictures Public .. code-block:: python :caption: ``list -l(long) and -h(human-readable)`` $ ls -l -h total 8 drwx------@ 5 TeslaPython staff 160 Mar 25 10:26 Applications drwx------+ 19 TeslaPython staff 608 Mar 18 21:20 Desktop drwx------+ 6 TeslaPython staff 192 Feb 1 22:22 Documents drwx------@ 50 TeslaPython staff 1600 Apr 4 11:35 Downloads drwx------@ 88 TeslaPython staff 2816 Mar 16 19:28 Library drwx------ 3 TeslaPython staff 96 Dec 30 10:02 Movies drwx------+ 4 TeslaPython staff 128 Dec 30 11:08 Music drwx------+ 5 TeslaPython staff 160 Jan 25 18:39 Pictures drwxr-xr-x+ 4 TeslaPython staff 128 Dec 30 10:02 Public Now, we explain this: .. image:: _images/linux_explained.png :alt: Linux Image :align: center .. code-block:: python :caption: ``cd - change directory`` $ pwd /Users/TeslaPython $ cd projects $ pwd /Users/TeslaPython/projects .. code-block:: python :caption: ``find - find files`` $ find / TeslaPython It means the above will search "/" the whole system with the name "TeslaPython". Keep in mind that when you are not executing this as the all powerful root (administrator) user, "find" will not have permissions to list the contents of many directories, so you will receive output like find: '/root': Permission denied .. code-block:: python :caption: ``fing - find files`` $ find / -type d -name TeslaPython The above will search "/" the whole system for a directory "-type d" with the name "TeslaPython" .. code-block:: python :caption: ``less - Reading files`` $ less teslapython.txt alabaster==1.0.0 asgiref==3.8.1 babel==2.17.0 cachetools==5.5.2 certifi==2025.1.31 For example, the above will read "teslapython.txt" file, to quit hit q. .. code-block:: python :caption: ``mkdir - make a directory`` $ mkdir TeslaPython $ ls TeslaPython .. code-block:: python :caption: ``rmdir - remove (empty) directories`` $ rmdir TeslaPython $ ls (nothing) .. code-block:: python :caption: ``rm - remove (not empty) files and directories`` $ rm filename .. code-block:: python :caption: ``rm -rf remove (not empty) files and directories`` $ rm -rf filename The above will let you delete directories that are critical to the operation of your system. You'd like to delete the root directory, which contains everything on the system. -rf means recursively force. Move or rename files and directories. First, we'll create a file using touch: .. code-block:: python :caption: ``mv - move or rename files and directories`` $ touch teslapython.txt $ ls teslapython.txt Then, we'll rename the file in place, this command would overwrite any existing file name teslapython.txt: .. code-block:: python :caption: ``mv - move or rename files and directories`` $ touch teslapython.txt docsteslapython.txt $ ls docsteslapythonlab.txt To move the file to a new directory, we'll create a new directory and then move the file there: .. code-block:: python :caption: ``mv - move or rename files and directories`` $ mkdir teslapythondir $ mv docsteslapython.txt teslapythondir/ $ ls teslapythondir/ docsteslapython.txt Remember you can always skim the relevant information using specific flags, "man" (man means manual) will print something like this: .. code-block:: python :caption: ``man - getting help`` $ man find NAME find – walk a file hierarchy SYNOPSIS find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression] DESCRIPTION The find utility recursively descends the directory tree for each path listed, evaluating an expression (composed of the “primaries” and “operands” listed below) in terms of each file in the tree. The options are as follows: -E Interpret regular expressions following the -regex and -iregex primaries as extended (modern) regular expressions rather than basic regular expressions (BRE's). The re_format(7) manual page fully describes both formats. Or using "apropos" .. code-block:: python :caption: ``apropos - display online manual documentation pages`` $ apropos find git-bisect(1) - Use binary search to find the commit that introduced a bug git-cherry(1) - Find commits yet to be applied to upstream git-merge-base(1) - Find as good common ancestors as possible for a merge git-name-rev(1) - Find symbolic names for given revs git-pack-redundant(1) - Find redundant pack files strings(1) - find the printable strings in a object, or other binary, file BIO_find_type(3ssl), BIO_next(3ssl), BIO_method_type(3ssl) - BIO chain traversal Or using "whatis" .. code-block:: python :caption: ``whatis - display online manual documentation pages`` $ whatis find git-bisect(1) - Use binary search to find the commit that introduced a bug git-cherry(1) - Find commits yet to be applied to upstream git-merge-base(1) - Find as good common ancestors as possible for a merge git-name-rev(1) - Find symbolic names for given revs git-pack-redundant(1) - Find redundant pack files strings(1) - find the printable strings in a object, or other binary, file SPI_cursor_find(3) - find an existing cursor by name XkbFindOverlayForKey(3) - Find the alternate name by using the primary name for a key that is part of an overlay XkbLookupKeyBinding(3) - Find the string bound to a key by XRebindKeySym XkbLookupKeySym(3) - Find the symbol associated with a key for a particular state XkbTranslateKeySym(3) - Find the string and symbol associated with a keysym for a given keyboard state Connecting to Remote Servers via SSH SSH stands for Secure Shell. It is a cryptographic network protocol that allows secure communication between two systems. The default port for SSH is 22 .. code-block:: python :caption: ``ssh`` $ ssh -p 443 teslapython@216.24.57.252 Linux API ========= Why Linux API? - Development - Malware analysis - Vulnerability analysis and exploitation - Reversing - Diagnostics - Debugging - Monitoring - Memory forensics - Crash and hang analysis - Secure coding - Static code analysis - Trace and log analysis What Linux API? - Source code prespective - ABI (Application Binary Interface) perspective: Libraries and Syscalls `Downloading WinDbg`_ or `Debugging Tools for Windows`_ .. _Downloading WinDbg: https://learn.microsoft.com/en-gb/windows-hardware/drivers/debugger/ .. _Debugging Tools for Windows: https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools