Pages

Monday, January 3, 2011

How To Install Apache, MYSQL And PHP (Lamp) On Centos

Recently my laptop was having some issue, and send to hewlett packet service center for repair. Due to no computer use, and kinda free at office, I decide to continue setup a linux base web server which is in my wish list long time ago. (As mention on free antivirus for linux operating system).

Centos Operating System

I have download Centos 5.2 (www.centos.org) few month ago, also try to install it and experience it, but not much time to really put my self in study on Linux base operating system. After install centos linux base operation system, now I require web server script, Apache, web programming script, PHP, and a database script,MySql. So how to install all this script? I found a easy way to install Linux Apache MySql PHP (LAMP) using Yum command. Just simple 5 step to fully setup your own web server.

How to install Apache using Yum command:
install apache using Yam

Open Terminal, type in ” yum install httpd “, the command will instruct the centos to download apache web server and install it into the server.

How to install MySql using Yum command:
install mysql using yum

After install Apache Web Server, now we require to install MySql database. Type in ”yum install mysql-server mysql “, this command will download MySql dabatase into the server and install it.

How to install PHP using Yum command:
install php using yum

Once finish install MySql server script, lastly, we need to install PHP programming script by type in ” yum install php ” it will download php script and install into the linux server.

After finish install Apache, MySql and PHP, now we require to start the Apache Web Server service and MySql database service.

Optional Method: You can install Apache, MySql and PHP into centos together with using ” yum install httpd php mysql-server mysql ” command, after hit enter, you can sit a side wait for all this 3 script install into your Linux Web Server.

How to start Apache web server:
start apache

Simply type in ” service httpd start ” in the terminal, and the service will be activated.

How to start MySql database service:

To start the MySql server, type in ” service mysqld start ” in the terminal, and MySql service is ready to use. You can create a database, create table, and create record using MySql command line at the terminal.

How to test the Web Server and ensure it is running?
After both Apache Web server and MySql database is start running, now we open a internet explorer, access “http://localhost/” or “http://127.0.0.1” and you will see a welcome page!

centos welcome page

The root directory for the web server will be located at ” var/www/html “, you can try to create an index.html, save it at ” var/www/html “, you will saw this webpage when you access “ http://localhost/ ” or “ http://127.0.0.1/

How to test the Web Server and ensure it is running on the network?
If you are in the network environment, you can use the other computer within the network, and access the web server IP address. For example, the web server local IP address is 192.168.1.5, you can use other computer within the network to access ” http://192.168.1.5 “, you will see the welcome page or the index.html you create in ” var/www/html ” at the web server.

Ok, is time for me to play around the web server, will keep you guys posted if I found any special during my hand on experience. :D

Windows Run Command

Did you use windows run command? As a normal user point of view, command and short cut key are very difficult to use, mostly prefer using mouse to click, but when you become a good friend to your computer, command and short cut key help a lot in daily job.

For example, I always like to use ms paint to do some simple editing, to open a paint, I need to click on start button, go to program, then Accessories, only I can found the Paint program there.

Now with using run command, I just require to click start, run, and key in mspaint, then hit Ok

Tips: Some Windows Vista does not have “RUN” button when click on start button, to open run, simply press windows button on your keyboard and press R, the run box will come out already.

Other then this, I experience before few time when looking for some application such as “hyperterminal” in the computer, it does not located in the correct place. If you don’t mind extra step, can go into C drive, one by one folder search, but with using run comand, just type “hypertrm“, hola, it come out already.

More windows run command here

Accessibility Controls
access.cpl
Where to get Accessibility Controls: Start -> Setting -> Control Panel -> Accessibility Option
Actual Location: C:\windows\system32

Add Hardware Wizard
hdwwiz.cpl
Location: C:\windows\system32
Where to get Add Hardware Wizard: Start -> Setting -> Control Panel -> Add Hardware

Add/Remove Programs
appwiz.cpl
Location: C:\windows\system32

Administrative Tools
control admintools

Automatic Updates
wuaucpl.cpl

Bluetooth Transfer Wizard
fsquirt

Calculator
calc

Certificate Manager
certmgr.msc

Character Map
charmap

Check Disk Utility
chkdsk

Clipboard Viewer
clipbrd

Command Prompt
cmd

