<Week5 - File system and partitioning>
File System
1) A collection of directories and files
2) It does not have to exist on a single hard disk
3) One hard disk -> may have several filesystems
4) Single filesystem -> may be spread across multiple hard disks
5) All input and output devices and directories are treated as files
6) the root (/) filesystem has its own partition
7) all other filesystems are mounted as subdirectories of root
inode
ls -i
1) Linux stores information about each file in inode
2) It is identified by a unique number called the inode number
3) Each filesystem begins with a set of inode numbers
4) Files are created -> system creates an inode, assign the inode an empty inode number
5) A file is deleted -> system removes its inode, mark the inode number empty
6) It stores inode numbers in inode list
Filenames
extension: part of a filename following a period
hidden filename: a filename begins with a period
File types
1) Simple/Ordinary file
2) Directory
- named file contained within the / (root)
- contains names of other files and/or directories
- files sometimes referred to as nondirectory files
3) Symbolic Link
- Soft link
- Hard link: a connection between a filename and inode number
4) Special file (Device)
5) Named pipe (FIFO)
Identifying Partitions
Naming partitions: sd(a,b,c...)
i.e. sdx1 - sdx4
Naming logical drives
i.e. sdx5 - sdx63
You can have 4 primary partitions, only one extended partition
Linux Partitioning
Partition: a section of the disk that holds a filesystem
Master Boot Sector contains the Disk Partition Table
2 Requirement for partitioning
(1) / (root) partition
- ext2, ext3, ext4 filesystem type
(2) <swap> partition
- must be Linux swap filesystem type
- use free command to determine swap space size
fdisk command
fdisk [options] device
i.e. fdisk -l /dev/sda
Creating Filesystems
step 1. Prepare the drive
- Create, modify or change the partition information
- fdisk [-v or -l] [device]
step 2. Create the filesystem
- Format the drive/partition to the appropriate filesystem required
- mkfs [options] device
i.e. mkfs -t ext3 /dev/sda5 (format the first logical drive with ext3 filesystem)
step 3. Verify the filesystem
- Check filesystem for inconsistencies or errors
- fsck [options] [device]
i.e. fsck -t ext3 /dev/sda2
step 4. Mount the filesystem for access/use
- mount or /etc/fstab
Mounting a File System
The mount utility connects filesystems to the Linux directory hierarchy.
Mounting makes a file system available for use.
The mounting point is a directory in the local filesystem you can access mounted filesystem.
/mnt
Filesystem Cmds
| create, move & delete file and dirs | touch, mkdir, cp, mv, rmdir, rm |
| modify filename | mv |
| open files for reading and writing | vim |
| search for files | find |
| seek within a file | grep |
| list content of a directory | ls |
| root directory | / |
| root user's home directory | /root |
| most essential UNIX/Linux commands | /bin |
| executable programs that are mostly administrative tools | /sbin |
| kernel and other files used during booting are stored | /boot |
| device files, which is the interface between filesystem and hardware | /dev |
| system configuration files | /etc |
| administrative files such as log files | /var |
| default directory for mounting non-pernament devices | /mnt |
| where user personal directory and files are stored | /home |
| libraries necessary to run executables in /bin and /sbin | /lib |
| interface between the filesystem and the running processes | /proc |
| displays the pathname of the working directory | pwd |
| To create a symbolic link from slinkname to oldfilename | ln -s oldfilename slinkname |
| To create a hard link from slinkname to oldfilename | ln oldfilename newfilename |
| Copy a soft link | cp -d |
| Copy a hard link | cp -l |
| the first partition of the second SATA/SCSI drive | /dev/sdb1 |
| create swap Linux partition | mkswap [options] device |
| activates swap partition usage | swapon device |
| de-activates swap partition usage | swapoff device |
<Week9 - Vim>
Starting vim
vim [options] ( [filename] )
with filename: opens that file for editing
without filename: opens a default screen
How does it work?
copies the contents of the file into memory (Work Buffer)
Changes are made to buffer, not the file
Modes
1) Command
- ESC: get you back to Command Mode
- Default
- Case sensitive
| move cursor left | h |
| move cursor right | j |
| move cursor up | k |
| move cursor down | l |
| delete character | x |
| delete word | dw |
| delete line | dd |
| write and quit | zz |
| search forward | /regexpr (regular expression) |
| search backward | ?regexpr |
| repeat the last search | n |
| repeat the last search in opposite direction | N |
| jump to line n | nG |
2) Input (Insert)
- edit and enter text
- insert, append, open, replace, change
| insert before cursor | i |
| insert before the non-blank character on line | I |
| after cursor | a |
| at the end of line | A |
| open line below | o |
| open line above | O |
| replace current character | r |
| replace characters | R |
3) Last Line
- From command mode, press :
- Cursor jumps to the last line on the screen
- Can manage files, issue shell commands, change the editor settings
| write file | w |
| quit | q |
| write read-only file | w! |
| quit without saving changes | q! |
| opens a file for editing | e filename |
| open a shell | sh |
| open a shell, run a command, then exit the shell | !command |
| open a shell, run a command, then exit the shell, placing the standard output into the work buffer | .!command (or !!command) |
Buffer
Purpose: contains edited or deleted text, undo information is stored

grep Command
-i: ignore uppercase and lowercase when comparing
-v: print only lines that do not match the pattern
-c: print only a count of the matching lines
-n: display the line number before each matching line
Backslash
- preserve the literal meaning of the immediate character following the symbol
Single quote
- protect all characters within the single quotes
- it cannot protect single quote
Double quote
- protects all symbols and characters except $, ', backslash
- it can protect single quote