- 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
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
- A user’s path is a list of directories that are searched for commands typed at the command line.
Some Important Directories
- Home Directories:
- User Executables:
- System Executables:
- Shared Libraries:
- Kernels & Boot-loaders:
- Configuration Files:
- Device Files:
- Temporary Files:
- Other Mount-points:
- Server Data:
- System Informations:
- Optional Applications:
1. Home Directories
- Every user has a home directory.
- The root user’s home directory is
- Most non-root user’s home directories are in
2/3. User/System Executables
- The essential binaries reside in
/binfor user and
- The non essential binaries, such as graphical environments or office tools installed in
- The software compiled from the source code, usually go in
4. Shared Libraries
libdirectory 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
6. Configuration Files
- Most of the configuration files are stored in
/etcand its subdirectories.
7. Device Files
- Most of the device files are stored in
/devand its subdirectories.
8. Temporary Files
/tmpdirectory is usually used by many Linux Applications for storing temporary data.
- Once a day system automatically deletes any files over ten days old in
9. Other Mount-points
- Filesystems of the removable media are usually mounted under
- For Example: A cdrom is usually mounted under
10. Server Data
/vardirectory contains the regularly changing system files such as logs, print spools and email spools.
/srvdirectory contains the server data such as databases and web pages.
11. System Informations
/procdirectory is a special dynamic directory that provides the informations about a running Linux system and allows some tweaking while a system is running.
/sysdirectory is related to the hardware.
12. Optional Applications
/optdirectory 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
- Begin with a forward slash (/).
- Complete road map to the file location.
- For Example:
- For Example:
- Can be used anytime you wish to specify a file name, Regardless of the current working directory.
- 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.
pwdcommand displays the absolute path of the shell’s current working directory.
Changing Directories - cd command
cdcommand are used to change the directory.
- The only argument to the
cdcommand 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
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.
* -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)
- 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
- The touch command is used to creates empty files or update file timestamps
- The rm command is used to remove files.
- -i(interactive): Prompt before every removal
- -f(forcefully): Forcefully removed without any prompt
- -r(recursive): Remove directories and their contents recursively
- The mkdir command is used to creates the directories.
- -p(parents): Make parent directories as needed
- The rmdir command is used to remove empty directories.
rmdir command removes only empty directories.
To remove a directories and its contents, use
- Nautilus is a GNOME Graphical File System Browser.
- Nautilus can run in one of two modes:
1. Spatial Mode
- 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
Ctrl+lOpen Location dialog
Ctrl+qClose all nautilus windows
Ctrl+Shift+wClose all the parent windows
Ctrl+Shift+nCreates new Directory
Moving and Copying in Nautilus
Drag: Move on same filesystem, copy on different filesystem
Drag+Ctrl: Always Copy
Drag+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.
filecommand prints its best guess of the type of data contained in a file. (by using
- 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).