Component Services
dcomcnfg

Computer Management
compmgmt.msc

Date and Time Properties
timedate.cpl

DDE Shares
ddeshare

Device Manager
devmgmt.msc

Direct X Control Panel (If Installed)*
directx.cpl

Direct X Troubleshooter
dxdiag

Disk Cleanup Utility
cleanmgr

Disk Defragment
dfrg.msc

Disk Management
diskmgmt.msc

Disk Partition Manager
diskpart

Display Properties
control desktop

Display Properties
desk.cpl

Display Properties (w/Appearance Tab Preselected)
control color

Dr. Watson System Troubleshooting Utility
drwtsn32

Driver Verifier Utility
verifier

Event Viewer
eventvwr.msc

File Signature Verification Tool
sigverif

Findfast
findfast.cpl

Folders Properties
control folders

Fonts
control fonts

Fonts Folder
fonts

Free Cell Card Game
freecell

Game Controllers
joy.cpl

Group Policy Editor (XP Prof)
gpedit.msc

Hearts Card Game
mshearts

Hyper Terminal
hypertrm

Iexpress Wizard
iexpress

Indexing Service
ciadv.msc

Internet Properties
inetcpl.cpl

IP Configuration (Display Connection Configuration)
ipconfig /all

IP Configuration (Display DNS Cache Contents)
ipconfig /displaydns

IP Configuration (Delete DNS Cache Contents)
ipconfig /flushdns

IP Configuration (Release All Connections)
ipconfig /release

IP Configuration (Renew All Connections)
ipconfig /renew

IP Configuration (Refreshes DHCP & Re-Registers DNS)
ipconfig /registerdns

IP Configuration (Display DHCP Class ID)
ipconfig /showclassid

IP Configuration (Modifies DHCP Class ID)
ipconfig /setclassid

ava Control Panel (If Installed)
jpicpl32.cpl

Java Control Panel (If Installed)
javaws

Keyboard Properties
control keyboard

Local Security Settings
secpol.msc

Local Users and Groups
lusrmgr.msc

Logs You Out Of Windows
logoff

Mcft Chat
winchat

Minesweeper Game
winmine

Mouse Properties
control mouse

Mouse Properties
main.cpl

Network Connections
control netconnections

Network Connections
ncpa.cpl

Network Setup Wizard
netsetup.cpl

Notepad
notepad

Nview Desktop Manager (If Installed)
nvtuicpl.cpl

Object Packager
packager

ODBC Data Source Administrator
odbccp32.cpl

On Screen Keyboard
osk

Opens AC3 Filter (If Installed)
ac3filter.cpl

Password Properties
password.cpl

Performance Monitor
perfmon.msc

Performance Monitor
perfmon

Phone and Modem Options
telephon.cpl

Power Configuration
powercfg.cpl

Printers and Faxes
control printers

Printers Folder
printers

Private Character Editor
eudcedit

Quicktime (If Installed)
QuickTime.cpl

Regional Settings
intl.cpl

Registry Editor
regedit

Registry Editor
regedit32

Remote Desktop – Very convenience for computer administrator to remote back to their server.
mstsc

Removable Storage
ntmsmgr.msc

Removable Storage Operator Requests
ntmsoprq.msc

Resultant Set of Policy (XP Prof)
rsop.msc

Scanners and Cameras
sticpl.cpl

Scheduled Tasks
control schedtasks

Security Center
wscui.cpl

Services
services.msc

Shared Folders
fsmgmt.msc

Shuts Down Windows
shutdown

Sounds and Audio
mmsys.cpl

Spider Solitare Card Game
spider

SQL Client Configuration
cliconfg

System Configuration Editor
sysedit

System Configuration Utility
msconfig

System File Checker Utility (Scan Immediately)
sfc /scannow

System File Checker Utility (Scan Once At Next Boot)
sfc /scanonce

System File Checker Utility (Scan On Every Boot)
sfc /scanboot

System File Checker Utility (Return to Default Setting)
sfc /revert

System File Checker Utility (Purge File Cache)
sfc /purgecache

System File Checker Utility (Set Cache Size to size x)
sfc /cachesize=x

System Properties
sysdm.cpl

Task Manager
taskmgr

Telnet Client
telnet

