Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Unix operating system
1. UNIX OPERATING SYSTEM
Unix operating systems are widely used in servers, workstations, and mobile devices. The
Unix environment and the client–server program model were essential elements in the
development of the Internet and the reshaping of computing as centered in networks rather than
in individual computers.
Unix systems are characterized by various concepts: the use of plain text for storing data;
a hierarchical file system; treating devices and certain types of inter-process
communication (IPC) as files; and the use of a large number of software tools, small programs
that can be strung together through a command line interpreter using pipes, as opposed to using a
single monolithic program that includes all of the same functionality. These concepts are
collectively known as the Unix philosophy.
The microkernel concept was introduced in an effort to reverse the trend towards larger
kernels and return to a system in which most tasks were completed by smaller utilities. In an era
when a "normal" computer consisted of a hard disk for storage and a data terminal for input and
output (I/O), the Unix file model worked quite well as most I/O was "linear". However, modern
systems include networking and other new devices. As graphical user interfaces developed, the
file model proved inadequate to the task of handling asynchronous events such as those
generated by a mouse, and in the 1980s non-blocking I/O and the set of inter-process
communication mechanisms was augmented (sockets, shared memory, queues, semaphores), and
functionalities such as network protocols were moved out of the kernel.
A Unix kernel — the core or key components of the operating system — consists of
many kernel subsystems like process management, memory management, file management,
device management and network management.
Each of the subsystems has some features:
Concurrency: As Unix is a multiprocessing OS, many processes run concurrently to
improve the performance of the system.
Virtual memory (VM): Memory management subsystem implements the virtual memory
concept and a user need not worry about the executable program size and the RAM size.
Paging: It is a technique to minimize the internal as well as the external fragmentation in
the physical memory.
Virtual file system (VFS): A VFS is a file system used to help the user to hide the
different file systems complexities. A user can use the same standard file system related
calls to access different file systems.
The kernel provides these and other basic services: interrupt and trap handling, separation
between user and system space, system calls, scheduling, timer and clock handling, file
descriptor management.
2. Unix Architecture:
Here is a basic block diagram of a UNIX system:
The main concept that unites all versions of UNIX is the following four basics:
Kernel: The kernel is the heart of the operating system. It interacts with hardware and
most of the tasks like memory management, tash scheduling and file management.
Shell: The shell is the utility that processes your requests. When you type in a command
at your terminal, the shell interprets the command and calls the program that you want.
The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell
are most famous shells which are available with most of the Unix variants.
Commands and Utilities: There are various command and utilities which you would use
in your day to day activities. cp, mv, cat and grep etc. are few examples of commands
and utilities. There are over 250 standard commands plus numerous others provided
through 3rd party software. All the commands come along with various optional options.
Files and Directories: All data in UNIX is organized into files. All files are organized into
directories. These directories are organized into a tree-like structure called the filesystem.
3. System Bootup:
If you have a computer which has UNIX operating system installed on it, then you simply need
to turn on its power to make it live.
As soon as you turn on the power, system starts booting up and finally it prompts you to log into
the system, which is an activity to log into the system and use it for your day to day activities.
Login Unix:
When you first connect to a UNIX system, you usually see a prompt such as the following:
To log in:
1. Have your userid (user identification) and password ready. Contact your system
administrator if you don't have these yet.
2. Type your userid at the login prompt, then press ENTER. Your userid is case-sensitive,
so be sure you type it exactly as your system administrator instructed.
3. Type your password at the password prompt, then press ENTER. Your password is also
case-sensitive.
4. If you provided correct userid and password then you would be allowed to enter into the
system. Read the information and messages that come up on the screen something as
below.
SHELL SCRIPT
A shell script is a script written for the shell, or command line interpreter, of an operating
system. It is often considered a simple domain-specific programming language. Typical
operations performed by shell scripts include file manipulation, program execution, and printing
text
Programming
Many modern shells also supply various features usually found only in more sophisticated
general-purpose programming languages, such as control-flow constructs, variables, comments,
arrays, subroutines, and so on. With these sorts of features available, it is possible to write
reasonably sophisticated applications as shell scripts. However, they are still limited by the fact
that most shell languages have little or no support for data typing systems, classes, threading,
complex math, and other common full language features, and are also generally much slower
than compiled code or interpreted languages written with speed as a performance goal.
4. Advantages and disadvantages
Often, writing a shell script is much quicker than writing the equivalent code in other
programming languages. The many advantages include easy program or file selection, quick
start, and interactive debugging. A shell script can be used to provide a sequencing and decision-
making linkage around existing programs, and for moderately-sized scripts the absence of a
compilation step is an advantage. Interpretive running makes it easy to write debugging code into
a script and re-run it to detect and fix bugs. Non-expert users can use scripting to tailor the
behavior of programs, and shell scripting provides some limited scope for multiprocessing.
Command line arguments to scripts
When you start a script from your interactive login shell, you can provide arguments to that
script on the command line. These are automatically turned into variables that can be used inside
the script.
If the command line contains filename wildcard characters, variable substitution references, or
command substitution references, those are expanded or substituted first. Then the command line
string is broken into separate arguments at blanks, except that a quoted string can contain
embedded blanks.
You refer to these arguments as separate variables within the script itself by using the dollar sign
(variable substitution operator) followed by an integer number, for example,
cp $1 $2
This statement inside a shell script would run the cp program with the first "argument" to the
shell script (first word on the command line that started the shell script) passed as the name of
the file to copy via $1, and the second argument to the shell script passed as the name of the new
copy via $2.
The entire list of command line arguments can be referenced as one string with the syntax
$*
Making and setting your own variables in a script
In addition to the command line arguments, the shell maintains a table of other user-created or
special purpose variables in memory. Each variable has a name and a value.
Names - up to 20 letters or digits (start with letter) - case matters!
Values are strings of characters or digits of arbitrary length without any intrinsic "type".
They are treated as character strings or numeric values, depending upon how they are
used.
It is also possible to treat any variable as an array of words and access each word separately (see
detailed documentation on the C-shell).
5. Certain variable names are reserved by the shell for special uses, such as path or term.
You can create any number of variables.
Using variables in the script
"Variable substitution" is the process of replacing a reference to the name of a variable with its
actual value. This is how we use variables.
The dollar sign ($) is the basic substitution operator when it is used as the prefix for a variable
name. Anytime you use the dollar sign as the first letter of a word in a shell command, it will
expect the word to be the name of a variable. If you want the dollar sign to be interpreted as just
a simple dollar sign, precede it wth the backslash () "escape" character. Here are the basic
formats for variable substitution:
$?name
This tests whether the name variable exists. If the variable does exist, the shell substitutes the
value 1 (one, true); if not, the value 0 (zero, false). Use this form if you are just using the variable
as a flag. The result can be used in an if statement to conditionally execute some commands.
$name
This form causes the entire word list value of name to be substituted for the reference. If name is
not defined (was never set), you get an error.
$#name
This substitutes the number of words contained within the name variable. If the variable has a
null value (that is, simply set as a "flag" variable), it substitutes zero. If the variable has never
been set, you get an error.
$name[n]
This substitutes the "nth" word (blank separated value) from the name variable. The square
brackets are required to enclose the value n that specifies which word is wanted, and must follow
the variable name with no intervening spaces. This is a way to treat a variable containing a multi-
word value as an array of separate words. If you specify a word index value n that is greater than
the actual number of words in the variable, you get an error.
Examples:
set a = ($b)
Sets new variable a equal to the word list in existing variable b.
echo $b
Echoes (prints) the value of existing variable b to the standard output (terminal).
Flow-of-control statments
6. if and foreach are the basic flow-of-control statements. There are more advanced ones named
switch and while which are similar to the statements of the same name in the C language.
if
The if command allows you to conditionally execute a command or set of commands depending
upon whether some expression is true. There are two forms.
if ( logical_expression ) command ...
This form will execute command (which can have a long list of arguments) if the
logical__expression is true. This expression can be one of the logical or file testing
expressions described above. For example, you can test if a file whose name is stored in
the shell's built-in variable $1 (first argument to the shell script) exists as a plain file, and
if so, make a backup copy of it with:
if ( -f $1 ) cp $1 $1.bak
This simple cp command will not work if given a directory to copy, which is why there
is the test for a "plain" file.
if ( logical_expression ) then
block of commands - any number of lines
to be executed if logical_expression is "true"
(or has non-zero value).
else
another block of commands - any number of lines
to be executed if logical_expression is "false"
(or has value 0).
endif
This form allows you to execute more than one command if the expression is true. The
then keyword must follow the logical_expression test on the same line, and the endif
keyword must be on a line by itself to end the entire if command. The else statement is
optional. If you use this, the else keyword must be on a line by itself. The following
lines up to the endif are executed if the expression was false. The "blocks of
commands" may in turn contain additional nested if commands. Just be sure that each if
has a matching endif statement enclosed in the same block.
Relational operators
7. -eq: equal to
-ne: not equal to
-ge: greater than or equal to
-le: less than or equal to
-gt: greater than
-lt: less than
Logical operators
!: not
-a: and
-o: or