11/19/2019
Mastering Linux Command-line
[Link]
Mastering Linux Command Line [Link]
Linux File System
File System Layout
Unix Files
File Names
File Categories
File Organization
Pathnames
Working with directories
Working with files
Comparing files
etc.
[Link]
Mastering Linux Command Line [Link]
Linux File System
[Link]
Mastering Linux Command Line [Link]
1
11/19/2019
Analogy - House
Living Room Living Room
Kitchen Kitchen
Master Bedroom Bedroom
Guest Bedroom Bathroom
Game Room
Bathroom
[Link]
Mastering Linux Command Line [Link]
Linux File System Organization
/ (root)
directory1 directory2 directory3 file1
sub-directory1
file2
sub-directory2 sub-directory3
file2
[Link]
Mastering Linux Command Line [Link]
Linux File System Organization - Sample
/ (root)
tmp bin etc sbin dev opt usr home var ……….
cat cd who john mary
[Link]
Mastering Linux Command Line [Link]
2
11/19/2019
Directories
Directory Purpose
/ Represents the root of the file system. Everything else falls under root.
/bin Contains binaries
/sbin Contains system binaries
/var A place for files that may change often. Example of usage: User Emails
/usr The "user file system”. Contains executables, libraries, man files and other types of documention
/opt Contains locally installed software.
/home User’s home directories are located under this directory
/etc Contains system-wide configuration files and system databases i.e system administration related files.
/dev Contains files that represent hardware like hard drives etc.
/lib Stores the needed libraries and data files for programs stored within /usr or elsewhere.
/tmp, /var/tmp Location for temporary files.
[Link]
Mastering Linux Command Line [Link]
System Administration Related Info
Hard Disk – Partitions & Mount-points
Hard disk is partitioned into multiple partitions at the time of OS installation.
These PARTITIONS are mounted (or mapped or linked) to desired spot.
A partition with the mount-point “/” (called as root) is MUST!
A partition is configured as “swap partition” which us used by the OS. This is also MUST!
Optionally, more partitions can be created and mount at:
/opt (/opt is referred as the mount-point for the partition mounted)
/var (/var is referred as the mount-point for the partition mounted)
etc.
If /opt partition is not created, /opt is still created and becomes part of “/” partition.
[Link]
Mastering Linux Command Line [Link]
System Administration Related Info
“lost+found”
Each partition has a “lost+found” directory.
If a partition is mounted at /opt, then you will see /opt/lost+found.
It is used by the “fsck” command or similar functionality commands.
File System Check.
Used by Linux System Administrators for filesystem management.
[Link]
Mastering Linux Command Line [Link]
3
11/19/2019
Home Directory
[Link]
Mastering Linux Command Line [Link]
10
Home Directory
Every user has a home directory
/ (root)
User Login home directory.
$HOME holds user’s home directory path.
tmp bin etc sbin usr home var
john’s home directory
cat cd who john mary
[Link]
Mastering Linux Command Line [Link]
11
File Types
[Link]
Mastering Linux Command Line [Link]
12
4
11/19/2019
File Types
Regular Files (-)
Directory Files (d)
Special Files
Block Device Files (b)
Character Device Files (c)
Named pipe files (p)
Symbolic link files (l)
Socket files (s)
[Link]
Mastering Linux Command Line [Link]
13
Regular Files
Readable file
A binary file
Image file
Compressed file
[Link]
Mastering Linux Command Line [Link]
14
Directory Files
This type of file contains other files and sub-directories.
[Link]
Mastering Linux Command Line [Link]
15
5
11/19/2019
Special Files
Block Device File Character Device File
These files are hardware files Provides a serial stream of input or
most of them are present in /dev. output. Your terminals are classic
example for this type of files.
Pipe File Symbolic Link File
Pipes allow separate processes to These are links to other files.
communicate without having
been designed explicitly to work Socket Files
together. A socket file is used to pass
information between applications
Example: | for communication purpose
[Link]
Mastering Linux Command Line [Link]
16
Everything is a file
Everything is a file in Linux.
Hard Disk
CD-ROM
Memory
Printer
[Link]
Mastering Linux Command Line [Link]
17
File Naming Restrictions
[Link]
Mastering Linux Command Line [Link]
18
6
11/19/2019
File Names
Case-sensitive myfile
You can use: Myfile
Alphabets – Upper & Lower
Numbers
. (dot)
_ (underscore)
- (hyphen)
Etc
[Link]
Mastering Linux Command Line [Link]
19
File Names – Avoid these
/ : > (
)
* & <
{
? }
[Link]
Mastering Linux Command Line [Link]
20
File Names – File Extension
File extension has no significance
It only adds visual value.
Example:
myfile
[Link]
[Link]
Mastering Linux Command Line [Link]
21
7
11/19/2019
Understanding Linux Paths
[Link]
Mastering Linux Command Line [Link]
22
Paths
Parent Directory / (root)
Sub-directory or Child-directory
Absolute Paths
Relative Paths
./ tmp bin etc sbin usr home var
.
..
cat cd who john mary
Home Directory
~
[Link] dir2
[Link]
Mastering Linux Command Line [Link]
23
Paths
/ (root)
Absolute Path Example
/home/john/[Link]
Relative Path Example
tmp bin etc sbin usr home var ./[Link]
~/[Link]
cat cd who john mary
. Current Directory
.. Parent Directory
[Link] dir2
~ Home Directory
[Link]
Mastering Linux Command Line [Link]
24
8
11/19/2019
DOTS
Hidden Files/Folders
Filenames or directory names that start with a dot (.)
Command Purpose
System/User level dot files
ls List contents of a folder
.profile
ls –l Long list
.exrc ls –a List hidden files also
.bashrc
DOT (.)
Two DOTS (..)
[Link]
Mastering Linux Command Line [Link]
25
Wild Cards
Special Character Purpose
* Match all character
? Match any one character
[] Match specified between [ and ]
[Link]
Mastering Linux Command Line [Link]
26