User Account Management
nusrmgr.cpl

Utility Manager
utilman

Windows Firewall
firewall.cpl

Windows Magnifier
magnify

Windows Management Infrastructure
wmimgmt.msc

Windows System Security Tool
syskey

Windows Update Launches
wupdmgr

Windows XP Tour Wizard
tourstart

Wordpad
write

After study all the above run command, it speed up a lot for me to open some of this program. Hope the above windowns run command can help you too

Linux Files Types

ordinary files

Recently I come across some linux command during I login to my customer site to retrieve activity log file, and also studies some of the linux file types, and simple command to know what is the file types at Linux Operating System.

Linux uses four basic file types:

  • directories
  • symbolic links
  • block and character device files

You determine a file’s type by issuing the ls -l command and reading the first character of each row of the output.
The typical output of the ls command is as follows:

$ ls –l
total 8
-rw-r–r– 1 root root 22 Oct 6 15:33 anormalfile
brw-rw—- 2 root disk 41, 0 May 5 1998 blockdev
crw-rw-rw- 2 root root 5, 0 May 5 1998 characterdev
drwxr-xr-x 2 root root 4096 Oct 6 15:33 subdir
lrwxrwxrwx 1 root root 11 Oct 6 15:35 symbolic -> anormalfile

Ordinary files begin with a dash (-), directories begin with d, symbolic links begin with the character l, block devices are prefaced with the character b, and character devices begin with the letter c.

Ordinary files
An ordinary file can consist of any kind of data, including executable programs. Most of the files in the Linux file system are of this type.

Directories
A directory is a file that contains other files and directories, and provides pointers to them.
It performs a similar function to a folder in a filing cabinet, in that it enables you to group related files in an organized fashion. However, whereas folders can normally contain files only, directories can contain additional directories, often referred to as subdirectories.

Symbolic links
A symbolic – or soft – link points to the name and location of a completely separate file. So when you open, copy, move or otherwise refer to the link, the operation is in fact performed on the referenced file. This distinction is usually invisible to the user. If the referenced file is removed or renamed, the link is broken and an error occurs if you try to open it.

You can also create hard links. A hard link points to the actual data in a file in exactly the same way as an ordinary file does. Therefore, other than the name, there is no difference between the original file and a hard link that points to the same data, and both can be regarded as ordinary files. You can distinguish a hard link from any other ordinary file only by the number of links that each one has. The number of links is displayed in the second field of an ls -l listing. If this number is greater than one, then you know there are additional hard links to the data.

Device files
All the physical devices that Linux uses are represented by device files.
Device files can be classified as character special or block special. Character-special files represent devices that interact with Linux on a character-by-character, or serial, basis. Printers and terminals are examples of this type of device. Block-special files represent devices such as hard or floppy disks and CD-ROMs, which interact with Linux using blocks of data.

All the device files are contained in the /dev directory – for example, the file associated with the system’s first floppy drive is /dev/fd0.

Device files are extremely powerful because they enable users to access hardware devices such as disk drives, modems, and printers as though they were data files. Therefore, you can move, copy, and transfer data between such devices easily, often without having to use special commands or syntax.

Filenames and pathnames

Every file is assigned a filename, which can be up to 256 characters long. This name can consist of a mixture of uppercase and lowercase letters, numbers, and certain punctuation marks such as the period, dash, or underscore.

Certain characters cannot be used in filenames. For example, you cannot use characters that represent a field separator – such as a comma – or other special characters that have particular meaning to the shell. The special characters that you cannot use are

! @ # $ % ^ & * ( ) [ ] { } ‘ ” \ / | ; < > ‘

Pathnames
You can navigate between directories on the command line using pathnames. To use pathnames, you must understand the directory structure of the Linux file system. The highest-level directory in the Linux file system is the root directory, which is represented by a forward slash (/). Located under the root directory are the top-level directories, followed by one or more subdirectory levels.

linux file type

File structure of a Linux file system
You can move between directories using relative or absolute pathnames.

A relative pathname starts with your current directory. For example, if you want to change to the expenses directory from within your home directory, you enter

cd expenses

Relative pathnames can begin with the name of a file or directory, or with symbolic references to the current directory (.) or its parent directory (..), but never with a forward slash.

linux file type

