Pages

Friday, January 25, 2013

Linux see the file size in MB with ls -l command

linux ls -l command

manohar@mani:~/git/prime-services$ ls -l
total 76
drwxrwxr-x 6 manohar manohar  4096 2013-01-25 11:37 authentication
-rw-rw-r-- 1 manohar manohar 10020 2013-01-24 14:10 build.gradle
-rw-rw-r-- 1 manohar manohar 10085 2012-10-31 22:16 build.gradle.cobertura
drwxrwxr-x 4 manohar manohar  4096 2012-07-02 14:50 ci
drwxrwxr-x 6 manohar manohar  4096 2013-01-25 11:37 context
drwxrwxr-x 9 manohar manohar  4096 2013-01-25 11:37 eventrouter
drwxrwxr-x 3 manohar manohar  4096 2012-07-02 14:50 example
-rw-rw-r-- 1 manohar manohar   602 2012-07-02 14:50 README
drwxrwxr-x 6 manohar manohar  4096 2013-01-25 11:37 reporting-dao
drwxrwxr-x 5 manohar manohar  4096 2013-01-25 11:37 routing-service
drwxrwxr-x 2 manohar manohar  4096 2013-01-21 11:30 scripts
-rw-rw-r-- 1 manohar manohar   129 2012-11-24 17:26 settings.gradle
drwxrwxr-x 6 manohar manohar  4096 2013-01-25 11:37 shared
drwxrwxr-x 9 manohar manohar  4096 2013-01-25 11:37 web-service
drwxrwxr-x 5 manohar manohar  4096 2013-01-25 11:37 ws-reporting
manohar@mani:~/git/prime-services$ 
To see file size in MB in linux ls -l command.

ls -l | awk '{printf "%s %i %s %s %.3fMB %s %i %s %s\n", $1,$2,$3,$4,$5/1024000,$6,$7,$8,$9}'


manohar@mani:~/git/prime-services$ ls -l | awk '{printf "%s %i %s %s %.3fMB %s %i %s %s\n", $1,$2,$3,$4,$5/1024000,$6,$7,$8,$9}'
total 76   0.000MB  0  
drwxrwxr-x 6 manohar manohar 0.004MB 2013-01-25 11 authentication 
-rw-rw-r-- 1 manohar manohar 0.010MB 2013-01-24 14 build.gradle 
-rw-rw-r-- 1 manohar manohar 0.010MB 2012-10-31 22 build.gradle.cobertura 
drwxrwxr-x 4 manohar manohar 0.004MB 2012-07-02 14 ci 
drwxrwxr-x 6 manohar manohar 0.004MB 2013-01-25 11 context 
drwxrwxr-x 9 manohar manohar 0.004MB 2013-01-25 11 eventrouter 
drwxrwxr-x 3 manohar manohar 0.004MB 2012-07-02 14 example 
-rw-rw-r-- 1 manohar manohar 0.001MB 2012-07-02 14 README 
drwxrwxr-x 6 manohar manohar 0.004MB 2013-01-25 11 reporting-dao 
drwxrwxr-x 5 manohar manohar 0.004MB 2013-01-25 11 routing-service 
drwxrwxr-x 2 manohar manohar 0.004MB 2013-01-21 11 scripts 
-rw-rw-r-- 1 manohar manohar 0.000MB 2012-11-24 17 settings.gradle 
drwxrwxr-x 6 manohar manohar 0.004MB 2013-01-25 11 shared 
drwxrwxr-x 9 manohar manohar 0.004MB 2013-01-25 11 web-service 
drwxrwxr-x 5 manohar manohar 0.004MB 2013-01-25 11 ws-reporting 
manohar@mani:~/git/prime-services$ 

Mysql Insert From Cross Join

Think of a scenario like this, we have a database of Doctors and Patients. All the doctors have access to all the patients information and all the patients can visit any doctor.
-- ----------------------------------------
-- Table `Doctors`
-- ----------------------------------------
CREATE TABLE IF NOT EXISTS `Doctors` (
  `doc_id` int(10) unsigned NOT NULL,
  `doc_first_name` VARCHAR(104) NOT NULL,
  `doc_last_name` VARCHAR(104) NOT NULL,
  `doc_discipline` VARCHAR(104) NOT NULL,
  PRIMARY KEY (`doc_id`)
) 
ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `Doctors` VALUES(1,'Sintu', 'Kumar', 'otholaringology');
INSERT INTO `Doctors` VALUES(2,'R', 'Chinch', 'dentistry');
-- ----------------------------------------
-- Table `Patients`
-- ----------------------------------------
CREATE TABLE IF NOT EXISTS `Patients` (
  `p_id` int(10) unsigned NOT NULL,
  `p_first_name` VARCHAR(104) NOT NULL,
  `p_last_name` VARCHAR(104) NOT NULL,
  PRIMARY KEY (`p_id`)
) 
ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `Patients` VALUES(1,'Jim','Cary');
INSERT INTO `Patients` VALUES(2,'John','Cook');
-- ----------------------------------------
-- Table `Doctors_Patients`
-- ----------------------------------------
CREATE TABLE IF NOT EXISTS `Doctors_Patients` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `doctor_id` int(10) unsigned NOT NULL,
  `patient_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  FOREIGN KEY (`doctor_id`) REFERENCES `Doctors` (`doc_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  FOREIGN KEY (`patient_id`) REFERENCES `Patients` (`p_id`) ON DELETE NO ACTION ON UPDATE NO ACTION

) 
ENGINE=InnoDB DEFAULT CHARSET=utf8;
Now we want to populate the table `Doctors_Patients` with the Cartesian  product of the other two tables. For this we can simply use cross join as listed below.

INSERT INTO `Doctors_Patients`(doctor_id,patient_id) SELECT `doc_id`, `p_id` FROM `Doctors`  CROSS JOIN `Patients`;

And this is what it did.
select * from Doctors_Patients;

+----+-----------+------------+
| id | doctor_id | patient_id |
+----+-----------+------------+
|  1 |         1 |          1 |
|  2 |         2 |          1 |
|  3 |         1 |          2 |
|  4 |         2 |          2 |
+----+-----------+------------+
4 rows in set (0.08 sec)