Browsing the Filesystem
Overview
- Linux File Hierarchy Concepts
- Some Important Directories
- Files and Directory Names
- Absolute and Relative Pathnames
- Current Working Directory
- Changing Directories - cd command
- Listing Directory Contents - ls command
- Copying Files and Directories - cp command
- Moving and Renaming Files and Directories - mv command
- Creating and Removing Files and Directories
- Using Nautilus
- Determining File Content
Linux File Hierarchy Concepts
- Files and Directories are organized into a single rooted inverted tree structure, including distinct physical volumes such as Floppy Disks, CD-ROMs and Multiple Hard Drives.
- Filesystem begins at the root directory, represented by lonely forward slash (/).
- Names in Linux File Hierarchy are case sensitive.
- Paths are delimited by / such as
/usr/share/bin/X11/X
-
Each shell and system process has a current working directory.
.
refers to the current working directory.-
..
refers to the parent directory of any particular directory - just one level up in the file hierarchy. - Files and Directories whose name begin with a
.
are hidden. - A user’s path is a list of directories that are searched for commands typed at the command line.
Some Important Directories
- Home Directories:
/root
,/home/username
- User Executables:
/bin
,/usr/bin
,/usr/local/bin
- System Executables:
/sbin
,/usr/sbin
,/usr/local/sbin
- Shared Libraries:
/lib
,/usr/lib
,/usr/local/lib
- Kernels & Boot-loaders:
/boot
- Configuration Files:
/etc
- Device Files:
/dev
- Temporary Files:
/tmp
- Other Mount-points:
/media
,/mnt
- Server Data:
/var
,/srv
- System Informations:
/proc
,/sys
- Optional Applications:
/opt
1. Home Directories
- Every user has a home directory.
- The root user’s home directory is
/root
. - Most non-root user’s home directories are in
/home/username
.
2/3. User/System Executables
- The essential binaries reside in
/bin
for user and/sbin
for systems. - The non essential binaries, such as graphical environments or office tools installed in
/usr/bin
and/usr/sbin
. - The software compiled from the source code, usually go in
/usr/local/bin
and/usr/local/sbin
.
4. Shared Libraries
- The
lib
directory contains the libraries that provide shared code used by many Linux Applications.
5. Kernels & Boot-loaders
- The boot loader is in charge of loading the core of the Linux, called kernel, into the memory.
- The boot loader, kernel and loader’s configuration files are stored in
/boot
.
6. Configuration Files
- Most of the configuration files are stored in
/etc
and its subdirectories.
7. Device Files
- Most of the device files are stored in
/dev
and its subdirectories.
8. Temporary Files
- The
/tmp
directory is usually used by many Linux Applications for storing temporary data. - Once a day system automatically deletes any files over ten days old in
/tmp
.
9. Other Mount-points
- Filesystems of the removable media are usually mounted under
/media
. - For Example: A cdrom is usually mounted under
/media/cdrom
.
10. Server Data
- The
/var
directory contains the regularly changing system files such as logs, print spools and email spools. - The
/srv
directory contains the server data such as databases and web pages.
11. System Informations
- The
/proc
directory is a special dynamic directory that provides the informations about a running Linux system and allows some tweaking while a system is running. - The
/sys
directory is related to the hardware.
12. Optional Applications
- The
/opt
directory provides a location for optional applications to be installed.
Files and Directory Names
- Names may be up to 255 characters.
- Names are case sensitive.
- For Examples: MAIL, Mail, mail and maiL
- Again, possible, but not be wise.
- All characters are valid, except forward-slash (/).
- It maybe unwise to use certain special characters in files and directory names.
- Among the characters to avoid are: <>?*” and quotation marks, as well as spaces, tabs, and other non-printable characters.
- Some characters should be protected with quotes when referencing them.
NOTE!: Absent the quotes, you would be asking the system to list the four different files.
Absolute and Relative Pathnames
Absolute Pathnames
- Begin with a forward slash (/).
- Complete road map to the file location.
- For Example:
/usr/share/doc/HTML/index.html
- For Example:
- Can be used anytime you wish to specify a file name, Regardless of the current working directory.
Relative Pathnames
- Do not begin with a forward slash.
- Specify location relative to your current working directory.
- Can be used as a shorter way to specify the file name.
Current Working Directory
- Each shell and system process has a current working directory.
- The
pwd
command displays the absolute path of the shell’s current working directory.
Changing Directories - cd command
- The
cd
command are used to change the directory. - The only argument to the
cd
command is either an absolute or relative pathname, or a shortcut representing the directory to which you wish to change.
To absolute or relative path
To your home directory
To a directory just one level up
To your previous working directory
Listing Directory Contents - ls command
- List the contents of the current working directory or a specified directory.
List the files and directories in the current working directory
List the hidden files and directories
List the files and directories of the specified directory
Long Listing
Display directory information, not their contents
NOTES!: It has no effect when filenames are passed as arguments.
Recurse though directories
Copying Files and Directories - cp command
- The cp command is used to copy files and directories.
Options
* -i(interactive): Ask before overwriting a file * -r(recursive): Recursively copy an entire directory tree * -p(preserve): Preserve the permissions, ownership, and time stamps * -a(archive): Copy files and directories recursively (like -r) while preserving permissions (like -p)
The Destination
- If the destination is a directory, a copy of the source file is placed in that directory with the same name as the source.
- If the destination is a file, a copy of the source file is created with that destination name.
WARNING THE CP COMMAND ALWAYS OVERWRITES THE DESTINATIONS!!
Moving and Renaming Files and Directories - mv command
- The mv command is used to move/rename files and directories.
-
Aside from a couple of switches, mv and cp function identically -- The only difference is that with cp source and destination both are presents and with mv source disappears only destination is there.
-
Destination works like cp command.
Creating and Removing Files and Directories
Touch command
- The touch command is used to creates empty files or update file timestamps
rm command
- The rm command is used to remove files.
Options
- -i(interactive): Prompt before every removal
- -f(forcefully): Forcefully removed without any prompt
- -r(recursive): Remove directories and their contents recursively
mkdir command
- The mkdir command is used to creates the directories.
Options
- -p(parents): Make parent directories as needed
rmdir command
- The rmdir command is used to remove empty directories.
NOTE!: The rmdir
command removes only empty directories.
To remove a directories and its contents, use rm -r
.
Using Nautilus
- Nautilus is a GNOME Graphical File System Browser.
- Nautilus can run in one of two modes:
1. Spatial Mode
- Spatial mode is designed for new users and the simplest in the terms of user interface clutter.
- Windows have a very basic layout with no toolbar and when a directory is double-clicked it opens in its own window.
- A menu in the lower-left of each window allows the user to list and select parent directories.
2. Browser Mode
- Browser Mode provides a more traditional file manager interface.
- Windows have a very advance layout with toolbar, menubar, and side panel and when a directory is double-clicked it opens in the same windo.
- Browser mode can be started by selecting Application -> System Tools -> File Browser
Nautilus can be accessed in a number of ways
- Desktop Icons
- Home: Your home directory
- Computer: Root filesystems, Network resources, and Removable media
Nautilus Shortcuts
Ctrl+c
CopyCtrl+v
PasteCtrl+a
Select AllCtrl+l
Open Location dialogCtrl+q
Close all nautilus windowsCtrl+Shift+w
Close all the parent windowsCtrl+Shift+n
Creates new Directory
Moving and Copying in Nautilus
- Drag-and-Drop
Drag
: Move on same filesystem, copy on different filesystemDrag+Ctrl
: Always CopyDrag+Alt
: Ask whether to copy,move or creates symbolic link (alias)
- Context Menu
- Right-click to rename, cut, copy or paste
Determining File Content
- Check file type before opening it with file command.
file
command prints its best guess of the type of data contained in a file. (by using/usr/share/magic
)- Files can contains many types of data such as ASCII (Plain Text, HTML, Executable Shell Scripts, C Program Source Code, Mailbox-format Text) or Binary ( Compiled Executables, Compressed Data, Images and Sound Samples).
Newsletter
Get updated when I create new content.
Unsubscribe whenever. Never any spam.