chapter 4

37
Linux file system administration Chapter 4

Upload: tass

Post on 05-Jan-2016

22 views

Category:

Documents


0 download

DESCRIPTION

Chapter 4. Linux file system administration. Directory structure. Linux organizes its files differently from Windows First the directory structure may seem unlogical and strange and you have no idea where all the programs, icons, config files, and others are. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Chapter 4

Linux file system administration

Chapter 4

Page 2: Chapter 4

Directory structureLinux organizes its files differently from WindowsFirst the directory structure may seem unlogical

and strange and you have no idea where all the programs, icons, config files, and others are.

There are two types of Linux's directory structure: full/absolute path and relative path

Page 3: Chapter 4

Directory structure cont..When you request to open or save a file, your

shell uses the current directory as the point of reference.

Simply provide a filename when you save a file, and it is placed in the current directory.

Alternatively, you can identify a file by its relation to the current directory (relative path), or you can ignore the current directory and identify a file by the full directory hierarchy that locates it (absolute path/full path).

Page 4: Chapter 4

ABSOLUTE PATHNAME

Tells about the complete path to a certain file or

directory is.

All absolute file names start with a slash because the

slash indicates the root directory and then followed by

the file system tree directory by directory.

We use the slash not only for indicating the root directory,

but also for separating the directories on the path.

This is different from windows where we use a backslash

for separating the directories.

Page 5: Chapter 4

RELATIVE PATHNAME

It starts from the working directory.

This is why you need some special symbols for

indicating the relative positions in the filesystem.

These symbols are a dot (.) and two dots (..) and

they mean the working directory and the parent

directory respectively.

Page 6: Chapter 4

Linux File Systems Versus Windows-Based File SystemsFile systems are organized differently in Linux than

they are in Microsoft Windows operating systems. Instead of drive letters (for example, A:, B:, C:) for each

local disk, network file system, CD-ROM, or other type of storage medium, everything fits neatly into the directory structure.

Some drives are connected (mounted) automatically into the file system. For example, a CD might be mounted on /media/cdrom. If the drive isn’t mounted automatically, it is up to an administrator to create a mount point in the file system and then connect the disk to that point.

Page 7: Chapter 4

Linux File Systems Versus Windows-Based File Systems cont..Although similar in many ways, the Linux file

system has some striking differences from file systems used in MS-DOS and Windows operating systems. Here are a few:In MS-DOS and Windows file systems, drive letters

represent different storage devices (for example, A: is a floppy drive and C: is a hard disk). In Linux, all storage devices are fit into the file system hierarchy. So, the fact that all of /usr may be on a separate hard disk or that /mnt/rem1 is a file system from another computer is invisible to the user.

Page 8: Chapter 4

Linux File Systems Versus Windows-Based File Systems cont..

Slashes, rather than backslashes, are used to separate directory names in Linux. So, C:\home\izwan in an MS system is /home/izwan in a Linux system.

Every file and directory in a Linux system has permissions and ownership associated with it. Security varies among Microsoft systems. Because DOS and MS Windows began as single-user systems, file ownership was not built into those systems when they were designed. Later releases added features such as file and folder attributes to address this problem.

Page 9: Chapter 4

Linux File Systems Versus Windows-Based File Systems cont..

Filenames almost always have suffixes in DOS (such as .txt for text files or .doc for wordprocessing files). Although at times you can use that convention in Linux, three-character suffixes have no required meaning in Linux. They can be useful for identifying a file type.

Many Linux applications and desktop environments use file suffixes to determine the contents of a file. In Linux, however, DOS command extensions such as .com, .exe, and .bat don’t necessarily signify an executable (permission flags make Linux files executable).

Page 10: Chapter 4

Linux file system, basic Linux directoriesThe Linux file system is organized as a hierarchy of

directories.

Page 11: Chapter 4

Linux file system, basic Linux directories cont..

DIRECTORY CONTENTS

/bin/ contains binaries of useful commands and shells

/dev/ contains files that communicate with hardware

/etc/ contains system configuration files

/home/ contains home directories for users

/lib/ contains shared libraries (Windows equivalent is .dll files)