A simple example of a Linux file system
An absolute pathname shows the full pathname from the root directory (/). For example, the following command allows you to move from your current directory directly to the applic subdirectory in the usr directory that’s located under the root directory:

cd /usr/applic

Inodes, blocks, and special files

Inodes
Every file is assigned a unique inode number. An inode is a structure that defines the file’s location and attributes. You can check for a file’s inode number using the -i option with the ls command. You can view the information that a file’s inode contains using the stat filename syntax. This command output (the stat results) displays the information related to the “results” file’s inode.

$ stat results
File: ”results”
Size: 8
Filetype: Regular file
Mode: (0644/-rw-r–r–)
Uid: ( 0/ root)
Gid: ( 0/ root)
Device: 3,7 Inode: 123256 Links: 1
Access: Tue Jul 25 16:45:00 2000 (00072.18:31:07)
Modify: Thu Jul 20 12:35:20 2000 (00077.22:40:47)
Change: Thu Jul 20 12:35:20 2000 (00077.22:40:47)

In this example, some of the attributes that are displayed include the file type, file size, the owner’s User ID (UID), the number of hard links associated with it, and the file’s creation, access, and modification times.

An inode does not store a file’s name. Filenames are stored in directories with their associated inode numbers. In the example of the stat command, the name of the file is obtained from the filename parameter that you entered.

Blocks
In the Linux file system, files are stored in blocks, which are identically sized segments of disk space. Generally, the size of a block varies from 512 bytes to 32 KB, depending on the Linux installation. The maximum size of a file depends on the block size used in the file system. For example, the maximum file size for an ext2 file system is 2 GB if it uses 512-byte blocks.

Disk systems retrieve data in block-sized chunks, so the larger the block size the more efficient the access. The problem with creating large blocks is that it can waste disk space. For example, if the block size is 4 KB and most files contain only a few bytes of data, most of the 4096 bytes of disk space is wasted for each file. But if you make the block sizes small, disk access will be relatively less efficient.

Some commands, such as df, output disk information in 1 KB blocks, even if the installation stores files in a different block size. A simple way to check your system’s block size is to use the du command to display the disk usage. In this example, the disk usage for all files beginning with “m” is displayed.

$ du -h m*
36k mail
4.0k mail.rc
12k mailcap
12k mailcap.vga
4.0k man.config
4.0k mc.global
148k midi
40k mime-magic
104k mime-magic.dat
8.0k mime.types
4.0k minicom.users
0 motd
4.0k mtab

In this example, the du command output displays the file sizes on the disk in increments of the block size, which is 4.0 KB in this case. One exception to this rule is when zero is displayed, which indicates that the file is completely empty.

Special files
In addition to other file types, Linux makes use of special files, which are system-defined files that perform unique functions when accessed.

Special files and their functions

linux file types

For example, if you need to get rid of unwanted output from a command, you can redirect the output to the /dev/null file. In this example, any errors generated by the find command are redirected from stderr to /dev/null.

$ find / -n myfile 2> /dev/null





Mounting Linux File Systems

After talking on the Linux File Types in the previous entries, is time to learn the basic on mounting linux file systems. For the data contained on hard disks, disk partitions, network drives, and removable media to be accessed under Linux, it is necessary to attach – or mount – the devices containing the data to the Linux directory structure. The reason for this is that Linux treats every device or partition as a separate and independent file system. It also views all data as though it were in a subdirectory of the root (/) directory, regardless of the kind of device on which it is stored – even when it is kept on a separate computer.

disk drive

It is an important part of the role of the Linux system administrator to ensure that file systems are mounted correctly, whether at boot time or manually, to ensure that all required data is available at the expected locations.

Advantages of mounting Linux file systems and devices

Devices are mounted at predetermined directories below the root file system. These are usually, although not always, special directories created for the purpose. The file systems that belong under the /var, /home, and /usr directories, for example, are kept on separate partitions or devices from the root file system. Network machines are frequently configured so that the /home data for all machines is actually stored on a single Network File System (NFS) server, which is then mounted under the /home directory on each individual machine. This enables users to access their own home directories in the usual locations, regardless of which computers they are actually logged on at.

Because all devices and file systems appear below the root directory, the transition from one device or file system to another is entirely seamless. So a user can access a file on an NFS server over a network as though the file were on the local hard drive.

