Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
SalmaAlassal committed Nov 25, 2022
1 parent 9405f78 commit 5bd0c7d
Show file tree
Hide file tree
Showing 18 changed files with 419 additions and 69 deletions.
183 changes: 147 additions & 36 deletions CLI & Linux File System/README.md

Large diffs are not rendered by default.

126 changes: 126 additions & 0 deletions CLI & Linux File System/Terminal-Types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Terminal Types

Terminal equipment can be divided into the following types:

- Virtual Terminal
- Pseudo Terminal
- Serial Port Terminal

# Virtual Console

> A virtual console (VC) – also known as a virtual terminal (VT)
**In the 1970s and 1980s,** people can often use only one terminal. Heavyweight people in a company or university can use multiple terminals, because they need to do many things with the operating system. So there would be several terminals on their desks.

**Nowadays,** we don’t need to put multiple terminals on the desk, because Linux can create **multiple virtual terminals**. One of them is **graphics terminal**, the other six is **character terminal**. The 7 virtual terminals are more commonly known as **virtual consoles**, and they use the same keyboard and monitor.

When Linux boots up, it creates the 6 (maybe differ) virtual consoles and by default brings you to the graphics console, i.e, the desktop environment. Each virtual console supports an **independent login session**.

The file name is `/dev/ttyn` (e.g, `dev/tty1`, `dev/tty2`).

> Many system administrators choose not to run a graphical environment on their servers. This allows resources which would be used by the graphical environment to be used by the server's services instead.
> Virtual Terminals are similar to Terminal. The only difference is that you cannot use the mouse with the Virtual Terminals.
> The graphical environment also runs on a virtual console.
## Navigating through Virtual Terminals

You can navigate between the 6 virtual terminals using the following command:

```bash
Ctrl + Alt + F (1 to 6) key # or more, if you have configured more
```

### Example

```
CTRL + ALT + F1 – Lockscreen
CTRL + ALT + F2 – Desktop Environment
CTRL + ALT + F3 – TTY3
CTRL + ALT + F4 – TTY4
CTRL + ALT + F5 – TT5
CTRL + ALT + F6 – TTY6
```

You can work on all of at the same time.

> By default, in Fedora 36 the desktop runs on TTY2. In case of Ubuntu, it defaults to TTY7.
> A desktop needs a tty to run but that does not make the GUI a tty. You should call it a session and a tty you use to login either to command line session or a desktop session.
> If you are already logged in to a graphical session, and log in as another user on the graphical login screen or use the Switch User menu item to switch users in the graphical environment without logging out, another graphical environment will be started for that user on the next free virtual console.
### Logging out

When you are finished using the shell and want to quit, you can choose one of several ways to end the session. You can enter the `exit` command to terminate the current shell session. Alternatively, finish a session by pressing `Ctrl+D`.

## Check TTY Number

- To know the TTY number you are connected to, just type in `tty`. And, if there are multiple users connected to the Linux machine remotely, you can use the `who` command to check what other users are connected to.

> `/dev/pts` shows you are in virtual terminal.
> `/dev/tty` shows you are in actual terminal.
- You can also run the `sudo fgconsole` command to check which tty you are using.



----------------------------------------------------------------

# Usages

### Single User

It should come in handy in case the graphical desktop environment **freezes**. In some cases, reinstalling the desktop environment from the TTY helps resolve the program.

Or, you can also choose to carry out **tasks** in TTY like updating the Linux system and similar, where you do not want visual issues to interrupt your process.

Worst-case scenario, you can go to the TTY and **reboot** the computer if your graphical user interface is unresponsive.

### Multi-user System

Remember that Linux was originally a command-line only system and designed for multiple users. So what if different users need to work on the same system at a time? How do you do that? This is where we need the **virtual terminals**.

The idea was that each user could log into a single **tty**. This would not happen on the same physical machine of course, think of servers that many computer terminals would connect to. Each user would connect using a different computer and the server log them in to a **tty**.

Virtual Terminals enable a number of users to work on different programs at the same time on the same computer.

Usually, there are six (default) virtual terminals on a Linux operating system, and you can log into them as different users to conducts different tasks.

