How to find File-Directory creation date ?

$stat <file name> command basically displays file or file-system status. stat command is used to find Access , Modify, Change date and time for any file or directory in Unix like operating systems. e.g

$stat /root/install.log
File: `/root/install.log'
Size: 17154           Blocks: 48         IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 1177346     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2011-09-30 16:24:39.000000000 +0100
Modify: 2011-09-30 16:28:59.000000000 +0100
Change: 2011-09-30 16:29:04.000000000 +0100


As show in above example, It also displays owner and group associated with particular file. permissions on particular file. etc
There is no creation date available as far as I know unless you log the file creation date in a script. You can use the stat command as mentioned above to get the time stamp for last access, last change and last modification time.

$stat --version
stat (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Michael Meskes.

In linux, centos, fedora, redhat, suse, ubuntu, mint, debian, mandrake, caldera, yolinux, gnulinux

How to find directory last change / modification date and time?
How to find file / filesystem last change / modification date and time?
How to find last “access” date and time for file / directory?

As we are talking about time stamp (access, change, modify) for files / directories in linux, we much consider talking about “touch” command.
“touch” [options] <file name(s)>  :
Mainly touch command is used to change time stamp for files. If file does not exist then touch command creates file with current time stamp. e.g

$touch file1 file2 file3

will create 3 files in your present working directory with current time stamp.
Several of touch’s options are specifically designed to allow the user to change the timestamps for files. For example, the -a option changes only the access time, while the -m option changes only the modification time. The use of both of these options together changes both the access and modification times to the current time, for example:

$touch -am file11

The -r (i.e., reference) option followed directly by a space and then by a file name tells touch to use that file’s time stamps instead of current time. For example, the following would tell it to use the times of file4 for file5:

$touch -r myfile yourfile

The -B option modifies the timestamps by going back the specified number of seconds, and the -F option modifies the time by going forward the specified number of seconds. For example, the following command would make file7 30 seconds older than file6.

$touch -r myfile -B 30 yourfile

Importance of touch command.
Ah, beware before you use touch command on production system.
How to change times tamp using touch command?

What is PHP? server-side-scripting

What is PHP? <?php … ?>

PHP (Hypertext Preprocessor) is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. PHP is a scripting language designed to fill the gap between SSI (Server Side Includes) and Perl, intended largely for the web environment. PHP has gained quite a following in recent times, and it is one of the forerunners in the Open Source software movement. Its popularity derives from its C-like syntax, and its simplicity. PHP is currently divided into two major versions: PHP 4 and PHP 5, although PHP 4 is deprecated and is no longer developed or supplied with critical bug fixes. PHP 6 is currently under development.

PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.

  • PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.
  • It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.
  • PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the Unix side. The MySQL server, once started, executes even very complex queries with huge result sets in record-setting time.
  • PHP supports a large number of major protocols such as POP3, IMAP, and LDAP.

Common uses of PHP:

  • Access control on websites / web applications using php. you can restrict users to access some pages of your website.
  • PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them.
  • PHP can handle forms, i.e. gather data from files, save data to a file, through email you can send data, return data to the user.
  • You add, delete, modify elements within your database through PHP.
  • Access cookies variables and set cookies.
  • It can encrypt data.

“Hello Web World” Script in PHP:

To get a taste of PHP, first start with simple PHP scripts. Since “Hello, Web World!” is an essential example, first we will create a friendly little “Hello, World!” script.

As mentioned earlier, PHP is embedded in HTML. That means that in amongst your normal HTML (or XHTML if you’re cutting-edge) you’ll have PHP statements like this:

<html>
<head>
<title>Hello Web World</title>
<body>
    <?php echo "Hello, Web World!";?>
</body>
</html>

It will produce following result:

Hello, Web World!

If you examine the HTML output of the above example, you’ll notice that the PHP code is not present in the file sent from the server to your Web browser. All of the PHP present in the Web page is processed and stripped from the page; the only thing returned to the client from the Web server is pure HTML output.

All PHP code must be included inside one of the three special markup tags ate are recognised by the PHP Parser.

<?php PHP code goes here ?>

<?    PHP code goes here ?>

<script language="php"> PHP code goes here </script>

Most common tag is the <?php…?> and we will also use same tag in our tutorial.

From the next chapter we will start with PHP Environment Setup on your machine and then we will dig out almost all concepts related to PHP to make you comfortable with the PHP language.
Is PHP a buzz word ?
Why php is so popular ?
PHP uh.. never heard of it ? what is php?
php a hypertext preprocessor?
A powerful server-side-scripting language, PHP.

What is sed? linux/unix

sed is stream editor for filtering and transforming text.
Sed  is a stream editor.  A stream editor is used to perform basic text transformations on an input stream (a file or input from  a  pipeline). While  in  some  ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s),  and is consequently more efficient.  But it is sed’s ability to filter text in a pipeline which particularly distinguishes it from other  types  of  editors.

sed is very useful when you are making same changes on multiple files or multiples times in same file. Imagine using regular text editor for such scenario. you will feel rest-less when you do such changes manually. once you start using sed, those changes will be done easily.. quickly..How to find version of sed on your system ?

$sed --version
GNU sed version 4.2.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
$man sed
--- Read this man page for more details.

Example 1 :

$sed 's/wrong pattern/correct pattern/' original.file

substitutes in EVERY line of a file called wrong.file the first and only the first occurrence of “wrong pattern” by “good pattern” and displays the corrected text at standard output. Check the output until everything is ok, then redirect the output (you can not overwrite the old file)

$sed 's/wrong pattern/correct pattern/' original.file > updated.file

Another way to redirect the output:

$cat wrong_file.txt | sed 's/wrong pattern/good pattern/g' > correct_file.txt

If you want to replace the “wrong pattern” globally (whole file), e.g. several times a line, then enter

$sed 's/wrong pattern/good pattern/g' wrong.file > correct.file

To replace the “wrong pattern” only once at the very first occurrence we need to adress the substitution. Either we know at which line the “wrong pattern” is located, i.e. line 16, then type

$sed '16s/wrong pattern/good pattern/' original.file > correct_new.file

If we don’t know the position of the “wrong pattern”, we need to give an address range where sed should do the substitution, i.e.

$sed '1,16s/wrong pattern/correct pattern/' original.file > correct_new.file

but in an general case we won’t know if the “wrong pattern” occurs exactly once in the first 20 lines… But we can define the range with the pattern itself, so we expect

$sed '1,/wrong pattern/s/wrong pattern/correct pattern/' correct_new.file

to do the job: start at line 1 and substitute until the first occurrence is found. Unfortunately this doesn’t work IF the “wrong pattern” appears in the first AND second line! Because the 1 activates the first line the second address of the range is at least the second line. In this case the “wrong pattern” will be substituted in both lines. What we need is

$sed '0,/wrong pattern/s/wrong pattern/good pattern/' wrong.file

to prevent the activation of the second line where the “wrong pattern”
could appear again.
How to perform different append operations using sed?
Append content of file year.txt at line 3 of data.txt.

$sed '3 r file1.txt' file2.txt > file1_2.txt

Append after each line with the string “pattern” a line with text “new”.

$sed '/pattern/anew' original.file

Append after each line a new line with text “new”.

$sed 'a/new' original.file

 Why “sed” is system administrators friend ?
How do is edit multiple files in 1 go ?
Make your edit/update/delete/replace easier with sed?
Sed “The King” of stream / patter edditing / formating and transforming

Getting started with Postgresql. Centos Redhat Fedora

How to install PostgreSQL on Centos / Redhat / Fedora.

Hi All, In this article I want to quickly show you specific steps to install PostgreSQL 8 database on CENTOS Linux 5. As we all know that we can use yum to install packages / softwares, I am using yum for this installation. To make sure that you have everything needed do:

#yum list | grep postgresql

Then verify that you see:

postgresql.i386, postgresql-server.i386 and postgres-libs.i386. if you have 64 bit version then you will see x86_64.

Centos installation comes with postgresql-lib installed. If it is not installed then please follow:

#yum install postgresql-libs

Now, the general installation. As root install postgres core and postgresql server:

#yum install postgresql postgresql-server

We need a seperate user as owner of postgresql database owner so create postgres user:

#adduser postgres

A directory to store datafiles caleed the ‘datafile’ for the database:

#mkdir -p /usr/local/pgsql/data

It is necessary to change ownership of the data files to the postgres user:

#chown postgres /usr/local/pgsql/data

now change your role to postgres user from root user:

#su – postgres

Initialize the datafiles for the database:

#/usr/bin/initdb -D /usr/local/pgsql/data

In most of the cases it will starStart the database with initialized datafiles as the background process (&) and log all messages and errors (2&1) in the logfile:

#/usr/bin/postgres -D /usr/local/pgsql/data > logfile 2>&1 &

Create the test database:

#/usr/bin/createdb firstdb

Log in to the test database:

$/usr/bin/psql firstdb
Welcome to psql 8.3.7, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

firstdb=>

Setup PostgreSQL database (RDBMS) on Centos-Redhat-Fedora.
Install and configure PostgreSQL database (RDBMS) using rpm. (redhat packages)
One of the best open source RDBMS system – PostgreSQL (pgsql)
Powerful yet free RDBMS system with active development – PostgreSQL.

Getting started with PostgreSQL. ubuntu debian mint

PostgreSQL database server installation and configuration in debian / ubuntu

Introduction :
PostgreSQL is a fully featured object-relational database management system. It supports a large part of the SQL standard and is designed to be extensible by users in many aspects. Some of the features are: ACID transactions, foreign keys, views, sequences, subqueries, triggers, user-defined types and functions, outer joins, multiversion concurrency control. Graphical user interfaces and bindings for many programming languages
are available as well.

Postgresql Database Installation in Debian

If you want to install the PostgreSQL base system as well as a textual clientrun the following command from your shell

apt-get update
apt-get install postgresql-8.3 postgresql-client-8.3 postgresql-contrib-8.3 postgresql-common

This will install a lot of package dependencies as well. The version of PostgreSQL installed should be 8.3.7 on a debian lenny (5.0.1 in my case) system. If you want to check the official documentation click here. http://www.postgresql.org/docs/8.3/interactive/index.html

NOTE: After installation if you will try to start postgresql then it may not start if you have not created database cluster.
it is simple to initialize database cluster [It is being used to store databases].

#pg_createcluster 8.3 main –start That will display some information on your screen. once it completes successfully, you will able to login to postgresql database using default way to login as mentioned below.

The only (default) way to log into your newly created database system is to log as root, then to log as user postgres, by issuing

#su
#su postgres
#psql template1
#template1=# \q
#exit

However, you would probably like to be able to login as your unix user, or any other user you choose. There are several ways to set up these accesses, so let’s decomposeAlowing local users to login is done by editing the /etc/postgresql/pg_hba.conf file (a complete documentation of this file is available here). There, you have to retrieve a series of lines like the following ones

local all postgres ident sameuser
#
# All other connections by UNIX sockets
local all all ident sameuser
#
# All IPv4 connections from localhost
host all all 127.0.0.1 255.255.255.255 md5
# All IPv6 localhost connections
host all all ::1 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff ident sameuser
host all all ::ffff:127.0.0.1/128 ident sameuser
#
# reject all other connection attempts
host all all 0.0.0.0 0.0.0.0 reject

This file has limited accesses but we will come back here later.Now what we have told PostgreSQL is that all users on the local machine should be able to access all databases, using their UNIX login and passwords. You need to restart your database to take new changes effect

Restart postgresql using the following command

#/etc/init.d/postgresql restart

Now the problem is that you have authorized users to log into the database, but they will only be able to log in if they also exist in the database. So you need to create accounts with their usernames. This is done by issuing the createuser command as user postgres as follows

#su postgres
#createuser firstuser
#exit

The createuser command will ask you if the user should be able to create databases or create new users. Answer truly.

Now you have a new user in the database, and you should be able to connect as this user (let’s call him firstuser) like this:

#su – firstuser
#firstuser@localhost:~$ psql -W template1
#template1=# \q
#exit

The -W parameter is to ask for a password prompt. You should enter your system password when asked.
So that’s it, we got the first part of this installation running. Now let’s prepare this for the web.

If some of your web scripts are going to need a connection to the database, you will need to grant them some access via a new user, reserved for this web usage.

Let’s first create this new user (as user postgres). Let’s call him webuser.

#su postgres
#createuser webuser
#exit

Now you want to give him access to one or several databases (let’s say you will let him access the databases which name is web). To do this, you need to edit once more the pg_hba.conf file. Retrieve the first line below and write the second one just beneath the first.

host all all 127.0.0.1 255.255.255.255 md5
host web webuser 127.0.0.1 255.255.255.255 md5

Would you like to give this user access from any computer on the sub-network 192.168.0.xxx, you would have to add the following line

host web webuser 192.168.1.1 255.255.255.0 md5

You have to grant him access to the host as it will probably use the TCP/IP protocol to get a connection to the database, and that’s what host is for. But as you have given him an md5 authentication type, you need to give him a password as well. In order to do this, you need to connect to the database and issue a special command, all as postgres user:

#su postgres
#postgres@localhost:~$ psql template1
#template1=# alter user webuser password ‘some_password’;
#ALTER USER
#template1=# \q
#exit

Now the user should have a nice ‘some_password’ password that you can use after restarting PostgreSQL to make it remember your changes to pg_hba.conf.

Restart postgresql using the following command

#/etc/init.d/postgresql restart

And you should be able to create his own database if you gave him the permission

#createdb -h localhost -U webuser -W web

And connect to this newly-created database using the following command

#psql -h localhost -U webuser -W web

As you might have noticed, we use -h localhost here. This is to force the PostgreSQL client to use TCP/IP instead of UNIX sockets. If you don’t want is, you need to add a new line into the “local” category of pg_hba.conf for the user webuser to connect via sockets.The line would be something like

local web webuser md5

Using SQL

The first important command you might want to know is

#psql -h localhost -U webuser -W -l

This will give you a list of available databases.

Now connect to the PostgreSQL database using the psql client, and let’s create a small table, just after a few tests

web=> SELECT version();
web=> SELECT current_date;
web=> SELECT 2+2;
web=> \h
web=> \d
web=> \dt
web=> CREATE TABLE weather(
web=> city varchar(80),
web=> temp_lo int, — low temperature
web=> temp_hi int, — high temperature
web=> prcp real, — precipitation
web=> date date
web=> );
web=> INSERT INTO weather (city, temp_lo, temp_hi, prcp, date)
web=> VALUES (‘London’, 12, 13, 0.0, ’2005-05-29′);
web=> INSERT INTO weather (date, city, temp_hi, temp_lo)
web=> VALUES (’2005-05-19′, ‘Miltons’, 10, 25);
web=> SELECT city, temp_lo as ‘Lowest Temperature’, temp_hi as ‘Highest Temperature’ FROM weather;
web=> SELECT city FROM weather WHERE temp_lo < 30;
web=> SELECT max(temp_lo) FROM weather;
web=> UPDATE weather SET temp_lo = 18 WHERE city = ‘London’;
web=> SELECT * FROM weather;
web=> DELETE FROM weather WHERE prcp IS NULL;
web=> SELECT * FROM weather;
web=> \q

Now you’ve had a nice overview of several SQL statements and how to use them in PostgreSQL.

Later, you might want to create a table with a numerical sequence as an index. This link will help you get through this step which I find counter-intuitive and user-unfriendly at will. You might as well know of a shortcut. If you want to create a default auto-incremental key that will be used by your table, you need to define (for every table) a SEQUENCE. This id done, for the weather table above, like this (with the help of user comments here):

web=> CREATE SEQUENCE my_table_pk_sequence;
web=> CREATE TABLE weather(
web=> id int not null default nextval(‘my_table_pk_sequence’) PRIMARY KEY,
web=> city varchar(80),
web=> temp_lo int, — low temperature
web=> temp_hi int, — high temperature
web=> prcp real, — precipitation
web=> date date
web=> );

And then insert elements as before, ignoring the id field

web=> INSERT INTO weather (date, city, temp_hi, temp_lo)
web=> VALUES (’2009-06-20′, ‘London’, 14, 27);
web=> SELECT * FROM weather;

This should have inserted an auto-incremented id.

Postgresql: show databases, show tables, show columns

Hi all, In this article you will know some very very basic commands about postgresql. When i started learning postgresql, I found bit strange when “show databases”, “show tables”, and “show columns” command did not work. I was using mysql and I am still using mysql but it is just matter of learning one more database as postgresql started becomming popular now. So.. If you have question in your mind how to list databases, tables and colums in postgresql database then I have answer for you.

First of all to connect to postgresql you need to use :
psql -d “database name” -h “hostname OR IP” -U “user name” command. This will prompt you to enter password.
Note: By default you can not connect to postgresql with user name root.

  1. To list databases aaccessible to user you connected with
    mysql: SHOW DATABASES
    postgresql: \l
    postgresql: SELECT datname FROM pg_database;
  2. To list tables in your database 
    mysql: SHOW TABLES
    postgresql: \d
    postgresql: SELECT table_name FROM information_schema.tables WHERE table_schema = ‘public’;
  3. To list columns in particular table / schema use : 
    mysql: SHOW COLUMNS
    postgresql: \d table
    postgresql: SELECT column_name FROM information_schema.columns WHERE table_name =’table‘;
  • Login to post comments

PostgreSQL Cheat Sheet

CREATE DATABASE

CREATE DATABASE dbName;

CREATE TABLE (with auto numbering integer id)

CREATE TABLE tableName (
 id serial PRIMARY KEY,
 name varchar(50) UNIQUE NOT NULL,
 dateCreated timestamp DEFAULT current_timestamp
);

Add a primary key

ALTER TABLE tableName ADD PRIMARY KEY (id);

Create an INDEX

CREATE UNIQUE INDEX indexName ON tableName (columnNames);

Backup a database (command line)

pg_dump dbName > dbName.sql

Backup all databases (command line)

pg_dumpall > pgbackup.sql

Run a SQL script (command line)

psql -f script.sql databaseName

Search using a regular expression

SELECT column FROM table WHERE column ~ 'foo.*';

The first N records

SELECT columns FROM table LIMIT 10;

Pagination

SELECT cols FROM table LIMIT 10 OFFSET 30;

Prepared Statements

PREPARE preparedInsert (int, varchar) AS
  INSERT INTO tableName (intColumn, charColumn) VALUES ($1, $2);
EXECUTE preparedInsert (1,'a');
EXECUTE preparedInsert (2,'b');
DEALLOCATE preparedInsert;

Create a Function

CREATE OR REPLACE FUNCTION month (timestamp) RETURNS integer
 AS 'SELECT date_part(''month'', $1)::integer;'
LANGUAGE 'sql';

Table Maintenance

VACUUM ANALYZE table;

Reindex a database, table or index

REINDEX DATABASE dbName;

Show query plan

EXPLAIN SELECT * FROM table;

Import from a file

COPY destTable FROM '/tmp/somefile';

Show all runtime parameters

SHOW ALL;

Grant all permissions to a user

GRANT ALL PRIVILEGES ON table TO username;

Perform a transaction

BEGIN TRANSACTION
 UPDATE accounts SET balance += 50 WHERE id = 1;
COMMIT;

Basic SQL

Get all columns and rows from a table

SELECT * FROM table;

Add a new row

INSERT INTO table (column1,column2)
VALUES (1, 'one');

Update a row

UPDATE table SET foo = 'bar' WHERE id = 1;

Delete a row

DELETE FROM table WHERE id = 1;

http://www.mydailylinux.com/my-daily-linux/node/pgsql-cheat-sheet

How to add swap space on-the-fly ? unix-linux

In Linux, as in most other Unix-like operating systems, it is common to use a whole partition of a hard disk for swapping (paging). However, with the 2.6 and later Linux kernel, swap files are just as fast as swap partitions, although Red Hat recommends using a swap partition. The administrative flexibility of swap files outweighs that of partitions; since modern high capacity hard drives can remap physical sectors, no partition is guaranteed to be contiguous. You can add swap file as a dedicated partition or use following instructions to create a swap file.

Procedure to add a swap file. Steps to add swap file

You need to use dd command to create swap-file. Next you need to use mkswap command to set up a Linux swap area on a device or in a file.

a) Login as the root user
b) Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):
# dd if=/dev/zero of=/swapfile1 bs=1024 count=524288 
c) Set up a Linux swap area:
# mkswap /swapfile1 
d) Activate /swapfile1 swap space immediately:
# swapon /swapfile1 
e) To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using text editor such as vi:
# vi /etc/fstab 
Append following line:
/swapfile1 swap swap defaults 0 0
So next time Linux comes up after reboot, it enables the new swap file for you automatically.
g) How do I verify swap is activated or not?
Simply use free command:
$ free -m

This is very useful when you want to add more memory to your system.

How to increase memory on Linux / Unix System ? without rebooting
How to add paging files in Linux / Unix System ?  without rebooting
What is Swap file in Linux / Unix System ? without rebooting

The /proc filesystem

Linux System Configuration and the proc filesystem

The /proc filesystem

The /proc is a virtual filesystem which is getting mounted everything when your system starts. It is used to store many system configuration parameters. It is a filesystem that resides in the kernels memory. Some of the areas in this filesystem cannot be written to by the root user including /proc/sys. Much information here is based on the proc man page. Fro more information refer to that page. Elements of the proc filesystem include:

* Numerical subdirectories getting created for every process. The following files or directories are contained in each processes directory:

  • 1. cmdline – The command line the process was invoked with
    2. cwd – A link to the current working directory of the process
    3. environ – The process environment
    4. exe – A pointer appearing as a symbolic link to the binary that was executed.
    5. fd – A subdirectory with one entry per file that the process has open. 0-std input, 1-std output, 2-std err.
    6. maps – Contains the currently mapped memory regions and their access permissions. The format is:
address perms offset dev inode filename
08048000-0805d000 r-xp 00000000 08:08 81491 /sbin/init
0805d000-0805e000 rwxp 00015000 08:08 81491 /sbin/init
0805e000-081ab000 rwxp 0805e000 00:00 0 [heap]
b7e1d000-b7e1e000 rwxp b7e1d000 00:00 0
b7e1e000-b7f59000 r-xp 00000000 08:08 538659 /lib/tls/i686/cmov/libc-2.5.so
b7f59000-b7f5a000 r-xp 0013b000 08:08 538659 /lib/tls/i686/cmov/libc-2.5.so
b7f5a000-b7f5c000 rwxp 0013c000 08:08 538659 /lib/tls/i686/cmov/libc-2.5.so
b7f5c000-b7f5f000 rwxp b7f5c000 00:00 0
b7f72000-b7f74000 rwxp b7f72000 00:00 0
b7f74000-b7f8d000 r-xp 00000000 08:08 504949 /lib/ld-2.5.so
b7f8d000-b7f8f000 rwxp 00019000 08:08 504949 /lib/ld-2.5.so
bfdc0000-bfdd6000 rw-p bfdc0000 00:00 0 [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]

Permission s=private, s=shared
7. mem – The memory of the process that accesses the /dev/mem device
8. root – Points to the root filesystem
9. stat – Status information about the process used by the ps(1) command. Fields are:
1. pid – Process id
2. comm – The executable filename
3. state – R (running), S(sleeping interruptable), D(sleeping), Z(zombie), or T(stopped on a signal).
4. ppid – Parent process ID
5. pgrp – Process group ID
6. session – The process session ID.
7. tty – The tty the process is using
8. tpgid – The process group ID of the owning process of the tty the current process is connected to.
9. flags – Process flags, currently with bugs
10. minflt – Minor faults the process has made
11. cminflt – Minor faults the process and its children have made.
12. majflt
13. cmajflt
14. utime – The number of jiffies (processor time) that this process has been scheduled in user mode
15. stime – in kernel mode
16. cutime – This process and its children in user mode
17. cstime – in kernel mode
18. counter – The maximum time of this processes next time slice.
19. priority – The priority of the nice(1) (process priority) value plus fifteen.
20. timeout – The time in jiffies of the process’s next timeout.
21. itrealvalue – The time in jiffies before the next SIGALRM is sent to the process because of an internal timer.
22. starttime – Time the process started after system boot
23. vsize – Virtual memory size
24. rlim – Current limit in bytes of the rss of the process.
25. startcode – The address above which program text can run.
26. endcode – The address below which program text can run.
27. startstack – The address of the start of the stack
28. kstkesp – The current value of esp for the process as found in the kernel stack page.
29. kstkeip – The current 32 bit instruction pointer, EIP.
30. signal – The bitmap of pending signals
31. blocked – The bitmap of blocked signals
32. sigignore – The bitmap of ignored signals
33. sigcatch – The bitmap of catched signals
34. wchan – The channel in which the process is waiting. The “ps -l” command gives somewhat of a list.

* apm – A file containing the string “1.9 1.2 0×07 0×01 0xff 0×80 -1% -1 ?” on my system.
* bus – A directory
o pci – A directory
+ 00 – A directory containing filenames like 00.0, 07.0, 07.1, 07.2, 08.0, 09.0, and 0b.0. Each are 256 bytes long and appear to be in binary form.
+ devices – I think this file numerically identifies devices on the pci bus. My file contains:

Character devices:

1 mem
2 pty
3 ttyp
4 /dev/vc/0
4 tty
4 ttyS
5 /dev/tty
5 /dev/console
5 /dev/ptmx
6 lp
7 vcs
10 misc
13 input
14 sound
21 sg
29 fb
99 ppdev
116 alsa
128 ptm
136 pts
180 usb
189 usb_device
216 rfcomm
226 drm
253 pcmcia
254 usb_endpoint

Block devices:
1 ramdisk
8 sd
65 sd
66 sd
67 sd
68 sd
69 sd
70 sd
71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd

* cmdline – The command line at system startup. My file contains “auto BOOT_IMAGE=rhl ro root=302″.
* cpuinfo – CPU architecture information
* devices – Text listing of major numbers and device groups
* dma – A list of ISA direct memory access channels in use.
* fb – On my system, this file is empty
* filesystems – A text listing of the filesystems compiled into the kernel. The file on my system:

nodev sysfs
nodev rootfs
nodev bdev
nodev proc
nodev cpuset
nodev debugfs
nodev securityfs
nodev sockfs
nodev pipefs
nodev futexfs
nodev tmpfs
nodev inotifyfs
nodev eventpollfs
nodev devpts
cramfs
nodev ramfs
nodev mqueue
nodev usbfs
ext3
nodev fuse
fuseblk
nodev fusectl
vfat
ntfs
nodev binfmt_misc

* fs – A directory
o nfs – A directory
+ exports – A file containing information similar to that in the /etc/exports file. My listing:
# Version 1.0
# Path Client(Flags) # IPs
/tftpboot/lts/ltsroot linux1(ro,no_root_squash,async,wdelay) # 192.168.200.201
/tftpboot/lts/ltsroot linux3(ro,no_root_squash,async,wdelay) # 192.168.200.203
/tftpboot/lts/ltsroot linux2(ro,no_root_squash,async,wdelay) # 192.168.200.202

+ time-diff-margin – A file containing a numerical string value. On my system it is “10″.
* ide – A directory containing information on ide devices.
o drivers – A file describing the ide drivers on the system. My file:

ide-cdrom version 4.54
ide-disk version 1.08

o hda – Symbolic link to ide0/hda
o hdb – Symbolic link to ide0/hdb
o hdd – Symbolic link to ide1/hdd
o ide0 – A directory containing information on the device ide0.
+ channel – A file containing the channel number of the… device? My file contains the number 0.
+ config – A file. My file:

pci bus 00 device 39 vid 8086 did 7111 channel 0
86 80 11 71 05 00 80 02 01 80 01 01 00 40 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
77 e3 30 c0 9b 00 00 00 03 00 22 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 28 0f 00 00 00 00 00 00

+ hda – A directory containing the following files
# cache – The amount of cache capability in KB? On my system it is the number “256″
# capacity – The capacity of the device. On my system it is 12500460 on a 6GB hard drive.
# driver – the type of driver. On my system it is “ide-disk version 1.08″.
# geometry – The disk geometry of the device. On my system:

physical 13228/15/63
logical 778/255/63

# identify – On my system:

0c5a 33ac 0000 000f 0000 0000 003f 0000
0000 0000 3541 4330 3336 3350 2020 2020
2020 2020 2020 2020 0000 0200 0000 332e
3034 2020 2020 5354 3336 3432 3241 2020
2020 2020 2020 2020 2020 2020 2020 2020
2020 2020 2020 2020 2020 2020 2020 8010
0000 2f00 0000 0200 0200 0007 33ac 000f
003f bdec 00be 0010 bdec 00be 0000 0007
0003 0078 0078 00f0 0078 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
001e 0000 3069 4001 4000 3068 0001 4000
0407 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 85c4 00cb 85c4 00cb 2020 0002 0000
0001 0000 0001 0401 0001 0140 0201 0000
3c24 0001 4001 3cb4 0100 0100 0072 3001
0001 0128 0000 0000 1000 0105 00e9 0009
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000

# media – On my system it is “disk”.
# model – The manufacturers model. On my system it is “ST36422A”.
# settings – On my system:

name value min max mode
—- —– — — —-
bios_cyl 778 0 65535 rw
bios_head 255 0 255 rw
bios_sect 63 0 63 rw
breada_readahead 4 0 127 rw
bswap 0 0 1 r
file_readahead 124 0 2097151 rw
io_32bit 0 0 3 rw
keepsettings 0 0 1 rw
max_kb_per_request 64 1 127 rw
multcount 0 0 8 rw
nice1 1 0 1 rw
nowerr 0 0 1 rw
pio_mode write-only 0 255 w
slow 0 0 1 rw
unmaskirq 0 0 1 rw
using_dma 1 0 1 rw

# smart_thresholds – A table of numbers similar to the file identify.
# smart_values – A table of numbers as in smart_thresholds
+ hdb – A directory containing the same files as hda, above.
+ mate – A file containing the string “ide1″ on my system which I think is the companion disk device.
+ model – A file containing the string “pci” on my system.
o ide1 – A directory similar to the directory ide0, above with information on the device ide1.
* interrupts – The number of interrupts per IRQ.
* ioports – A list of currently registered input-output port regions that are in use.
* kcore – Represents the physical memory of the system stored in the core format.
* kmsg – This file can be used to log system messages.
* ksyms – Holds the kernel exported symbol definitions used by the modules(X) tools to dynamically link and bind loadable modules.
* loadavg – Load average numbers
* malloc – Present if CONFIGDEBUGMALLOC was defined during kernel compilation.
* locks – The file on my system:

1: POSIX ADVISORY WRITE 29396 08:08:509286 0 EOF
2: POSIX ADVISORY WRITE 6086 08:08:522914 0 EOF
3: POSIX ADVISORY WRITE 5508 08:08:602744 0 EOF
4: POSIX ADVISORY WRITE 5310 00:0f:17832 0 EOF
5: FLOCK ADVISORY WRITE 5194 00:0f:17594 0 EOF
6: POSIX ADVISORY WRITE 5181 00:0f:17583 0 EOF
7: POSIX ADVISORY WRITE 4880 08:08:130879 0 EOF
8: POSIX ADVISORY WRITE 4880 08:08:130878 0 EOF
9: POSIX ADVISORY WRITE 4880 08:08:130877 0 EOF
10: FLOCK ADVISORY WRITE 4780 00:0f:16731 0 EOF
11: FLOCK ADVISORY WRITE 4778 00:0f:16720 0 EOF

* mdstat – The file on my system:

Personalities :
read_ahead not set
md0 : inactive
md1 : inactive
md2 : inactive
md3 : inactive

* meminfo – Used by free(1) to report memory usage.
* misc – The file on my system:

135 rtc
134 apm
1 psaux

* modules – A list of kernel modules loaded by the system
* mounts – Shows mounted filesystems. Shows device, mount point, filesystem type, permissions, and two flags. The file on my system:

/dev/root / ext2 rw 0 0
/proc /proc proc rw 0 0
/dev/hdb1 /data vfat rw 0 0
/dev/hda1 /dos vfat rw 0 0
/dev/hda3 /slackw ext2 rw 0 0
none /dev/pts devpts rw 0 0
automount(pid640) /mnt autofs rw 0 0
ENG_SRV/MYUSER /eng_srv ncpfs rw 0 0

* mtrr – The file on my system:

reg00: base=0x000a0000 ( 0MB), size= 128kB: write-combining, count=1
reg01: base=0x000c0000 ( 0MB), size= 256kB: uncachable, count=1
reg03: base=0x000a8000 ( 0MB), size= 32kB: write-combining, count=1
reg07: base=0×00000000 ( 0MB), size= 64MB: write-back, count=1

* net – Various network pseudo files. The netstat(8) command suite provides cleaner access to these files. Files:
1. arp – The kernel address resolution protocol table.
2. dev – Network device status information
3. ipx
4. ipx_route
5. rarp – used to provide rarp(8) services.
6. raw – A dump of the RAW socket table
7. route – Looks like route(8).
8. snmp – Holds the ASCII databases used for the IP, ICMP, TCP, and UDP management information bases for an snmp agent.
9. tcp – A dump of the TCP socket table.
10. udp – A dump of the UDP socket table
11. unix – Lists UNIX domain sockets and their status.
* partitions – Lists the partitions and their device major and minor numbers. The file on my system:

major minor #blocks name

3 0 6250230 hda
3 1 208813 hda1
3 2 3068415 hda2
3 3 2843505 hda3
3 4 128520 hda4
3 64 6250230 hdb
3 65 6249253 hdb1
22 64 1073741823 hdd

* pci – A listing of all PCI devices that the system is aware of.
* rtc – A file containing clock information. The file on my system:

rtc_time : 20:15:03
rtc_date : 2000-05-07
rtc_epoch : 1900
alarm : 16:29:44
DST_enable : no
BCD : yes
24hr : yes
square_wave : no
alarm_IRQ : no
update_IRQ : no
periodic_IRQ : no
periodic_freq : 1024
batt_status : okay

* scsi – A directory with scsi files and driver directories.
1. scsi – A list of all scsi devices known to the kernel
2. drivername – Various scsi driver brand names
* self – Refers to the /proc filesystem.
* slabinfo – The file on my system

slabinfo – version: 1.0
kmem_cache 29 42
pio_request 0 0
tcp_tw_bucket 0 42
tcp_bind_bucket 41 127
tcp_open_request 0 0
skbuff_head_cache 64 147
sock 150 242
dquot 0 0
filp 1505 1512
signal_queue 0 0
buffer_head 566 1428
mm_struct 65 93
vm_area_struct 2527 3528
dentry_cache 4704 4743
files_cache 72 99
uid_cache 4 127
size-131072 0 0
size-65536 0 0
size-32768 0 0
size-16384 16 16
size-8192 0 1
size-4096 3 8
size-2048 151 176
size-1024 20 32
size-512 37 72
size-256 33 70
size-128 546 700
size-64 192 210
size-32 1080 1197
slab_cache 78 126

* stat – kernel statistics subdirectory
1. cpu – Jiffies spent in user mode, user mode with low priority, system mode, and idle.
2. disk – Four disk entries not yet implemented
3. page – The number of pages the system paged in and out.
4. swap – Swap pages that have been brought in and out.
5. intr – The number of interrupts received form the system boot
6. ctxt – The number of context switches that the system underwent.
7. btime – Boot time in seconds since Jan 1, 1970.
* swaps – A file defining swap partitions. The file on my system:

Filename Type Size Used Priority
/dev/hda4 partition 128516 7600 -1

* sys – Directory corresponding to kernel variables
o debug
o dev
o fs
o kernel
+ domainname
+ file-max
+ file-nr
+ hostname
+ inode-max
+ inode-nr
+ osrelease
+ ostype
+ panic
+ real-root-dev
+ securelevel
+ version
o net
o proc
o sunrpc
o vm
* tty
o driver – A directory
+ serial – A file
o drivers – A file listing device drivers. The file on my system:

pty_slave /dev/pts 136 0-255 pty:slave
pty_master /dev/ptm 128 0-255 pty:master
pty_slave /dev/ttyp 3 0-255 pty:slave
pty_master /dev/pty 2 0-255 pty:master
serial /dev/cua 5 64-95 serial:callout
serial /dev/ttyS 4 64-95 serial
/dev/tty0 /dev/tty0 4 0 system:vtmaster
/dev/ptmx /dev/ptmx 5 2 system
/dev/console /dev/console 5 1 system:console
/dev/tty /dev/tty 5 0 system:/dev/tty
unknown /dev/tty 4 1-63 console

o ldisc – A directory containing no files on my system.
o ldiscs – The file on my system:

n_tty 0

* uptime
* version

The sysctl tool

This tool is worth mentioning in this section since it is used to manipulate kernel parameters. If you type “sysctl -a |more” you will see a long list of kernel parameters. You can use this sysctl program to modify these parameters. However, I have been unable to add new parameters.

Filesystems ext2 ext3 ext4 reiserfs

ext2, ext3, ext4 and reiserfs are all filesystems created for Linux (GNU-Linux).
This article explains the following:

  1. High level difference between these filesystems.
  2. How to create these filesystems.
  3. How to convert from one filesystem type to another.

Ext2

  • Ext2 stands for second extended file system.
  • It was introduced in 1993. Developed by Rémy Card.
  • This was developed to overcome the limitation of the original ext file system.
  • Ext2 does not have journaling feature.
  • On flash drives, usb drives, ext2 is recommended, as it doesn’t need to do the over head of journaling.
  • Maximum individual file size can be from 16 GB to 2 TB
  • Overall ext2 file system size can be from 2 TB to 32 TB

Ext3

  • Ext3 stands for third extended file system.
  • It was introduced in 2001. Developed by Stephen Tweedie.
  • Starting from Linux Kernel 2.4.15 ext3 was available.
  • The main benefit of ext3 is that it allows journaling.
  • Journaling has a dedicated area in the file system, where all the changes are tracked. When the system crashes, the possibility of file system corruption is less because of journaling.
  • Maximum individual file size can be from 16 GB to 2 TB
  • Overall ext3 file system size can be from 2 TB to 32 TB
  • There are three types of journaling available in ext3 file system.
    • Journal – Metadata and content are saved in the journal.
    • Ordered – Only metadata is saved in the journal. Metadata are journaled only after writing the content to disk. This is the default.
    • Writeback – Only metadata is saved in the journal. Metadata might be journaled either before or after the content is written to the disk.
  • You can convert a ext2 file system to ext3 file system directly (without backup/restore).

Ext4

  • Ext4 stands for fourth extended file system.
  • It was introduced in 2008.
  • Starting from Linux Kernel 2.6.19 ext4 was available.
  • Supports huge individual file size and overall file system size.
  • Maximum individual file size can be from 16 GB to 16 TB
  • Overall maximum ext4 file system size is 1 EB (exabyte). 1 EB = 1024 PB (petabyte). 1 PB = 1024 TB (terabyte).
  • Directory can contain a maximum of 64,000 subdirectories (as opposed to 32,000 in ext3)
  • You can also mount an existing ext3 fs as ext4 fs (without having to upgrade it).
  • Several other new features are introduced in ext4: multiblock allocation, delayed allocation, journal checksum. fast fsck, etc. All you need to know is that these new features have improved the performance and reliability of the filesystem when compared to ext3.
  • In ext4, you also have the option of turning the journaling feature “off”.

Use the method we discussed earlier to identify whether you have ext2 or ext3 or ext4 file system.

Warning: Don’t execute any of the commands given below, if you don’t know what you are doing. You will lose your data!

Creating an ext2, or ext3, or ext4 filesystem

Once you’ve partitioned your hard disk using fdisk command, use mke2fs to create either ext2, ext3, or ext4 file system.

Create an ext2 file system:

mke2fs /dev/sda1

Create an ext3 file system:

mkfs.ext3 /dev/sda1

(or)

 mke2fs –j /dev/sda1

Create an ext4 file system:

mkfs.ext4 /dev/sda1

(or)

mke2fs -t ext4 /dev/sda1

Converting ext2 to ext3

For example, if you are upgrading /dev/sda2 that is mounted as /home, from ext2 to ext3, do the following.

umount /dev/sda2
 tune2fs -j /dev/sda2
 mount /dev/sda2 /home

Note: You really don’t need to umount and mount it, as ext2 to ext3 conversion can happen on a live file system. But, I feel better doing the conversion offline.

Converting ext3 to ext4

If you are upgrading /dev/sda2 that is mounted as /home, from ext3 to ext4, do the following.

umount /dev/sda2
 tune2fs -O extents,uninit_bg,dir_index /dev/sda2
 e2fsck -pf /dev/sda2
 mount /dev/sda2 /home

Again, try all of the above commands only on a test system, where you can afford to lose all your data.

ReiserFS is a general-purpose, journaled computer file system designed and implemented by a team at Namesys led by Hans Reiser. ReiserFS is currently supported on Linux (without quota support). Introduced in version 2.4.1 of the Linux kernel, it 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, and Yoper Linux distributions. ReiserFS was the default file system in Novell‘s SUSE Linux Enterprise until Novell decided to move to ext3 on October 12, 2006 for future releases.

Namesys considered ReiserFS (now occasionally referred to as Reiser3) stable and feature-complete and, with the exception of security updates and critical bug fixes, ceased development on it to concentrate on its successor, Reiser4.