Basic Commands in Linux & The Linux Filesystem (Oct 15, 2023)

 Topic D02 (Basic Commands in Linux)



Knowing the proper commands makes file management in Linux simple.

Since the program code created specifically for each command is performed every time you run one, commands are also referred to as "programs".
Linux Commands
Listing Files(ls)
- Shows the files/directories in the current dictionary

**
The blue color is used to indicate directories.
White is used to indicate files.
Similar color palettes are used in several Linux distributions.

*ls-R(case sensitive command)
shows all the files not only in directories but also in subdirectories. 

*ls-al
gives detailed information on the files.
provides information in a columnar format.
insert the table here 

*ls -a
gives access to the hidden files
hidden items begin with the '.' period symbol at the start.
any file/item starting with the '.' symbol cannot be seen unless it is requested. 


creating and viewing files

*cat 
used to display text files 
can be also used for copying, combining, and creating new text files.
- to create a new file; cat>file name
- to view the file; cat filename
- to combine two files; cat file1 file 2 > new filename
Deleting files(- rm)

*rm
removes files from the system without confirmation 

*mv 
move a file to a different directory
needs superuser/root user permission, so use sudo at the beginning of the command to avoid errors
Sudo; is a program that allows regular users to run programs with the security privileges of the superuser or root user.
Moving and re-naming files
The sudo command asks for password authentication 
Only after authentication will the system will the system invoke your requested command. 
mv can be also used for renaming files(mv filename new filename)
Directory Manipulations(mk dir)
Used to create directories on a Linux operating system 
can also create a subdirectory in the present working directory(home directory)
- to create a directory; mkdir directory name 
- to remove a directory; rmdir * make sure that there is no file/ sub-directory under the directory that you are planning to delete 
Renaming directories(mv directory name newdirectory name)
mv command is also used to rename directories 
search command
grep(global regular expression print)
used to search text files and print that matches a given pattern. 
patterns can be defined by the regular expression

Other important commands 
1. History 
2. Clear; used to clear all the clutter on the terminal and gives you a clean window to work on. 
3. Text editor(vi or vim)is a text editor that is terminal-based and can be used to create any type of file.

Topic E01(The Linux Filesystem)

A Linux operating system's built-in layer known as the file system is often utilized to manage the storage's data.
A tree-like structure may be seen in the Linux file system. The directory tree is another name for the tree-like structure.It controls a file's name, size, date of creation, and a lot more details.
A filesystem's primary function is to represent and arrange the system's storage resources.
It has a root directory that houses other directories and files.
pathnames/ root directory
A pathname is a text string made up of one or more names separated by forward slashes(/) e.g ./etc/ passwd,/var/log/auth.log, assignment 02 /check, etc. 
A pathname is a path of names that indicates how to find something in the hierarchical file system tree. 
Here are some examples of pathnames: 
/home /
etc/passwd 
usr / wc 
/var/ ntpstats loopstats
The filesystem is shown as a single, cohesive hierarchy that descends through any number of subdirectories after beginning at the directory.

Unix/Linux files are arranged in a single tree-hierarchical file system structure made up of directories (which may include additional sub-directories and files) and files that may contain data (such as documents and applications).
A good example of a relative and absolute path
Let's say you wish to switch to the directory home/kt/abc from where you are presently located in home/kt. To achieve this, let's examine both the absolute and relative route concepts:
Changing directories using the idea of a relative path:
/home/kt $pwd
$cd abc                   

/home/kt/abc $pwd        
File Types in Linux
everything is a file and if not it is not a file, it is a process
most file system implementations define seven types
1. Regular files 
2. Directories 
3. Character device files
4. Block device files
5. Local domain files 
6. Named pipes (FIFO)
7. Link files ** yana hoe chi mae slide na


1. Regular files
- Regular/ Ordinary files store data of various content types such as text, audio, video, images, script, and programs. 
-  A large majority of the files found on UNIX and Linux are ordinary files
- can be created with/ without an extensions
- start with -

2.  Directories
- contains named references to other files 
- binary files used to track and locate other files and directories
- can create directories with mkdir and delete them with rmdir if they are empty
- to organize files in a hierarchy, file systems use directories 
- Linux file system starts with a directory called / or root directory

3.  Character device file or Block device file
- Hard drives, printers, displays, terminal emulators, and CD/DVD drives are just a few examples of the hardware that Linux handles as unique files.
- A special file's function is to make the device visible as a file in the file system because tools for file I/O may access the device, a particular file offers a common interface for physical devices (including virtual devices produced and utilized by the kernel).
- Data is read from or written to a specific file instantaneously, and the process is not governed by standard filesystem conventions. 
- A character special file depicts a piece of equipment that sends data in bytes, such as a printer or a monitor. A device that transfers data in blocks, such as a hard drive, is represented by a block special file.
- A block-specific file that gives users access to a device that sends data in fixed-size groups. For instance, a disk.
- A character-unique file that grants access to a computer or other device that sends data in units of one character, such as a terminal.

4. Link files(Hard link & soft link)
- Can utilize a file from a different place and with a different filename, so Link files are used for this.
- A pointer to another file is what a link file is. connections come in two varieties: physical connections and symbolic or soft linkages.
- A mirror duplicate of the original file is made through a hard link.
- It is impossible to build a hard link to a directory or file on another filesystem.
- The name of a file is referenced through a symbolic or "soft" link.
- To a directory or a file on another filesystem, a soft link can be established.

5. Socket file 
- Is a communication endpoint that applications use to exchange data. 
- For instance, if a local system program wishes to talk to a distant system application, it connects to that application's socket using the socket's associated IP address and port number.
- A socket is used by each application that offers services to distant customers or other programs.
- Each socket has an associated IP address and port number that allow it to accept connections from clients. 
- Linux employs socket files to simplify communication between local programs.
- Applications running on the local system can communicate data using socket files without having to go through the difficult networking and sockets process.
- Instead of using an IP address and port number, socket files utilize a file name as their address.
- The sendmsg() and recvmsg() system functions are used by socket files to provide inter-process communication between local programs.

5. Named files(FIFO files)
- allows communication between two processes running on the same host. 
- can be created with mknod and removed with rm

Comments