## Number of virtual consoles

Different Linux flavors offer different number of virtual consoles. For instance, **RHEL** provides **six** virtual consoles while **Ubuntu** provides **seven** virtual consoles.

Virtual consoles are always mentioned along with **one physical console** (also known as default console). So, the actual number of virtual consoles remains one less than the total number of consoles. For example, in RHEL and Ubuntu the number of actual virtual consoles are 5 (six - one) and 6 (seven - one) respectively.

----------------------------------------------------------------------------------

# Pseudo Terminal (PTY)

Running the **terminal application** provides you with a **virtual environment** called a **pseudo terminal** which is running a shell that allows you to issue commands at its prompt.

So a **pty** is virtual terminal device which is emulated by another program (e.g, xterm, screen, telnet, ssh …etc.).

The file name of the pseudo terminal is `/dev/pts/n`

> A **pts** is the slave part of a **pty**.
> A **pts device** is actually a **pseudo tty device**. Whenever you launch a terminal emulator or use any kind of shell in your system, it interacts with virtual TTYs that are known as **pseudo-TTYs** or **PTY**.
----------------------------------------------------------------------------------

# Serial Port Terminal

The computer considers each **serial port** to be a **"device"**. It's sometimes called a **terminal device**.

For each such serial port there is a special file in the `/dev` (device) directory. The file name of the serial port terminal `/dev/ttySn`(the "S" stands for Serial port), for example `/dev/ttyS0` is the special file for the serial port known as `COM1` in the DOS/Windows world.

----------------------------------------------------------------------------------

# Extras