/mnt/ contains - mountpoints

/root/ home directory of the root user

/sbin/ contains all binary files essential to the running of Linux

/tmp/ files that are required temporarily

/usr/ contains all user binaries including programs like telnet, ftp, etc.

/var/ contains spooling data like mail

Page 12: Chapter 4

Basic Linux command and conceptls - List the contents of a directory.ps - see which programs are running, the resources

they are using, and who is running them.usermod - to modify settings for an existing accountid - To find out information about your identity,

Page 13: Chapter 4

Basic Linux command and concept cont..who - You can see information about your current

login sessionecho – To find out the name of your home

directory,pwd - To find out what your current directory (the

present working directory)cd - To get back to your home directory, just type

the change directory (cd) command. (Although cd followed by a directory name changes the current directory to the directory that you choose, simply typing cd with no directory name takes you to your home directory.)

Page 14: Chapter 4

Basic Linux command and concept cont..df - display the space available in your file systemsdu - To find out how much space is being consumed

by a particular directory (and its subdirectories)man - To learn more about a particular command,

type man command. (Replace command with the command name you want.) A description of the command and its options appears on the screen.

You also can always see other option for every command by typing command --help, e.g. ls --help

Page 15: Chapter 4

Basic Linux command and concept cont..chmod - Change the permissions on a file or

directory. The format is chmod permissions filename

chown - to change the owner of a file or directory The format is chown newowner filename

chgrp - to change the group that has access to files and directories. The format is chgrp newgroup filename(s) [-options]

Page 16: Chapter 4

Here are some examples of how to change permissions on a file (named file) and what the resulting permission would be:

# chmod 777 file rwxrwxrwx# chmod 755 file rwxr-xr-x# chmod 644 file rw-r--r-# chmod 000 file ---------

Page 17: Chapter 4

Basic Linux command and concept cont..chmod> ls -l

-rwxr--r-- 1 root root 765 Apr 23 09:22 file.txt > chmod 755 file.txt

The permissions are the first 10 characters of the line (-rwxrwx---) and can be broken down as follows.

Page 18: Chapter 4

The r,w and x stand for: r = read,w = writex = execute

The first character on the line shows what type of file or directory it is, and can be one of these things...- = filed = directoryl = symbolic linkb = block-type special filec = character-type special filep = named pipeS = sockets = XENIX semaphorem = XENIX shared data (memory) fileD = Solaris doorn = HP-UX network special file

Page 19: Chapter 4

Basic Linux command and concept cont..The remaining 9 characters are broken down into 3

groups of 3 characters. The first three are the permissions for the owner, the middle three are permissions for the group which has access to the file and the last three are the permissions for everybody else.

Page 20: Chapter 4

Basic Linux command and concept cont..chown> chown izwan file.txt This will cause file.txt to now be owned by izwan.

Page 21: Chapter 4

chgrp>ls -l

-rwxrwx--- 1 izwan grup 35 Jun 13 21:14 file.txt>chgrp kumpulan file.txt>ls -l-rwxrwx--- 1 izwan kumpulan 35 Jun 13 21:14 file.txt> Line 1 is the list command (ls), with long formatLine 2 is the output of ls, showing there is one file, called

file.txt (owned by ‘izwan', group access for group ‘grup')Line 3 is the chgrp command, with the new group name

being ‘kumpulan‘Line 4 is the ls command again, to show us if the chgrp

command was successfulLine 5 shows that the file is owned by izwan, but now

group access is ‘kumpulan'

Page 22: Chapter 4

mv - Move files to directory / Move or rename files. E.g.

mv file1 file3 – rename file1 to file3mv file3 home/user/directory – move file 3 into

directory

Page 23: Chapter 4

cp - Copy files cp source destination E.g. cp files1 files2

Copy file1 as file2 in same directoryE.g. cp files1 files2 home/user/directory

Copy files1 and files2 to other directory

Page 24: Chapter 4

rm – Remove (delete) files. You must own the file in order to be able to remove it.

On many systems, you will be asked or confirmation of deleation, if you don't want this, use the "-f" (=force) option, e.g., rm -f *  will remove all files in my current working directory, no questions asked.

