Navigating Linux Filesystem
The Linux filesystem is a tree-like hierarchy of files and directories. At the base of this filesystem, is the "/" directory, known as "root"(Don't confuse with root user). Unlike DOS and Windows, where there is separate "/" for every disk drive, Linux filesystem mounts all disks somewhere under / filesystem. For example: /dev/sda , /dev/sdb etc. Everything in Linux is a file i.e a device attached to your Linux machine is shown as file in filesystem.
Directory Layout
/ : The nameless base of filesystem. All other files, directories, drives, and devices are attached to this root.
/bin : Essential command binaries stored here.(ls, cd, tar etc)
/boot : Boot loader files.(Files needed for booting of system)
/dev : Device files. In Linux, all hardware devices are accessed like other files and are kept under this dorectory
/etc : Machine specific configuration files. (/etc/hosts.conf)
/home : Users' personal home directory.
/lib : Important shared libraries and kernel modules.
/proc : Process information.
/root : root(superuser) home direcotory.
/sbin : Essential system binaries.(fdisk, fsck, init etc.)
/tmp : Temporary directory. Each user has rights to put their files to this location.
/usr : Base directory for most shareable and read-only data. For example program files of an application.
/var : Variable data-- Mail and printer spool data, log files, lock files etc.
Commands for Navigating Linux Filesystem
The first thing you do while learning about the Linux filesystem is to look around!! What is all around?
Next few commands will tell: 1. Where you are? 2. Take you to somewhere else. 3. Whats there at current place?
pwd : print working directory.[In Linux prompt, it does not show the complete/absolute path of your current location but it shows the name of current directory. Hence pwd command helps in knowing absolute path of your current location ].
cd: For changing your current working directory to some other directory. If used only 'cd', without argument, it will take you to your home directory.
cd .. will take you one level up i.e. to parent directory.
cd - will take you to your previous location, before changing your location.
ls will List all your files/directory in current directory.(more than one file per line)
ls -l will display one filename/directory per line including various details.(refer man page).
ls -a will display all files/directories including hidden files.
ls -ld /dir will display detailed info. about /dir directory rather contents of /dir directory. Try and compare output of ls -l /usr/bin & ls -ld /usr/bin.
Piping and Redirection
Before we start learning more commands, lets have a look in to Piping and Redirection. In Linux, user has to combine different small commands and make more useful command sequences using those commands/programs.
Piping Commands
The Pipe character, "|" is used to combine two or more commands. The output of first command is "piped" in to another command and works as input to that command. If there is another 2nd pipe then output is sent to 3rd command.
For Example: ls -al | more
Here we are piping the output of ls -al in to more command. As output of ls -al is very long list hence we used more to display one screen at a time using more command.
Redirecting Output to Files
At times we have to save the output of a command rather displaying it on screen.
For example: we want to create a list of text(.txt) files in current directory. So we can do this using ">" redirection character.
">" operator will overwrite the file if exist and create newfile if given file does not exist.
">>" operator can be used if you want to append the output i.e you do not wish to overwrite file.
We shall have look in to more filesystem navigation commands in later topics. Till then keep learning LinuxWithEase. Smile :)
No comments:
Post a Comment