forked from SalmaAlassal/BeRoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9405f78
commit 5bd0c7d
Showing
18 changed files
with
419 additions
and
69 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.) |
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
BIN
+19.7 KB
CLI & Linux File System/imgs/Continuing-a-long-command-on-another-line.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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
 | ||
To view the inodes of the files use `ls -li`. | ||
|
||
`-i` prints the index number of each file. | ||
|
||
 | ||
|
||
## 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. | ||
 | ||
|
||
# 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. | ||
|
||
 | ||
|
||
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. | ||
|
||
 | ||
|
||
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** | ||
 | ||
|
||
`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. | ||
|
||
 | ||
|
||
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. | ||
|
||
 | ||
|
||
***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:** | ||
|
||
 | ||
|
||
And since a link is a file after all, you can also delete it with ```rm```. | ||
|
||
**Example:** | ||
|
||
 | ||
|
||
|
||
### 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. | ||
|
||
 | ||
|
||
---------------------------------------------------------- |
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.
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.