Linux makes it easy to expand the space available to overloaded file systems by mounting new partitions. For example, say the directory /home/project is filling up with so much data that it threatens to take over the hard drive on which it is stored. The system administrator can easily move the data from the existing /home/project to an empty disk partition with more available space, and remount the new partition at /home/project. To users, there won’t be a difference between the old configuration and the new one – they still access their files under /home/project, even though the files are now stored on a completely different hard drive.

It is important to mount file systems in the correct order. This is sometimes necessary to ensure that the mount point required by a given file system exists and is available when the mount command is issued. Taking the /home/project example again, the project data exists on one disk partition and all the remaining /home data is on another, including the /home/project directory under which the /home/project partition is to be mounted. Clearly, if an attempt is made to mount the /home/project partition before the /home partition, this will result in an error, as the /home/project directory doesn’t yet exist. The correct order is to mount the /home partition first, followed by the /home/project partition.

It is also important to be aware when mounting devices under a given directory that any files previously available under that directory will be hidden while the device is mounted. So any files that still remain in the /home/project directory of the /home partition will become invisible as soon as the /home/project partition is mounted in that directory. Furthermore, the disk space those files occupy will remain unavailable to the system until the project partition is unmounted. You should therefore check what already exists in a directory before you use it as the mount point for some other file system, to avoid duplicating files or wasting disk space.

File system mounting management

To assist in the management of file system mounting, a special directory called /mnt exists in most Linux distributions. This directory contains dedicated directories for mounting specific devices such as CD-ROM, floppy disk, and zip disk drives. This is a convenient way to ensure that such devices have a suitable mount point available to them at all times.

Removable media

It is impossible to access the data on removable media without mounting them first. To use a floppy disk drive, for example, you need to issue the mount command before the disk contents will be visible to the system.

Similarly, when you have finished using any kind of removable medium, it is very important to unmount the device using the umount command before removing the disk from the drive. This is because Linux improves efficiency by often storing information in memory buffers rather than writing it directly to the disk. If a removable disk is removed without being unmounted first, there is a high probability of data loss, just as there is from a hard drive if you shut down the system by turning off the power without running the proper shutdown procedure.





Why Use The Linux Shell?

Most PC users communicate with the operating system on their machines using a graphical user interface (GUI), such as those used in Microsoft Windows 2000 or Mac OS 9. Linux has its own GUIs, most notably GNU Network Object Model Environment (GNOME) and the K Desktop Environment (KDE). GUIs provide buttons, menus, icons, and all the other point-and-click features that have simplified modern computing so greatly. However, it is a mistake to assume that GUIs are always the best way to communicate with an operating system. Although GUIs certainly provide simplicity, they tend to obscure some of a computer’s capabilities from the user. This is where a shell comes in.

linux shell

Advantages of using a shell

Greater control
A shell is a program that acts as an interface between the user and the operating system, just as a GUI does. However, a shell works without graphics – when you use one, you issue instructions to the operating system by typing in commands. In fact, the shell is often referred to as a command interpreter.

This may seem like a return to basic computing, but a command-line interface lets you exercise a degree of control over the operating system that would otherwise be lacking. There are a number of reasons for this:

  • with a GUI, only the options provided by the interface are available to the user
  • lack of space on a screen can limit the number of options that a GUI displays
  • no standard methods exist within GUIs for performing standard command-line tasks, such as linking commands in sequences, redirecting output from one destination to another, or collecting commands into scripts

A disadvantage of using a command-line interface is that the user needs to learn a wide variety of sometimes cryptic commands and their associated options. However, the commands are more powerful and adaptable than their GUI counterparts, because they can be extended and fine-tuned through the use of options. An expert user of a command-line interface can issue complex commands very quickly. Techniques also exist to link multiple commands together with pipes and redirections, so that the output of one command becomes the input of another. Linux can interpret commands issued using the shell more quickly than GUI commands. This is because shell commands are nothing more than simple ASCII text. Some shells even enable you to define your own commands.

Automation of common tasks
A shell has another advantage over a GUI in that it keeps a history list of recently issued commands. This enables a user to step back and forth through this list, reusing commands at any point. In addition, a shell enables you to string commands together to form a shell script. These scripts work in a similar way to batch files, issuing multiple commands as one. You can use them to automate common tasks that would otherwise require you to issue several, consecutive commands.