E.g. rm file1

Page 25: Chapter 4

rmdir - Remove an empty directory. rm directoryrm -r files - (recursive remove) Remove files,

directories, and their subdirectories. Careful with this command as root--you can easily remove all files on the system with such a command executed on the top of your directory tree, and there is no undelete in Linux (yet).

Page 26: Chapter 4

find – finding filesE.g. find filename

Find the file called "filename" on your filesystem starting the search from the root directory "/". The "filename" may contain wildcards (*,?).

locate – finding files.E.g. locate filename Find the file name of which contains the string

"filename". which – locate a command e.g which ls, the

output would be /bin/ls etc..

Page 27: Chapter 4

View text files

head – print the first 10 lines of each file to standard output

tail - print the last 10 lines of each file to standard output

cat – concatenate (combine) files and print on the standard output

tac - write each file to standard output, last line first. With no file or file is -, read standard output

more – filter for paging through text one screenful at a time. This version is especially primitive

less – opposite of more

Page 28: Chapter 4

File Compression

Usually when you want to install applications or software, we can use a DEB (Debian software package )or RPM (RPM Package Management – for Red Hat) packages.

Software not available in .DEB or RPM format can often be installed from installer scripts (.sh) or by compiling source code from a tarball.

A tarball is an archive of files createdwith a special utility (named tar) and usually compressed using another utility, gzip. Source code distributions are often packaged as gzipped tarballs. Compiling from source enables you to do things the “old way” if needed and to exercise granular control of unpackaged software.

Page 29: Chapter 4

tar.bz2tar.gz

Uncompress tarball# 1: Uncompress tarball

To uncompress them, execute the following command(s) depending on the extension:

$ tar zxf file.tar.gz

$ tar zxf file.tgz

$ tar jxf file.tar.bz2

$ tar jxf file.tbz2

Page 30: Chapter 4

Now change directory

# 2: Build and install softwareGenerally you need to type 3 commands as follows for

building and compiling software:

$ ls

$ cd path-to-software/

# ./configure# make# make install

Page 31: Chapter 4

Where,./configure will configure the software to

ensure your system has the necessary functionality and libraries to successfully compile the package

make will compile all the source files into executable binaries.

Finally, make install will install the binaries and any supporting files into the appropriate locations.

Page 32: Chapter 4

# 3: Read INSTALL / README fileEach tarball comes with installation and build

instructions. Open INSTALL or README file for more information:

$ vi INSTALL

Page 33: Chapter 4

FILE SYSTEM ADMINISTRATION

ext2 File systems

The ext2 or second extended filesystem

is a file system for the Linux kernel.

It was initially designed by Rémy Card as a

replacement for the extended file system (ext).

ext2 was the default filesystem in Debian and Red

Hat Linux

Page 34: Chapter 4

FILE SYSTEM ADMINISTRATION

ext3 File systems

The ext3 or third extended filesystem

is a journaled file system that is commonly used by the

Linux kernel.

It is the default file system for many popular Linux

distributions.

Page 35: Chapter 4

FILE SYSTEM ADMINISTRATION

ReiserFS File systemsis a general-purpose, journaled file system designed

and implemented by a team at Namesys led by Hans Reiser.

ReiserFS is currently supported on Linux. Introduced in version 2.4.1 of the Linux kernelit was the first journaling file system to be included in the

standard kernel. ReiserFS is the default file system on the Elive,

Xandros, Linspire, GoboLinux, SUSE and Yoper Linux distributions.

Page 36: Chapter 4

FILE SYSTEM ADMINISTRATION

XFS File systems

is a high-performance journaling file system created by

Silicon Graphics,

originally for their IRIX operating system and later

ported to the Linux kernel.

XFS is particularly proficient at handling large files and

at offering smooth data transfers.

Page 37: Chapter 4

FILE SYSTEM ADMINISTRATION

VFAT File systems

Short for Virtual File Allocation Table,

a virtual installable files system driver used in Windows

for Workgroups and Windows 95.

VFAT operates in protected mode

serves as an interface between applications and the File

Allocation Table (FAT).