When you open a terminal, usually, you land up in your home /home/<your name>
-
pwd
- Print Working directory -
cd
- Change directory -
ls
- List the contents of directory
Option | Meaning |
---|---|
-a |
Shows hidden files (The ones whose name begins with . ) |
-i |
Show inode number |
-l |
Long List |
-h |
Human Readable file sizes |
-
file
- Identifies the type of file -
cp
andmv
- Copy and move, respectively
.
- The current directory..
- The previous directory/
- Root~
- Your home
/
├── bin
├── boot
├── dev
├── etc
├── home
├── lib
├── proc
├── sys
├── tmp
.
.
Directory | Purpose |
---|---|
/bin |
Binary files to be used by all users |
/boot |
Bootloader files |
/dev |
Device files |
/etc |
Configuration files |
/home |
home of users |
/lib |
Static and dynamic libraries |
/proc |
procfs - Process file system |
/sys |
sysfs - The filesystem exported by the kernel to control hardware |
/tmp |
tempfs - Temporary files go here |
The procfs
- Virtual file system
- On-demand file access (so all file sizes are 0)
- Can be used to interact with the kernel (you can use system calls also)
- Provides information related to the system as a whole, and of individual processes
- Following is a list of some files providing information related to system
File | Description |
---|---|
/proc/uptime |
System uptime in seconds. |
/proc/cpuinfo |
CPU Information (Can also get using lscpu ) |
/proc/meminfo |
Memory information |
/proc/vmstat |
Virtual memory information |
/proc/mounts |
Information on mounted file systems (Can also get it using mount command) |
/proc/filesystems |
Supported file systems |
/proc/self/fd/0 |
stdin - The standard input stream |
/proc/self/fd/1 |
stdout - The standard output stream |
/proc/self/fd/2 |
stderr - The standard error stream |
- Following is a list of some files provinding information related to each process. They reside in
/proc/<pid>
File | Description |
---|---|
cmdline |
Command line used to start the process |
comm |
The process name in the command line |
cwd |
Link to the directory in which the process has started |
exe |
Link to the program executable |
environ |
Environment variables inside the process |
limits |
Resource limits for the current process |
maps |
Memory map of the process |
status |
Status of the process |
- Also a virtual file system
kobject
hierarchy exported by the kernel- Used to activate/deactivate kernel features (without coding)
- If a file has write flag enabled, it can be used to do configuration
- We can play with
/sys/class/leds/<device>/brightness
value to turn LEDs of the device on and off by just usingecho
.
- The real and pseudo devices that are attached to the system
- 2 types - block (
b
) and character (c
) - Out of pseudo devices, terminal devices
/dev/tty*
and/dev/pts/*
can be used to communicate with other real terminals and terminal emulator sessions, respectively /dev/zero
,/dev/null
act as an infinite supply of zeros, and, infinite sink, respectively/dev/random
is the random number generator provided bt the kernelstdin
,stdout
andstderr
provide the streams to process to read and write the data.- Other files corresponding to real devices have drivers implemented for them. According to the driver specifications, we can communicate with them
- Temporary filesystem, as the name implies!
- Files on a volatile memory
- Fast access, but not too much files
- Storing intermediate data
- Many configuration files are stored here, organized by application
- The configuration is a plain text that is read by the application
- Some important files are listed below
File | Description |
---|---|
passwd |
List of users |
shadow |
Hashed passwords! |
fstab |
Default mounts file |
hosts |
Host definition for local system |
hostname |
Current hostname |
resolv.conf |
DNS server configuration |
~
- Your files are stored here, under your ownership
- Per-user configurations and data are stored in
~/.local
- But, home of the root is
/home/root
, but/root
Many times, we become lazy to walk the file system tree, so shortcuts are needed. They are called links in Linux.
There are 2 types of links in Linux.
- Soft links
- Hard links
---------- ---------
| file1 |<--- | link |
---------- | ---------
| | |
V | V
---------- | ---------
| Inode1 | ---- |Inode2 |
--------- ---------
ln -s file1 link
---------
---------- -------| file1 |
| Inode1 |<-------| ---------
-------- | ---------
-------| link |
---------
ln file1 link
- Impossible to hard link directories
rm
is not deleting the files, but unlinking them.- Due to the above reason, if we delete
file1
, we can still access its content usinglink
.
Linux allows you to attach an external filesystem to a point in the existing file system tree. This process is called mounting
The point at which external filesystem gets attached is called mount point
Use mount
to list currently mounted filesystems.
mount <disk path> <mountpoint>
to mount an external file systems
umount <dispath or mountpoint>
is used to unmount the file system
Before mount
=============================
Host System
--------------
/
├── ...
├── ...
├── volume1
├── ...
├── ...
.
.
Extenral Filesystem at /dev/disk1s2
-----------------------------------
/
├── dir1
├── dir2
├── dir3
├── ...
.
.
After `mount /dev/disk1s2 volume1`
===================================
/
├── ...
├── ...
├── volume1
│ ├── dir1
│ ├── dir2
│ ├── dir3
│ ├── ...
| .
| .
├── ...
.
.
- If the mounted directory is a Linux root, you can get the shell of mounted Linux using
chroot <mountpoint>
. - But you need to link
/dev
and/proc
of the host (either usingln -s
ormount -o bind
) to that of the inside of the mount point. - If we want network access inside the shell, we also have to copy
/etc/resolv.conf
to the inside of the mount point. - This process is typically done from live-boot media to gain access to OS on a hard disk to repair it.
mount
supports filesystems implemented in the kernel- To add new filesystem, we have to implement a kernel module
- But, FUSE (File system in USEr space) allows us to implement file system in userspace
- Just have to implement a bunch of functions!
- Your classmates are working on a project on FUSE 😄
exfat-fuse
,apfs-fuse
, ...
Linux has several utilities to work with filesystem. They are listed below
Utility | Uses |
---|---|
mount and umount |
Mounting and unmounting a filesystem, respectively |
df |
List amount of disk space available on file system |
du |
Disk usage of each file in particular directory. -h to human readble sizes |
fdisk |
Partition table manipulation |
Stay
~
, Stay Safe!