Speed and efficiency
In hardware terms, a shell is a more attractive proposition than a GUI. Shells are much less resource-intensive than GUIs – they require less memory, for example. This means that a command issued in the shell will run more quickly and efficiently than the same command run in a GUI. It also means that a shell supports Linux’s multitasking environment, in which multiple tasks run simultaneously, more comfortably than a GUI, in which the GUI itself competes for CPU resources.

Shell evolution

Since its creation as a derivative of UNIX, Linux has given rise to a number of shells, which have evolved along with the operating system itself. When a new shell is developed, it doesn’t spell the end for all previous shells. Many different Linux shells are available, and each has particular strengths. The one you use depends on your own preferences and on the task you wish to undertake.

The default shell in most Linux installations is the Bourne Again shell, or /bin/bash. It is a successor to the Bourne shell, or /bin/sh, which was an early and less powerful Linux shell. The Bourne Again shell was created and is distributed by the Free Software Foundation. It offers features such as command-line editing and filename completion. It is an ideal first shell for Linux newcomers. In addition, bash supports the syntax used by another Linux shell called the C shell, or /bin/csh, which increases its flexibility.

You can find out which shell you’re running at any time by typing the command echo $SHELL at the shell prompt. The default shell is specified in the /etc/passwd file and can be changed there for each user.

Since we are talking about Linux here, you might want to know how to mount linux file system also understand on Linux File Types.






Special Characters On The Linux Command Line

Specially defined characters are essential for many of the Linux shell’s powerful features, such as filename completion and command substitution. The shell interprets these characters in a different way from other, regular characters on the command line. However, if you want to disable these characters, you can use a process called quoting.

Filename completion characters

Filename completion characters are metacharacters that enable you to abbreviate filenames or directory names. This saves time and lets you process files selectively, even if you don’t know their full names or locations.

Commonly used filename completion characters are included in the table below.

Filename completion characters
special characters on linux command line

The * character (asterisk) is the most frequently used file completion character. You can use the string b*, for example, to match all the filenames beginning with the letter “b”. You can also use multiple asterisks to define a file. For example, *xx*.gif retrieves any filename that contains “xx” anywhere in its name and that has the .gif extension.

The ? character (question mark) represents any single character, so the string ??? refers to all files with a three-letter name. This special character is more restrictive than the asterisk, because it requires the character to be present. For example, the code file?.txt signifies all files that begin with “file”, include one additional character, and have the .txt extension. So the filename “file1.txt” matches, but “file.txt” and “file01.txt” don’t.

Using [] characters (square brackets) allows for a more selective approach to retrieving files. The string [abc] will find files a, b, and c only. You can include a hyphen between characters inside the brackets to match a continuous range of characters. To specify the characters 0 through 9, for example, it is a lot easier and less time-consuming to type [0-9] rather than [0123456789]. If the brackets precede an asterisk, as in [0-9]*, filenames starting with any numbers between 0 and 9 are found. The pattern *[0-9] will match filenames ending with numbers between 0 and 9. Inserting an exclamation mark inside the brackets, as in [!b], will invert the pattern, matching any characters or ranges not specified in the brackets but ignoring those that are.

The $ (dollar sign) is used to identify shell variables at the command line. Variables are values that have been associated in memory with some kind of identifier. Variables have many uses in Linux. To give a simple example, a variable with the identifier PATH contains the list of directories within which the shell can search for executable files. To view this list, you invoke the following command:

echo $PATH

If you entered the command echo PATH, it would print the literal string “PATH”, rather than the value of the PATH variable, on your terminal.

The ~ character (tilde) enables you to refer quickly and easily to your home directory, no matter where in the file system you might be. Say that your current working directory is /usr/local/bin and you have a file called “usernames” in your own home directory, which you want to edit with vi. Rather than having to type the complete path to the file, you can just issue the command

vi ~/usernames

Quoting special characters

