Navigating The Linux File System: (Edwin Achimbi)
Navigating The Linux File System: (Edwin Achimbi)
(Edwin Achimbi)
The Linux file system is a tree structure. The top of the tree is denoted by a slash (/).
Under the root directory, you will find some or all of the following folders.
The bin folder contains commands that can be run by any user such as the cd command, ls,
mkdir, etc.
The boot folder contains everything required by the boot process.
The home folder is generally where all the user folders are stored and for the average user, is
the only area they should be concerned about.
The media folder is where mounted media such as USB drives are located
The root folder is the home directory for the root user.
The usr folder stands for unix system resources and also contains a bin and sbin folder.
The /usr/bin folder contains an extended set of commands. Similarly, the /usr/sbin folder
contains an extended set of system commands.
The sbin contains system binaries.
The cdrom folder is a mapping location for optical media.
The dev folder contains details about all the devices on the system.
The etc folder is generally where all the system configuration files are stored.
The lib and lib64 folders contain all the kernel and shared libraries.
The lost + found folder contains files that no longer have a name, which have been found by the
fsck command.
The mnt folder is also used to mount temporary storage such as USB drives, other file systems,
ISO images, etc.
The opt folder is used by some software packages as a place to store the binaries. Other
packages use /usr/local.
The proc folder is a system folder used by the kernel. You don't really need to worry about this
folder too much.
The run folder is a system folder for storing system runtime information.
The srv folder is where you would keep things like web folders, mysql databases, and subversion
repositories, etc.
The sys folder contains a folder structure to provide system information.
The tmp folder is a temporary folder.
The var folder contains a whole wealth of stuff specific to the system, including game data,
dynamic libraries, log files, process IDs, messages, and cached application data.
The following are essential commands for Navigating the Linux file system
1-To find out which directory you are in, use the pwd (print working directory) command as follows:
$ pwd
2-What are the files and folders under the current/present directory? use the following command
$ ls
(The first items listed are dots. The single dot is a meta-location, meaning the folder you are currently in.
The double dot is an indicator that you can move back from this location. That is, you're in a folder inside
of another folder).
The ls (list) command lists all the files and folders in the directory except for those beginning with a
period. To see all the files including hidden files (those starting with a period), use the following switch:
$ ls –a
To see all the files minus backups,
$ ls –B
To see a listing sorted by time, with the newest first,
$ ls - It
For listings including extensions, size and version;
$ ls – IU, $ ls - LX, $ ls – Lv
3 – Moving between directories and to a particular one. The cd (change directory) command opens a
folder and makes it your new current working directory. Use the cd command as follows
cd /home/username/Documents
4- Navigating back to home folder. The command for returning home is the cd command with no
location specified (shorthand for cd ~). To move out of that directory, use cd along with the path to some
other location, or use double dots to backtrack, or return home to navigate from there.
$ cd ~
$ cd ..
5- Create a new directory
$ mkdir directory_ name
6-To create an empty file use the touch command. Also used to update last access to a file. Note that if
file does not exist, touch will create one.
$ touch file_name
7- To view contents of a file and without making any changes use the following command
$ cat file_name
8 – To rename and move files around the file system use the mv (move) command as follows;
$ mv old_filename new_filename
$ mv /path/of/original/file /path/of/target/folder
Use the rename command as follows. Does not work on all system. mv command is preferred.
$ rename expression replacement filename(s)
Example: rename "Edwin" "Katy" *
All files in the folder with Edwin in it is replaced with Katy. So a file called Edwin.cv will become
Katy.cv.
9 – copy files. Use the copy command to copy files from one directory to the other.
Copy files using the cp command as follows:
cp filename1 filename2
Example:
cp /home/username/Documents/userdoc1 home/username/Documents/UserDocs
10- Delete files and folders using the rm (remove) command as follows.
$ rm file_name
11- Tab key auto-completes file paths as you type, so if you're changing to ~/people/marketing,
then all you need to type is cd ~/people/m and then press Tab.
If Tab is unable to complete the path, you know that you either have the wrong path or there are
several directories with similar names, so your shell is unable to choose which to use for auto-
completion.
Symbolic and Hard links
Links are files that are references to other files, and they're used to avoid having multiple copies
of the same file in different places. 2 types;
a) Hard link: points to data on the disk (inode).
Create a hard link as follows;
$ Ln poems.txt words.txt
b) Soft link (or symlink: symbolic link): points to a file on the disk (relative path).
Example; A desktop shortcut.
create a symbolic link as follows;
$ ln –s poems.txt writing.txt
Where poems.txt is the source file and writing.txt is the destination (or name of the link)
-writing.txt is the link to poems.txt file.
-original contents of poems.txt file is found in the writing.txt file.
-editing the writing.txt file would edit the original file as well.
-link is relative: moving it somewhere else file system breaks the link.
Unlike soft links, hard links can be moved around the file system and it doesn't matter if the
original file is moved and the link won’t break because a hard link points to the underlying
data for a file instead of the file itself.