- [Linux Virtual Console and Terminal Explained](https://www.computernetworkingnotes.com/linux-tutorials/linux-virtual-console-and-terminal-explained.html)

- [Linux Terminal and Console Explained](https://www.linuxbabe.com/command-line/linux-terminal#:~:text=Physical%20console%20is%20the%20combination,virtual%20console%20you%20are%20using.)
Binary file added CLI & Linux File System/imgs/Command-history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 25 additions & 16 deletions Introduction to Linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,39 +142,48 @@ If, however, you’ve pretty much mastered the craft of computer and system admi

------------------------------------------------------------------

## Why Linux?
# What makes Linux great and why to use it?

There are many reasons to use Linux, we will name a few, but there are always more reasons.

1. **Privacy and Security**
**- Linux is open source software.**
- Being open source does not just mean that you can see how the system works. You can also experiment with changes and share them freely for others to use. The open source model means that improvements are easier to make, enabling faster innovation.

The operating system respects the privacy of users to a unique extent, once the system starts running everything that happens is under your control unless a third party services is used.
**- Privacy and Security**

That is mainly due to it being open source, so developers can’t hide spyware or force anything on the user, as they will be able to somehow avoid or change it.
- The operating system respects the privacy of users to a unique extent, once the system starts running everything that happens is under your control unless a third party services is used.

2. **Required in Companies**
- That is mainly due to it being open source, so developers can’t hide spyware or force anything on the user, as they will be able to somehow avoid or change it.

It is required in many companies, including Microsoft, ITWorx, Mentor, Valeo, and a lot of other big popular companies.
**- Free**

3. **Good Development Environment**
GNU/Linux is both free as in freedom and free of charge, it has a lot of great alternatives for proprietary software that people use daily. Further, it provides various advantages over other operating systems, and we don't have to pay for it.

Linux is suitable for the developers, as it supports almost all of the most used programming languages such as C/C++, Java, Python, Ruby, and more. Further, it facilitates with a vast range of useful applications for development.
**- Decentralized Development**

Developers find that the Linux terminal is much better than the Windows command line, So, they prefer terminal over the Windows command line. The package manager on Linux system helps programmers to understand how things are done. Bash scripting is also a functional feature for the programmers. Also, the SSH support helps to manage the servers quickly.
- GNU/Linux isn’t owned by a single company, its development is community driven. People contribute to the Linux kernel and other assets of the GNU operating system.

4. **Free**
**- Linux provides easy access to a powerful and scriptable command-line interface (CLI).**

GNU/Linux is both free as in freedom and free of charge, it has a lot of great alternatives for proprietary software that people use daily. Further, it provides various advantages over other operating systems, and we don't have to pay for it.
- Linux was built around the basic design philosophy that users can perform all administration tasks from the CLI. It enables easier automation, deployment, and provisioning, and simplifies both local and remote system administration. Unlike other operating systems, these capabilities have been built in from the beginning, and the assumption has always been to enable these important capabilities.

**- Required in Companies**

- It is required in many companies, including Microsoft, ITWorx, Mentor, Valeo, and a lot of other big popular companies.

**- Good Development Environment**

- Linux is suitable for the developers, as it supports almost all of the most used programming languages such as C/C++, Java, Python, Ruby, and more. Further, it facilitates with a vast range of useful applications for development.

5. **Decentralized Development**
- Developers find that the Linux terminal is much better than the Windows command line, So, they prefer terminal over the Windows command line. The package manager on Linux system helps programmers to understand how things are done. Bash scripting is also a functional feature for the programmers. Also, the SSH support helps to manage the servers quickly.

GNU/Linux isn’t owned by a single company, its development is community driven. People contribute to the Linux kernel and other assets of the GNU operating system.
- Components of the system can be upgraded and updated as needed. A Linux system can be a general-purpose development workstation or an extremely stripped-down software appliance.

6. **Customisability**
**- Customisability**

The operating system is very modular and customisable, which allows you to create your own customized system according to your needs.
- Linux is a modular operating system that allows you to easily replace or remove components, which allows you to create your own customized system according to your needs.

7. **Much more!**
**- Much more!**

-------------------------------------------------------------------------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion Linux Desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ The display manager is a bit of code that provides the GUI login screen for your

### Installation

We will explain these commands later.

#### Step 1

- Update all the packages to their newest available versions.
Expand Down Expand Up @@ -99,6 +101,7 @@ Running Linux, changing or adding a different desktop environment is as easy as
### Most Popular Linux Desktop Environments

- GNOME
- GNOME Help command :`yelp`
- Xfce
- KDE
- LXDE
Expand Down Expand Up @@ -170,4 +173,3 @@ It's allowing the windows to be opened, closed, re-sized, and moved. It is also
# Resources

- https://en.wikipedia.org/wiki/Windowing_system
- https://github.com/SalmaAlassal/mrNetwork
File renamed without changes.
134 changes: 118 additions & 16 deletions making-links/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,137 @@
## Inodes
# Managing Links Between Files

There is a **DataBase** that manage and store data about all the files on your system called **inode table**.
# Inode

**Inode**
Inode is the abbreviation for **“index node”**.

inode is an entry in this table and describe every thing about the file like : file type , owner , group , access permissions , timestamps ... etc
but it doesn't store filename and the file itself .
An inode is a data structure that keeps track of all the files and directories within a Linux or UNIX-based filesystem. So, every file and directory in a filesystem is allocated an inode, which is identified by an integer known as “inode number”.

To view the inodes of the files use `ls -li`
These unique identifiers **store metadata** about each file and directory like : file type, owner, group, access permissions, timestamps ...etc., but it doesn't store filename and the file itself.

![](imgs/showing_inodes.png)
To view the inodes of the files use `ls -li`.

`-i` prints the index number of each file.

![showing_inodes](imgs/showing_inodes.png)

## Types of links

### Hard links
# Inode Table

`ln file_path link_path`
There is a **Database** that contains all the Inodes which is created when file system is created.

-----------------------------------------------------------------------------------------

# What are Links?

A link in Linux is a file that points to another file/directory. Creating links is similar to creating shortcuts. A file can have multiple links linked to it. But a link can only be linked to (pointed to) one file.

There are two types of links:
1. Soft or Symbolic links.
2. Hard links.

_These links behave differently when the source of the link (what is being linked to) is moved or removed._

> You can think of links like pointers in programming languages, if you’re familiar with them.
![meme](imgs/meme1.jpeg)

# Creating Hard Links

Every file starts with a single hard link, from its initial name to the data on the file system. When you create a new hard link to a file, you create another name that points to that same data. The new hard link acts exactly like the original file name.

A hard link is similar to creating a copy that is always synced with the original file.

If the original file is deleted or moved, the hard link will still work.

> _A hard link can’t link to a directory._
You can find out if a file has multiple hard links with the `ls -l` command. One of the things it reports is each file's link count, the number of hard links the file has.


### Example

Make a hard link using the ``ln`` command.

![](imgs/hard-link.png)

In this example you can see that H_Link is treated as a normal file, it is just linked to File.txt. After editing File.txt, H_Link was edited too.

It is exactly like a synced copy of the file.

![](imgs/hard_link.png)

If the files are on the same file system and their inode numbers are the same, the files are hard links pointing to the same data.

All hard links that reference the same file will have the same link count, access permissions, user and group ownerships, time stamps, and file content. If any of that information is changed using one hard link, all other hard links pointing to the same file will show the new information as well. This is because each hard link points to the same data on the storage device.


### Limitations of Hard Links

Hard links have some limitations:

- **Firstly**, hard links can only be used with regular files. You cannot use `ln` to create a hard link to a directory or special file.

- **Secondly,** hard links can only be used if both files are on the same file system. The file-system hierarchy can be made up of multiple storage devices. Depending on the configuration of your system, when you change into a new directory, that directory and its contents may be stored on a different file system.


### Symbolic links or Soft links
You can use the `df` command to list the directories that are on different file systems. For example, you might see output like the following:

It's the equvilant of shortcuts in **windows**
![Limitations of Hard Links](imgs/Limitations-of-Hard%20Links.png)

`ln -s file_path link_path`
Files in two different "Mounted on" directories and their subdirectories are on different file systems. (The most specific match wins.) So, the system in this example, you can create a hard link between `/var/tmp/link1` and `/home/user/file` because they are both subdirectories of `/` but not any other directory on the list. But you cannot create a hard link between `/boot/test/badlink` and `/home/user/file` because the first file is in a subdirectory of` /boot` (on the "Mounted on" list) and the second file is not.

----------------------------------------------------------

# Creating Soft (Symbolic) Links

A soft link is similar to the file **shortcut** feature which is used in Windows operating systems.

_Soft links contain the path for original file but not the content._

The `ln -s` command creates a soft link, which is also called a **"symbolic link."** A soft link is not a regular file, but a special type of file that points to an existing file or directory.

Soft links have some advantages over hard links:
- They can link two files on different file systems, although if the original file is deleted or moved, the soft link will not work correctly and is referred to as a **“hanging link”**.
- They can point to a directory or special file, not just a regular file.


### Example:

`ln -s [file path] [link path]`

The option ``-s`` makes the link a soft link and not a hard one.

![](imgs/soft-link.png)

You can see that indeed, S_Link is pointing to File.txt

In the preceding example, the first character of the long listing for s_Link is `l` instead of `-`. This indicates that the file is a soft link and not a regular file.

![](imgs/soft_link.png)

***Note:***
- you should specify the absolute path to the file that you want to make a ***soft link*** to it
- Note that in **soft links** the inode value **changed** but in **hard links** the inodes are the **same** .
> Note that in **soft links** the inode value **changed** but in **hard links** the inodes are the **same**.
----------------------------------------------------------

# Deleting Links

To delete a link you can use ``unlink`` or ``rm``

**Example:**

![](imgs/unlink.png)

And since a link is a file after all, you can also delete it with ```rm```.

**Example:**

![](imgs/remove%20link.png)


### Dangling Soft Link

One side-effect of the dangling soft link is that if you later create a new file with the same name as the deleted file (/home/user/newfile-link2.txt), the soft link will no longer be "dangling" and will point to the new file.

![](imgs/dangling-soft-link.png)

----------------------------------------------------------
Binary file added making-links/imgs/Limitations-of-Hard Links.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added making-links/imgs/dangling-soft-link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added making-links/imgs/hard-link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added making-links/imgs/meme1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added making-links/imgs/remove link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified making-links/imgs/showing_inodes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added making-links/imgs/soft-link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added making-links/imgs/unlink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5bd0c7d

Please sign in to comment.