There are occasions when you might want to suppress the special meanings of metacharacters. A special character must be quoted in order to represent its own literal meaning rather than its special meaning to the shell. Quoting causes the shell to overlook the unique capabilities of special characters and negate parameter expansion. This mechanism uses the following quote symbols:

  • \ (backslash)
  • ” (double quotes)
  • ‘ (single quotes)
  • ` (backquote)

The backslash is also known as the bash shell escape character. This is because it turns off or “escapes” the special meaning of the character that follows it. For example, as we have already seen, the following command returns the value of the PATH environment variable:

echo $PATH

However, the following command will return the literal output “$PATH”, because the backslash negates the special meaning of the dollar sign:

echo \$PATH

If a line itself ends with a backslash, it acts as a continuation character for the line and the newline character is ignored.

Single quotes negate the translation of all special characters. They prevent the substitution of alternative values for the characters. For example, the following command will output a list of single-character filenames:

ls ?

However, this command will attempt to list the file with the literal name “?”:

ls ‘?’

Double quotes cause most metacharacter special meanings to be ignored. The exceptions to this rule are the dollar sign, backquote, and backslash. So double quotes have the effect of canceling the process of filename generation by the shell, but still allow the expansion of shell variables and command substitution. The dollar sign and backquote continue to function as special characters when included between double quotes. The backslash character only does so when it’s followed by a dollar sign, backquote, double quote, backslash, or a newline character. In these circumstances, the backslash itself is removed and the special meaning of the following character is ignored. This makes it possible to quote a double quote between double quotes if it is preceded by a backslash. For example, the commands echo”\”" or echo\” output a double quote character by suppressing the special meaning of the embedded double quote.

The backquote is still often used for command substitution, although the $() combination (a dollar sign and brackets) is generally preferred. The shell interprets the text between a pair of backquotes as a command before translating the rest of the command line. The output of the command replaces the original backquoted text.
In the following code, the double quotes disable the date command:

> echo “date”
date

However, the backquotes in this command enable command substitution to occur:

>echo ‘date’
Thu Jun 10 17:18:56 IST 2004





Understanding Disk Quotas In Linux

After talk about special character on linux command last week, now let understand on disk quota here. In Linux, a system of disk quotas enables the system administrator to restrict disk usage by individuals and groups.

linux

Quotas can specify

  • the maximum amount of total disk space allotted to a user or group
  • The maximum number of files a user or group can create

You assign quotas by partition, so an individual or group who creates files on two partitions may have a different quota for each partition, or a quota for only one of the two partitions.

User and group quotas
User quotas and group quotas are independent of each other – so the value of the group quota is not the sum of the values of the users’ quotas in a group. When a user attempts to create a file, Linux first checks if there is a group quota for the user’s group. If a group quota for the group to which the user belongs has already been filled, the user can’t create the file, regardless of the status of the user’s quota. To create the file, the user must change groups. Every file that an individual user creates counts towards the quota of the user’s group. If the user isn’t part of a quota-restricted group, or if group quotas aren’t switched on for a partition, the user can create files on the partition as long as the user’s quota isn’t filled.

Hard and soft limits
When you set quotas, you can specify both a hard and a soft limit. When a user exceeds a soft limit, a warning is issued, but the user can continue to create files for the duration of a grace period. The default grace period is seven days, but the administrator can change this period. At the end of the grace period, the user must reduce their disk usage so that they don’t exceed the soft limit. The soft limit acts as a warning to the user that they are approaching a hard limit. When the user reaches a hard limit, they can no longer create files at all.

Viewing quotas
The quota command checks the file system in the /etc/fstab directory for quotas and reports them. As a root user, you can use the quota command to view the quotas of any user or group on a system. Users can check their own quotas and the quotas of any groups to which they belong. The syntax for viewing quotas is

quota option who

In the syntax, who can be either a username or a group name.

The following options are used with the quota command:

  • g checks a group quota
  • u checks a user quota
  • q checks which quotas have been filled

Users can use the -g option and the -u option together, to check both their user and group quotas.

The repquota command reports quotas and provides a summary of disk usage for a specified file system. So you can see how many files a user or group owns in a file system and how much space they occupy. The syntax for using the repquota command is

repquota options file_system

The following table shows the repquota command options.

Options for the repquota command

disk quotas in linux

As for the quota command, the root user can use the repquota command to view all quotas in the system, whereas other users can view only their own user and group quotas.

Related Posts Plugin for WordPress, Blogger...