Some changes after the horrible problem of writing the same ch9 on all the html pages
--- a/SEESenv/web/hgbook/comments/p_list.py Mon Feb 22 18:46:07 2010 +0530
+++ b/SEESenv/web/hgbook/comments/p_list.py Mon Feb 22 22:38:51 2010 +0530
@@ -1,1 +1,1 @@
-p_list= {'ch6oop': ['ch6oop_1', 'ch6oop_2', 'ch6oop_3', 'ch6oop_4', 'ch6oop_5', 'ch6oop_6', 'ch6oop_7', 'ch6oop_8', 'ch6oop_9', 'ch6oop_a', 'ch6oop_b', 'ch6oop_c', 'ch6oop_d', 'ch6oop_e', 'ch6oop_f', 'ch6oop_10', 'ch6oop_11', 'ch6oop_12', 'ch6oop_13', 'ch6oop_14', 'ch6oop_15', 'ch6oop_16', 'ch6oop_17', 'ch6oop_18', 'ch6oop_19', 'ch6oop_1a', 'ch6oop_1b', 'ch6oop_1c', 'ch6oop_1d', 'ch6oop_1e', 'ch6oop_1f', 'ch6oop_20', 'ch6oop_21', 'ch6oop_22', 'ch6oop_23', 'ch6oop_24', 'ch6oop_25', 'ch6oop_26', 'ch6oop_27', 'ch6oop_28', 'ch6oop_29', 'ch6oop_2a', 'ch6oop_2b', 'ch6oop_2c', 'ch6oop_2d', 'ch6oop_2e', 'ch6oop_2f', 'ch6oop_30', 'ch6oop_31', 'ch6oop_32', 'ch6oop_33', 'ch6oop_34', 'ch6oop_35', 'ch6oop_36', 'ch6oop_37', 'ch6oop_38', 'ch6oop_39', 'ch6oop_3a', 'ch6oop_3b', 'ch6oop_3c', 'ch6oop_3d', 'ch6oop_3e', 'ch6oop_3f', 'ch6oop_40', 'ch6oop_41', 'ch6oop_42', 'ch6oop_43', 'ch6oop_44', 'ch6oop_45', 'ch6oop_46', 'ch6oop_47', 'ch6oop_48', 'ch6oop_49', 'ch6oop_4a', 'ch6oop_4b', 'ch6oop_4c', 'ch6oop_4d', 'ch6oop_4e', 'ch6oop_4f', 'ch6oop_50', 'ch6oop_51', 'ch6oop_52', 'ch6oop_53', 'ch6oop_54', 'ch6oop_55', 'ch6oop_56', 'ch6oop_57', 'ch6oop_58', 'ch6oop_59', 'ch6oop_5a', 'ch6oop_5b', 'ch6oop_5c', 'ch6oop_5d', 'ch6oop_5e', 'ch6oop_5f', 'ch6oop_60', 'ch6oop_61', 'ch6oop_62', 'ch6oop_63', 'ch6oop_64', 'ch6oop_65', 'ch6oop_66', 'ch6oop_67', 'ch6oop_68', 'ch6oop_69', 'ch6oop_6a', 'ch6oop_6b', 'ch6oop_6c', 'ch6oop_6d', 'ch6oop_6e', 'ch6oop_6f', 'ch6oop_70', 'ch6oop_71', 'ch6oop_72', 'ch6oop_73', 'ch6oop_74', 'ch6oop_75', 'ch6oop_76', 'ch6oop_77', 'ch6oop_78', 'ch6oop_79', 'ch6oop_7a', 'ch6oop_7b', 'ch6oop_7c', 'ch6oop_7d', 'ch6oop_7e', 'ch6oop_7f', 'ch6oop_80', 'ch6oop_81', 'ch6oop_82', 'ch6oop_83', 'ch6oop_84', 'ch6oop_85', 'ch6oop_86', 'ch6oop_87', 'ch6oop_88', 'ch6oop_89', 'ch6oop_8a', 'ch6oop_8b', 'ch6oop_8c', 'ch6oop_8d', 'ch6oop_8e', 'ch6oop_8f', 'ch6oop_90', 'ch6oop_91', 'ch6oop_92', 'ch6oop_93', 'ch6oop_94', 'ch6oop_95', 'ch6oop_96', 'ch6oop_97', 'ch6oop_98', 'ch6oop_99', 'ch6oop_9a', 'ch6oop_9b', 'ch6oop_9c', 'ch6oop_9d', 'ch6oop_9e', 'ch6oop_9f', 'ch6oop_a0', 'ch6oop_a1', 'ch6oop_a2', 'ch6oop_a3', 'ch6oop_a4', 'ch6oop_a5', 'ch6oop_a6', 'ch6oop_a7', 'ch6oop_a8', 'ch6oop_a9', 'ch6oop_aa', 'ch6oop_ab', 'ch6oop_ac', 'ch6oop_ad', 'ch6oop_ae', 'ch6oop_af', 'ch6oop_b0', 'ch6oop_b1', 'ch6oop_b2', 'ch6oop_b3', 'ch6oop_b4', 'ch6oop_b5', 'ch6oop_b6', 'ch6oop_b7', 'ch6oop_b8', 'ch6oop_b9', 'ch6oop_ba', 'ch6oop_bb', 'ch6oop_bc', 'ch6oop_bd', 'ch6oop_be', 'ch6oop_bf', 'ch6oop_c0', 'ch6oop_c1', 'ch6oop_c2', 'ch6oop_c3', 'ch6oop_c4', 'ch6oop_c5', 'ch6oop_c6', 'ch6oop_c7', 'ch6oop_c8', 'ch6oop_c9', 'ch6oop_ca', 'ch6oop_cb', 'ch6oop_cc', 'ch6oop_cd', 'ch6oop_ce', 'ch6oop_cf', 'ch6oop_d0', 'ch6oop_d1', 'ch6oop_d2', 'ch6oop_d3', 'ch6oop_d4', 'ch6oop_d5', 'ch6oop_d6', 'ch6oop_d7', 'ch6oop_d8', 'ch6oop_d9', 'ch6oop_da', 'ch6oop_db', 'ch6oop_dc', 'ch6oop_dd', 'ch6oop_de', 'ch6oop_df', 'ch6oop_e0', 'ch6oop_e1', 'ch6oop_e2', 'ch6oop_e3', 'ch6oop_e4', 'ch6oop_e5', 'ch6oop_e6', 'ch6oop_e7', 'ch6oop_e8', 'ch6oop_e9', 'ch6oop_ea', 'ch6oop_eb', 'ch6oop_ec', 'ch6oop_ed', 'ch6oop_ee', 'ch6oop_ef', 'ch6oop_f0', 'ch6oop_f1', 'ch6oop_f2', 'ch6oop_f3', 'ch6oop_f4', 'ch6oop_f5', 'ch6oop_f6', 'ch6oop_f7', 'ch6oop_f8', 'ch6oop_f9', 'ch6oop_fa', 'ch6oop_fb', 'ch6oop_fc', 'ch6oop_fd', 'ch6oop_fe', 'ch6oop_ff', 'ch6oop_100', 'ch6oop_101', 'ch6oop_102', 'ch6oop_103', 'ch6oop_104', 'ch6oop_105', 'ch6oop_106', 'ch6oop_107', 'ch6oop_108', 'ch6oop_109', 'ch6oop_10a', 'ch6oop_10b', 'ch6oop_10c', 'ch6oop_10d', 'ch6oop_10e', 'ch6oop_10f', 'ch6oop_110', 'ch6oop_111', 'ch6oop_112', 'ch6oop_113', 'ch6oop_114', 'ch6oop_115', 'ch6oop_116', 'ch6oop_117', 'ch6oop_118', 'ch6oop_119', 'ch6oop_11a', 'ch6oop_11b', 'ch6oop_11c', 'ch6oop_11d', 'ch6oop_11e', 'ch6oop_11f', 'ch6oop_120', 'ch6oop_121', 'ch6oop_122', 'ch6oop_123', 'ch6oop_124', 'ch6oop_125', 'ch6oop_126', 'ch6oop_127', 'ch6oop_128', 'ch6oop_129', 'ch6oop_12a', 'ch6oop_12b', 'ch6oop_12c', 'ch6oop_12d', 'ch6oop_12e', 'ch6oop_12f', 'ch6oop_130', 'ch6oop_131', 'ch6oop_132', 'ch6oop_133', 'ch6oop_134', 'ch6oop_135', 'ch6oop_136', 'ch6oop_137', 'ch6oop_138', 'ch6oop_139', 'ch6oop_13a', 'ch6oop_13b', 'ch6oop_13c', 'ch6oop_13d', 'ch6oop_13e', 'ch6oop_13f', 'ch6oop_140', 'ch6oop_141', 'ch6oop_142', 'ch6oop_143', 'ch6oop_144', 'ch6oop_145', 'ch6oop_146', 'ch6oop_147', 'ch6oop_148', 'ch6oop_149', 'ch6oop_14a', 'ch6oop_14b', 'ch6oop_14c', 'ch6oop_14d', 'ch6oop_14e', 'ch6oop_14f', 'ch6oop_150', 'ch6oop_151', 'ch6oop_152', 'ch6oop_153', 'ch6oop_154', 'ch6oop_155', 'ch6oop_156', 'ch6oop_157', 'ch6oop_158', 'ch6oop_159', 'ch6oop_15a', 'ch6oop_15b', 'ch6oop_15c', 'ch6oop_15d', 'ch6oop_15e', 'ch6oop_15f', 'ch6oop_160', 'ch6oop_161', 'ch6oop_162', 'ch6oop_163', 'ch6oop_164', 'ch6oop_165', 'ch6oop_166', 'ch6oop_167', 'ch6oop_168', 'ch6oop_169', 'ch6oop_16a', 'ch6oop_16b', 'ch6oop_16c', 'ch6oop_16d', 'ch6oop_16e', 'ch6oop_16f', 'ch6oop_170', 'ch6oop_171', 'ch6oop_172', 'ch6oop_173', 'ch6oop_174', 'ch6oop_175', 'ch6oop_176', 'ch6oop_177', 'ch6oop_178', 'ch6oop_179', 'ch6oop_17a', 'ch6oop_17b', 'ch6oop_17c', 'ch6oop_17d', 'ch6oop_17e', 'ch6oop_17f', 'ch6oop_180', 'ch6oop_181', 'ch6oop_182', 'ch6oop_183', 'ch6oop_184', 'ch6oop_185', 'ch6oop_186', 'ch6oop_187', 'ch6oop_188', 'ch6oop_189', 'ch6oop_18a', 'ch6oop_18b', 'ch6oop_18c', 'ch6oop_18d', 'ch6oop_18e', 'ch6oop_18f', 'ch6oop_190', 'ch6oop_191', 'ch6oop_192', 'ch6oop_193', 'ch6oop_194', 'ch6oop_195', 'ch6oop_196', 'ch6oop_197', 'ch6oop_198', 'ch6oop_199', 'ch6oop_19a', 'ch6oop_19b', 'ch6oop_19c', 'ch6oop_19d', 'ch6oop_19e', 'ch6oop_19f', 'ch6oop_1a0', 'ch6oop_1a1', 'ch6oop_1a2', 'ch6oop_1a3', 'ch6oop_1a4', 'ch6oop_1a5', 'ch6oop_1a6', 'ch6oop_1a7', 'ch6oop_1a8', 'ch6oop_1a9', 'ch6oop_1aa', 'ch6oop_1ab', 'ch6oop_1ac', 'ch6oop_1ad', 'ch6oop_1ae', 'ch6oop_1af', 'ch6oop_1b0', 'ch6oop_1b1', 'ch6oop_1b2', 'ch6oop_1b3', 'ch6oop_1b4', 'ch6oop_1b5', 'ch6oop_1b6', 'ch6oop_1b7', 'ch6oop_1b8', 'ch6oop_1b9', 'ch6oop_1ba', 'ch6oop_1bb', 'ch6oop_1bc', 'ch6oop_1bd', 'ch6oop_1be', 'ch6oop_1bf', 'ch6oop_1c0', 'ch6oop_1c1', 'ch6oop_1c2', 'ch6oop_1c3', 'ch6oop_1c4', 'ch6oop_1c5', 'ch6oop_1c6', 'ch6oop_1c7', 'ch6oop_1c8', 'ch6oop_1c9', 'ch6oop_1ca', 'ch6oop_1cb', 'ch6oop_1cc', 'ch6oop_1cd', 'ch6oop_1ce', 'ch6oop_1cf', 'ch6oop_1d0', 'ch6oop_1d1', 'ch6oop_1d2', 'ch6oop_1d3', 'ch6oop_1d4', 'ch6oop_1d5', 'ch6oop_1d6', 'ch6oop_1d7', 'ch6oop_1d8', 'ch6oop_1d9', 'ch6oop_1da', 'ch6oop_1db', 'ch6oop_1dc', 'ch6oop_1dd', 'ch6oop_1de', 'ch6oop_1df', 'ch6oop_1e0', 'ch6oop_1e1'], 'ch9Using_Linux_Tools': ['ch9Using_Linux_Tools_1', 'ch9Using_Linux_Tools_2', 'ch9Using_Linux_Tools_3', 'ch9Using_Linux_Tools_4', 'ch9Using_Linux_Tools_5', 'ch9Using_Linux_Tools_6', 'ch9Using_Linux_Tools_7', 'ch9Using_Linux_Tools_8', 'ch9Using_Linux_Tools_9', 'ch9Using_Linux_Tools_a', 'ch9Using_Linux_Tools_b', 'ch9Using_Linux_Tools_c', 'ch9Using_Linux_Tools_d', 'ch9Using_Linux_Tools_e', 'ch9Using_Linux_Tools_f', 'ch9Using_Linux_Tools_10', 'ch9Using_Linux_Tools_11', 'ch9Using_Linux_Tools_12', 'ch9Using_Linux_Tools_13', 'ch9Using_Linux_Tools_14', 'ch9Using_Linux_Tools_15', 'ch9Using_Linux_Tools_16', 'ch9Using_Linux_Tools_17', 'ch9Using_Linux_Tools_18', 'ch9Using_Linux_Tools_19', 'ch9Using_Linux_Tools_1a', 'ch9Using_Linux_Tools_1b', 'ch9Using_Linux_Tools_1c', 'ch9Using_Linux_Tools_1d', 'ch9Using_Linux_Tools_1e', 'ch9Using_Linux_Tools_1f', 'ch9Using_Linux_Tools_20', 'ch9Using_Linux_Tools_21', 'ch9Using_Linux_Tools_22', 'ch9Using_Linux_Tools_23', 'ch9Using_Linux_Tools_24', 'ch9Using_Linux_Tools_25', 'ch9Using_Linux_Tools_26', 'ch9Using_Linux_Tools_27', 'ch9Using_Linux_Tools_28', 'ch9Using_Linux_Tools_29', 'ch9Using_Linux_Tools_2a', 'ch9Using_Linux_Tools_2b', 'ch9Using_Linux_Tools_2c', 'ch9Using_Linux_Tools_2d', 'ch9Using_Linux_Tools_2e', 'ch9Using_Linux_Tools_2f', 'ch9Using_Linux_Tools_30', 'ch9Using_Linux_Tools_31', 'ch9Using_Linux_Tools_32', 'ch9Using_Linux_Tools_33', 'ch9Using_Linux_Tools_34', 'ch9Using_Linux_Tools_35', 'ch9Using_Linux_Tools_36', 'ch9Using_Linux_Tools_37', 'ch9Using_Linux_Tools_38', 'ch9Using_Linux_Tools_39', 'ch9Using_Linux_Tools_3a', 'ch9Using_Linux_Tools_3b', 'ch9Using_Linux_Tools_3c', 'ch9Using_Linux_Tools_3d', 'ch9Using_Linux_Tools_3e', 'ch9Using_Linux_Tools_3f', 'ch9Using_Linux_Tools_40', 'ch9Using_Linux_Tools_41', 'ch9Using_Linux_Tools_42', 'ch9Using_Linux_Tools_43', 'ch9Using_Linux_Tools_44', 'ch9Using_Linux_Tools_45', 'ch9Using_Linux_Tools_46', 'ch9Using_Linux_Tools_47', 'ch9Using_Linux_Tools_48', 'ch9Using_Linux_Tools_49', 'ch9Using_Linux_Tools_4a', 'ch9Using_Linux_Tools_4b', 'ch9Using_Linux_Tools_4c', 'ch9Using_Linux_Tools_4d', 'ch9Using_Linux_Tools_4e', 'ch9Using_Linux_Tools_4f', 'ch9Using_Linux_Tools_50', 'ch9Using_Linux_Tools_51', 'ch9Using_Linux_Tools_52', 'ch9Using_Linux_Tools_53', 'ch9Using_Linux_Tools_54', 'ch9Using_Linux_Tools_55', 'ch9Using_Linux_Tools_56', 'ch9Using_Linux_Tools_57', 'ch9Using_Linux_Tools_58', 'ch9Using_Linux_Tools_59', 'ch9Using_Linux_Tools_5a', 'ch9Using_Linux_Tools_5b', 'ch9Using_Linux_Tools_5c', 'ch9Using_Linux_Tools_5d', 'ch9Using_Linux_Tools_5e', 'ch9Using_Linux_Tools_5f', 'ch9Using_Linux_Tools_60', 'ch9Using_Linux_Tools_61', 'ch9Using_Linux_Tools_62', 'ch9Using_Linux_Tools_63', 'ch9Using_Linux_Tools_64', 'ch9Using_Linux_Tools_65', 'ch9Using_Linux_Tools_66', 'ch9Using_Linux_Tools_67', 'ch9Using_Linux_Tools_68', 'ch9Using_Linux_Tools_69', 'ch9Using_Linux_Tools_6a', 'ch9Using_Linux_Tools_6b', 'ch9Using_Linux_Tools_6c', 'ch9Using_Linux_Tools_6d', 'ch9Using_Linux_Tools_6e', 'ch9Using_Linux_Tools_6f', 'ch9Using_Linux_Tools_70', 'ch9Using_Linux_Tools_71', 'ch9Using_Linux_Tools_72', 'ch9Using_Linux_Tools_73', 'ch9Using_Linux_Tools_74', 'ch9Using_Linux_Tools_75', 'ch9Using_Linux_Tools_76', 'ch9Using_Linux_Tools_77', 'ch9Using_Linux_Tools_78', 'ch9Using_Linux_Tools_79', 'ch9Using_Linux_Tools_7a', 'ch9Using_Linux_Tools_7b', 'ch9Using_Linux_Tools_7c', 'ch9Using_Linux_Tools_7d', 'ch9Using_Linux_Tools_7e', 'ch9Using_Linux_Tools_7f', 'ch9Using_Linux_Tools_80', 'ch9Using_Linux_Tools_81', 'ch9Using_Linux_Tools_82', 'ch9Using_Linux_Tools_83', 'ch9Using_Linux_Tools_84', 'ch9Using_Linux_Tools_85', 'ch9Using_Linux_Tools_86', 'ch9Using_Linux_Tools_87', 'ch9Using_Linux_Tools_88', 'ch9Using_Linux_Tools_89', 'ch9Using_Linux_Tools_8a', 'ch9Using_Linux_Tools_8b', 'ch9Using_Linux_Tools_8c', 'ch9Using_Linux_Tools_8d', 'ch9Using_Linux_Tools_8e', 'ch9Using_Linux_Tools_8f', 'ch9Using_Linux_Tools_90', 'ch9Using_Linux_Tools_91', 'ch9Using_Linux_Tools_92', 'ch9Using_Linux_Tools_93', 'ch9Using_Linux_Tools_94', 'ch9Using_Linux_Tools_95', 'ch9Using_Linux_Tools_96', 'ch9Using_Linux_Tools_97', 'ch9Using_Linux_Tools_98', 'ch9Using_Linux_Tools_99', 'ch9Using_Linux_Tools_9a', 'ch9Using_Linux_Tools_9b', 'ch9Using_Linux_Tools_9c', 'ch9Using_Linux_Tools_9d', 'ch9Using_Linux_Tools_9e', 'ch9Using_Linux_Tools_9f', 'ch9Using_Linux_Tools_a0', 'ch9Using_Linux_Tools_a1', 'ch9Using_Linux_Tools_a2', 'ch9Using_Linux_Tools_a3', 'ch9Using_Linux_Tools_a4', 'ch9Using_Linux_Tools_a5', 'ch9Using_Linux_Tools_a6', 'ch9Using_Linux_Tools_a7', 'ch9Using_Linux_Tools_a8', 'ch9Using_Linux_Tools_a9', 'ch9Using_Linux_Tools_aa', 'ch9Using_Linux_Tools_ab', 'ch9Using_Linux_Tools_ac', 'ch9Using_Linux_Tools_ad', 'ch9Using_Linux_Tools_ae', 'ch9Using_Linux_Tools_af', 'ch9Using_Linux_Tools_b0', 'ch9Using_Linux_Tools_b1', 'ch9Using_Linux_Tools_b2', 'ch9Using_Linux_Tools_b3', 'ch9Using_Linux_Tools_b4', 'ch9Using_Linux_Tools_b5', 'ch9Using_Linux_Tools_b6', 'ch9Using_Linux_Tools_b7', 'ch9Using_Linux_Tools_b8', 'ch9Using_Linux_Tools_b9', 'ch9Using_Linux_Tools_ba', 'ch9Using_Linux_Tools_bb', 'ch9Using_Linux_Tools_bc', 'ch9Using_Linux_Tools_bd', 'ch9Using_Linux_Tools_be', 'ch9Using_Linux_Tools_bf', 'ch9Using_Linux_Tools_c0', 'ch9Using_Linux_Tools_c1', 'ch9Using_Linux_Tools_c2', 'ch9Using_Linux_Tools_c3', 'ch9Using_Linux_Tools_c4', 'ch9Using_Linux_Tools_c5', 'ch9Using_Linux_Tools_c6', 'ch9Using_Linux_Tools_c7', 'ch9Using_Linux_Tools_c8', 'ch9Using_Linux_Tools_c9', 'ch9Using_Linux_Tools_ca', 'ch9Using_Linux_Tools_cb', 'ch9Using_Linux_Tools_cc', 'ch9Using_Linux_Tools_cd', 'ch9Using_Linux_Tools_ce', 'ch9Using_Linux_Tools_cf', 'ch9Using_Linux_Tools_d0', 'ch9Using_Linux_Tools_d1', 'ch9Using_Linux_Tools_d2', 'ch9Using_Linux_Tools_d3', 'ch9Using_Linux_Tools_d4', 'ch9Using_Linux_Tools_d5', 'ch9Using_Linux_Tools_d6', 'ch9Using_Linux_Tools_d7', 'ch9Using_Linux_Tools_d8', 'ch9Using_Linux_Tools_d9', 'ch9Using_Linux_Tools_da', 'ch9Using_Linux_Tools_db', 'ch9Using_Linux_Tools_dc', 'ch9Using_Linux_Tools_dd', 'ch9Using_Linux_Tools_de', 'ch9Using_Linux_Tools_df', 'ch9Using_Linux_Tools_e0', 'ch9Using_Linux_Tools_e1', 'ch9Using_Linux_Tools_e2', 'ch9Using_Linux_Tools_e3', 'ch9Using_Linux_Tools_e4', 'ch9Using_Linux_Tools_e5', 'ch9Using_Linux_Tools_e6', 'ch9Using_Linux_Tools_e7', 'ch9Using_Linux_Tools_e8', 'ch9Using_Linux_Tools_e9', 'ch9Using_Linux_Tools_ea', 'ch9Using_Linux_Tools_eb', 'ch9Using_Linux_Tools_ec', 'ch9Using_Linux_Tools_ed', 'ch9Using_Linux_Tools_ee', 'ch9Using_Linux_Tools_ef', 'ch9Using_Linux_Tools_f0', 'ch9Using_Linux_Tools_f1', 'ch9Using_Linux_Tools_f2', 'ch9Using_Linux_Tools_f3', 'ch9Using_Linux_Tools_f4', 'ch9Using_Linux_Tools_f5', 'ch9Using_Linux_Tools_f6', 'ch9Using_Linux_Tools_f7', 'ch9Using_Linux_Tools_f8', 'ch9Using_Linux_Tools_f9', 'ch9Using_Linux_Tools_fa', 'ch9Using_Linux_Tools_fb', 'ch9Using_Linux_Tools_fc', 'ch9Using_Linux_Tools_fd', 'ch9Using_Linux_Tools_fe', 'ch9Using_Linux_Tools_ff', 'ch9Using_Linux_Tools_100', 'ch9Using_Linux_Tools_101', 'ch9Using_Linux_Tools_102', 'ch9Using_Linux_Tools_103', 'ch9Using_Linux_Tools_104', 'ch9Using_Linux_Tools_105', 'ch9Using_Linux_Tools_106', 'ch9Using_Linux_Tools_107', 'ch9Using_Linux_Tools_108', 'ch9Using_Linux_Tools_109', 'ch9Using_Linux_Tools_10a', 'ch9Using_Linux_Tools_10b', 'ch9Using_Linux_Tools_10c', 'ch9Using_Linux_Tools_10d', 'ch9Using_Linux_Tools_10e', 'ch9Using_Linux_Tools_10f', 'ch9Using_Linux_Tools_110', 'ch9Using_Linux_Tools_111', 'ch9Using_Linux_Tools_112', 'ch9Using_Linux_Tools_113', 'ch9Using_Linux_Tools_114', 'ch9Using_Linux_Tools_115', 'ch9Using_Linux_Tools_116', 'ch9Using_Linux_Tools_117', 'ch9Using_Linux_Tools_118', 'ch9Using_Linux_Tools_119', 'ch9Using_Linux_Tools_11a', 'ch9Using_Linux_Tools_11b', 'ch9Using_Linux_Tools_11c', 'ch9Using_Linux_Tools_11d', 'ch9Using_Linux_Tools_11e', 'ch9Using_Linux_Tools_11f', 'ch9Using_Linux_Tools_120', 'ch9Using_Linux_Tools_121', 'ch9Using_Linux_Tools_122', 'ch9Using_Linux_Tools_123', 'ch9Using_Linux_Tools_124', 'ch9Using_Linux_Tools_125', 'ch9Using_Linux_Tools_126', 'ch9Using_Linux_Tools_127', 'ch9Using_Linux_Tools_128', 'ch9Using_Linux_Tools_129', 'ch9Using_Linux_Tools_12a', 'ch9Using_Linux_Tools_12b', 'ch9Using_Linux_Tools_12c', 'ch9Using_Linux_Tools_12d', 'ch9Using_Linux_Tools_12e', 'ch9Using_Linux_Tools_12f', 'ch9Using_Linux_Tools_130', 'ch9Using_Linux_Tools_131', 'ch9Using_Linux_Tools_132', 'ch9Using_Linux_Tools_133', 'ch9Using_Linux_Tools_134', 'ch9Using_Linux_Tools_135', 'ch9Using_Linux_Tools_136', 'ch9Using_Linux_Tools_137', 'ch9Using_Linux_Tools_138', 'ch9Using_Linux_Tools_139', 'ch9Using_Linux_Tools_13a', 'ch9Using_Linux_Tools_13b', 'ch9Using_Linux_Tools_13c', 'ch9Using_Linux_Tools_13d', 'ch9Using_Linux_Tools_13e', 'ch9Using_Linux_Tools_13f', 'ch9Using_Linux_Tools_140', 'ch9Using_Linux_Tools_141', 'ch9Using_Linux_Tools_142', 'ch9Using_Linux_Tools_143', 'ch9Using_Linux_Tools_144', 'ch9Using_Linux_Tools_145', 'ch9Using_Linux_Tools_146', 'ch9Using_Linux_Tools_147', 'ch9Using_Linux_Tools_148', 'ch9Using_Linux_Tools_149', 'ch9Using_Linux_Tools_14a', 'ch9Using_Linux_Tools_14b', 'ch9Using_Linux_Tools_14c', 'ch9Using_Linux_Tools_14d', 'ch9Using_Linux_Tools_14e', 'ch9Using_Linux_Tools_14f', 'ch9Using_Linux_Tools_150', 'ch9Using_Linux_Tools_151', 'ch9Using_Linux_Tools_152', 'ch9Using_Linux_Tools_153', 'ch9Using_Linux_Tools_154', 'ch9Using_Linux_Tools_155', 'ch9Using_Linux_Tools_156', 'ch9Using_Linux_Tools_157', 'ch9Using_Linux_Tools_158', 'ch9Using_Linux_Tools_159', 'ch9Using_Linux_Tools_15a', 'ch9Using_Linux_Tools_15b', 'ch9Using_Linux_Tools_15c', 'ch9Using_Linux_Tools_15d', 'ch9Using_Linux_Tools_15e', 'ch9Using_Linux_Tools_15f', 'ch9Using_Linux_Tools_160', 'ch9Using_Linux_Tools_161', 'ch9Using_Linux_Tools_162', 'ch9Using_Linux_Tools_163', 'ch9Using_Linux_Tools_164', 'ch9Using_Linux_Tools_165', 'ch9Using_Linux_Tools_166', 'ch9Using_Linux_Tools_167', 'ch9Using_Linux_Tools_168', 'ch9Using_Linux_Tools_169', 'ch9Using_Linux_Tools_16a', 'ch9Using_Linux_Tools_16b', 'ch9Using_Linux_Tools_16c', 'ch9Using_Linux_Tools_16d', 'ch9Using_Linux_Tools_16e', 'ch9Using_Linux_Tools_16f', 'ch9Using_Linux_Tools_170', 'ch9Using_Linux_Tools_171', 'ch9Using_Linux_Tools_172', 'ch9Using_Linux_Tools_173', 'ch9Using_Linux_Tools_174', 'ch9Using_Linux_Tools_175', 'ch9Using_Linux_Tools_176', 'ch9Using_Linux_Tools_177', 'ch9Using_Linux_Tools_178', 'ch9Using_Linux_Tools_179', 'ch9Using_Linux_Tools_17a', 'ch9Using_Linux_Tools_17b', 'ch9Using_Linux_Tools_17c', 'ch9Using_Linux_Tools_17d', 'ch9Using_Linux_Tools_17e', 'ch9Using_Linux_Tools_17f', 'ch9Using_Linux_Tools_180', 'ch9Using_Linux_Tools_181', 'ch9Using_Linux_Tools_182', 'ch9Using_Linux_Tools_183', 'ch9Using_Linux_Tools_184', 'ch9Using_Linux_Tools_185', 'ch9Using_Linux_Tools_186', 'ch9Using_Linux_Tools_187', 'ch9Using_Linux_Tools_188', 'ch9Using_Linux_Tools_189', 'ch9Using_Linux_Tools_18a', 'ch9Using_Linux_Tools_18b', 'ch9Using_Linux_Tools_18c', 'ch9Using_Linux_Tools_18d', 'ch9Using_Linux_Tools_18e', 'ch9Using_Linux_Tools_18f', 'ch9Using_Linux_Tools_190', 'ch9Using_Linux_Tools_191', 'ch9Using_Linux_Tools_192', 'ch9Using_Linux_Tools_193', 'ch9Using_Linux_Tools_194', 'ch9Using_Linux_Tools_195', 'ch9Using_Linux_Tools_196', 'ch9Using_Linux_Tools_197', 'ch9Using_Linux_Tools_198', 'ch9Using_Linux_Tools_199', 'ch9Using_Linux_Tools_19a', 'ch9Using_Linux_Tools_19b', 'ch9Using_Linux_Tools_19c', 'ch9Using_Linux_Tools_19d', 'ch9Using_Linux_Tools_19e', 'ch9Using_Linux_Tools_19f', 'ch9Using_Linux_Tools_1a0', 'ch9Using_Linux_Tools_1a1', 'ch9Using_Linux_Tools_1a2', 'ch9Using_Linux_Tools_1a3', 'ch9Using_Linux_Tools_1a4', 'ch9Using_Linux_Tools_1a5', 'ch9Using_Linux_Tools_1a6', 'ch9Using_Linux_Tools_1a7', 'ch9Using_Linux_Tools_1a8', 'ch9Using_Linux_Tools_1a9', 'ch9Using_Linux_Tools_1aa', 'ch9Using_Linux_Tools_1ab', 'ch9Using_Linux_Tools_1ac', 'ch9Using_Linux_Tools_1ad', 'ch9Using_Linux_Tools_1ae', 'ch9Using_Linux_Tools_1af', 'ch9Using_Linux_Tools_1b0', 'ch9Using_Linux_Tools_1b1', 'ch9Using_Linux_Tools_1b2', 'ch9Using_Linux_Tools_1b3', 'ch9Using_Linux_Tools_1b4', 'ch9Using_Linux_Tools_1b5', 'ch9Using_Linux_Tools_1b6', 'ch9Using_Linux_Tools_1b7', 'ch9Using_Linux_Tools_1b8', 'ch9Using_Linux_Tools_1b9', 'ch9Using_Linux_Tools_1ba', 'ch9Using_Linux_Tools_1bb', 'ch9Using_Linux_Tools_1bc', 'ch9Using_Linux_Tools_1bd', 'ch9Using_Linux_Tools_1be', 'ch9Using_Linux_Tools_1bf', 'ch9Using_Linux_Tools_1c0', 'ch9Using_Linux_Tools_1c1', 'ch9Using_Linux_Tools_1c2', 'ch9Using_Linux_Tools_1c3', 'ch9Using_Linux_Tools_1c4', 'ch9Using_Linux_Tools_1c5', 'ch9Using_Linux_Tools_1c6', 'ch9Using_Linux_Tools_1c7', 'ch9Using_Linux_Tools_1c8', 'ch9Using_Linux_Tools_1c9', 'ch9Using_Linux_Tools_1ca', 'ch9Using_Linux_Tools_1cb', 'ch9Using_Linux_Tools_1cc', 'ch9Using_Linux_Tools_1cd', 'ch9Using_Linux_Tools_1ce', 'ch9Using_Linux_Tools_1cf', 'ch9Using_Linux_Tools_1d0', 'ch9Using_Linux_Tools_1d1', 'ch9Using_Linux_Tools_1d2', 'ch9Using_Linux_Tools_1d3', 'ch9Using_Linux_Tools_1d4', 'ch9Using_Linux_Tools_1d5', 'ch9Using_Linux_Tools_1d6', 'ch9Using_Linux_Tools_1d7', 'ch9Using_Linux_Tools_1d8', 'ch9Using_Linux_Tools_1d9', 'ch9Using_Linux_Tools_1da', 'ch9Using_Linux_Tools_1db', 'ch9Using_Linux_Tools_1dc', 'ch9Using_Linux_Tools_1dd', 'ch9Using_Linux_Tools_1de', 'ch9Using_Linux_Tools_1df', 'ch9Using_Linux_Tools_1e0', 'ch9Using_Linux_Tools_1e1'], 'ch1Introduction': ['ch1Introduction_1', 'ch1Introduction_2', 'ch1Introduction_3', 'ch1Introduction_4', 'ch1Introduction_5', 'ch1Introduction_6', 'ch1Introduction_7', 'ch1Introduction_8', 'ch1Introduction_9', 'ch1Introduction_a', 'ch1Introduction_b', 'ch1Introduction_c', 'ch1Introduction_d', 'ch1Introduction_e', 'ch1Introduction_f', 'ch1Introduction_10', 'ch1Introduction_11', 'ch1Introduction_12', 'ch1Introduction_13', 'ch1Introduction_14', 'ch1Introduction_15', 'ch1Introduction_16', 'ch1Introduction_17', 'ch1Introduction_18', 'ch1Introduction_19', 'ch1Introduction_1a', 'ch1Introduction_1b', 'ch1Introduction_1c', 'ch1Introduction_1d', 'ch1Introduction_1e', 'ch1Introduction_1f', 'ch1Introduction_20', 'ch1Introduction_21', 'ch1Introduction_22', 'ch1Introduction_23', 'ch1Introduction_24', 'ch1Introduction_25', 'ch1Introduction_26', 'ch1Introduction_27', 'ch1Introduction_28', 'ch1Introduction_29', 'ch1Introduction_2a', 'ch1Introduction_2b', 'ch1Introduction_2c', 'ch1Introduction_2d', 'ch1Introduction_2e', 'ch1Introduction_2f', 'ch1Introduction_30', 'ch1Introduction_31', 'ch1Introduction_32', 'ch1Introduction_33', 'ch1Introduction_34', 'ch1Introduction_35', 'ch1Introduction_36', 'ch1Introduction_37', 'ch1Introduction_38', 'ch1Introduction_39', 'ch1Introduction_3a', 'ch1Introduction_3b', 'ch1Introduction_3c', 'ch1Introduction_3d', 'ch1Introduction_3e', 'ch1Introduction_3f', 'ch1Introduction_40', 'ch1Introduction_41', 'ch1Introduction_42', 'ch1Introduction_43', 'ch1Introduction_44', 'ch1Introduction_45', 'ch1Introduction_46', 'ch1Introduction_47', 'ch1Introduction_48', 'ch1Introduction_49', 'ch1Introduction_4a', 'ch1Introduction_4b', 'ch1Introduction_4c', 'ch1Introduction_4d', 'ch1Introduction_4e', 'ch1Introduction_4f', 'ch1Introduction_50', 'ch1Introduction_51', 'ch1Introduction_52', 'ch1Introduction_53', 'ch1Introduction_54', 'ch1Introduction_55', 'ch1Introduction_56', 'ch1Introduction_57', 'ch1Introduction_58', 'ch1Introduction_59', 'ch1Introduction_5a', 'ch1Introduction_5b', 'ch1Introduction_5c', 'ch1Introduction_5d', 'ch1Introduction_5e', 'ch1Introduction_5f', 'ch1Introduction_60', 'ch1Introduction_61', 'ch1Introduction_62', 'ch1Introduction_63', 'ch1Introduction_64', 'ch1Introduction_65', 'ch1Introduction_66', 'ch1Introduction_67', 'ch1Introduction_68', 'ch1Introduction_69', 'ch1Introduction_6a', 'ch1Introduction_6b', 'ch1Introduction_6c', 'ch1Introduction_6d', 'ch1Introduction_6e', 'ch1Introduction_6f', 'ch1Introduction_70', 'ch1Introduction_71', 'ch1Introduction_72', 'ch1Introduction_73', 'ch1Introduction_74', 'ch1Introduction_75', 'ch1Introduction_76', 'ch1Introduction_77', 'ch1Introduction_78', 'ch1Introduction_79', 'ch1Introduction_7a', 'ch1Introduction_7b', 'ch1Introduction_7c', 'ch1Introduction_7d', 'ch1Introduction_7e', 'ch1Introduction_7f', 'ch1Introduction_80', 'ch1Introduction_81', 'ch1Introduction_82', 'ch1Introduction_83', 'ch1Introduction_84', 'ch1Introduction_85', 'ch1Introduction_86', 'ch1Introduction_87', 'ch1Introduction_88', 'ch1Introduction_89', 'ch1Introduction_8a', 'ch1Introduction_8b', 'ch1Introduction_8c', 'ch1Introduction_8d', 'ch1Introduction_8e', 'ch1Introduction_8f', 'ch1Introduction_90', 'ch1Introduction_91', 'ch1Introduction_92', 'ch1Introduction_93', 'ch1Introduction_94', 'ch1Introduction_95', 'ch1Introduction_96', 'ch1Introduction_97', 'ch1Introduction_98', 'ch1Introduction_99', 'ch1Introduction_9a', 'ch1Introduction_9b', 'ch1Introduction_9c', 'ch1Introduction_9d', 'ch1Introduction_9e', 'ch1Introduction_9f', 'ch1Introduction_a0', 'ch1Introduction_a1', 'ch1Introduction_a2', 'ch1Introduction_a3', 'ch1Introduction_a4', 'ch1Introduction_a5', 'ch1Introduction_a6', 'ch1Introduction_a7', 'ch1Introduction_a8', 'ch1Introduction_a9', 'ch1Introduction_aa', 'ch1Introduction_ab', 'ch1Introduction_ac', 'ch1Introduction_ad', 'ch1Introduction_ae', 'ch1Introduction_af', 'ch1Introduction_b0', 'ch1Introduction_b1', 'ch1Introduction_b2', 'ch1Introduction_b3', 'ch1Introduction_b4', 'ch1Introduction_b5', 'ch1Introduction_b6', 'ch1Introduction_b7', 'ch1Introduction_b8', 'ch1Introduction_b9', 'ch1Introduction_ba', 'ch1Introduction_bb', 'ch1Introduction_bc', 'ch1Introduction_bd', 'ch1Introduction_be', 'ch1Introduction_bf', 'ch1Introduction_c0', 'ch1Introduction_c1', 'ch1Introduction_c2', 'ch1Introduction_c3', 'ch1Introduction_c4', 'ch1Introduction_c5', 'ch1Introduction_c6', 'ch1Introduction_c7', 'ch1Introduction_c8', 'ch1Introduction_c9', 'ch1Introduction_ca', 'ch1Introduction_cb', 'ch1Introduction_cc', 'ch1Introduction_cd', 'ch1Introduction_ce', 'ch1Introduction_cf', 'ch1Introduction_d0', 'ch1Introduction_d1', 'ch1Introduction_d2', 'ch1Introduction_d3', 'ch1Introduction_d4', 'ch1Introduction_d5', 'ch1Introduction_d6', 'ch1Introduction_d7', 'ch1Introduction_d8', 'ch1Introduction_d9', 'ch1Introduction_da', 'ch1Introduction_db', 'ch1Introduction_dc', 'ch1Introduction_dd', 'ch1Introduction_de', 'ch1Introduction_df', 'ch1Introduction_e0', 'ch1Introduction_e1', 'ch1Introduction_e2', 'ch1Introduction_e3', 'ch1Introduction_e4', 'ch1Introduction_e5', 'ch1Introduction_e6', 'ch1Introduction_e7', 'ch1Introduction_e8', 'ch1Introduction_e9', 'ch1Introduction_ea', 'ch1Introduction_eb', 'ch1Introduction_ec', 'ch1Introduction_ed', 'ch1Introduction_ee', 'ch1Introduction_ef', 'ch1Introduction_f0', 'ch1Introduction_f1', 'ch1Introduction_f2', 'ch1Introduction_f3', 'ch1Introduction_f4', 'ch1Introduction_f5', 'ch1Introduction_f6', 'ch1Introduction_f7', 'ch1Introduction_f8', 'ch1Introduction_f9', 'ch1Introduction_fa', 'ch1Introduction_fb', 'ch1Introduction_fc', 'ch1Introduction_fd', 'ch1Introduction_fe', 'ch1Introduction_ff', 'ch1Introduction_100', 'ch1Introduction_101', 'ch1Introduction_102', 'ch1Introduction_103', 'ch1Introduction_104', 'ch1Introduction_105', 'ch1Introduction_106', 'ch1Introduction_107', 'ch1Introduction_108', 'ch1Introduction_109', 'ch1Introduction_10a', 'ch1Introduction_10b', 'ch1Introduction_10c', 'ch1Introduction_10d', 'ch1Introduction_10e', 'ch1Introduction_10f', 'ch1Introduction_110', 'ch1Introduction_111', 'ch1Introduction_112', 'ch1Introduction_113', 'ch1Introduction_114', 'ch1Introduction_115', 'ch1Introduction_116', 'ch1Introduction_117', 'ch1Introduction_118', 'ch1Introduction_119', 'ch1Introduction_11a', 'ch1Introduction_11b', 'ch1Introduction_11c', 'ch1Introduction_11d', 'ch1Introduction_11e', 'ch1Introduction_11f', 'ch1Introduction_120', 'ch1Introduction_121', 'ch1Introduction_122', 'ch1Introduction_123', 'ch1Introduction_124', 'ch1Introduction_125', 'ch1Introduction_126', 'ch1Introduction_127', 'ch1Introduction_128', 'ch1Introduction_129', 'ch1Introduction_12a', 'ch1Introduction_12b', 'ch1Introduction_12c', 'ch1Introduction_12d', 'ch1Introduction_12e', 'ch1Introduction_12f', 'ch1Introduction_130', 'ch1Introduction_131', 'ch1Introduction_132', 'ch1Introduction_133', 'ch1Introduction_134', 'ch1Introduction_135', 'ch1Introduction_136', 'ch1Introduction_137', 'ch1Introduction_138', 'ch1Introduction_139', 'ch1Introduction_13a', 'ch1Introduction_13b', 'ch1Introduction_13c', 'ch1Introduction_13d', 'ch1Introduction_13e', 'ch1Introduction_13f', 'ch1Introduction_140', 'ch1Introduction_141', 'ch1Introduction_142', 'ch1Introduction_143', 'ch1Introduction_144', 'ch1Introduction_145', 'ch1Introduction_146', 'ch1Introduction_147', 'ch1Introduction_148', 'ch1Introduction_149', 'ch1Introduction_14a', 'ch1Introduction_14b', 'ch1Introduction_14c', 'ch1Introduction_14d', 'ch1Introduction_14e', 'ch1Introduction_14f', 'ch1Introduction_150', 'ch1Introduction_151', 'ch1Introduction_152', 'ch1Introduction_153', 'ch1Introduction_154', 'ch1Introduction_155', 'ch1Introduction_156', 'ch1Introduction_157', 'ch1Introduction_158', 'ch1Introduction_159', 'ch1Introduction_15a', 'ch1Introduction_15b', 'ch1Introduction_15c', 'ch1Introduction_15d', 'ch1Introduction_15e', 'ch1Introduction_15f', 'ch1Introduction_160', 'ch1Introduction_161', 'ch1Introduction_162', 'ch1Introduction_163', 'ch1Introduction_164', 'ch1Introduction_165', 'ch1Introduction_166', 'ch1Introduction_167', 'ch1Introduction_168', 'ch1Introduction_169', 'ch1Introduction_16a', 'ch1Introduction_16b', 'ch1Introduction_16c', 'ch1Introduction_16d', 'ch1Introduction_16e', 'ch1Introduction_16f', 'ch1Introduction_170', 'ch1Introduction_171', 'ch1Introduction_172', 'ch1Introduction_173', 'ch1Introduction_174', 'ch1Introduction_175', 'ch1Introduction_176', 'ch1Introduction_177', 'ch1Introduction_178', 'ch1Introduction_179', 'ch1Introduction_17a', 'ch1Introduction_17b', 'ch1Introduction_17c', 'ch1Introduction_17d', 'ch1Introduction_17e', 'ch1Introduction_17f', 'ch1Introduction_180', 'ch1Introduction_181', 'ch1Introduction_182', 'ch1Introduction_183', 'ch1Introduction_184', 'ch1Introduction_185', 'ch1Introduction_186', 'ch1Introduction_187', 'ch1Introduction_188', 'ch1Introduction_189', 'ch1Introduction_18a', 'ch1Introduction_18b', 'ch1Introduction_18c', 'ch1Introduction_18d', 'ch1Introduction_18e', 'ch1Introduction_18f', 'ch1Introduction_190', 'ch1Introduction_191', 'ch1Introduction_192', 'ch1Introduction_193', 'ch1Introduction_194', 'ch1Introduction_195', 'ch1Introduction_196', 'ch1Introduction_197', 'ch1Introduction_198', 'ch1Introduction_199', 'ch1Introduction_19a', 'ch1Introduction_19b', 'ch1Introduction_19c', 'ch1Introduction_19d', 'ch1Introduction_19e', 'ch1Introduction_19f', 'ch1Introduction_1a0', 'ch1Introduction_1a1', 'ch1Introduction_1a2', 'ch1Introduction_1a3', 'ch1Introduction_1a4', 'ch1Introduction_1a5', 'ch1Introduction_1a6', 'ch1Introduction_1a7', 'ch1Introduction_1a8', 'ch1Introduction_1a9', 'ch1Introduction_1aa', 'ch1Introduction_1ab', 'ch1Introduction_1ac', 'ch1Introduction_1ad', 'ch1Introduction_1ae', 'ch1Introduction_1af', 'ch1Introduction_1b0', 'ch1Introduction_1b1', 'ch1Introduction_1b2', 'ch1Introduction_1b3', 'ch1Introduction_1b4', 'ch1Introduction_1b5', 'ch1Introduction_1b6', 'ch1Introduction_1b7', 'ch1Introduction_1b8', 'ch1Introduction_1b9', 'ch1Introduction_1ba', 'ch1Introduction_1bb', 'ch1Introduction_1bc', 'ch1Introduction_1bd', 'ch1Introduction_1be', 'ch1Introduction_1bf', 'ch1Introduction_1c0', 'ch1Introduction_1c1', 'ch1Introduction_1c2', 'ch1Introduction_1c3', 'ch1Introduction_1c4', 'ch1Introduction_1c5', 'ch1Introduction_1c6', 'ch1Introduction_1c7', 'ch1Introduction_1c8', 'ch1Introduction_1c9', 'ch1Introduction_1ca', 'ch1Introduction_1cb', 'ch1Introduction_1cc', 'ch1Introduction_1cd', 'ch1Introduction_1ce', 'ch1Introduction_1cf', 'ch1Introduction_1d0', 'ch1Introduction_1d1', 'ch1Introduction_1d2', 'ch1Introduction_1d3', 'ch1Introduction_1d4', 'ch1Introduction_1d5', 'ch1Introduction_1d6', 'ch1Introduction_1d7', 'ch1Introduction_1d8', 'ch1Introduction_1d9', 'ch1Introduction_1da', 'ch1Introduction_1db', 'ch1Introduction_1dc', 'ch1Introduction_1dd', 'ch1Introduction_1de', 'ch1Introduction_1df', 'ch1Introduction_1e0', 'ch1Introduction_1e1'], 'ch5func': ['ch5func_1', 'ch5func_2', 'ch5func_3', 'ch5func_4', 'ch5func_5', 'ch5func_6', 'ch5func_7', 'ch5func_8', 'ch5func_9', 'ch5func_a', 'ch5func_b', 'ch5func_c', 'ch5func_d', 'ch5func_e', 'ch5func_f', 'ch5func_10', 'ch5func_11', 'ch5func_12', 'ch5func_13', 'ch5func_14', 'ch5func_15', 'ch5func_16', 'ch5func_17', 'ch5func_18', 'ch5func_19', 'ch5func_1a', 'ch5func_1b', 'ch5func_1c', 'ch5func_1d', 'ch5func_1e', 'ch5func_1f', 'ch5func_20', 'ch5func_21', 'ch5func_22', 'ch5func_23', 'ch5func_24', 'ch5func_25', 'ch5func_26', 'ch5func_27', 'ch5func_28', 'ch5func_29', 'ch5func_2a', 'ch5func_2b', 'ch5func_2c', 'ch5func_2d', 'ch5func_2e', 'ch5func_2f', 'ch5func_30', 'ch5func_31', 'ch5func_32', 'ch5func_33', 'ch5func_34', 'ch5func_35', 'ch5func_36', 'ch5func_37', 'ch5func_38', 'ch5func_39', 'ch5func_3a', 'ch5func_3b', 'ch5func_3c', 'ch5func_3d', 'ch5func_3e', 'ch5func_3f', 'ch5func_40', 'ch5func_41', 'ch5func_42', 'ch5func_43', 'ch5func_44', 'ch5func_45', 'ch5func_46', 'ch5func_47', 'ch5func_48', 'ch5func_49', 'ch5func_4a', 'ch5func_4b', 'ch5func_4c', 'ch5func_4d', 'ch5func_4e', 'ch5func_4f', 'ch5func_50', 'ch5func_51', 'ch5func_52', 'ch5func_53', 'ch5func_54', 'ch5func_55', 'ch5func_56', 'ch5func_57', 'ch5func_58', 'ch5func_59', 'ch5func_5a', 'ch5func_5b', 'ch5func_5c', 'ch5func_5d', 'ch5func_5e', 'ch5func_5f', 'ch5func_60', 'ch5func_61', 'ch5func_62', 'ch5func_63', 'ch5func_64', 'ch5func_65', 'ch5func_66', 'ch5func_67', 'ch5func_68', 'ch5func_69', 'ch5func_6a', 'ch5func_6b', 'ch5func_6c', 'ch5func_6d', 'ch5func_6e', 'ch5func_6f', 'ch5func_70', 'ch5func_71', 'ch5func_72', 'ch5func_73', 'ch5func_74', 'ch5func_75', 'ch5func_76', 'ch5func_77', 'ch5func_78', 'ch5func_79', 'ch5func_7a', 'ch5func_7b', 'ch5func_7c', 'ch5func_7d', 'ch5func_7e', 'ch5func_7f', 'ch5func_80', 'ch5func_81', 'ch5func_82', 'ch5func_83', 'ch5func_84', 'ch5func_85', 'ch5func_86', 'ch5func_87', 'ch5func_88', 'ch5func_89', 'ch5func_8a', 'ch5func_8b', 'ch5func_8c', 'ch5func_8d', 'ch5func_8e', 'ch5func_8f', 'ch5func_90', 'ch5func_91', 'ch5func_92', 'ch5func_93', 'ch5func_94', 'ch5func_95', 'ch5func_96', 'ch5func_97', 'ch5func_98', 'ch5func_99', 'ch5func_9a', 'ch5func_9b', 'ch5func_9c', 'ch5func_9d', 'ch5func_9e', 'ch5func_9f', 'ch5func_a0', 'ch5func_a1', 'ch5func_a2', 'ch5func_a3', 'ch5func_a4', 'ch5func_a5', 'ch5func_a6', 'ch5func_a7', 'ch5func_a8', 'ch5func_a9', 'ch5func_aa', 'ch5func_ab', 'ch5func_ac', 'ch5func_ad', 'ch5func_ae', 'ch5func_af', 'ch5func_b0', 'ch5func_b1', 'ch5func_b2', 'ch5func_b3', 'ch5func_b4', 'ch5func_b5', 'ch5func_b6', 'ch5func_b7', 'ch5func_b8', 'ch5func_b9', 'ch5func_ba', 'ch5func_bb', 'ch5func_bc', 'ch5func_bd', 'ch5func_be', 'ch5func_bf', 'ch5func_c0', 'ch5func_c1', 'ch5func_c2', 'ch5func_c3', 'ch5func_c4', 'ch5func_c5', 'ch5func_c6', 'ch5func_c7', 'ch5func_c8', 'ch5func_c9', 'ch5func_ca', 'ch5func_cb', 'ch5func_cc', 'ch5func_cd', 'ch5func_ce', 'ch5func_cf', 'ch5func_d0', 'ch5func_d1', 'ch5func_d2', 'ch5func_d3', 'ch5func_d4', 'ch5func_d5', 'ch5func_d6', 'ch5func_d7', 'ch5func_d8', 'ch5func_d9', 'ch5func_da', 'ch5func_db', 'ch5func_dc', 'ch5func_dd', 'ch5func_de', 'ch5func_df', 'ch5func_e0', 'ch5func_e1', 'ch5func_e2', 'ch5func_e3', 'ch5func_e4', 'ch5func_e5', 'ch5func_e6', 'ch5func_e7', 'ch5func_e8', 'ch5func_e9', 'ch5func_ea', 'ch5func_eb', 'ch5func_ec', 'ch5func_ed', 'ch5func_ee', 'ch5func_ef', 'ch5func_f0', 'ch5func_f1', 'ch5func_f2', 'ch5func_f3', 'ch5func_f4', 'ch5func_f5', 'ch5func_f6', 'ch5func_f7', 'ch5func_f8', 'ch5func_f9', 'ch5func_fa', 'ch5func_fb', 'ch5func_fc', 'ch5func_fd', 'ch5func_fe', 'ch5func_ff', 'ch5func_100', 'ch5func_101', 'ch5func_102', 'ch5func_103', 'ch5func_104', 'ch5func_105', 'ch5func_106', 'ch5func_107', 'ch5func_108', 'ch5func_109', 'ch5func_10a', 'ch5func_10b', 'ch5func_10c', 'ch5func_10d', 'ch5func_10e', 'ch5func_10f', 'ch5func_110', 'ch5func_111', 'ch5func_112', 'ch5func_113', 'ch5func_114', 'ch5func_115', 'ch5func_116', 'ch5func_117', 'ch5func_118', 'ch5func_119', 'ch5func_11a', 'ch5func_11b', 'ch5func_11c', 'ch5func_11d', 'ch5func_11e', 'ch5func_11f', 'ch5func_120', 'ch5func_121', 'ch5func_122', 'ch5func_123', 'ch5func_124', 'ch5func_125', 'ch5func_126', 'ch5func_127', 'ch5func_128', 'ch5func_129', 'ch5func_12a', 'ch5func_12b', 'ch5func_12c', 'ch5func_12d', 'ch5func_12e', 'ch5func_12f', 'ch5func_130', 'ch5func_131', 'ch5func_132', 'ch5func_133', 'ch5func_134', 'ch5func_135', 'ch5func_136', 'ch5func_137', 'ch5func_138', 'ch5func_139', 'ch5func_13a', 'ch5func_13b', 'ch5func_13c', 'ch5func_13d', 'ch5func_13e', 'ch5func_13f', 'ch5func_140', 'ch5func_141', 'ch5func_142', 'ch5func_143', 'ch5func_144', 'ch5func_145', 'ch5func_146', 'ch5func_147', 'ch5func_148', 'ch5func_149', 'ch5func_14a', 'ch5func_14b', 'ch5func_14c', 'ch5func_14d', 'ch5func_14e', 'ch5func_14f', 'ch5func_150', 'ch5func_151', 'ch5func_152', 'ch5func_153', 'ch5func_154', 'ch5func_155', 'ch5func_156', 'ch5func_157', 'ch5func_158', 'ch5func_159', 'ch5func_15a', 'ch5func_15b', 'ch5func_15c', 'ch5func_15d', 'ch5func_15e', 'ch5func_15f', 'ch5func_160', 'ch5func_161', 'ch5func_162', 'ch5func_163', 'ch5func_164', 'ch5func_165', 'ch5func_166', 'ch5func_167', 'ch5func_168', 'ch5func_169', 'ch5func_16a', 'ch5func_16b', 'ch5func_16c', 'ch5func_16d', 'ch5func_16e', 'ch5func_16f', 'ch5func_170', 'ch5func_171', 'ch5func_172', 'ch5func_173', 'ch5func_174', 'ch5func_175', 'ch5func_176', 'ch5func_177', 'ch5func_178', 'ch5func_179', 'ch5func_17a', 'ch5func_17b', 'ch5func_17c', 'ch5func_17d', 'ch5func_17e', 'ch5func_17f', 'ch5func_180', 'ch5func_181', 'ch5func_182', 'ch5func_183', 'ch5func_184', 'ch5func_185', 'ch5func_186', 'ch5func_187', 'ch5func_188', 'ch5func_189', 'ch5func_18a', 'ch5func_18b', 'ch5func_18c', 'ch5func_18d', 'ch5func_18e', 'ch5func_18f', 'ch5func_190', 'ch5func_191', 'ch5func_192', 'ch5func_193', 'ch5func_194', 'ch5func_195', 'ch5func_196', 'ch5func_197', 'ch5func_198', 'ch5func_199', 'ch5func_19a', 'ch5func_19b', 'ch5func_19c', 'ch5func_19d', 'ch5func_19e', 'ch5func_19f', 'ch5func_1a0', 'ch5func_1a1', 'ch5func_1a2', 'ch5func_1a3', 'ch5func_1a4', 'ch5func_1a5', 'ch5func_1a6', 'ch5func_1a7', 'ch5func_1a8', 'ch5func_1a9', 'ch5func_1aa', 'ch5func_1ab', 'ch5func_1ac', 'ch5func_1ad', 'ch5func_1ae', 'ch5func_1af', 'ch5func_1b0', 'ch5func_1b1', 'ch5func_1b2', 'ch5func_1b3', 'ch5func_1b4', 'ch5func_1b5', 'ch5func_1b6', 'ch5func_1b7', 'ch5func_1b8', 'ch5func_1b9', 'ch5func_1ba', 'ch5func_1bb', 'ch5func_1bc', 'ch5func_1bd', 'ch5func_1be', 'ch5func_1bf', 'ch5func_1c0', 'ch5func_1c1', 'ch5func_1c2', 'ch5func_1c3', 'ch5func_1c4', 'ch5func_1c5', 'ch5func_1c6', 'ch5func_1c7', 'ch5func_1c8', 'ch5func_1c9', 'ch5func_1ca', 'ch5func_1cb', 'ch5func_1cc', 'ch5func_1cd', 'ch5func_1ce', 'ch5func_1cf', 'ch5func_1d0', 'ch5func_1d1', 'ch5func_1d2', 'ch5func_1d3', 'ch5func_1d4', 'ch5func_1d5', 'ch5func_1d6', 'ch5func_1d7', 'ch5func_1d8', 'ch5func_1d9', 'ch5func_1da', 'ch5func_1db', 'ch5func_1dc', 'ch5func_1dd', 'ch5func_1de', 'ch5func_1df', 'ch5func_1e0', 'ch5func_1e1'], 'ch3list_tuples': ['ch3list_tuples_1', 'ch3list_tuples_2', 'ch3list_tuples_3', 'ch3list_tuples_4', 'ch3list_tuples_5', 'ch3list_tuples_6', 'ch3list_tuples_7', 'ch3list_tuples_8', 'ch3list_tuples_9', 'ch3list_tuples_a', 'ch3list_tuples_b', 'ch3list_tuples_c', 'ch3list_tuples_d', 'ch3list_tuples_e', 'ch3list_tuples_f', 'ch3list_tuples_10', 'ch3list_tuples_11', 'ch3list_tuples_12', 'ch3list_tuples_13', 'ch3list_tuples_14', 'ch3list_tuples_15', 'ch3list_tuples_16', 'ch3list_tuples_17', 'ch3list_tuples_18', 'ch3list_tuples_19', 'ch3list_tuples_1a', 'ch3list_tuples_1b', 'ch3list_tuples_1c', 'ch3list_tuples_1d', 'ch3list_tuples_1e', 'ch3list_tuples_1f', 'ch3list_tuples_20', 'ch3list_tuples_21', 'ch3list_tuples_22', 'ch3list_tuples_23', 'ch3list_tuples_24', 'ch3list_tuples_25', 'ch3list_tuples_26', 'ch3list_tuples_27', 'ch3list_tuples_28', 'ch3list_tuples_29', 'ch3list_tuples_2a', 'ch3list_tuples_2b', 'ch3list_tuples_2c', 'ch3list_tuples_2d', 'ch3list_tuples_2e', 'ch3list_tuples_2f', 'ch3list_tuples_30', 'ch3list_tuples_31', 'ch3list_tuples_32', 'ch3list_tuples_33', 'ch3list_tuples_34', 'ch3list_tuples_35', 'ch3list_tuples_36', 'ch3list_tuples_37', 'ch3list_tuples_38', 'ch3list_tuples_39', 'ch3list_tuples_3a', 'ch3list_tuples_3b', 'ch3list_tuples_3c', 'ch3list_tuples_3d', 'ch3list_tuples_3e', 'ch3list_tuples_3f', 'ch3list_tuples_40', 'ch3list_tuples_41', 'ch3list_tuples_42', 'ch3list_tuples_43', 'ch3list_tuples_44', 'ch3list_tuples_45', 'ch3list_tuples_46', 'ch3list_tuples_47', 'ch3list_tuples_48', 'ch3list_tuples_49', 'ch3list_tuples_4a', 'ch3list_tuples_4b', 'ch3list_tuples_4c', 'ch3list_tuples_4d', 'ch3list_tuples_4e', 'ch3list_tuples_4f', 'ch3list_tuples_50', 'ch3list_tuples_51', 'ch3list_tuples_52', 'ch3list_tuples_53', 'ch3list_tuples_54', 'ch3list_tuples_55', 'ch3list_tuples_56', 'ch3list_tuples_57', 'ch3list_tuples_58', 'ch3list_tuples_59', 'ch3list_tuples_5a', 'ch3list_tuples_5b', 'ch3list_tuples_5c', 'ch3list_tuples_5d', 'ch3list_tuples_5e', 'ch3list_tuples_5f', 'ch3list_tuples_60', 'ch3list_tuples_61', 'ch3list_tuples_62', 'ch3list_tuples_63', 'ch3list_tuples_64', 'ch3list_tuples_65', 'ch3list_tuples_66', 'ch3list_tuples_67', 'ch3list_tuples_68', 'ch3list_tuples_69', 'ch3list_tuples_6a', 'ch3list_tuples_6b', 'ch3list_tuples_6c', 'ch3list_tuples_6d', 'ch3list_tuples_6e', 'ch3list_tuples_6f', 'ch3list_tuples_70', 'ch3list_tuples_71', 'ch3list_tuples_72', 'ch3list_tuples_73', 'ch3list_tuples_74', 'ch3list_tuples_75', 'ch3list_tuples_76', 'ch3list_tuples_77', 'ch3list_tuples_78', 'ch3list_tuples_79', 'ch3list_tuples_7a', 'ch3list_tuples_7b', 'ch3list_tuples_7c', 'ch3list_tuples_7d', 'ch3list_tuples_7e', 'ch3list_tuples_7f', 'ch3list_tuples_80', 'ch3list_tuples_81', 'ch3list_tuples_82', 'ch3list_tuples_83', 'ch3list_tuples_84', 'ch3list_tuples_85', 'ch3list_tuples_86', 'ch3list_tuples_87', 'ch3list_tuples_88', 'ch3list_tuples_89', 'ch3list_tuples_8a', 'ch3list_tuples_8b', 'ch3list_tuples_8c', 'ch3list_tuples_8d', 'ch3list_tuples_8e', 'ch3list_tuples_8f', 'ch3list_tuples_90', 'ch3list_tuples_91', 'ch3list_tuples_92', 'ch3list_tuples_93', 'ch3list_tuples_94', 'ch3list_tuples_95', 'ch3list_tuples_96', 'ch3list_tuples_97', 'ch3list_tuples_98', 'ch3list_tuples_99', 'ch3list_tuples_9a', 'ch3list_tuples_9b', 'ch3list_tuples_9c', 'ch3list_tuples_9d', 'ch3list_tuples_9e', 'ch3list_tuples_9f', 'ch3list_tuples_a0', 'ch3list_tuples_a1', 'ch3list_tuples_a2', 'ch3list_tuples_a3', 'ch3list_tuples_a4', 'ch3list_tuples_a5', 'ch3list_tuples_a6', 'ch3list_tuples_a7', 'ch3list_tuples_a8', 'ch3list_tuples_a9', 'ch3list_tuples_aa', 'ch3list_tuples_ab', 'ch3list_tuples_ac', 'ch3list_tuples_ad', 'ch3list_tuples_ae', 'ch3list_tuples_af', 'ch3list_tuples_b0', 'ch3list_tuples_b1', 'ch3list_tuples_b2', 'ch3list_tuples_b3', 'ch3list_tuples_b4', 'ch3list_tuples_b5', 'ch3list_tuples_b6', 'ch3list_tuples_b7', 'ch3list_tuples_b8', 'ch3list_tuples_b9', 'ch3list_tuples_ba', 'ch3list_tuples_bb', 'ch3list_tuples_bc', 'ch3list_tuples_bd', 'ch3list_tuples_be', 'ch3list_tuples_bf', 'ch3list_tuples_c0', 'ch3list_tuples_c1', 'ch3list_tuples_c2', 'ch3list_tuples_c3', 'ch3list_tuples_c4', 'ch3list_tuples_c5', 'ch3list_tuples_c6', 'ch3list_tuples_c7', 'ch3list_tuples_c8', 'ch3list_tuples_c9', 'ch3list_tuples_ca', 'ch3list_tuples_cb', 'ch3list_tuples_cc', 'ch3list_tuples_cd', 'ch3list_tuples_ce', 'ch3list_tuples_cf', 'ch3list_tuples_d0', 'ch3list_tuples_d1', 'ch3list_tuples_d2', 'ch3list_tuples_d3', 'ch3list_tuples_d4', 'ch3list_tuples_d5', 'ch3list_tuples_d6', 'ch3list_tuples_d7', 'ch3list_tuples_d8', 'ch3list_tuples_d9', 'ch3list_tuples_da', 'ch3list_tuples_db', 'ch3list_tuples_dc', 'ch3list_tuples_dd', 'ch3list_tuples_de', 'ch3list_tuples_df', 'ch3list_tuples_e0', 'ch3list_tuples_e1', 'ch3list_tuples_e2', 'ch3list_tuples_e3', 'ch3list_tuples_e4', 'ch3list_tuples_e5', 'ch3list_tuples_e6', 'ch3list_tuples_e7', 'ch3list_tuples_e8', 'ch3list_tuples_e9', 'ch3list_tuples_ea', 'ch3list_tuples_eb', 'ch3list_tuples_ec', 'ch3list_tuples_ed', 'ch3list_tuples_ee', 'ch3list_tuples_ef', 'ch3list_tuples_f0', 'ch3list_tuples_f1', 'ch3list_tuples_f2', 'ch3list_tuples_f3', 'ch3list_tuples_f4', 'ch3list_tuples_f5', 'ch3list_tuples_f6', 'ch3list_tuples_f7', 'ch3list_tuples_f8', 'ch3list_tuples_f9', 'ch3list_tuples_fa', 'ch3list_tuples_fb', 'ch3list_tuples_fc', 'ch3list_tuples_fd', 'ch3list_tuples_fe', 'ch3list_tuples_ff', 'ch3list_tuples_100', 'ch3list_tuples_101', 'ch3list_tuples_102', 'ch3list_tuples_103', 'ch3list_tuples_104', 'ch3list_tuples_105', 'ch3list_tuples_106', 'ch3list_tuples_107', 'ch3list_tuples_108', 'ch3list_tuples_109', 'ch3list_tuples_10a', 'ch3list_tuples_10b', 'ch3list_tuples_10c', 'ch3list_tuples_10d', 'ch3list_tuples_10e', 'ch3list_tuples_10f', 'ch3list_tuples_110', 'ch3list_tuples_111', 'ch3list_tuples_112', 'ch3list_tuples_113', 'ch3list_tuples_114', 'ch3list_tuples_115', 'ch3list_tuples_116', 'ch3list_tuples_117', 'ch3list_tuples_118', 'ch3list_tuples_119', 'ch3list_tuples_11a', 'ch3list_tuples_11b', 'ch3list_tuples_11c', 'ch3list_tuples_11d', 'ch3list_tuples_11e', 'ch3list_tuples_11f', 'ch3list_tuples_120', 'ch3list_tuples_121', 'ch3list_tuples_122', 'ch3list_tuples_123', 'ch3list_tuples_124', 'ch3list_tuples_125', 'ch3list_tuples_126', 'ch3list_tuples_127', 'ch3list_tuples_128', 'ch3list_tuples_129', 'ch3list_tuples_12a', 'ch3list_tuples_12b', 'ch3list_tuples_12c', 'ch3list_tuples_12d', 'ch3list_tuples_12e', 'ch3list_tuples_12f', 'ch3list_tuples_130', 'ch3list_tuples_131', 'ch3list_tuples_132', 'ch3list_tuples_133', 'ch3list_tuples_134', 'ch3list_tuples_135', 'ch3list_tuples_136', 'ch3list_tuples_137', 'ch3list_tuples_138', 'ch3list_tuples_139', 'ch3list_tuples_13a', 'ch3list_tuples_13b', 'ch3list_tuples_13c', 'ch3list_tuples_13d', 'ch3list_tuples_13e', 'ch3list_tuples_13f', 'ch3list_tuples_140', 'ch3list_tuples_141', 'ch3list_tuples_142', 'ch3list_tuples_143', 'ch3list_tuples_144', 'ch3list_tuples_145', 'ch3list_tuples_146', 'ch3list_tuples_147', 'ch3list_tuples_148', 'ch3list_tuples_149', 'ch3list_tuples_14a', 'ch3list_tuples_14b', 'ch3list_tuples_14c', 'ch3list_tuples_14d', 'ch3list_tuples_14e', 'ch3list_tuples_14f', 'ch3list_tuples_150', 'ch3list_tuples_151', 'ch3list_tuples_152', 'ch3list_tuples_153', 'ch3list_tuples_154', 'ch3list_tuples_155', 'ch3list_tuples_156', 'ch3list_tuples_157', 'ch3list_tuples_158', 'ch3list_tuples_159', 'ch3list_tuples_15a', 'ch3list_tuples_15b', 'ch3list_tuples_15c', 'ch3list_tuples_15d', 'ch3list_tuples_15e', 'ch3list_tuples_15f', 'ch3list_tuples_160', 'ch3list_tuples_161', 'ch3list_tuples_162', 'ch3list_tuples_163', 'ch3list_tuples_164', 'ch3list_tuples_165', 'ch3list_tuples_166', 'ch3list_tuples_167', 'ch3list_tuples_168', 'ch3list_tuples_169', 'ch3list_tuples_16a', 'ch3list_tuples_16b', 'ch3list_tuples_16c', 'ch3list_tuples_16d', 'ch3list_tuples_16e', 'ch3list_tuples_16f', 'ch3list_tuples_170', 'ch3list_tuples_171', 'ch3list_tuples_172', 'ch3list_tuples_173', 'ch3list_tuples_174', 'ch3list_tuples_175', 'ch3list_tuples_176', 'ch3list_tuples_177', 'ch3list_tuples_178', 'ch3list_tuples_179', 'ch3list_tuples_17a', 'ch3list_tuples_17b', 'ch3list_tuples_17c', 'ch3list_tuples_17d', 'ch3list_tuples_17e', 'ch3list_tuples_17f', 'ch3list_tuples_180', 'ch3list_tuples_181', 'ch3list_tuples_182', 'ch3list_tuples_183', 'ch3list_tuples_184', 'ch3list_tuples_185', 'ch3list_tuples_186', 'ch3list_tuples_187', 'ch3list_tuples_188', 'ch3list_tuples_189', 'ch3list_tuples_18a', 'ch3list_tuples_18b', 'ch3list_tuples_18c', 'ch3list_tuples_18d', 'ch3list_tuples_18e', 'ch3list_tuples_18f', 'ch3list_tuples_190', 'ch3list_tuples_191', 'ch3list_tuples_192', 'ch3list_tuples_193', 'ch3list_tuples_194', 'ch3list_tuples_195', 'ch3list_tuples_196', 'ch3list_tuples_197', 'ch3list_tuples_198', 'ch3list_tuples_199', 'ch3list_tuples_19a', 'ch3list_tuples_19b', 'ch3list_tuples_19c', 'ch3list_tuples_19d', 'ch3list_tuples_19e', 'ch3list_tuples_19f', 'ch3list_tuples_1a0', 'ch3list_tuples_1a1', 'ch3list_tuples_1a2', 'ch3list_tuples_1a3', 'ch3list_tuples_1a4', 'ch3list_tuples_1a5', 'ch3list_tuples_1a6', 'ch3list_tuples_1a7', 'ch3list_tuples_1a8', 'ch3list_tuples_1a9', 'ch3list_tuples_1aa', 'ch3list_tuples_1ab', 'ch3list_tuples_1ac', 'ch3list_tuples_1ad', 'ch3list_tuples_1ae', 'ch3list_tuples_1af', 'ch3list_tuples_1b0', 'ch3list_tuples_1b1', 'ch3list_tuples_1b2', 'ch3list_tuples_1b3', 'ch3list_tuples_1b4', 'ch3list_tuples_1b5', 'ch3list_tuples_1b6', 'ch3list_tuples_1b7', 'ch3list_tuples_1b8', 'ch3list_tuples_1b9', 'ch3list_tuples_1ba', 'ch3list_tuples_1bb', 'ch3list_tuples_1bc', 'ch3list_tuples_1bd', 'ch3list_tuples_1be', 'ch3list_tuples_1bf', 'ch3list_tuples_1c0', 'ch3list_tuples_1c1', 'ch3list_tuples_1c2', 'ch3list_tuples_1c3', 'ch3list_tuples_1c4', 'ch3list_tuples_1c5', 'ch3list_tuples_1c6', 'ch3list_tuples_1c7', 'ch3list_tuples_1c8', 'ch3list_tuples_1c9', 'ch3list_tuples_1ca', 'ch3list_tuples_1cb', 'ch3list_tuples_1cc', 'ch3list_tuples_1cd', 'ch3list_tuples_1ce', 'ch3list_tuples_1cf', 'ch3list_tuples_1d0', 'ch3list_tuples_1d1', 'ch3list_tuples_1d2', 'ch3list_tuples_1d3', 'ch3list_tuples_1d4', 'ch3list_tuples_1d5', 'ch3list_tuples_1d6', 'ch3list_tuples_1d7', 'ch3list_tuples_1d8', 'ch3list_tuples_1d9', 'ch3list_tuples_1da', 'ch3list_tuples_1db', 'ch3list_tuples_1dc', 'ch3list_tuples_1dd', 'ch3list_tuples_1de', 'ch3list_tuples_1df', 'ch3list_tuples_1e0', 'ch3list_tuples_1e1'], 'ch2intro': ['ch2intro_1', 'ch2intro_2', 'ch2intro_3', 'ch2intro_4', 'ch2intro_5', 'ch2intro_6', 'ch2intro_7', 'ch2intro_8', 'ch2intro_9', 'ch2intro_a', 'ch2intro_b', 'ch2intro_c', 'ch2intro_d', 'ch2intro_e', 'ch2intro_f', 'ch2intro_10', 'ch2intro_11', 'ch2intro_12', 'ch2intro_13', 'ch2intro_14', 'ch2intro_15', 'ch2intro_16', 'ch2intro_17', 'ch2intro_18', 'ch2intro_19', 'ch2intro_1a', 'ch2intro_1b', 'ch2intro_1c', 'ch2intro_1d', 'ch2intro_1e', 'ch2intro_1f', 'ch2intro_20', 'ch2intro_21', 'ch2intro_22', 'ch2intro_23', 'ch2intro_24', 'ch2intro_25', 'ch2intro_26', 'ch2intro_27', 'ch2intro_28', 'ch2intro_29', 'ch2intro_2a', 'ch2intro_2b', 'ch2intro_2c', 'ch2intro_2d', 'ch2intro_2e', 'ch2intro_2f', 'ch2intro_30', 'ch2intro_31', 'ch2intro_32', 'ch2intro_33', 'ch2intro_34', 'ch2intro_35', 'ch2intro_36', 'ch2intro_37', 'ch2intro_38', 'ch2intro_39', 'ch2intro_3a', 'ch2intro_3b', 'ch2intro_3c', 'ch2intro_3d', 'ch2intro_3e', 'ch2intro_3f', 'ch2intro_40', 'ch2intro_41', 'ch2intro_42', 'ch2intro_43', 'ch2intro_44', 'ch2intro_45', 'ch2intro_46', 'ch2intro_47', 'ch2intro_48', 'ch2intro_49', 'ch2intro_4a', 'ch2intro_4b', 'ch2intro_4c', 'ch2intro_4d', 'ch2intro_4e', 'ch2intro_4f', 'ch2intro_50', 'ch2intro_51', 'ch2intro_52', 'ch2intro_53', 'ch2intro_54', 'ch2intro_55', 'ch2intro_56', 'ch2intro_57', 'ch2intro_58', 'ch2intro_59', 'ch2intro_5a', 'ch2intro_5b', 'ch2intro_5c', 'ch2intro_5d', 'ch2intro_5e', 'ch2intro_5f', 'ch2intro_60', 'ch2intro_61', 'ch2intro_62', 'ch2intro_63', 'ch2intro_64', 'ch2intro_65', 'ch2intro_66', 'ch2intro_67', 'ch2intro_68', 'ch2intro_69', 'ch2intro_6a', 'ch2intro_6b', 'ch2intro_6c', 'ch2intro_6d', 'ch2intro_6e', 'ch2intro_6f', 'ch2intro_70', 'ch2intro_71', 'ch2intro_72', 'ch2intro_73', 'ch2intro_74', 'ch2intro_75', 'ch2intro_76', 'ch2intro_77', 'ch2intro_78', 'ch2intro_79', 'ch2intro_7a', 'ch2intro_7b', 'ch2intro_7c', 'ch2intro_7d', 'ch2intro_7e', 'ch2intro_7f', 'ch2intro_80', 'ch2intro_81', 'ch2intro_82', 'ch2intro_83', 'ch2intro_84', 'ch2intro_85', 'ch2intro_86', 'ch2intro_87', 'ch2intro_88', 'ch2intro_89', 'ch2intro_8a', 'ch2intro_8b', 'ch2intro_8c', 'ch2intro_8d', 'ch2intro_8e', 'ch2intro_8f', 'ch2intro_90', 'ch2intro_91', 'ch2intro_92', 'ch2intro_93', 'ch2intro_94', 'ch2intro_95', 'ch2intro_96', 'ch2intro_97', 'ch2intro_98', 'ch2intro_99', 'ch2intro_9a', 'ch2intro_9b', 'ch2intro_9c', 'ch2intro_9d', 'ch2intro_9e', 'ch2intro_9f', 'ch2intro_a0', 'ch2intro_a1', 'ch2intro_a2', 'ch2intro_a3', 'ch2intro_a4', 'ch2intro_a5', 'ch2intro_a6', 'ch2intro_a7', 'ch2intro_a8', 'ch2intro_a9', 'ch2intro_aa', 'ch2intro_ab', 'ch2intro_ac', 'ch2intro_ad', 'ch2intro_ae', 'ch2intro_af', 'ch2intro_b0', 'ch2intro_b1', 'ch2intro_b2', 'ch2intro_b3', 'ch2intro_b4', 'ch2intro_b5', 'ch2intro_b6', 'ch2intro_b7', 'ch2intro_b8', 'ch2intro_b9', 'ch2intro_ba', 'ch2intro_bb', 'ch2intro_bc', 'ch2intro_bd', 'ch2intro_be', 'ch2intro_bf', 'ch2intro_c0', 'ch2intro_c1', 'ch2intro_c2', 'ch2intro_c3', 'ch2intro_c4', 'ch2intro_c5', 'ch2intro_c6', 'ch2intro_c7', 'ch2intro_c8', 'ch2intro_c9', 'ch2intro_ca', 'ch2intro_cb', 'ch2intro_cc', 'ch2intro_cd', 'ch2intro_ce', 'ch2intro_cf', 'ch2intro_d0', 'ch2intro_d1', 'ch2intro_d2', 'ch2intro_d3', 'ch2intro_d4', 'ch2intro_d5', 'ch2intro_d6', 'ch2intro_d7', 'ch2intro_d8', 'ch2intro_d9', 'ch2intro_da', 'ch2intro_db', 'ch2intro_dc', 'ch2intro_dd', 'ch2intro_de', 'ch2intro_df', 'ch2intro_e0', 'ch2intro_e1', 'ch2intro_e2', 'ch2intro_e3', 'ch2intro_e4', 'ch2intro_e5', 'ch2intro_e6', 'ch2intro_e7', 'ch2intro_e8', 'ch2intro_e9', 'ch2intro_ea', 'ch2intro_eb', 'ch2intro_ec', 'ch2intro_ed', 'ch2intro_ee', 'ch2intro_ef', 'ch2intro_f0', 'ch2intro_f1', 'ch2intro_f2', 'ch2intro_f3', 'ch2intro_f4', 'ch2intro_f5', 'ch2intro_f6', 'ch2intro_f7', 'ch2intro_f8', 'ch2intro_f9', 'ch2intro_fa', 'ch2intro_fb', 'ch2intro_fc', 'ch2intro_fd', 'ch2intro_fe', 'ch2intro_ff', 'ch2intro_100', 'ch2intro_101', 'ch2intro_102', 'ch2intro_103', 'ch2intro_104', 'ch2intro_105', 'ch2intro_106', 'ch2intro_107', 'ch2intro_108', 'ch2intro_109', 'ch2intro_10a', 'ch2intro_10b', 'ch2intro_10c', 'ch2intro_10d', 'ch2intro_10e', 'ch2intro_10f', 'ch2intro_110', 'ch2intro_111', 'ch2intro_112', 'ch2intro_113', 'ch2intro_114', 'ch2intro_115', 'ch2intro_116', 'ch2intro_117', 'ch2intro_118', 'ch2intro_119', 'ch2intro_11a', 'ch2intro_11b', 'ch2intro_11c', 'ch2intro_11d', 'ch2intro_11e', 'ch2intro_11f', 'ch2intro_120', 'ch2intro_121', 'ch2intro_122', 'ch2intro_123', 'ch2intro_124', 'ch2intro_125', 'ch2intro_126', 'ch2intro_127', 'ch2intro_128', 'ch2intro_129', 'ch2intro_12a', 'ch2intro_12b', 'ch2intro_12c', 'ch2intro_12d', 'ch2intro_12e', 'ch2intro_12f', 'ch2intro_130', 'ch2intro_131', 'ch2intro_132', 'ch2intro_133', 'ch2intro_134', 'ch2intro_135', 'ch2intro_136', 'ch2intro_137', 'ch2intro_138', 'ch2intro_139', 'ch2intro_13a', 'ch2intro_13b', 'ch2intro_13c', 'ch2intro_13d', 'ch2intro_13e', 'ch2intro_13f', 'ch2intro_140', 'ch2intro_141', 'ch2intro_142', 'ch2intro_143', 'ch2intro_144', 'ch2intro_145', 'ch2intro_146', 'ch2intro_147', 'ch2intro_148', 'ch2intro_149', 'ch2intro_14a', 'ch2intro_14b', 'ch2intro_14c', 'ch2intro_14d', 'ch2intro_14e', 'ch2intro_14f', 'ch2intro_150', 'ch2intro_151', 'ch2intro_152', 'ch2intro_153', 'ch2intro_154', 'ch2intro_155', 'ch2intro_156', 'ch2intro_157', 'ch2intro_158', 'ch2intro_159', 'ch2intro_15a', 'ch2intro_15b', 'ch2intro_15c', 'ch2intro_15d', 'ch2intro_15e', 'ch2intro_15f', 'ch2intro_160', 'ch2intro_161', 'ch2intro_162', 'ch2intro_163', 'ch2intro_164', 'ch2intro_165', 'ch2intro_166', 'ch2intro_167', 'ch2intro_168', 'ch2intro_169', 'ch2intro_16a', 'ch2intro_16b', 'ch2intro_16c', 'ch2intro_16d', 'ch2intro_16e', 'ch2intro_16f', 'ch2intro_170', 'ch2intro_171', 'ch2intro_172', 'ch2intro_173', 'ch2intro_174', 'ch2intro_175', 'ch2intro_176', 'ch2intro_177', 'ch2intro_178', 'ch2intro_179', 'ch2intro_17a', 'ch2intro_17b', 'ch2intro_17c', 'ch2intro_17d', 'ch2intro_17e', 'ch2intro_17f', 'ch2intro_180', 'ch2intro_181', 'ch2intro_182', 'ch2intro_183', 'ch2intro_184', 'ch2intro_185', 'ch2intro_186', 'ch2intro_187', 'ch2intro_188', 'ch2intro_189', 'ch2intro_18a', 'ch2intro_18b', 'ch2intro_18c', 'ch2intro_18d', 'ch2intro_18e', 'ch2intro_18f', 'ch2intro_190', 'ch2intro_191', 'ch2intro_192', 'ch2intro_193', 'ch2intro_194', 'ch2intro_195', 'ch2intro_196', 'ch2intro_197', 'ch2intro_198', 'ch2intro_199', 'ch2intro_19a', 'ch2intro_19b', 'ch2intro_19c', 'ch2intro_19d', 'ch2intro_19e', 'ch2intro_19f', 'ch2intro_1a0', 'ch2intro_1a1', 'ch2intro_1a2', 'ch2intro_1a3', 'ch2intro_1a4', 'ch2intro_1a5', 'ch2intro_1a6', 'ch2intro_1a7', 'ch2intro_1a8', 'ch2intro_1a9', 'ch2intro_1aa', 'ch2intro_1ab', 'ch2intro_1ac', 'ch2intro_1ad', 'ch2intro_1ae', 'ch2intro_1af', 'ch2intro_1b0', 'ch2intro_1b1', 'ch2intro_1b2', 'ch2intro_1b3', 'ch2intro_1b4', 'ch2intro_1b5', 'ch2intro_1b6', 'ch2intro_1b7', 'ch2intro_1b8', 'ch2intro_1b9', 'ch2intro_1ba', 'ch2intro_1bb', 'ch2intro_1bc', 'ch2intro_1bd', 'ch2intro_1be', 'ch2intro_1bf', 'ch2intro_1c0', 'ch2intro_1c1', 'ch2intro_1c2', 'ch2intro_1c3', 'ch2intro_1c4', 'ch2intro_1c5', 'ch2intro_1c6', 'ch2intro_1c7', 'ch2intro_1c8', 'ch2intro_1c9', 'ch2intro_1ca', 'ch2intro_1cb', 'ch2intro_1cc', 'ch2intro_1cd', 'ch2intro_1ce', 'ch2intro_1cf', 'ch2intro_1d0', 'ch2intro_1d1', 'ch2intro_1d2', 'ch2intro_1d3', 'ch2intro_1d4', 'ch2intro_1d5', 'ch2intro_1d6', 'ch2intro_1d7', 'ch2intro_1d8', 'ch2intro_1d9', 'ch2intro_1da', 'ch2intro_1db', 'ch2intro_1dc', 'ch2intro_1dd', 'ch2intro_1de', 'ch2intro_1df', 'ch2intro_1e0', 'ch2intro_1e1'], 'ch4strings_dicts': ['ch4strings_dicts_1', 'ch4strings_dicts_2', 'ch4strings_dicts_3', 'ch4strings_dicts_4', 'ch4strings_dicts_5', 'ch4strings_dicts_6', 'ch4strings_dicts_7', 'ch4strings_dicts_8', 'ch4strings_dicts_9', 'ch4strings_dicts_a', 'ch4strings_dicts_b', 'ch4strings_dicts_c', 'ch4strings_dicts_d', 'ch4strings_dicts_e', 'ch4strings_dicts_f', 'ch4strings_dicts_10', 'ch4strings_dicts_11', 'ch4strings_dicts_12', 'ch4strings_dicts_13', 'ch4strings_dicts_14', 'ch4strings_dicts_15', 'ch4strings_dicts_16', 'ch4strings_dicts_17', 'ch4strings_dicts_18', 'ch4strings_dicts_19', 'ch4strings_dicts_1a', 'ch4strings_dicts_1b', 'ch4strings_dicts_1c', 'ch4strings_dicts_1d', 'ch4strings_dicts_1e', 'ch4strings_dicts_1f', 'ch4strings_dicts_20', 'ch4strings_dicts_21', 'ch4strings_dicts_22', 'ch4strings_dicts_23', 'ch4strings_dicts_24', 'ch4strings_dicts_25', 'ch4strings_dicts_26', 'ch4strings_dicts_27', 'ch4strings_dicts_28', 'ch4strings_dicts_29', 'ch4strings_dicts_2a', 'ch4strings_dicts_2b', 'ch4strings_dicts_2c', 'ch4strings_dicts_2d', 'ch4strings_dicts_2e', 'ch4strings_dicts_2f', 'ch4strings_dicts_30', 'ch4strings_dicts_31', 'ch4strings_dicts_32', 'ch4strings_dicts_33', 'ch4strings_dicts_34', 'ch4strings_dicts_35', 'ch4strings_dicts_36', 'ch4strings_dicts_37', 'ch4strings_dicts_38', 'ch4strings_dicts_39', 'ch4strings_dicts_3a', 'ch4strings_dicts_3b', 'ch4strings_dicts_3c', 'ch4strings_dicts_3d', 'ch4strings_dicts_3e', 'ch4strings_dicts_3f', 'ch4strings_dicts_40', 'ch4strings_dicts_41', 'ch4strings_dicts_42', 'ch4strings_dicts_43', 'ch4strings_dicts_44', 'ch4strings_dicts_45', 'ch4strings_dicts_46', 'ch4strings_dicts_47', 'ch4strings_dicts_48', 'ch4strings_dicts_49', 'ch4strings_dicts_4a', 'ch4strings_dicts_4b', 'ch4strings_dicts_4c', 'ch4strings_dicts_4d', 'ch4strings_dicts_4e', 'ch4strings_dicts_4f', 'ch4strings_dicts_50', 'ch4strings_dicts_51', 'ch4strings_dicts_52', 'ch4strings_dicts_53', 'ch4strings_dicts_54', 'ch4strings_dicts_55', 'ch4strings_dicts_56', 'ch4strings_dicts_57', 'ch4strings_dicts_58', 'ch4strings_dicts_59', 'ch4strings_dicts_5a', 'ch4strings_dicts_5b', 'ch4strings_dicts_5c', 'ch4strings_dicts_5d', 'ch4strings_dicts_5e', 'ch4strings_dicts_5f', 'ch4strings_dicts_60', 'ch4strings_dicts_61', 'ch4strings_dicts_62', 'ch4strings_dicts_63', 'ch4strings_dicts_64', 'ch4strings_dicts_65', 'ch4strings_dicts_66', 'ch4strings_dicts_67', 'ch4strings_dicts_68', 'ch4strings_dicts_69', 'ch4strings_dicts_6a', 'ch4strings_dicts_6b', 'ch4strings_dicts_6c', 'ch4strings_dicts_6d', 'ch4strings_dicts_6e', 'ch4strings_dicts_6f', 'ch4strings_dicts_70', 'ch4strings_dicts_71', 'ch4strings_dicts_72', 'ch4strings_dicts_73', 'ch4strings_dicts_74', 'ch4strings_dicts_75', 'ch4strings_dicts_76', 'ch4strings_dicts_77', 'ch4strings_dicts_78', 'ch4strings_dicts_79', 'ch4strings_dicts_7a', 'ch4strings_dicts_7b', 'ch4strings_dicts_7c', 'ch4strings_dicts_7d', 'ch4strings_dicts_7e', 'ch4strings_dicts_7f', 'ch4strings_dicts_80', 'ch4strings_dicts_81', 'ch4strings_dicts_82', 'ch4strings_dicts_83', 'ch4strings_dicts_84', 'ch4strings_dicts_85', 'ch4strings_dicts_86', 'ch4strings_dicts_87', 'ch4strings_dicts_88', 'ch4strings_dicts_89', 'ch4strings_dicts_8a', 'ch4strings_dicts_8b', 'ch4strings_dicts_8c', 'ch4strings_dicts_8d', 'ch4strings_dicts_8e', 'ch4strings_dicts_8f', 'ch4strings_dicts_90', 'ch4strings_dicts_91', 'ch4strings_dicts_92', 'ch4strings_dicts_93', 'ch4strings_dicts_94', 'ch4strings_dicts_95', 'ch4strings_dicts_96', 'ch4strings_dicts_97', 'ch4strings_dicts_98', 'ch4strings_dicts_99', 'ch4strings_dicts_9a', 'ch4strings_dicts_9b', 'ch4strings_dicts_9c', 'ch4strings_dicts_9d', 'ch4strings_dicts_9e', 'ch4strings_dicts_9f', 'ch4strings_dicts_a0', 'ch4strings_dicts_a1', 'ch4strings_dicts_a2', 'ch4strings_dicts_a3', 'ch4strings_dicts_a4', 'ch4strings_dicts_a5', 'ch4strings_dicts_a6', 'ch4strings_dicts_a7', 'ch4strings_dicts_a8', 'ch4strings_dicts_a9', 'ch4strings_dicts_aa', 'ch4strings_dicts_ab', 'ch4strings_dicts_ac', 'ch4strings_dicts_ad', 'ch4strings_dicts_ae', 'ch4strings_dicts_af', 'ch4strings_dicts_b0', 'ch4strings_dicts_b1', 'ch4strings_dicts_b2', 'ch4strings_dicts_b3', 'ch4strings_dicts_b4', 'ch4strings_dicts_b5', 'ch4strings_dicts_b6', 'ch4strings_dicts_b7', 'ch4strings_dicts_b8', 'ch4strings_dicts_b9', 'ch4strings_dicts_ba', 'ch4strings_dicts_bb', 'ch4strings_dicts_bc', 'ch4strings_dicts_bd', 'ch4strings_dicts_be', 'ch4strings_dicts_bf', 'ch4strings_dicts_c0', 'ch4strings_dicts_c1', 'ch4strings_dicts_c2', 'ch4strings_dicts_c3', 'ch4strings_dicts_c4', 'ch4strings_dicts_c5', 'ch4strings_dicts_c6', 'ch4strings_dicts_c7', 'ch4strings_dicts_c8', 'ch4strings_dicts_c9', 'ch4strings_dicts_ca', 'ch4strings_dicts_cb', 'ch4strings_dicts_cc', 'ch4strings_dicts_cd', 'ch4strings_dicts_ce', 'ch4strings_dicts_cf', 'ch4strings_dicts_d0', 'ch4strings_dicts_d1', 'ch4strings_dicts_d2', 'ch4strings_dicts_d3', 'ch4strings_dicts_d4', 'ch4strings_dicts_d5', 'ch4strings_dicts_d6', 'ch4strings_dicts_d7', 'ch4strings_dicts_d8', 'ch4strings_dicts_d9', 'ch4strings_dicts_da', 'ch4strings_dicts_db', 'ch4strings_dicts_dc', 'ch4strings_dicts_dd', 'ch4strings_dicts_de', 'ch4strings_dicts_df', 'ch4strings_dicts_e0', 'ch4strings_dicts_e1', 'ch4strings_dicts_e2', 'ch4strings_dicts_e3', 'ch4strings_dicts_e4', 'ch4strings_dicts_e5', 'ch4strings_dicts_e6', 'ch4strings_dicts_e7', 'ch4strings_dicts_e8', 'ch4strings_dicts_e9', 'ch4strings_dicts_ea', 'ch4strings_dicts_eb', 'ch4strings_dicts_ec', 'ch4strings_dicts_ed', 'ch4strings_dicts_ee', 'ch4strings_dicts_ef', 'ch4strings_dicts_f0', 'ch4strings_dicts_f1', 'ch4strings_dicts_f2', 'ch4strings_dicts_f3', 'ch4strings_dicts_f4', 'ch4strings_dicts_f5', 'ch4strings_dicts_f6', 'ch4strings_dicts_f7', 'ch4strings_dicts_f8', 'ch4strings_dicts_f9', 'ch4strings_dicts_fa', 'ch4strings_dicts_fb', 'ch4strings_dicts_fc', 'ch4strings_dicts_fd', 'ch4strings_dicts_fe', 'ch4strings_dicts_ff', 'ch4strings_dicts_100', 'ch4strings_dicts_101', 'ch4strings_dicts_102', 'ch4strings_dicts_103', 'ch4strings_dicts_104', 'ch4strings_dicts_105', 'ch4strings_dicts_106', 'ch4strings_dicts_107', 'ch4strings_dicts_108', 'ch4strings_dicts_109', 'ch4strings_dicts_10a', 'ch4strings_dicts_10b', 'ch4strings_dicts_10c', 'ch4strings_dicts_10d', 'ch4strings_dicts_10e', 'ch4strings_dicts_10f', 'ch4strings_dicts_110', 'ch4strings_dicts_111', 'ch4strings_dicts_112', 'ch4strings_dicts_113', 'ch4strings_dicts_114', 'ch4strings_dicts_115', 'ch4strings_dicts_116', 'ch4strings_dicts_117', 'ch4strings_dicts_118', 'ch4strings_dicts_119', 'ch4strings_dicts_11a', 'ch4strings_dicts_11b', 'ch4strings_dicts_11c', 'ch4strings_dicts_11d', 'ch4strings_dicts_11e', 'ch4strings_dicts_11f', 'ch4strings_dicts_120', 'ch4strings_dicts_121', 'ch4strings_dicts_122', 'ch4strings_dicts_123', 'ch4strings_dicts_124', 'ch4strings_dicts_125', 'ch4strings_dicts_126', 'ch4strings_dicts_127', 'ch4strings_dicts_128', 'ch4strings_dicts_129', 'ch4strings_dicts_12a', 'ch4strings_dicts_12b', 'ch4strings_dicts_12c', 'ch4strings_dicts_12d', 'ch4strings_dicts_12e', 'ch4strings_dicts_12f', 'ch4strings_dicts_130', 'ch4strings_dicts_131', 'ch4strings_dicts_132', 'ch4strings_dicts_133', 'ch4strings_dicts_134', 'ch4strings_dicts_135', 'ch4strings_dicts_136', 'ch4strings_dicts_137', 'ch4strings_dicts_138', 'ch4strings_dicts_139', 'ch4strings_dicts_13a', 'ch4strings_dicts_13b', 'ch4strings_dicts_13c', 'ch4strings_dicts_13d', 'ch4strings_dicts_13e', 'ch4strings_dicts_13f', 'ch4strings_dicts_140', 'ch4strings_dicts_141', 'ch4strings_dicts_142', 'ch4strings_dicts_143', 'ch4strings_dicts_144', 'ch4strings_dicts_145', 'ch4strings_dicts_146', 'ch4strings_dicts_147', 'ch4strings_dicts_148', 'ch4strings_dicts_149', 'ch4strings_dicts_14a', 'ch4strings_dicts_14b', 'ch4strings_dicts_14c', 'ch4strings_dicts_14d', 'ch4strings_dicts_14e', 'ch4strings_dicts_14f', 'ch4strings_dicts_150', 'ch4strings_dicts_151', 'ch4strings_dicts_152', 'ch4strings_dicts_153', 'ch4strings_dicts_154', 'ch4strings_dicts_155', 'ch4strings_dicts_156', 'ch4strings_dicts_157', 'ch4strings_dicts_158', 'ch4strings_dicts_159', 'ch4strings_dicts_15a', 'ch4strings_dicts_15b', 'ch4strings_dicts_15c', 'ch4strings_dicts_15d', 'ch4strings_dicts_15e', 'ch4strings_dicts_15f', 'ch4strings_dicts_160', 'ch4strings_dicts_161', 'ch4strings_dicts_162', 'ch4strings_dicts_163', 'ch4strings_dicts_164', 'ch4strings_dicts_165', 'ch4strings_dicts_166', 'ch4strings_dicts_167', 'ch4strings_dicts_168', 'ch4strings_dicts_169', 'ch4strings_dicts_16a', 'ch4strings_dicts_16b', 'ch4strings_dicts_16c', 'ch4strings_dicts_16d', 'ch4strings_dicts_16e', 'ch4strings_dicts_16f', 'ch4strings_dicts_170', 'ch4strings_dicts_171', 'ch4strings_dicts_172', 'ch4strings_dicts_173', 'ch4strings_dicts_174', 'ch4strings_dicts_175', 'ch4strings_dicts_176', 'ch4strings_dicts_177', 'ch4strings_dicts_178', 'ch4strings_dicts_179', 'ch4strings_dicts_17a', 'ch4strings_dicts_17b', 'ch4strings_dicts_17c', 'ch4strings_dicts_17d', 'ch4strings_dicts_17e', 'ch4strings_dicts_17f', 'ch4strings_dicts_180', 'ch4strings_dicts_181', 'ch4strings_dicts_182', 'ch4strings_dicts_183', 'ch4strings_dicts_184', 'ch4strings_dicts_185', 'ch4strings_dicts_186', 'ch4strings_dicts_187', 'ch4strings_dicts_188', 'ch4strings_dicts_189', 'ch4strings_dicts_18a', 'ch4strings_dicts_18b', 'ch4strings_dicts_18c', 'ch4strings_dicts_18d', 'ch4strings_dicts_18e', 'ch4strings_dicts_18f', 'ch4strings_dicts_190', 'ch4strings_dicts_191', 'ch4strings_dicts_192', 'ch4strings_dicts_193', 'ch4strings_dicts_194', 'ch4strings_dicts_195', 'ch4strings_dicts_196', 'ch4strings_dicts_197', 'ch4strings_dicts_198', 'ch4strings_dicts_199', 'ch4strings_dicts_19a', 'ch4strings_dicts_19b', 'ch4strings_dicts_19c', 'ch4strings_dicts_19d', 'ch4strings_dicts_19e', 'ch4strings_dicts_19f', 'ch4strings_dicts_1a0', 'ch4strings_dicts_1a1', 'ch4strings_dicts_1a2', 'ch4strings_dicts_1a3', 'ch4strings_dicts_1a4', 'ch4strings_dicts_1a5', 'ch4strings_dicts_1a6', 'ch4strings_dicts_1a7', 'ch4strings_dicts_1a8', 'ch4strings_dicts_1a9', 'ch4strings_dicts_1aa', 'ch4strings_dicts_1ab', 'ch4strings_dicts_1ac', 'ch4strings_dicts_1ad', 'ch4strings_dicts_1ae', 'ch4strings_dicts_1af', 'ch4strings_dicts_1b0', 'ch4strings_dicts_1b1', 'ch4strings_dicts_1b2', 'ch4strings_dicts_1b3', 'ch4strings_dicts_1b4', 'ch4strings_dicts_1b5', 'ch4strings_dicts_1b6', 'ch4strings_dicts_1b7', 'ch4strings_dicts_1b8', 'ch4strings_dicts_1b9', 'ch4strings_dicts_1ba', 'ch4strings_dicts_1bb', 'ch4strings_dicts_1bc', 'ch4strings_dicts_1bd', 'ch4strings_dicts_1be', 'ch4strings_dicts_1bf', 'ch4strings_dicts_1c0', 'ch4strings_dicts_1c1', 'ch4strings_dicts_1c2', 'ch4strings_dicts_1c3', 'ch4strings_dicts_1c4', 'ch4strings_dicts_1c5', 'ch4strings_dicts_1c6', 'ch4strings_dicts_1c7', 'ch4strings_dicts_1c8', 'ch4strings_dicts_1c9', 'ch4strings_dicts_1ca', 'ch4strings_dicts_1cb', 'ch4strings_dicts_1cc', 'ch4strings_dicts_1cd', 'ch4strings_dicts_1ce', 'ch4strings_dicts_1cf', 'ch4strings_dicts_1d0', 'ch4strings_dicts_1d1', 'ch4strings_dicts_1d2', 'ch4strings_dicts_1d3', 'ch4strings_dicts_1d4', 'ch4strings_dicts_1d5', 'ch4strings_dicts_1d6', 'ch4strings_dicts_1d7', 'ch4strings_dicts_1d8', 'ch4strings_dicts_1d9', 'ch4strings_dicts_1da', 'ch4strings_dicts_1db', 'ch4strings_dicts_1dc', 'ch4strings_dicts_1dd', 'ch4strings_dicts_1de', 'ch4strings_dicts_1df', 'ch4strings_dicts_1e0', 'ch4strings_dicts_1e1'], 'ch11Section_5': ['ch11Section_5_1', 'ch11Section_5_2', 'ch11Section_5_3', 'ch11Section_5_4', 'ch11Section_5_5', 'ch11Section_5_6', 'ch11Section_5_7', 'ch11Section_5_8', 'ch11Section_5_9', 'ch11Section_5_a', 'ch11Section_5_b', 'ch11Section_5_c', 'ch11Section_5_d', 'ch11Section_5_e', 'ch11Section_5_f', 'ch11Section_5_10', 'ch11Section_5_11', 'ch11Section_5_12', 'ch11Section_5_13', 'ch11Section_5_14', 'ch11Section_5_15', 'ch11Section_5_16', 'ch11Section_5_17', 'ch11Section_5_18', 'ch11Section_5_19', 'ch11Section_5_1a', 'ch11Section_5_1b', 'ch11Section_5_1c', 'ch11Section_5_1d', 'ch11Section_5_1e', 'ch11Section_5_1f', 'ch11Section_5_20', 'ch11Section_5_21', 'ch11Section_5_22', 'ch11Section_5_23', 'ch11Section_5_24', 'ch11Section_5_25', 'ch11Section_5_26', 'ch11Section_5_27', 'ch11Section_5_28', 'ch11Section_5_29', 'ch11Section_5_2a', 'ch11Section_5_2b', 'ch11Section_5_2c', 'ch11Section_5_2d', 'ch11Section_5_2e', 'ch11Section_5_2f', 'ch11Section_5_30', 'ch11Section_5_31', 'ch11Section_5_32', 'ch11Section_5_33', 'ch11Section_5_34', 'ch11Section_5_35', 'ch11Section_5_36', 'ch11Section_5_37', 'ch11Section_5_38', 'ch11Section_5_39', 'ch11Section_5_3a', 'ch11Section_5_3b', 'ch11Section_5_3c', 'ch11Section_5_3d', 'ch11Section_5_3e', 'ch11Section_5_3f', 'ch11Section_5_40', 'ch11Section_5_41', 'ch11Section_5_42', 'ch11Section_5_43', 'ch11Section_5_44', 'ch11Section_5_45', 'ch11Section_5_46', 'ch11Section_5_47', 'ch11Section_5_48', 'ch11Section_5_49', 'ch11Section_5_4a', 'ch11Section_5_4b', 'ch11Section_5_4c', 'ch11Section_5_4d', 'ch11Section_5_4e', 'ch11Section_5_4f', 'ch11Section_5_50', 'ch11Section_5_51', 'ch11Section_5_52', 'ch11Section_5_53', 'ch11Section_5_54', 'ch11Section_5_55', 'ch11Section_5_56', 'ch11Section_5_57', 'ch11Section_5_58', 'ch11Section_5_59', 'ch11Section_5_5a', 'ch11Section_5_5b', 'ch11Section_5_5c', 'ch11Section_5_5d', 'ch11Section_5_5e', 'ch11Section_5_5f', 'ch11Section_5_60', 'ch11Section_5_61', 'ch11Section_5_62', 'ch11Section_5_63', 'ch11Section_5_64', 'ch11Section_5_65', 'ch11Section_5_66', 'ch11Section_5_67', 'ch11Section_5_68', 'ch11Section_5_69', 'ch11Section_5_6a', 'ch11Section_5_6b', 'ch11Section_5_6c', 'ch11Section_5_6d', 'ch11Section_5_6e', 'ch11Section_5_6f', 'ch11Section_5_70', 'ch11Section_5_71', 'ch11Section_5_72', 'ch11Section_5_73', 'ch11Section_5_74', 'ch11Section_5_75', 'ch11Section_5_76', 'ch11Section_5_77', 'ch11Section_5_78', 'ch11Section_5_79', 'ch11Section_5_7a', 'ch11Section_5_7b', 'ch11Section_5_7c', 'ch11Section_5_7d', 'ch11Section_5_7e', 'ch11Section_5_7f', 'ch11Section_5_80', 'ch11Section_5_81', 'ch11Section_5_82', 'ch11Section_5_83', 'ch11Section_5_84', 'ch11Section_5_85', 'ch11Section_5_86', 'ch11Section_5_87', 'ch11Section_5_88', 'ch11Section_5_89', 'ch11Section_5_8a', 'ch11Section_5_8b', 'ch11Section_5_8c', 'ch11Section_5_8d', 'ch11Section_5_8e', 'ch11Section_5_8f', 'ch11Section_5_90', 'ch11Section_5_91', 'ch11Section_5_92', 'ch11Section_5_93', 'ch11Section_5_94', 'ch11Section_5_95', 'ch11Section_5_96', 'ch11Section_5_97', 'ch11Section_5_98', 'ch11Section_5_99', 'ch11Section_5_9a', 'ch11Section_5_9b', 'ch11Section_5_9c', 'ch11Section_5_9d', 'ch11Section_5_9e', 'ch11Section_5_9f', 'ch11Section_5_a0', 'ch11Section_5_a1', 'ch11Section_5_a2', 'ch11Section_5_a3', 'ch11Section_5_a4', 'ch11Section_5_a5', 'ch11Section_5_a6', 'ch11Section_5_a7', 'ch11Section_5_a8', 'ch11Section_5_a9', 'ch11Section_5_aa', 'ch11Section_5_ab', 'ch11Section_5_ac', 'ch11Section_5_ad', 'ch11Section_5_ae', 'ch11Section_5_af', 'ch11Section_5_b0', 'ch11Section_5_b1', 'ch11Section_5_b2', 'ch11Section_5_b3', 'ch11Section_5_b4', 'ch11Section_5_b5', 'ch11Section_5_b6', 'ch11Section_5_b7', 'ch11Section_5_b8', 'ch11Section_5_b9', 'ch11Section_5_ba', 'ch11Section_5_bb', 'ch11Section_5_bc', 'ch11Section_5_bd', 'ch11Section_5_be', 'ch11Section_5_bf', 'ch11Section_5_c0', 'ch11Section_5_c1', 'ch11Section_5_c2', 'ch11Section_5_c3', 'ch11Section_5_c4', 'ch11Section_5_c5', 'ch11Section_5_c6', 'ch11Section_5_c7', 'ch11Section_5_c8', 'ch11Section_5_c9', 'ch11Section_5_ca', 'ch11Section_5_cb', 'ch11Section_5_cc', 'ch11Section_5_cd', 'ch11Section_5_ce', 'ch11Section_5_cf', 'ch11Section_5_d0', 'ch11Section_5_d1', 'ch11Section_5_d2', 'ch11Section_5_d3', 'ch11Section_5_d4', 'ch11Section_5_d5', 'ch11Section_5_d6', 'ch11Section_5_d7', 'ch11Section_5_d8', 'ch11Section_5_d9', 'ch11Section_5_da', 'ch11Section_5_db', 'ch11Section_5_dc', 'ch11Section_5_dd', 'ch11Section_5_de', 'ch11Section_5_df', 'ch11Section_5_e0', 'ch11Section_5_e1', 'ch11Section_5_e2', 'ch11Section_5_e3', 'ch11Section_5_e4', 'ch11Section_5_e5', 'ch11Section_5_e6', 'ch11Section_5_e7', 'ch11Section_5_e8', 'ch11Section_5_e9', 'ch11Section_5_ea', 'ch11Section_5_eb', 'ch11Section_5_ec', 'ch11Section_5_ed', 'ch11Section_5_ee', 'ch11Section_5_ef', 'ch11Section_5_f0', 'ch11Section_5_f1', 'ch11Section_5_f2', 'ch11Section_5_f3', 'ch11Section_5_f4', 'ch11Section_5_f5', 'ch11Section_5_f6', 'ch11Section_5_f7', 'ch11Section_5_f8', 'ch11Section_5_f9', 'ch11Section_5_fa', 'ch11Section_5_fb', 'ch11Section_5_fc', 'ch11Section_5_fd', 'ch11Section_5_fe', 'ch11Section_5_ff', 'ch11Section_5_100', 'ch11Section_5_101', 'ch11Section_5_102', 'ch11Section_5_103', 'ch11Section_5_104', 'ch11Section_5_105', 'ch11Section_5_106', 'ch11Section_5_107', 'ch11Section_5_108', 'ch11Section_5_109', 'ch11Section_5_10a', 'ch11Section_5_10b', 'ch11Section_5_10c', 'ch11Section_5_10d', 'ch11Section_5_10e', 'ch11Section_5_10f', 'ch11Section_5_110', 'ch11Section_5_111', 'ch11Section_5_112', 'ch11Section_5_113', 'ch11Section_5_114', 'ch11Section_5_115', 'ch11Section_5_116', 'ch11Section_5_117', 'ch11Section_5_118', 'ch11Section_5_119', 'ch11Section_5_11a', 'ch11Section_5_11b', 'ch11Section_5_11c', 'ch11Section_5_11d', 'ch11Section_5_11e', 'ch11Section_5_11f', 'ch11Section_5_120', 'ch11Section_5_121', 'ch11Section_5_122', 'ch11Section_5_123', 'ch11Section_5_124', 'ch11Section_5_125', 'ch11Section_5_126', 'ch11Section_5_127', 'ch11Section_5_128', 'ch11Section_5_129', 'ch11Section_5_12a', 'ch11Section_5_12b', 'ch11Section_5_12c', 'ch11Section_5_12d', 'ch11Section_5_12e', 'ch11Section_5_12f', 'ch11Section_5_130', 'ch11Section_5_131', 'ch11Section_5_132', 'ch11Section_5_133', 'ch11Section_5_134', 'ch11Section_5_135', 'ch11Section_5_136', 'ch11Section_5_137', 'ch11Section_5_138', 'ch11Section_5_139', 'ch11Section_5_13a', 'ch11Section_5_13b', 'ch11Section_5_13c', 'ch11Section_5_13d', 'ch11Section_5_13e', 'ch11Section_5_13f', 'ch11Section_5_140', 'ch11Section_5_141', 'ch11Section_5_142', 'ch11Section_5_143', 'ch11Section_5_144', 'ch11Section_5_145', 'ch11Section_5_146', 'ch11Section_5_147', 'ch11Section_5_148', 'ch11Section_5_149', 'ch11Section_5_14a', 'ch11Section_5_14b', 'ch11Section_5_14c', 'ch11Section_5_14d', 'ch11Section_5_14e', 'ch11Section_5_14f', 'ch11Section_5_150', 'ch11Section_5_151', 'ch11Section_5_152', 'ch11Section_5_153', 'ch11Section_5_154', 'ch11Section_5_155', 'ch11Section_5_156', 'ch11Section_5_157', 'ch11Section_5_158', 'ch11Section_5_159', 'ch11Section_5_15a', 'ch11Section_5_15b', 'ch11Section_5_15c', 'ch11Section_5_15d', 'ch11Section_5_15e', 'ch11Section_5_15f', 'ch11Section_5_160', 'ch11Section_5_161', 'ch11Section_5_162', 'ch11Section_5_163', 'ch11Section_5_164', 'ch11Section_5_165', 'ch11Section_5_166', 'ch11Section_5_167', 'ch11Section_5_168', 'ch11Section_5_169', 'ch11Section_5_16a', 'ch11Section_5_16b', 'ch11Section_5_16c', 'ch11Section_5_16d', 'ch11Section_5_16e', 'ch11Section_5_16f', 'ch11Section_5_170', 'ch11Section_5_171', 'ch11Section_5_172', 'ch11Section_5_173', 'ch11Section_5_174', 'ch11Section_5_175', 'ch11Section_5_176', 'ch11Section_5_177', 'ch11Section_5_178', 'ch11Section_5_179', 'ch11Section_5_17a', 'ch11Section_5_17b', 'ch11Section_5_17c', 'ch11Section_5_17d', 'ch11Section_5_17e', 'ch11Section_5_17f', 'ch11Section_5_180', 'ch11Section_5_181', 'ch11Section_5_182', 'ch11Section_5_183', 'ch11Section_5_184', 'ch11Section_5_185', 'ch11Section_5_186', 'ch11Section_5_187', 'ch11Section_5_188', 'ch11Section_5_189', 'ch11Section_5_18a', 'ch11Section_5_18b', 'ch11Section_5_18c', 'ch11Section_5_18d', 'ch11Section_5_18e', 'ch11Section_5_18f', 'ch11Section_5_190', 'ch11Section_5_191', 'ch11Section_5_192', 'ch11Section_5_193', 'ch11Section_5_194', 'ch11Section_5_195', 'ch11Section_5_196', 'ch11Section_5_197', 'ch11Section_5_198', 'ch11Section_5_199', 'ch11Section_5_19a', 'ch11Section_5_19b', 'ch11Section_5_19c', 'ch11Section_5_19d', 'ch11Section_5_19e', 'ch11Section_5_19f', 'ch11Section_5_1a0', 'ch11Section_5_1a1', 'ch11Section_5_1a2', 'ch11Section_5_1a3', 'ch11Section_5_1a4', 'ch11Section_5_1a5', 'ch11Section_5_1a6', 'ch11Section_5_1a7', 'ch11Section_5_1a8', 'ch11Section_5_1a9', 'ch11Section_5_1aa', 'ch11Section_5_1ab', 'ch11Section_5_1ac', 'ch11Section_5_1ad', 'ch11Section_5_1ae', 'ch11Section_5_1af', 'ch11Section_5_1b0', 'ch11Section_5_1b1', 'ch11Section_5_1b2', 'ch11Section_5_1b3', 'ch11Section_5_1b4', 'ch11Section_5_1b5', 'ch11Section_5_1b6', 'ch11Section_5_1b7', 'ch11Section_5_1b8', 'ch11Section_5_1b9', 'ch11Section_5_1ba', 'ch11Section_5_1bb', 'ch11Section_5_1bc', 'ch11Section_5_1bd', 'ch11Section_5_1be', 'ch11Section_5_1bf', 'ch11Section_5_1c0', 'ch11Section_5_1c1', 'ch11Section_5_1c2', 'ch11Section_5_1c3', 'ch11Section_5_1c4', 'ch11Section_5_1c5', 'ch11Section_5_1c6', 'ch11Section_5_1c7', 'ch11Section_5_1c8', 'ch11Section_5_1c9', 'ch11Section_5_1ca', 'ch11Section_5_1cb', 'ch11Section_5_1cc', 'ch11Section_5_1cd', 'ch11Section_5_1ce', 'ch11Section_5_1cf', 'ch11Section_5_1d0', 'ch11Section_5_1d1', 'ch11Section_5_1d2', 'ch11Section_5_1d3', 'ch11Section_5_1d4', 'ch11Section_5_1d5', 'ch11Section_5_1d6', 'ch11Section_5_1d7', 'ch11Section_5_1d8', 'ch11Section_5_1d9', 'ch11Section_5_1da', 'ch11Section_5_1db', 'ch11Section_5_1dc', 'ch11Section_5_1dd', 'ch11Section_5_1de', 'ch11Section_5_1df', 'ch11Section_5_1e0', 'ch11Section_5_1e1'], 'ch7interim_assessment': ['ch7interim_assessment_1', 'ch7interim_assessment_2', 'ch7interim_assessment_3', 'ch7interim_assessment_4', 'ch7interim_assessment_5', 'ch7interim_assessment_6', 'ch7interim_assessment_7', 'ch7interim_assessment_8', 'ch7interim_assessment_9', 'ch7interim_assessment_a', 'ch7interim_assessment_b', 'ch7interim_assessment_c', 'ch7interim_assessment_d', 'ch7interim_assessment_e', 'ch7interim_assessment_f', 'ch7interim_assessment_10', 'ch7interim_assessment_11', 'ch7interim_assessment_12', 'ch7interim_assessment_13', 'ch7interim_assessment_14', 'ch7interim_assessment_15', 'ch7interim_assessment_16', 'ch7interim_assessment_17', 'ch7interim_assessment_18', 'ch7interim_assessment_19', 'ch7interim_assessment_1a', 'ch7interim_assessment_1b', 'ch7interim_assessment_1c', 'ch7interim_assessment_1d', 'ch7interim_assessment_1e', 'ch7interim_assessment_1f', 'ch7interim_assessment_20', 'ch7interim_assessment_21', 'ch7interim_assessment_22', 'ch7interim_assessment_23', 'ch7interim_assessment_24', 'ch7interim_assessment_25', 'ch7interim_assessment_26', 'ch7interim_assessment_27', 'ch7interim_assessment_28', 'ch7interim_assessment_29', 'ch7interim_assessment_2a', 'ch7interim_assessment_2b', 'ch7interim_assessment_2c', 'ch7interim_assessment_2d', 'ch7interim_assessment_2e', 'ch7interim_assessment_2f', 'ch7interim_assessment_30', 'ch7interim_assessment_31', 'ch7interim_assessment_32', 'ch7interim_assessment_33', 'ch7interim_assessment_34', 'ch7interim_assessment_35', 'ch7interim_assessment_36', 'ch7interim_assessment_37', 'ch7interim_assessment_38', 'ch7interim_assessment_39', 'ch7interim_assessment_3a', 'ch7interim_assessment_3b', 'ch7interim_assessment_3c', 'ch7interim_assessment_3d', 'ch7interim_assessment_3e', 'ch7interim_assessment_3f', 'ch7interim_assessment_40', 'ch7interim_assessment_41', 'ch7interim_assessment_42', 'ch7interim_assessment_43', 'ch7interim_assessment_44', 'ch7interim_assessment_45', 'ch7interim_assessment_46', 'ch7interim_assessment_47', 'ch7interim_assessment_48', 'ch7interim_assessment_49', 'ch7interim_assessment_4a', 'ch7interim_assessment_4b', 'ch7interim_assessment_4c', 'ch7interim_assessment_4d', 'ch7interim_assessment_4e', 'ch7interim_assessment_4f', 'ch7interim_assessment_50', 'ch7interim_assessment_51', 'ch7interim_assessment_52', 'ch7interim_assessment_53', 'ch7interim_assessment_54', 'ch7interim_assessment_55', 'ch7interim_assessment_56', 'ch7interim_assessment_57', 'ch7interim_assessment_58', 'ch7interim_assessment_59', 'ch7interim_assessment_5a', 'ch7interim_assessment_5b', 'ch7interim_assessment_5c', 'ch7interim_assessment_5d', 'ch7interim_assessment_5e', 'ch7interim_assessment_5f', 'ch7interim_assessment_60', 'ch7interim_assessment_61', 'ch7interim_assessment_62', 'ch7interim_assessment_63', 'ch7interim_assessment_64', 'ch7interim_assessment_65', 'ch7interim_assessment_66', 'ch7interim_assessment_67', 'ch7interim_assessment_68', 'ch7interim_assessment_69', 'ch7interim_assessment_6a', 'ch7interim_assessment_6b', 'ch7interim_assessment_6c', 'ch7interim_assessment_6d', 'ch7interim_assessment_6e', 'ch7interim_assessment_6f', 'ch7interim_assessment_70', 'ch7interim_assessment_71', 'ch7interim_assessment_72', 'ch7interim_assessment_73', 'ch7interim_assessment_74', 'ch7interim_assessment_75', 'ch7interim_assessment_76', 'ch7interim_assessment_77', 'ch7interim_assessment_78', 'ch7interim_assessment_79', 'ch7interim_assessment_7a', 'ch7interim_assessment_7b', 'ch7interim_assessment_7c', 'ch7interim_assessment_7d', 'ch7interim_assessment_7e', 'ch7interim_assessment_7f', 'ch7interim_assessment_80', 'ch7interim_assessment_81', 'ch7interim_assessment_82', 'ch7interim_assessment_83', 'ch7interim_assessment_84', 'ch7interim_assessment_85', 'ch7interim_assessment_86', 'ch7interim_assessment_87', 'ch7interim_assessment_88', 'ch7interim_assessment_89', 'ch7interim_assessment_8a', 'ch7interim_assessment_8b', 'ch7interim_assessment_8c', 'ch7interim_assessment_8d', 'ch7interim_assessment_8e', 'ch7interim_assessment_8f', 'ch7interim_assessment_90', 'ch7interim_assessment_91', 'ch7interim_assessment_92', 'ch7interim_assessment_93', 'ch7interim_assessment_94', 'ch7interim_assessment_95', 'ch7interim_assessment_96', 'ch7interim_assessment_97', 'ch7interim_assessment_98', 'ch7interim_assessment_99', 'ch7interim_assessment_9a', 'ch7interim_assessment_9b', 'ch7interim_assessment_9c', 'ch7interim_assessment_9d', 'ch7interim_assessment_9e', 'ch7interim_assessment_9f', 'ch7interim_assessment_a0', 'ch7interim_assessment_a1', 'ch7interim_assessment_a2', 'ch7interim_assessment_a3', 'ch7interim_assessment_a4', 'ch7interim_assessment_a5', 'ch7interim_assessment_a6', 'ch7interim_assessment_a7', 'ch7interim_assessment_a8', 'ch7interim_assessment_a9', 'ch7interim_assessment_aa', 'ch7interim_assessment_ab', 'ch7interim_assessment_ac', 'ch7interim_assessment_ad', 'ch7interim_assessment_ae', 'ch7interim_assessment_af', 'ch7interim_assessment_b0', 'ch7interim_assessment_b1', 'ch7interim_assessment_b2', 'ch7interim_assessment_b3', 'ch7interim_assessment_b4', 'ch7interim_assessment_b5', 'ch7interim_assessment_b6', 'ch7interim_assessment_b7', 'ch7interim_assessment_b8', 'ch7interim_assessment_b9', 'ch7interim_assessment_ba', 'ch7interim_assessment_bb', 'ch7interim_assessment_bc', 'ch7interim_assessment_bd', 'ch7interim_assessment_be', 'ch7interim_assessment_bf', 'ch7interim_assessment_c0', 'ch7interim_assessment_c1', 'ch7interim_assessment_c2', 'ch7interim_assessment_c3', 'ch7interim_assessment_c4', 'ch7interim_assessment_c5', 'ch7interim_assessment_c6', 'ch7interim_assessment_c7', 'ch7interim_assessment_c8', 'ch7interim_assessment_c9', 'ch7interim_assessment_ca', 'ch7interim_assessment_cb', 'ch7interim_assessment_cc', 'ch7interim_assessment_cd', 'ch7interim_assessment_ce', 'ch7interim_assessment_cf', 'ch7interim_assessment_d0', 'ch7interim_assessment_d1', 'ch7interim_assessment_d2', 'ch7interim_assessment_d3', 'ch7interim_assessment_d4', 'ch7interim_assessment_d5', 'ch7interim_assessment_d6', 'ch7interim_assessment_d7', 'ch7interim_assessment_d8', 'ch7interim_assessment_d9', 'ch7interim_assessment_da', 'ch7interim_assessment_db', 'ch7interim_assessment_dc', 'ch7interim_assessment_dd', 'ch7interim_assessment_de', 'ch7interim_assessment_df', 'ch7interim_assessment_e0', 'ch7interim_assessment_e1', 'ch7interim_assessment_e2', 'ch7interim_assessment_e3', 'ch7interim_assessment_e4', 'ch7interim_assessment_e5', 'ch7interim_assessment_e6', 'ch7interim_assessment_e7', 'ch7interim_assessment_e8', 'ch7interim_assessment_e9', 'ch7interim_assessment_ea', 'ch7interim_assessment_eb', 'ch7interim_assessment_ec', 'ch7interim_assessment_ed', 'ch7interim_assessment_ee', 'ch7interim_assessment_ef', 'ch7interim_assessment_f0', 'ch7interim_assessment_f1', 'ch7interim_assessment_f2', 'ch7interim_assessment_f3', 'ch7interim_assessment_f4', 'ch7interim_assessment_f5', 'ch7interim_assessment_f6', 'ch7interim_assessment_f7', 'ch7interim_assessment_f8', 'ch7interim_assessment_f9', 'ch7interim_assessment_fa', 'ch7interim_assessment_fb', 'ch7interim_assessment_fc', 'ch7interim_assessment_fd', 'ch7interim_assessment_fe', 'ch7interim_assessment_ff', 'ch7interim_assessment_100', 'ch7interim_assessment_101', 'ch7interim_assessment_102', 'ch7interim_assessment_103', 'ch7interim_assessment_104', 'ch7interim_assessment_105', 'ch7interim_assessment_106', 'ch7interim_assessment_107', 'ch7interim_assessment_108', 'ch7interim_assessment_109', 'ch7interim_assessment_10a', 'ch7interim_assessment_10b', 'ch7interim_assessment_10c', 'ch7interim_assessment_10d', 'ch7interim_assessment_10e', 'ch7interim_assessment_10f', 'ch7interim_assessment_110', 'ch7interim_assessment_111', 'ch7interim_assessment_112', 'ch7interim_assessment_113', 'ch7interim_assessment_114', 'ch7interim_assessment_115', 'ch7interim_assessment_116', 'ch7interim_assessment_117', 'ch7interim_assessment_118', 'ch7interim_assessment_119', 'ch7interim_assessment_11a', 'ch7interim_assessment_11b', 'ch7interim_assessment_11c', 'ch7interim_assessment_11d', 'ch7interim_assessment_11e', 'ch7interim_assessment_11f', 'ch7interim_assessment_120', 'ch7interim_assessment_121', 'ch7interim_assessment_122', 'ch7interim_assessment_123', 'ch7interim_assessment_124', 'ch7interim_assessment_125', 'ch7interim_assessment_126', 'ch7interim_assessment_127', 'ch7interim_assessment_128', 'ch7interim_assessment_129', 'ch7interim_assessment_12a', 'ch7interim_assessment_12b', 'ch7interim_assessment_12c', 'ch7interim_assessment_12d', 'ch7interim_assessment_12e', 'ch7interim_assessment_12f', 'ch7interim_assessment_130', 'ch7interim_assessment_131', 'ch7interim_assessment_132', 'ch7interim_assessment_133', 'ch7interim_assessment_134', 'ch7interim_assessment_135', 'ch7interim_assessment_136', 'ch7interim_assessment_137', 'ch7interim_assessment_138', 'ch7interim_assessment_139', 'ch7interim_assessment_13a', 'ch7interim_assessment_13b', 'ch7interim_assessment_13c', 'ch7interim_assessment_13d', 'ch7interim_assessment_13e', 'ch7interim_assessment_13f', 'ch7interim_assessment_140', 'ch7interim_assessment_141', 'ch7interim_assessment_142', 'ch7interim_assessment_143', 'ch7interim_assessment_144', 'ch7interim_assessment_145', 'ch7interim_assessment_146', 'ch7interim_assessment_147', 'ch7interim_assessment_148', 'ch7interim_assessment_149', 'ch7interim_assessment_14a', 'ch7interim_assessment_14b', 'ch7interim_assessment_14c', 'ch7interim_assessment_14d', 'ch7interim_assessment_14e', 'ch7interim_assessment_14f', 'ch7interim_assessment_150', 'ch7interim_assessment_151', 'ch7interim_assessment_152', 'ch7interim_assessment_153', 'ch7interim_assessment_154', 'ch7interim_assessment_155', 'ch7interim_assessment_156', 'ch7interim_assessment_157', 'ch7interim_assessment_158', 'ch7interim_assessment_159', 'ch7interim_assessment_15a', 'ch7interim_assessment_15b', 'ch7interim_assessment_15c', 'ch7interim_assessment_15d', 'ch7interim_assessment_15e', 'ch7interim_assessment_15f', 'ch7interim_assessment_160', 'ch7interim_assessment_161', 'ch7interim_assessment_162', 'ch7interim_assessment_163', 'ch7interim_assessment_164', 'ch7interim_assessment_165', 'ch7interim_assessment_166', 'ch7interim_assessment_167', 'ch7interim_assessment_168', 'ch7interim_assessment_169', 'ch7interim_assessment_16a', 'ch7interim_assessment_16b', 'ch7interim_assessment_16c', 'ch7interim_assessment_16d', 'ch7interim_assessment_16e', 'ch7interim_assessment_16f', 'ch7interim_assessment_170', 'ch7interim_assessment_171', 'ch7interim_assessment_172', 'ch7interim_assessment_173', 'ch7interim_assessment_174', 'ch7interim_assessment_175', 'ch7interim_assessment_176', 'ch7interim_assessment_177', 'ch7interim_assessment_178', 'ch7interim_assessment_179', 'ch7interim_assessment_17a', 'ch7interim_assessment_17b', 'ch7interim_assessment_17c', 'ch7interim_assessment_17d', 'ch7interim_assessment_17e', 'ch7interim_assessment_17f', 'ch7interim_assessment_180', 'ch7interim_assessment_181', 'ch7interim_assessment_182', 'ch7interim_assessment_183', 'ch7interim_assessment_184', 'ch7interim_assessment_185', 'ch7interim_assessment_186', 'ch7interim_assessment_187', 'ch7interim_assessment_188', 'ch7interim_assessment_189', 'ch7interim_assessment_18a', 'ch7interim_assessment_18b', 'ch7interim_assessment_18c', 'ch7interim_assessment_18d', 'ch7interim_assessment_18e', 'ch7interim_assessment_18f', 'ch7interim_assessment_190', 'ch7interim_assessment_191', 'ch7interim_assessment_192', 'ch7interim_assessment_193', 'ch7interim_assessment_194', 'ch7interim_assessment_195', 'ch7interim_assessment_196', 'ch7interim_assessment_197', 'ch7interim_assessment_198', 'ch7interim_assessment_199', 'ch7interim_assessment_19a', 'ch7interim_assessment_19b', 'ch7interim_assessment_19c', 'ch7interim_assessment_19d', 'ch7interim_assessment_19e', 'ch7interim_assessment_19f', 'ch7interim_assessment_1a0', 'ch7interim_assessment_1a1', 'ch7interim_assessment_1a2', 'ch7interim_assessment_1a3', 'ch7interim_assessment_1a4', 'ch7interim_assessment_1a5', 'ch7interim_assessment_1a6', 'ch7interim_assessment_1a7', 'ch7interim_assessment_1a8', 'ch7interim_assessment_1a9', 'ch7interim_assessment_1aa', 'ch7interim_assessment_1ab', 'ch7interim_assessment_1ac', 'ch7interim_assessment_1ad', 'ch7interim_assessment_1ae', 'ch7interim_assessment_1af', 'ch7interim_assessment_1b0', 'ch7interim_assessment_1b1', 'ch7interim_assessment_1b2', 'ch7interim_assessment_1b3', 'ch7interim_assessment_1b4', 'ch7interim_assessment_1b5', 'ch7interim_assessment_1b6', 'ch7interim_assessment_1b7', 'ch7interim_assessment_1b8', 'ch7interim_assessment_1b9', 'ch7interim_assessment_1ba', 'ch7interim_assessment_1bb', 'ch7interim_assessment_1bc', 'ch7interim_assessment_1bd', 'ch7interim_assessment_1be', 'ch7interim_assessment_1bf', 'ch7interim_assessment_1c0', 'ch7interim_assessment_1c1', 'ch7interim_assessment_1c2', 'ch7interim_assessment_1c3', 'ch7interim_assessment_1c4', 'ch7interim_assessment_1c5', 'ch7interim_assessment_1c6', 'ch7interim_assessment_1c7', 'ch7interim_assessment_1c8', 'ch7interim_assessment_1c9', 'ch7interim_assessment_1ca', 'ch7interim_assessment_1cb', 'ch7interim_assessment_1cc', 'ch7interim_assessment_1cd', 'ch7interim_assessment_1ce', 'ch7interim_assessment_1cf', 'ch7interim_assessment_1d0', 'ch7interim_assessment_1d1', 'ch7interim_assessment_1d2', 'ch7interim_assessment_1d3', 'ch7interim_assessment_1d4', 'ch7interim_assessment_1d5', 'ch7interim_assessment_1d6', 'ch7interim_assessment_1d7', 'ch7interim_assessment_1d8', 'ch7interim_assessment_1d9', 'ch7interim_assessment_1da', 'ch7interim_assessment_1db', 'ch7interim_assessment_1dc', 'ch7interim_assessment_1dd', 'ch7interim_assessment_1de', 'ch7interim_assessment_1df', 'ch7interim_assessment_1e0', 'ch7interim_assessment_1e1'], 'ch8ult_module_plan': ['ch8ult_module_plan_1', 'ch8ult_module_plan_2', 'ch8ult_module_plan_3', 'ch8ult_module_plan_4', 'ch8ult_module_plan_5', 'ch8ult_module_plan_6', 'ch8ult_module_plan_7', 'ch8ult_module_plan_8', 'ch8ult_module_plan_9', 'ch8ult_module_plan_a', 'ch8ult_module_plan_b', 'ch8ult_module_plan_c', 'ch8ult_module_plan_d', 'ch8ult_module_plan_e', 'ch8ult_module_plan_f', 'ch8ult_module_plan_10', 'ch8ult_module_plan_11', 'ch8ult_module_plan_12', 'ch8ult_module_plan_13', 'ch8ult_module_plan_14', 'ch8ult_module_plan_15', 'ch8ult_module_plan_16', 'ch8ult_module_plan_17', 'ch8ult_module_plan_18', 'ch8ult_module_plan_19', 'ch8ult_module_plan_1a', 'ch8ult_module_plan_1b', 'ch8ult_module_plan_1c', 'ch8ult_module_plan_1d', 'ch8ult_module_plan_1e', 'ch8ult_module_plan_1f', 'ch8ult_module_plan_20', 'ch8ult_module_plan_21', 'ch8ult_module_plan_22', 'ch8ult_module_plan_23', 'ch8ult_module_plan_24', 'ch8ult_module_plan_25', 'ch8ult_module_plan_26', 'ch8ult_module_plan_27', 'ch8ult_module_plan_28', 'ch8ult_module_plan_29', 'ch8ult_module_plan_2a', 'ch8ult_module_plan_2b', 'ch8ult_module_plan_2c', 'ch8ult_module_plan_2d', 'ch8ult_module_plan_2e', 'ch8ult_module_plan_2f', 'ch8ult_module_plan_30', 'ch8ult_module_plan_31', 'ch8ult_module_plan_32', 'ch8ult_module_plan_33', 'ch8ult_module_plan_34', 'ch8ult_module_plan_35', 'ch8ult_module_plan_36', 'ch8ult_module_plan_37', 'ch8ult_module_plan_38', 'ch8ult_module_plan_39', 'ch8ult_module_plan_3a', 'ch8ult_module_plan_3b', 'ch8ult_module_plan_3c', 'ch8ult_module_plan_3d', 'ch8ult_module_plan_3e', 'ch8ult_module_plan_3f', 'ch8ult_module_plan_40', 'ch8ult_module_plan_41', 'ch8ult_module_plan_42', 'ch8ult_module_plan_43', 'ch8ult_module_plan_44', 'ch8ult_module_plan_45', 'ch8ult_module_plan_46', 'ch8ult_module_plan_47', 'ch8ult_module_plan_48', 'ch8ult_module_plan_49', 'ch8ult_module_plan_4a', 'ch8ult_module_plan_4b', 'ch8ult_module_plan_4c', 'ch8ult_module_plan_4d', 'ch8ult_module_plan_4e', 'ch8ult_module_plan_4f', 'ch8ult_module_plan_50', 'ch8ult_module_plan_51', 'ch8ult_module_plan_52', 'ch8ult_module_plan_53', 'ch8ult_module_plan_54', 'ch8ult_module_plan_55', 'ch8ult_module_plan_56', 'ch8ult_module_plan_57', 'ch8ult_module_plan_58', 'ch8ult_module_plan_59', 'ch8ult_module_plan_5a', 'ch8ult_module_plan_5b', 'ch8ult_module_plan_5c', 'ch8ult_module_plan_5d', 'ch8ult_module_plan_5e', 'ch8ult_module_plan_5f', 'ch8ult_module_plan_60', 'ch8ult_module_plan_61', 'ch8ult_module_plan_62', 'ch8ult_module_plan_63', 'ch8ult_module_plan_64', 'ch8ult_module_plan_65', 'ch8ult_module_plan_66', 'ch8ult_module_plan_67', 'ch8ult_module_plan_68', 'ch8ult_module_plan_69', 'ch8ult_module_plan_6a', 'ch8ult_module_plan_6b', 'ch8ult_module_plan_6c', 'ch8ult_module_plan_6d', 'ch8ult_module_plan_6e', 'ch8ult_module_plan_6f', 'ch8ult_module_plan_70', 'ch8ult_module_plan_71', 'ch8ult_module_plan_72', 'ch8ult_module_plan_73', 'ch8ult_module_plan_74', 'ch8ult_module_plan_75', 'ch8ult_module_plan_76', 'ch8ult_module_plan_77', 'ch8ult_module_plan_78', 'ch8ult_module_plan_79', 'ch8ult_module_plan_7a', 'ch8ult_module_plan_7b', 'ch8ult_module_plan_7c', 'ch8ult_module_plan_7d', 'ch8ult_module_plan_7e', 'ch8ult_module_plan_7f', 'ch8ult_module_plan_80', 'ch8ult_module_plan_81', 'ch8ult_module_plan_82', 'ch8ult_module_plan_83', 'ch8ult_module_plan_84', 'ch8ult_module_plan_85', 'ch8ult_module_plan_86', 'ch8ult_module_plan_87', 'ch8ult_module_plan_88', 'ch8ult_module_plan_89', 'ch8ult_module_plan_8a', 'ch8ult_module_plan_8b', 'ch8ult_module_plan_8c', 'ch8ult_module_plan_8d', 'ch8ult_module_plan_8e', 'ch8ult_module_plan_8f', 'ch8ult_module_plan_90', 'ch8ult_module_plan_91', 'ch8ult_module_plan_92', 'ch8ult_module_plan_93', 'ch8ult_module_plan_94', 'ch8ult_module_plan_95', 'ch8ult_module_plan_96', 'ch8ult_module_plan_97', 'ch8ult_module_plan_98', 'ch8ult_module_plan_99', 'ch8ult_module_plan_9a', 'ch8ult_module_plan_9b', 'ch8ult_module_plan_9c', 'ch8ult_module_plan_9d', 'ch8ult_module_plan_9e', 'ch8ult_module_plan_9f', 'ch8ult_module_plan_a0', 'ch8ult_module_plan_a1', 'ch8ult_module_plan_a2', 'ch8ult_module_plan_a3', 'ch8ult_module_plan_a4', 'ch8ult_module_plan_a5', 'ch8ult_module_plan_a6', 'ch8ult_module_plan_a7', 'ch8ult_module_plan_a8', 'ch8ult_module_plan_a9', 'ch8ult_module_plan_aa', 'ch8ult_module_plan_ab', 'ch8ult_module_plan_ac', 'ch8ult_module_plan_ad', 'ch8ult_module_plan_ae', 'ch8ult_module_plan_af', 'ch8ult_module_plan_b0', 'ch8ult_module_plan_b1', 'ch8ult_module_plan_b2', 'ch8ult_module_plan_b3', 'ch8ult_module_plan_b4', 'ch8ult_module_plan_b5', 'ch8ult_module_plan_b6', 'ch8ult_module_plan_b7', 'ch8ult_module_plan_b8', 'ch8ult_module_plan_b9', 'ch8ult_module_plan_ba', 'ch8ult_module_plan_bb', 'ch8ult_module_plan_bc', 'ch8ult_module_plan_bd', 'ch8ult_module_plan_be', 'ch8ult_module_plan_bf', 'ch8ult_module_plan_c0', 'ch8ult_module_plan_c1', 'ch8ult_module_plan_c2', 'ch8ult_module_plan_c3', 'ch8ult_module_plan_c4', 'ch8ult_module_plan_c5', 'ch8ult_module_plan_c6', 'ch8ult_module_plan_c7', 'ch8ult_module_plan_c8', 'ch8ult_module_plan_c9', 'ch8ult_module_plan_ca', 'ch8ult_module_plan_cb', 'ch8ult_module_plan_cc', 'ch8ult_module_plan_cd', 'ch8ult_module_plan_ce', 'ch8ult_module_plan_cf', 'ch8ult_module_plan_d0', 'ch8ult_module_plan_d1', 'ch8ult_module_plan_d2', 'ch8ult_module_plan_d3', 'ch8ult_module_plan_d4', 'ch8ult_module_plan_d5', 'ch8ult_module_plan_d6', 'ch8ult_module_plan_d7', 'ch8ult_module_plan_d8', 'ch8ult_module_plan_d9', 'ch8ult_module_plan_da', 'ch8ult_module_plan_db', 'ch8ult_module_plan_dc', 'ch8ult_module_plan_dd', 'ch8ult_module_plan_de', 'ch8ult_module_plan_df', 'ch8ult_module_plan_e0', 'ch8ult_module_plan_e1', 'ch8ult_module_plan_e2', 'ch8ult_module_plan_e3', 'ch8ult_module_plan_e4', 'ch8ult_module_plan_e5', 'ch8ult_module_plan_e6', 'ch8ult_module_plan_e7', 'ch8ult_module_plan_e8', 'ch8ult_module_plan_e9', 'ch8ult_module_plan_ea', 'ch8ult_module_plan_eb', 'ch8ult_module_plan_ec', 'ch8ult_module_plan_ed', 'ch8ult_module_plan_ee', 'ch8ult_module_plan_ef', 'ch8ult_module_plan_f0', 'ch8ult_module_plan_f1', 'ch8ult_module_plan_f2', 'ch8ult_module_plan_f3', 'ch8ult_module_plan_f4', 'ch8ult_module_plan_f5', 'ch8ult_module_plan_f6', 'ch8ult_module_plan_f7', 'ch8ult_module_plan_f8', 'ch8ult_module_plan_f9', 'ch8ult_module_plan_fa', 'ch8ult_module_plan_fb', 'ch8ult_module_plan_fc', 'ch8ult_module_plan_fd', 'ch8ult_module_plan_fe', 'ch8ult_module_plan_ff', 'ch8ult_module_plan_100', 'ch8ult_module_plan_101', 'ch8ult_module_plan_102', 'ch8ult_module_plan_103', 'ch8ult_module_plan_104', 'ch8ult_module_plan_105', 'ch8ult_module_plan_106', 'ch8ult_module_plan_107', 'ch8ult_module_plan_108', 'ch8ult_module_plan_109', 'ch8ult_module_plan_10a', 'ch8ult_module_plan_10b', 'ch8ult_module_plan_10c', 'ch8ult_module_plan_10d', 'ch8ult_module_plan_10e', 'ch8ult_module_plan_10f', 'ch8ult_module_plan_110', 'ch8ult_module_plan_111', 'ch8ult_module_plan_112', 'ch8ult_module_plan_113', 'ch8ult_module_plan_114', 'ch8ult_module_plan_115', 'ch8ult_module_plan_116', 'ch8ult_module_plan_117', 'ch8ult_module_plan_118', 'ch8ult_module_plan_119', 'ch8ult_module_plan_11a', 'ch8ult_module_plan_11b', 'ch8ult_module_plan_11c', 'ch8ult_module_plan_11d', 'ch8ult_module_plan_11e', 'ch8ult_module_plan_11f', 'ch8ult_module_plan_120', 'ch8ult_module_plan_121', 'ch8ult_module_plan_122', 'ch8ult_module_plan_123', 'ch8ult_module_plan_124', 'ch8ult_module_plan_125', 'ch8ult_module_plan_126', 'ch8ult_module_plan_127', 'ch8ult_module_plan_128', 'ch8ult_module_plan_129', 'ch8ult_module_plan_12a', 'ch8ult_module_plan_12b', 'ch8ult_module_plan_12c', 'ch8ult_module_plan_12d', 'ch8ult_module_plan_12e', 'ch8ult_module_plan_12f', 'ch8ult_module_plan_130', 'ch8ult_module_plan_131', 'ch8ult_module_plan_132', 'ch8ult_module_plan_133', 'ch8ult_module_plan_134', 'ch8ult_module_plan_135', 'ch8ult_module_plan_136', 'ch8ult_module_plan_137', 'ch8ult_module_plan_138', 'ch8ult_module_plan_139', 'ch8ult_module_plan_13a', 'ch8ult_module_plan_13b', 'ch8ult_module_plan_13c', 'ch8ult_module_plan_13d', 'ch8ult_module_plan_13e', 'ch8ult_module_plan_13f', 'ch8ult_module_plan_140', 'ch8ult_module_plan_141', 'ch8ult_module_plan_142', 'ch8ult_module_plan_143', 'ch8ult_module_plan_144', 'ch8ult_module_plan_145', 'ch8ult_module_plan_146', 'ch8ult_module_plan_147', 'ch8ult_module_plan_148', 'ch8ult_module_plan_149', 'ch8ult_module_plan_14a', 'ch8ult_module_plan_14b', 'ch8ult_module_plan_14c', 'ch8ult_module_plan_14d', 'ch8ult_module_plan_14e', 'ch8ult_module_plan_14f', 'ch8ult_module_plan_150', 'ch8ult_module_plan_151', 'ch8ult_module_plan_152', 'ch8ult_module_plan_153', 'ch8ult_module_plan_154', 'ch8ult_module_plan_155', 'ch8ult_module_plan_156', 'ch8ult_module_plan_157', 'ch8ult_module_plan_158', 'ch8ult_module_plan_159', 'ch8ult_module_plan_15a', 'ch8ult_module_plan_15b', 'ch8ult_module_plan_15c', 'ch8ult_module_plan_15d', 'ch8ult_module_plan_15e', 'ch8ult_module_plan_15f', 'ch8ult_module_plan_160', 'ch8ult_module_plan_161', 'ch8ult_module_plan_162', 'ch8ult_module_plan_163', 'ch8ult_module_plan_164', 'ch8ult_module_plan_165', 'ch8ult_module_plan_166', 'ch8ult_module_plan_167', 'ch8ult_module_plan_168', 'ch8ult_module_plan_169', 'ch8ult_module_plan_16a', 'ch8ult_module_plan_16b', 'ch8ult_module_plan_16c', 'ch8ult_module_plan_16d', 'ch8ult_module_plan_16e', 'ch8ult_module_plan_16f', 'ch8ult_module_plan_170', 'ch8ult_module_plan_171', 'ch8ult_module_plan_172', 'ch8ult_module_plan_173', 'ch8ult_module_plan_174', 'ch8ult_module_plan_175', 'ch8ult_module_plan_176', 'ch8ult_module_plan_177', 'ch8ult_module_plan_178', 'ch8ult_module_plan_179', 'ch8ult_module_plan_17a', 'ch8ult_module_plan_17b', 'ch8ult_module_plan_17c', 'ch8ult_module_plan_17d', 'ch8ult_module_plan_17e', 'ch8ult_module_plan_17f', 'ch8ult_module_plan_180', 'ch8ult_module_plan_181', 'ch8ult_module_plan_182', 'ch8ult_module_plan_183', 'ch8ult_module_plan_184', 'ch8ult_module_plan_185', 'ch8ult_module_plan_186', 'ch8ult_module_plan_187', 'ch8ult_module_plan_188', 'ch8ult_module_plan_189', 'ch8ult_module_plan_18a', 'ch8ult_module_plan_18b', 'ch8ult_module_plan_18c', 'ch8ult_module_plan_18d', 'ch8ult_module_plan_18e', 'ch8ult_module_plan_18f', 'ch8ult_module_plan_190', 'ch8ult_module_plan_191', 'ch8ult_module_plan_192', 'ch8ult_module_plan_193', 'ch8ult_module_plan_194', 'ch8ult_module_plan_195', 'ch8ult_module_plan_196', 'ch8ult_module_plan_197', 'ch8ult_module_plan_198', 'ch8ult_module_plan_199', 'ch8ult_module_plan_19a', 'ch8ult_module_plan_19b', 'ch8ult_module_plan_19c', 'ch8ult_module_plan_19d', 'ch8ult_module_plan_19e', 'ch8ult_module_plan_19f', 'ch8ult_module_plan_1a0', 'ch8ult_module_plan_1a1', 'ch8ult_module_plan_1a2', 'ch8ult_module_plan_1a3', 'ch8ult_module_plan_1a4', 'ch8ult_module_plan_1a5', 'ch8ult_module_plan_1a6', 'ch8ult_module_plan_1a7', 'ch8ult_module_plan_1a8', 'ch8ult_module_plan_1a9', 'ch8ult_module_plan_1aa', 'ch8ult_module_plan_1ab', 'ch8ult_module_plan_1ac', 'ch8ult_module_plan_1ad', 'ch8ult_module_plan_1ae', 'ch8ult_module_plan_1af', 'ch8ult_module_plan_1b0', 'ch8ult_module_plan_1b1', 'ch8ult_module_plan_1b2', 'ch8ult_module_plan_1b3', 'ch8ult_module_plan_1b4', 'ch8ult_module_plan_1b5', 'ch8ult_module_plan_1b6', 'ch8ult_module_plan_1b7', 'ch8ult_module_plan_1b8', 'ch8ult_module_plan_1b9', 'ch8ult_module_plan_1ba', 'ch8ult_module_plan_1bb', 'ch8ult_module_plan_1bc', 'ch8ult_module_plan_1bd', 'ch8ult_module_plan_1be', 'ch8ult_module_plan_1bf', 'ch8ult_module_plan_1c0', 'ch8ult_module_plan_1c1', 'ch8ult_module_plan_1c2', 'ch8ult_module_plan_1c3', 'ch8ult_module_plan_1c4', 'ch8ult_module_plan_1c5', 'ch8ult_module_plan_1c6', 'ch8ult_module_plan_1c7', 'ch8ult_module_plan_1c8', 'ch8ult_module_plan_1c9', 'ch8ult_module_plan_1ca', 'ch8ult_module_plan_1cb', 'ch8ult_module_plan_1cc', 'ch8ult_module_plan_1cd', 'ch8ult_module_plan_1ce', 'ch8ult_module_plan_1cf', 'ch8ult_module_plan_1d0', 'ch8ult_module_plan_1d1', 'ch8ult_module_plan_1d2', 'ch8ult_module_plan_1d3', 'ch8ult_module_plan_1d4', 'ch8ult_module_plan_1d5', 'ch8ult_module_plan_1d6', 'ch8ult_module_plan_1d7', 'ch8ult_module_plan_1d8', 'ch8ult_module_plan_1d9', 'ch8ult_module_plan_1da', 'ch8ult_module_plan_1db', 'ch8ult_module_plan_1dc', 'ch8ult_module_plan_1dd', 'ch8ult_module_plan_1de', 'ch8ult_module_plan_1df', 'ch8ult_module_plan_1e0', 'ch8ult_module_plan_1e1'], 'ch10session4': ['ch10session4_1', 'ch10session4_2', 'ch10session4_3', 'ch10session4_4', 'ch10session4_5', 'ch10session4_6', 'ch10session4_7', 'ch10session4_8', 'ch10session4_9', 'ch10session4_a', 'ch10session4_b', 'ch10session4_c', 'ch10session4_d', 'ch10session4_e', 'ch10session4_f', 'ch10session4_10', 'ch10session4_11', 'ch10session4_12', 'ch10session4_13', 'ch10session4_14', 'ch10session4_15', 'ch10session4_16', 'ch10session4_17', 'ch10session4_18', 'ch10session4_19', 'ch10session4_1a', 'ch10session4_1b', 'ch10session4_1c', 'ch10session4_1d', 'ch10session4_1e', 'ch10session4_1f', 'ch10session4_20', 'ch10session4_21', 'ch10session4_22', 'ch10session4_23', 'ch10session4_24', 'ch10session4_25', 'ch10session4_26', 'ch10session4_27', 'ch10session4_28', 'ch10session4_29', 'ch10session4_2a', 'ch10session4_2b', 'ch10session4_2c', 'ch10session4_2d', 'ch10session4_2e', 'ch10session4_2f', 'ch10session4_30', 'ch10session4_31', 'ch10session4_32', 'ch10session4_33', 'ch10session4_34', 'ch10session4_35', 'ch10session4_36', 'ch10session4_37', 'ch10session4_38', 'ch10session4_39', 'ch10session4_3a', 'ch10session4_3b', 'ch10session4_3c', 'ch10session4_3d', 'ch10session4_3e', 'ch10session4_3f', 'ch10session4_40', 'ch10session4_41', 'ch10session4_42', 'ch10session4_43', 'ch10session4_44', 'ch10session4_45', 'ch10session4_46', 'ch10session4_47', 'ch10session4_48', 'ch10session4_49', 'ch10session4_4a', 'ch10session4_4b', 'ch10session4_4c', 'ch10session4_4d', 'ch10session4_4e', 'ch10session4_4f', 'ch10session4_50', 'ch10session4_51', 'ch10session4_52', 'ch10session4_53', 'ch10session4_54', 'ch10session4_55', 'ch10session4_56', 'ch10session4_57', 'ch10session4_58', 'ch10session4_59', 'ch10session4_5a', 'ch10session4_5b', 'ch10session4_5c', 'ch10session4_5d', 'ch10session4_5e', 'ch10session4_5f', 'ch10session4_60', 'ch10session4_61', 'ch10session4_62', 'ch10session4_63', 'ch10session4_64', 'ch10session4_65', 'ch10session4_66', 'ch10session4_67', 'ch10session4_68', 'ch10session4_69', 'ch10session4_6a', 'ch10session4_6b', 'ch10session4_6c', 'ch10session4_6d', 'ch10session4_6e', 'ch10session4_6f', 'ch10session4_70', 'ch10session4_71', 'ch10session4_72', 'ch10session4_73', 'ch10session4_74', 'ch10session4_75', 'ch10session4_76', 'ch10session4_77', 'ch10session4_78', 'ch10session4_79', 'ch10session4_7a', 'ch10session4_7b', 'ch10session4_7c', 'ch10session4_7d', 'ch10session4_7e', 'ch10session4_7f', 'ch10session4_80', 'ch10session4_81', 'ch10session4_82', 'ch10session4_83', 'ch10session4_84', 'ch10session4_85', 'ch10session4_86', 'ch10session4_87', 'ch10session4_88', 'ch10session4_89', 'ch10session4_8a', 'ch10session4_8b', 'ch10session4_8c', 'ch10session4_8d', 'ch10session4_8e', 'ch10session4_8f', 'ch10session4_90', 'ch10session4_91', 'ch10session4_92', 'ch10session4_93', 'ch10session4_94', 'ch10session4_95', 'ch10session4_96', 'ch10session4_97', 'ch10session4_98', 'ch10session4_99', 'ch10session4_9a', 'ch10session4_9b', 'ch10session4_9c', 'ch10session4_9d', 'ch10session4_9e', 'ch10session4_9f', 'ch10session4_a0', 'ch10session4_a1', 'ch10session4_a2', 'ch10session4_a3', 'ch10session4_a4', 'ch10session4_a5', 'ch10session4_a6', 'ch10session4_a7', 'ch10session4_a8', 'ch10session4_a9', 'ch10session4_aa', 'ch10session4_ab', 'ch10session4_ac', 'ch10session4_ad', 'ch10session4_ae', 'ch10session4_af', 'ch10session4_b0', 'ch10session4_b1', 'ch10session4_b2', 'ch10session4_b3', 'ch10session4_b4', 'ch10session4_b5', 'ch10session4_b6', 'ch10session4_b7', 'ch10session4_b8', 'ch10session4_b9', 'ch10session4_ba', 'ch10session4_bb', 'ch10session4_bc', 'ch10session4_bd', 'ch10session4_be', 'ch10session4_bf', 'ch10session4_c0', 'ch10session4_c1', 'ch10session4_c2', 'ch10session4_c3', 'ch10session4_c4', 'ch10session4_c5', 'ch10session4_c6', 'ch10session4_c7', 'ch10session4_c8', 'ch10session4_c9', 'ch10session4_ca', 'ch10session4_cb', 'ch10session4_cc', 'ch10session4_cd', 'ch10session4_ce', 'ch10session4_cf', 'ch10session4_d0', 'ch10session4_d1', 'ch10session4_d2', 'ch10session4_d3', 'ch10session4_d4', 'ch10session4_d5', 'ch10session4_d6', 'ch10session4_d7', 'ch10session4_d8', 'ch10session4_d9', 'ch10session4_da', 'ch10session4_db', 'ch10session4_dc', 'ch10session4_dd', 'ch10session4_de', 'ch10session4_df', 'ch10session4_e0', 'ch10session4_e1', 'ch10session4_e2', 'ch10session4_e3', 'ch10session4_e4', 'ch10session4_e5', 'ch10session4_e6', 'ch10session4_e7', 'ch10session4_e8', 'ch10session4_e9', 'ch10session4_ea', 'ch10session4_eb', 'ch10session4_ec', 'ch10session4_ed', 'ch10session4_ee', 'ch10session4_ef', 'ch10session4_f0', 'ch10session4_f1', 'ch10session4_f2', 'ch10session4_f3', 'ch10session4_f4', 'ch10session4_f5', 'ch10session4_f6', 'ch10session4_f7', 'ch10session4_f8', 'ch10session4_f9', 'ch10session4_fa', 'ch10session4_fb', 'ch10session4_fc', 'ch10session4_fd', 'ch10session4_fe', 'ch10session4_ff', 'ch10session4_100', 'ch10session4_101', 'ch10session4_102', 'ch10session4_103', 'ch10session4_104', 'ch10session4_105', 'ch10session4_106', 'ch10session4_107', 'ch10session4_108', 'ch10session4_109', 'ch10session4_10a', 'ch10session4_10b', 'ch10session4_10c', 'ch10session4_10d', 'ch10session4_10e', 'ch10session4_10f', 'ch10session4_110', 'ch10session4_111', 'ch10session4_112', 'ch10session4_113', 'ch10session4_114', 'ch10session4_115', 'ch10session4_116', 'ch10session4_117', 'ch10session4_118', 'ch10session4_119', 'ch10session4_11a', 'ch10session4_11b', 'ch10session4_11c', 'ch10session4_11d', 'ch10session4_11e', 'ch10session4_11f', 'ch10session4_120', 'ch10session4_121', 'ch10session4_122', 'ch10session4_123', 'ch10session4_124', 'ch10session4_125', 'ch10session4_126', 'ch10session4_127', 'ch10session4_128', 'ch10session4_129', 'ch10session4_12a', 'ch10session4_12b', 'ch10session4_12c', 'ch10session4_12d', 'ch10session4_12e', 'ch10session4_12f', 'ch10session4_130', 'ch10session4_131', 'ch10session4_132', 'ch10session4_133', 'ch10session4_134', 'ch10session4_135', 'ch10session4_136', 'ch10session4_137', 'ch10session4_138', 'ch10session4_139', 'ch10session4_13a', 'ch10session4_13b', 'ch10session4_13c', 'ch10session4_13d', 'ch10session4_13e', 'ch10session4_13f', 'ch10session4_140', 'ch10session4_141', 'ch10session4_142', 'ch10session4_143', 'ch10session4_144', 'ch10session4_145', 'ch10session4_146', 'ch10session4_147', 'ch10session4_148', 'ch10session4_149', 'ch10session4_14a', 'ch10session4_14b', 'ch10session4_14c', 'ch10session4_14d', 'ch10session4_14e', 'ch10session4_14f', 'ch10session4_150', 'ch10session4_151', 'ch10session4_152', 'ch10session4_153', 'ch10session4_154', 'ch10session4_155', 'ch10session4_156', 'ch10session4_157', 'ch10session4_158', 'ch10session4_159', 'ch10session4_15a', 'ch10session4_15b', 'ch10session4_15c', 'ch10session4_15d', 'ch10session4_15e', 'ch10session4_15f', 'ch10session4_160', 'ch10session4_161', 'ch10session4_162', 'ch10session4_163', 'ch10session4_164', 'ch10session4_165', 'ch10session4_166', 'ch10session4_167', 'ch10session4_168', 'ch10session4_169', 'ch10session4_16a', 'ch10session4_16b', 'ch10session4_16c', 'ch10session4_16d', 'ch10session4_16e', 'ch10session4_16f', 'ch10session4_170', 'ch10session4_171', 'ch10session4_172', 'ch10session4_173', 'ch10session4_174', 'ch10session4_175', 'ch10session4_176', 'ch10session4_177', 'ch10session4_178', 'ch10session4_179', 'ch10session4_17a', 'ch10session4_17b', 'ch10session4_17c', 'ch10session4_17d', 'ch10session4_17e', 'ch10session4_17f', 'ch10session4_180', 'ch10session4_181', 'ch10session4_182', 'ch10session4_183', 'ch10session4_184', 'ch10session4_185', 'ch10session4_186', 'ch10session4_187', 'ch10session4_188', 'ch10session4_189', 'ch10session4_18a', 'ch10session4_18b', 'ch10session4_18c', 'ch10session4_18d', 'ch10session4_18e', 'ch10session4_18f', 'ch10session4_190', 'ch10session4_191', 'ch10session4_192', 'ch10session4_193', 'ch10session4_194', 'ch10session4_195', 'ch10session4_196', 'ch10session4_197', 'ch10session4_198', 'ch10session4_199', 'ch10session4_19a', 'ch10session4_19b', 'ch10session4_19c', 'ch10session4_19d', 'ch10session4_19e', 'ch10session4_19f', 'ch10session4_1a0', 'ch10session4_1a1', 'ch10session4_1a2', 'ch10session4_1a3', 'ch10session4_1a4', 'ch10session4_1a5', 'ch10session4_1a6', 'ch10session4_1a7', 'ch10session4_1a8', 'ch10session4_1a9', 'ch10session4_1aa', 'ch10session4_1ab', 'ch10session4_1ac', 'ch10session4_1ad', 'ch10session4_1ae', 'ch10session4_1af', 'ch10session4_1b0', 'ch10session4_1b1', 'ch10session4_1b2', 'ch10session4_1b3', 'ch10session4_1b4', 'ch10session4_1b5', 'ch10session4_1b6', 'ch10session4_1b7', 'ch10session4_1b8', 'ch10session4_1b9', 'ch10session4_1ba', 'ch10session4_1bb', 'ch10session4_1bc', 'ch10session4_1bd', 'ch10session4_1be', 'ch10session4_1bf', 'ch10session4_1c0', 'ch10session4_1c1', 'ch10session4_1c2', 'ch10session4_1c3', 'ch10session4_1c4', 'ch10session4_1c5', 'ch10session4_1c6', 'ch10session4_1c7', 'ch10session4_1c8', 'ch10session4_1c9', 'ch10session4_1ca', 'ch10session4_1cb', 'ch10session4_1cc', 'ch10session4_1cd', 'ch10session4_1ce', 'ch10session4_1cf', 'ch10session4_1d0', 'ch10session4_1d1', 'ch10session4_1d2', 'ch10session4_1d3', 'ch10session4_1d4', 'ch10session4_1d5', 'ch10session4_1d6', 'ch10session4_1d7', 'ch10session4_1d8', 'ch10session4_1d9', 'ch10session4_1da', 'ch10session4_1db', 'ch10session4_1dc', 'ch10session4_1dd', 'ch10session4_1de', 'ch10session4_1df', 'ch10session4_1e0', 'ch10session4_1e1']}
\ No newline at end of file
+p_list= {'ch12index': [], 'ch6oop': ['ch6oop_1', 'ch6oop_2', 'ch6oop_3', 'ch6oop_4', 'ch6oop_5', 'ch6oop_6'], 'ch9Using_Linux_Tools': [], 'ch1Introduction': ['ch1Introduction_1', 'ch1Introduction_2', 'ch1Introduction_3', 'ch1Introduction_4', 'ch1Introduction_5', 'ch1Introduction_6', 'ch1Introduction_7', 'ch1Introduction_8', 'ch1Introduction_9', 'ch1Introduction_a', 'ch1Introduction_b', 'ch1Introduction_c', 'ch1Introduction_d'], 'ch5func': ['ch5func_1', 'ch5func_2', 'ch5func_3', 'ch5func_4', 'ch5func_5', 'ch5func_6', 'ch5func_7', 'ch5func_8', 'ch5func_9', 'ch5func_a', 'ch5func_b', 'ch5func_c', 'ch5func_d', 'ch5func_e', 'ch5func_f', 'ch5func_10', 'ch5func_11', 'ch5func_12', 'ch5func_13', 'ch5func_14', 'ch5func_15', 'ch5func_16', 'ch5func_17', 'ch5func_18', 'ch5func_19', 'ch5func_1a', 'ch5func_1b', 'ch5func_1c', 'ch5func_1d', 'ch5func_1e', 'ch5func_1f'], 'ch3list_tuples': ['ch3list_tuples_1', 'ch3list_tuples_2', 'ch3list_tuples_3', 'ch3list_tuples_4', 'ch3list_tuples_5', 'ch3list_tuples_6', 'ch3list_tuples_7', 'ch3list_tuples_8', 'ch3list_tuples_9', 'ch3list_tuples_a', 'ch3list_tuples_b', 'ch3list_tuples_c', 'ch3list_tuples_d', 'ch3list_tuples_e', 'ch3list_tuples_f', 'ch3list_tuples_10', 'ch3list_tuples_11', 'ch3list_tuples_12', 'ch3list_tuples_13', 'ch3list_tuples_14', 'ch3list_tuples_15', 'ch3list_tuples_16', 'ch3list_tuples_17', 'ch3list_tuples_18', 'ch3list_tuples_19', 'ch3list_tuples_1a', 'ch3list_tuples_1b', 'ch3list_tuples_1c', 'ch3list_tuples_1d', 'ch3list_tuples_1e', 'ch3list_tuples_1f', 'ch3list_tuples_20', 'ch3list_tuples_21', 'ch3list_tuples_22', 'ch3list_tuples_23', 'ch3list_tuples_24', 'ch3list_tuples_25', 'ch3list_tuples_26', 'ch3list_tuples_27', 'ch3list_tuples_28', 'ch3list_tuples_29', 'ch3list_tuples_2a', 'ch3list_tuples_2b', 'ch3list_tuples_2c', 'ch3list_tuples_2d', 'ch3list_tuples_2e', 'ch3list_tuples_2f', 'ch3list_tuples_30', 'ch3list_tuples_31', 'ch3list_tuples_32', 'ch3list_tuples_33', 'ch3list_tuples_34', 'ch3list_tuples_35', 'ch3list_tuples_36', 'ch3list_tuples_37'], 'ch2intro': ['ch2intro_1', 'ch2intro_2', 'ch2intro_3', 'ch2intro_4', 'ch2intro_5', 'ch2intro_6', 'ch2intro_7', 'ch2intro_8', 'ch2intro_9', 'ch2intro_a', 'ch2intro_b', 'ch2intro_c', 'ch2intro_d', 'ch2intro_e', 'ch2intro_f', 'ch2intro_10', 'ch2intro_11', 'ch2intro_12', 'ch2intro_13', 'ch2intro_14', 'ch2intro_15', 'ch2intro_16', 'ch2intro_17', 'ch2intro_18', 'ch2intro_19', 'ch2intro_1a', 'ch2intro_1b', 'ch2intro_1c', 'ch2intro_1d', 'ch2intro_1e', 'ch2intro_1f', 'ch2intro_20', 'ch2intro_21', 'ch2intro_22', 'ch2intro_23', 'ch2intro_24', 'ch2intro_25', 'ch2intro_26', 'ch2intro_27', 'ch2intro_28', 'ch2intro_29', 'ch2intro_2a', 'ch2intro_2b', 'ch2intro_2c', 'ch2intro_2d', 'ch2intro_2e', 'ch2intro_2f', 'ch2intro_30', 'ch2intro_31', 'ch2intro_32', 'ch2intro_33', 'ch2intro_34', 'ch2intro_35', 'ch2intro_36', 'ch2intro_37', 'ch2intro_38', 'ch2intro_39', 'ch2intro_3a', 'ch2intro_3b', 'ch2intro_3c', 'ch2intro_3d', 'ch2intro_3e', 'ch2intro_3f', 'ch2intro_40', 'ch2intro_41', 'ch2intro_42', 'ch2intro_43', 'ch2intro_44', 'ch2intro_45', 'ch2intro_46', 'ch2intro_47', 'ch2intro_48', 'ch2intro_49', 'ch2intro_4a', 'ch2intro_4b', 'ch2intro_4c', 'ch2intro_4d', 'ch2intro_4e', 'ch2intro_4f', 'ch2intro_50', 'ch2intro_51', 'ch2intro_52', 'ch2intro_53', 'ch2intro_54', 'ch2intro_55', 'ch2intro_56', 'ch2intro_57', 'ch2intro_58', 'ch2intro_59', 'ch2intro_5a', 'ch2intro_5b', 'ch2intro_5c', 'ch2intro_5d', 'ch2intro_5e', 'ch2intro_5f', 'ch2intro_60', 'ch2intro_61', 'ch2intro_62', 'ch2intro_63', 'ch2intro_64', 'ch2intro_65', 'ch2intro_66', 'ch2intro_67'], 'ch4strings_dicts': ['ch4strings_dicts_1', 'ch4strings_dicts_2', 'ch4strings_dicts_3', 'ch4strings_dicts_4', 'ch4strings_dicts_5', 'ch4strings_dicts_6', 'ch4strings_dicts_7', 'ch4strings_dicts_8', 'ch4strings_dicts_9', 'ch4strings_dicts_a', 'ch4strings_dicts_b', 'ch4strings_dicts_c', 'ch4strings_dicts_d', 'ch4strings_dicts_e', 'ch4strings_dicts_f', 'ch4strings_dicts_10', 'ch4strings_dicts_11', 'ch4strings_dicts_12', 'ch4strings_dicts_13', 'ch4strings_dicts_14', 'ch4strings_dicts_15', 'ch4strings_dicts_16', 'ch4strings_dicts_17', 'ch4strings_dicts_18', 'ch4strings_dicts_19', 'ch4strings_dicts_1a', 'ch4strings_dicts_1b', 'ch4strings_dicts_1c', 'ch4strings_dicts_1d', 'ch4strings_dicts_1e', 'ch4strings_dicts_1f', 'ch4strings_dicts_20', 'ch4strings_dicts_21', 'ch4strings_dicts_22', 'ch4strings_dicts_23', 'ch4strings_dicts_24', 'ch4strings_dicts_25', 'ch4strings_dicts_26', 'ch4strings_dicts_27', 'ch4strings_dicts_28', 'ch4strings_dicts_29', 'ch4strings_dicts_2a', 'ch4strings_dicts_2b', 'ch4strings_dicts_2c', 'ch4strings_dicts_2d', 'ch4strings_dicts_2e', 'ch4strings_dicts_2f', 'ch4strings_dicts_30'], 'ch11Section_5': [], 'ch7interim_assessment': [], 'ch8ult_module_plan': [], 'ch10session4': []}
\ No newline at end of file
--- a/SEESenv/web/html/ch1Introduction.html Mon Feb 22 18:46:07 2010 +0530
+++ b/SEESenv/web/html/ch1Introduction.html Mon Feb 22 22:38:51 2010 +0530
@@ -27,5227 +27,96 @@
<dl>
<dt>
<span class="article">
- <a href="#id2657318">
+ <a href="#id2480917">
+ Introduction to the Course
</a>
</span>
</dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2467443">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2655137">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2708378">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2708650">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2708782">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2708791">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2709069">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2709077">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709238">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709298">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709398">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709480">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2709646">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2709654">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709738">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709930">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2710016">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2710068">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2710077">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2710386">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2710534">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2710700">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2710792">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2710801">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2710887">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2711014">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2711100">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2711232">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2711344">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2711353">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2711556">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2711666">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2711904">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2712174">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2712190">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2712213">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2712221">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2713123">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2713159">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2713228">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2713289">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2713494">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2713528">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2713558">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2713567">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2713756">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2713906">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2714115">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2714191">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </dd>
</dl>
</div>
- <div class="article">
+ <div class="article" title="Introduction to the Course">
<div class="titlepage">
<div>
<div>
- <h2 class="title" id="id2657318">
+ <h2 class="title">
+ <a name="id2480917">
+ </a>
+ Introduction to the Course
</h2>
</div>
</div>
<hr />
</div>
- <div class="toc">
- <p>
- <b>
- Table of Contents
- </b>
- </p>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2467443">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2655137">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2708378">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2708650">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2708782">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2708791">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2709069">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2709077">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709238">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709298">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709398">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709480">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2709646">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2709654">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709738">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2709930">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2710016">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2710068">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2710077">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2710386">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2710534">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2710700">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2710792">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2710801">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2710887">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2711014">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2711100">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2711232">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2711344">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2711353">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2711556">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2711666">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2711904">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2712174">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2712190">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2712213">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2712221">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2713123">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2713159">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2713228">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2713289">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2713494">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2713528">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2713558">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2713567">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2713756">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2713906">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2714115">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2714191">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </div>
- <div class="section" title="1.Introducing Linux">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2467443">
- </a>
- 1.Introducing Linux
- </h2>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_1">
- (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
- </p>
- <p id="ch1Introduction_2">
- Linux (usually pronounced lnks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
- </p>
- <p id="ch1Introduction_3">
- Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
- </p>
- <p id="ch1Introduction_4">
- The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
- </p>
- <div class="section" title="1.1.Historical Background">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2655137">
- </a>
- 1.1.Historical Background
- </h3>
- </div>
- </div>
- </div>
- <div class="section" title="1.1.1.Events leading to the creation">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2655104">
- </a>
- 1.1.1.Events leading to the creation
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_5">
- The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_6">
- In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="1.1.2.The Creation of Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2708333">
- </a>
- 1.1.2.The Creation of Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_7">
- In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
- </p>
- <p id="ch1Introduction_8">
- Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
- </p>
- </div>
- </div>
- <div class="section" title="1.2.Design and Implications">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2708378">
- </a>
- 1.2.Design and Implications
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_9">
- A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
- </p>
- <div class="section" title="1.2.1.User Interface">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2708402">
- </a>
- 1.2.1.User Interface
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_a">
- Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
- </p>
- <p id="ch1Introduction_b">
- A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
- </p>
- </div>
- <div class="section" title="1.2.2.Development">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2708456">
- </a>
- 1.2.2.Development
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_c">
- The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
- </p>
- <p id="ch1Introduction_d">
- Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
- </p>
- <p id="ch1Introduction_e">
- A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
- </p>
- </div>
- <div class="section" title="1.2.3.Community">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2708513">
- </a>
- 1.2.3.Community
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_f">
- A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
- </p>
- <p id="ch1Introduction_10">
- In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
- </p>
- <p id="ch1Introduction_11">
- Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
- </p>
- </div>
- <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2708558">
- </a>
- 1.2.4.Can I make a profit out of running a business involving Linux?
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_12">
- The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
- </p>
- </div>
- <div class="section" title="1.2.5.Programming on Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2708603">
- </a>
- 1.2.5.Programming on Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_13">
- Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
- </p>
- <p id="ch1Introduction_14">
- Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
- </p>
- <p id="ch1Introduction_15">
- The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
- </p>
- </div>
- </div>
- <div class="section" title="1.3.Reasons for Using Linux">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2708650">
- </a>
- 1.3.Reasons for Using Linux
- </h3>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_16">
- Linux is free:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_17">
- As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
-Most of all, Linux is free as in "free speech":
-The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_18">
- Linux is portable to any hardware platform:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_19">
- A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_1a">
- Linux was made to keep on running:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_1b">
- As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_1c">
- Linux is secure and versatile:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_1d">
- The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_1e">
- Linux is scalable:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_1f">
- From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_20">
- The Linux OS and Linux applications have very short debugtimes:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_21">
- Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
- </p>
- </div>
- </div>
- <div class="section" title="2.Getting Started">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2708782">
- </a>
- 2.Getting Started
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="2.1.Logging in, activating the user interface and logging out">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2708791">
- </a>
- 2.1.Logging in, activating the user interface and logging out
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_22">
- In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PCbased Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multiuser features, or in graphical console mode, which looks better but eats more system resources.
- </p>
- <div class="section" title="2.1.1.Graphical Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2708821">
- </a>
- 2.1.1.Graphical Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_23">
- This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
- </p>
- <p id="ch1Introduction_24">
- To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
- <span class="emphasis">
- <em>
- OK
- </em>
- </span>
- or press
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- .
-It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
- </p>
- <p id="ch1Introduction_25">
- After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
- </p>
- <p id="ch1Introduction_26">
- To continue, you will need to open a
- <span class="emphasis">
- <em>
- terminal window
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
- <span class="emphasis">
- <em>
- Applications>Utilities->System Tools
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- Internet menu
- </em>
- </span>
- , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
- </p>
- <p id="ch1Introduction_27">
- While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old pointnclick method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
- </p>
- <p id="ch1Introduction_28">
- A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
- </p>
- <p id="ch1Introduction_29">
- Another common form for a prompt is this one:
-[
- </p>
- <div class="reference">
- <div class="titlepage">
- <hr />
- </div>
- user@host
- </div>
- <p>
- dir]
- </p>
- <p id="ch1Introduction_2a">
- In the above example,
- <span class="emphasis">
- <em>
- user
- </em>
- </span>
- will be your login name,
- <span class="emphasis">
- <em>
- hosts
- </em>
- </span>
- the name of the machine you are working on, and
- <span class="emphasis">
- <em>
- dir
- </em>
- </span>
- an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- icon or find
- <span class="emphasis">
- <em>
- Log Out
- </em>
- </span>
- in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
- </p>
- <p id="ch1Introduction_2b">
- When you see the login screen again, asking to enter user name and password, logout was successful.
- </p>
- </div>
- <div class="section" title="2.1.2.Text Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2708979">
- </a>
- 2.1.2.Text Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_2c">
- One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
- </p>
- <p id="ch1Introduction_2d">
- The login is different from a graphical login, in that you have to hit the
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- . You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
-reasons.
- </p>
- <p id="ch1Introduction_2e">
- When the system has accepted you as a valid user, you may get some more information, called the
- <span class="emphasis">
- <em>
- message of the day
- </em>
- </span>
- , which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
- </p>
- <p id="ch1Introduction_2f">
- Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a nonprivileged user.
- </p>
- <p id="ch1Introduction_30">
- Logging out is done by entering the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't poweroff the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
+ <p id="ch1Introduction_1">
+ Engineering students use computers for a large number of curricular
+tasks mostly computation centred. However, they do not see this as coding or programming tasks and usually are not even aware of the tools and
+techniques that will help them to handle these tasks better. This results
+in less than optimal use of their time and resources. This also causes
+difficulties when it comes tocollaboration and building on other peoples
+work. This course is intended to train such students in good software
+practices and tools for producing code and documentation.
+ </p>
+ <p id="ch1Introduction_2">
+ After successfully completing the program, the participants will be able to:
+ </p>
+ <div class="itemizedlist">
+ <ul class="itemizedlist" type="*">
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_3">
+ understand how software tools work together and how they can be used in tandem to carry out tasks,
</p>
- </div>
- </div>
- </div>
- <div class="section" title="3.Basic Commands">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2709069">
- </a>
- 3.Basic Commands
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="3.1.ls">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2709077">
- </a>
- 3.1.ls
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_31">
- When invoked without any arguments,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- is derived from
- <span class="emphasis">
- <em>
- list segments
- </em>
- </span>
- which was used in earlier systems.
- </p>
- <p id="ch1Introduction_32">
- Files whose names start with "." are not listed, unless the
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- flag is specified or the files are specified explicitly.
- </p>
- <p id="ch1Introduction_33">
- Without options,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_34">
- <span class="emphasis">
- <em>
- -l
- </em>
- </span>
- long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_35">
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_36">
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_37">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- recursively lists subdirectories. The command ls -R / would therefore list all files.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_38">
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_39">
- <span class="emphasis">
- <em>
- -t
- </em>
- </span>
- sort the list of files by modification time.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_3a">
- <span class="emphasis">
- <em>
- -h
- </em>
- </span>
- print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_3b">
- In some environments, providing the option
- <span class="emphasis">
- <em>
- --color
- </em>
- </span>
- (for GNU ls) or
- <span class="emphasis">
- <em>
- -G
- </em>
- </span>
- (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- would. To determine what color to use for a file, GNU
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks the Unix file type, the file permissions, and the file extension, while FreeBSD
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks only the Unix file type and file permissions.:
- </p>
- <pre class="programlisting">
- $ ls
-jeeves.rst psmith.html blandings.html
-$ ls -l
-drwxr--r-- 1 plum editors 4096 jeeves
--rw-r--r-- 1 plum editors 30405 psmith
--r-xr-xr-x 1 plum plum 8460 blandings
- </pre>
- <p id="ch1Introduction_3c">
- Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
- </p>
- </div>
- <div class="section" title="3.2.date">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2709238">
- </a>
- 3.2.date
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_3d">
- The Unix date command displays the time and date. The super-user can use it to set the system clock.
- </p>
- <p id="ch1Introduction_3e">
- With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:
- </p>
- <pre class="programlisting">
- $date
-Tue Sep 8 12:01:45 IST 2009
- </pre>
- <p id="ch1Introduction_3f">
- On some systems to set the current date and time to September 8, 2004 01:22 you type:
- </p>
- <pre class="programlisting">
- $date --set="20040908 01:22"
- </pre>
- <p id="ch1Introduction_40">
- In order to view the various options for the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command, type:
- </p>
- <pre class="programlisting">
- $man date
- </pre>
- <p id="ch1Introduction_41">
- This will take you to the "Manual" page comprising of all the details on the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command. You can return to the terminal from the "man" page by pressing the
- <span class="emphasis">
- <em>
- Esc
- </em>
- </span>
- key in the keyboard and typing ":q" in that order.
- </p>
- </div>
- <div class="section" title="3.3.cd">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2709298">
- </a>
- 3.3.cd
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_42">
- This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, cd .. can be used.
- </p>
- <p id="ch1Introduction_43">
- One dot '.' represents the current directory while two dots '..' represent the parent directory.
- </p>
- <p id="ch1Introduction_44">
- cd - will return you to the previous directory (a bit like an undo).
- </p>
- <p id="ch1Introduction_45">
- You can also use cd absolute path or cd relative path (see below):
- </p>
- <p id="ch1Introduction_46">
- Absolute paths:
- </p>
- <p id="ch1Introduction_47">
- An absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
- </p>
- <p id="ch1Introduction_48">
- For example to get to /boot/grub you would type:
- </p>
- <pre class="programlisting">
- $cd /boot/grub
- </pre>
- <p id="ch1Introduction_49">
- This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
- </p>
- <p id="ch1Introduction_4a">
- Relative paths:
- </p>
- <p id="ch1Introduction_4b">
- A relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
- </p>
- <p id="ch1Introduction_4c">
- For example if you are in root's home directory and want to get to /root/music, you type:
- </p>
- <pre class="programlisting">
- $ cd music
- </pre>
- <p id="ch1Introduction_4d">
- Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
- </p>
- </div>
- <div class="section" title="3.4.who">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2709398">
- </a>
- 3.4.who
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_4e">
- The standard Unix command
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- displays a list of users who are currently logged into a computer.
- </p>
- <p id="ch1Introduction_4f">
- The
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command is related to the command
- <span class="emphasis">
- <em>
- w
- </em>
- </span>
- , which provides the same information but also displays additional data and statistics.:
- </p>
- <pre class="programlisting">
- $who
-beeblebrox tty7 2009-09-08 10:50 (:0)
-beeblebrox pts/0 2009-09-08 11:25 (:0.0)
-dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in)
-beeblebrox pts/2 2009-09-08 18:53 (:0.0)
- </pre>
- <p id="ch1Introduction_50">
- The command can be invoked with the arguments
- <span class="emphasis">
- <em>
- am i
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- am I
- </em>
- </span>
- (so it is invoked as
- <span class="emphasis">
- <em>
- who am i
- </em>
- </span>
- or * who am I*), showing information about the current terminal only (see the
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- option below, of which this invocation is equivalent).
- </p>
- <p id="ch1Introduction_51">
- In order to find out the various options that can be appended to the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command, check the
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page by typing out the following in the terminal:
- </p>
- <pre class="programlisting">
- $man who
- </pre>
- <p id="ch1Introduction_52">
- This will take you to the "Manual" page containing details about the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command
- </p>
- </div>
- <div class="section" title="3.5.mkdir">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2709480">
- </a>
- 3.5.mkdir
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_53">
- This command is used to make a new directory. Normal usage is as straightforward as follows:
- </p>
- <pre class="programlisting">
- $mkdir name_of_directory
- </pre>
- <p id="ch1Introduction_54">
- Where
- <span class="emphasis">
- <em>
- name_of_directory
- </em>
- </span>
- is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- will try to create all of them.
- </p>
- <div class="section" title="3.5.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2709512">
- </a>
- 3.5.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_55">
- On Unix-like operating systems,
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- takes options. Three of the most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_56">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- : will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_57">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- : display each directory that mkdir creates. Most often used with -p.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_58">
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- : specify the octal permissions of directories created by mkdir.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_59">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
- </p>
- </div>
- <div class="section" title="3.5.2.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2709570">
- </a>
- 3.5.2.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_5a">
- An example of
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- in action is:
- </p>
- <pre class="programlisting">
- $mkdir -p /tmp/a/b/c
- </pre>
- <p id="ch1Introduction_5b">
- If
- <span class="emphasis">
- <em>
- /tmp/a
- </em>
- </span>
- exists but
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- does not, mkdir will create
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- before creating
- <span class="emphasis">
- <em>
- /tmp/a/b/c
- </em>
- </span>
- .
- </p>
- <p id="ch1Introduction_5c">
- And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
- </p>
- <pre class="programlisting">
- $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
- </pre>
- <p id="ch1Introduction_5d">
- This will create:
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_4">
+ use unix command line tools to carry out common (mostly text processing tasks,
</p>
- tmpdir - branches
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_5e">
- tag
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- trunk - sources - includes
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_5f">
- docs
- </p>
- </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="4.Getting Help">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2709646">
- </a>
- 4.Getting Help
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="4.1.apropos and whatis">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2709654">
- </a>
- 4.1.apropos and whatis
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_60">
- This is a command to search the manual pages files in Unix and Unix-like operating systems.
- </p>
- <pre class="programlisting">
- $ apropos grep
-egrep egrep (1) Search a file for a pattern using full regular expressions
-fgrep fgrep (1) Search a file for a fixed-character string
-fmlgrep fmlgrep (1) Search a file for a pattern
-grep grep (1) Search a file for a pattern
-gzgrep gzgrep (1) Search a possibly compressed file for a regular expression
-nisgrep nismatch (1) Utilities for searching NIS+ tables
-pgrep pgrep (1) Find or signal a process by name or other attribute
-zgrep zgrep (1) Search a possibly compressed file for a regular expression
-...
- </pre>
- <p id="ch1Introduction_61">
- In this example, the user uses
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- to search for the string "grep", and apropos returns the indicated
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- pages that include the term "grep".
- </p>
- <p id="ch1Introduction_62">
- A short index of explanations for commands is available using the
- <span class="emphasis">
- <em>
- whatis
- </em>
- </span>
- command, like in the examples below:
- </p>
- <pre class="programlisting">
- $whatis ls
-ls (1) - list directory contents
- </pre>
- <p id="ch1Introduction_63">
- This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
- </p>
- <p id="ch1Introduction_64">
- If you don't know where to get started and which man page to read,
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- gives more information. Say that you do not know how to start a browser, then you could enter the following command:
- </p>
- <pre class="programlisting">
- $apropos browser
-gmusicbrowser (1) - Jukebox for large collections of audio files
-infobrowser (1) - read Info documents
-libsmbclient (7) - An extension library for browsers and that can be used...
-opera (1) - a standards-compliant graphical Web browser
-sensible-browser (1) - sensible editing, paging, and web browsing
-smbtree (1) - A text based smb network browser
-tvtk_doc (1) - A GUI based TVTK documentation search browser.
-viewres (1) - graphical class browser for Xt
-w3m (1) - a text based Web browser and pager
-www-browser (1) - a text based Web browser and pager
-...
- </pre>
- </div>
- <div class="section" title="4.2.man">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2709738">
- </a>
- 4.2.man
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_65">
- Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- . Each page is a self-contained document.
- </p>
- <p id="ch1Introduction_66">
- To read a manual page for a Unix command, one can use:
- </p>
- <pre class="programlisting">
- $ man <command_name>
- </pre>
- <p id="ch1Introduction_67">
- at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- generally uses the less terminal pager.
- </p>
- <p id="ch1Introduction_68">
- Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are
- <span class="emphasis">
- <em>
- man(1)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- man(7)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- exit(2)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- exit(3)
- </em>
- </span>
- . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
- <span class="emphasis">
- <em>
- BSD, for example, the syntax for reading *printf(3)
- </em>
- </span>
- is:
- </p>
- <pre class="programlisting">
- $man 3 printf
- </pre>
- <p id="ch1Introduction_69">
- Another example:
- </p>
- <pre class="programlisting">
- $man man
- </pre>
- <p id="ch1Introduction_6a">
- The previous example will take you to the "Manual" page entry about manual pages!
- </p>
- <div class="section" title="4.2.1.Layout">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2709821">
- </a>
- 4.2.1.Layout
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_6b">
- All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
- </p>
- NAME
- <p id="ch1Introduction_6c">
- The name of the command or function, followed by a one-line description of what it does.
- </p>
- SYNOPSIS
- <p id="ch1Introduction_6d">
- In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
- </p>
- DESCRIPTION
- <p id="ch1Introduction_6e">
- A textual description of the functioning of the command or function.
- </p>
- EXAMPLES
- <p id="ch1Introduction_6f">
- Some examples of common usage.
- </p>
- SEE ALSO
- <p id="ch1Introduction_70">
- A list of related commands or functions.
- </p>
- <p id="ch1Introduction_71">
- Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
- </p>
- <p id="ch1Introduction_72">
- These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
- </p>
- <p id="ch1Introduction_73">
- However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
- </p>
- <p id="ch1Introduction_74">
- Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
- </p>
- <p id="ch1Introduction_75">
- Usually the man pages are written in English. Translations into other languages can be also available on the system.
- </p>
- <p id="ch1Introduction_76">
- The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
- </p>
- </div>
- </div>
- <div class="section" title="4.3.info">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2709930">
- </a>
- 4.3.info
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_77">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
- </p>
- <p id="ch1Introduction_78">
- The syntax is
- </p>
- <pre class="programlisting">
- $ info <command_name>
- </pre>
- <p id="ch1Introduction_79">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_7a">
- <span class="emphasis">
- <em>
- n
- </em>
- </span>
- goes to the next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_7b">
- <span class="emphasis">
- <em>
- p
- </em>
- </span>
- goes to the previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_7c">
- <span class="emphasis">
- <em>
- u
- </em>
- </span>
- goes to the upper page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_7d">
- <span class="emphasis">
- <em>
- l
- </em>
- </span>
- goes to the last(visited) node
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_7e">
- To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_7f">
- info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
- </p>
- </div>
- <div class="section" title="4.4.--help">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2710016">
- </a>
- 4.4.--help
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_80">
- Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command:
- </p>
- <pre class="programlisting">
- $ userprompt@host: cat --help
-Usage: cat [OPTION] [FILE]...
-Concatenate FILE(s), or standard input, to standard output.
-
- -A, --show-all equivalent to -vET
- -b, --number-nonblank number nonempty output lines
- -e equivalent to -vE
- -E, --show-ends display $ at end of each line
- -n, --number number all output lines
- -s, --squeeze-blank suppress repeated empty output lines
- -t equivalent to -vT
- -T, --show-tabs display TAB characters as ^I
- -u (ignored)
- -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
- --help display this help and exit
- --version output version information and exit
-
-With no FILE, or when FILE is -, read standard input.
-
-Examples:
- cat f - g Output f's contents, then standard input, then g's contents.
- cat Copy standard input to standard output.
-
-Report bugs to <bug-coreutils@gnu.org>.
- </pre>
- </div>
- </div>
- <div class="section" title="5.Basic file handling">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2710068">
- </a>
- 5.Basic file handling
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="5.1.cp">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2710077">
- </a>
- 5.1.cp
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_81">
- <span class="emphasis">
- <em>
- cp
- </em>
- </span>
- is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
- </p>
- <div class="section" title="5.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2710094">
- </a>
- 5.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_82">
- To copy a file to another file:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
- </pre>
- <p id="ch1Introduction_83">
- To copy a file to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
- </pre>
- <p id="ch1Introduction_84">
- To copy a directory to a directory:
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_5">
+ to generate professional documents,
</p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
-SourceDirectory ... TargetDirectory
- </pre>
- </div>
- <div class="section" title="5.1.2.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2710128">
- </a>
- 5.1.2.Flags
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_85">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (force) specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
- </p>
- <p id="ch1Introduction_86">
- <span class="emphasis">
- <em>
- -P
- </em>
- </span>
- makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
- </p>
- <p id="ch1Introduction_87">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- (interactive) prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
- </p>
- <p id="ch1Introduction_88">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- (preserve) duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_89">
- The time of the last data modification and the time of the last access.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_8a">
- The user ID and group ID (only if it has permissions to do this)
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_8b">
- The file permission bits and the SUID and SGID bits.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_8c">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- (recursive) copy directories (recursively copying all the contents)
- </p>
- </div>
- <div class="section" title="5.1.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2710225">
- </a>
- 5.1.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_8d">
- To make a copy of a file in the current directory, enter:
- </p>
- <pre class="programlisting">
- $ cp prog.c prog.bak
- </pre>
- <p id="ch1Introduction_8e">
- This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
- </p>
- <p id="ch1Introduction_8f">
- To copy a file in your current directory into another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod /home/books/hhgg
- </pre>
- <p id="ch1Introduction_90">
- This copies the jones file to /home/books/hhgg/zaphod.
- </p>
- <p id="ch1Introduction_91">
- To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
- </p>
- <pre class="programlisting">
- $ cp -p martin_luther_king martin_luther_king.jr
- </pre>
- <p id="ch1Introduction_92">
- This copies the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file to the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file. Instead of creating the file with the current date and time stamp, the system gives the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file the same date and time as the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file. The
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file also inherits the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file's access control protection.
- </p>
- <p id="ch1Introduction_93">
- To copy all the files in a directory to a new directory, enter:
- </p>
- <pre class="programlisting">
- $ cp /home/galactica/clients/* /home/hhgg/customers
- </pre>
- <p id="ch1Introduction_94">
- This copies only the files in the clients directory to the customers directory.
- </p>
- <p id="ch1Introduction_95">
- To copy a directory, including all its files and subdirectories, to another directory, enter:
- </p>
- <p id="ch1Introduction_96">
- $ cp -R /home/hhgg/clients /home/hhgg/customers
- </p>
- <p id="ch1Introduction_97">
- This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
- </p>
- <p id="ch1Introduction_98">
- To copy a specific set of files of any extension to another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod arthur ford /home/hhgg/clients
- </pre>
- <p id="ch1Introduction_99">
- This copies the
- <span class="emphasis">
- <em>
- zaphod
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- arthur
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- ford
- </em>
- </span>
- files in your current working directory to the /home/hhgg/clients directory.
- </p>
- <p id="ch1Introduction_9a">
- To use pattern-matching characters to copy files, enter:
- </p>
- <pre class="programlisting">
- $ cp programs/*.py .
- </pre>
- <p id="ch1Introduction_9b">
- This copies the files in the programs directory that end with
- <span class="emphasis">
- <em>
- .py
- </em>
- </span>
- to the current directory, signified by the single "." (dot). You must type a space between the
- <span class="emphasis">
- <em>
- py
- </em>
- </span>
- and the final dot.
- </p>
- </div>
- </div>
- <div class="section" title="5.2.mv">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2710386">
- </a>
- 5.2.mv
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_9c">
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system),
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- will rename the file instead. Write permission is required on all directories being modified.
- </p>
- <div class="section" title="5.2.1.Conflicting existing file">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2710410">
- </a>
- 5.2.1.Conflicting existing file
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_9d">
- In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
- </p>
- </div>
- <div class="section" title="5.2.2.Differences with copy and delete">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2710429">
- </a>
- 5.2.2.Differences with copy and delete
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_9e">
- Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
- </p>
- </div>
- <div class="section" title="5.2.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2710476">
- </a>
- 5.2.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ mv myfile mynewfilename renames a file
-$ mv myfile otherfilename renames a file and deletes the existing file "myfile"
-$ mv myfile /myfile moves 'myfile' from the current directory to the root directory
-$ mv myfile dir/myfile moves 'myfile' to 'dir/myfile' relative to the current directory
-$ mv myfile dir same as the previous command (the filename is implied to be the same)
-$ mv myfile dir/myfile2 moves 'myfile' to dir and renames it to 'myfile2'
-$ mv foo bar baz dir moves multiple files to directory dir
-$ mv --help shows a very concise help about the syntax of the command
-$ man mv prints an extensive user manual for 'mv' in the terminal
- </pre>
- <p id="ch1Introduction_9f">
- In all cases, the file or files being moved or renamed can be a directory.
- </p>
- <p id="ch1Introduction_a0">
- Note that when the command is called with two arguments (as
- <span class="emphasis">
- <em>
- mv name1 name2
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- mv name1 /dir/name2
- </em>
- </span>
- ), it can have three different effects, depending on whether
- <span class="emphasis">
- <em>
- name2
- </em>
- </span>
- does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
- <span class="emphasis">
- <em>
- /.
- </em>
- </span>
- (or in some Unix versions
- <span class="emphasis">
- <em>
- /
- </em>
- </span>
- is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
- </p>
- </div>
- </div>
- <div class="section" title="5.3.rm">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2710534">
- </a>
- 5.3.rm
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_a1">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
- </p>
- <p id="ch1Introduction_a2">
- Here's example to remove a file named "foo" from a directory, here shown with the -i option:
- </p>
- <pre class="programlisting">
- $ rm -i foo
-remove foo? y
- </pre>
- <div class="section" title="5.3.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2710564">
- </a>
- 5.3.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_a3">
- Common options that rm accepts include:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_a4">
- <span class="emphasis">
- <em>
- -r
- </em>
- </span>
- , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_a5">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- , which asks for every deletion to be confirmed ("interactive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_a6">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- , which ignores non-existent files and overrides any confirmation prompts ("force")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_a7">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- , which shows what is being removed as it happens ("verbose")
- </p>
- </li>
- </ul>
- </div>
- <p id="ch1Introduction_a8">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
- </p>
- <p id="ch1Introduction_a9">
- <span class="emphasis">
- <em>
- rm -rf
- </em>
- </span>
- (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
- </p>
- <p id="ch1Introduction_aa">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often used in conjunction with xargs to supply a list of files to delete:
- </p>
- <pre class="programlisting">
- xargs rm < filelist
- </pre>
- <p id="ch1Introduction_ab">
- When
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is used on a symbolic link, it deletes the link, but does not affect the target of the link.
- </p>
- </div>
- <div class="section" title="5.3.2.Permissions">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2710661">
- </a>
- 5.3.2.Permissions
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_ac">
- Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
- </p>
- <p id="ch1Introduction_ad">
- To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
- </p>
- <p id="ch1Introduction_ae">
- If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_6">
+ use version control effectively for both code and documents,
</p>
- </div>
- </div>
- </div>
- <div class="section" title="6.Command Line Arguments">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2710700">
- </a>
- 6.Command Line Arguments
- </h2>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_af">
- In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
- </p>
- <p id="ch1Introduction_b0">
- For example, in Unix and Unix-like environments, an example of a command-line argument is:
- </p>
- <pre class="programlisting">
- rm file.s
- </pre>
- <p id="ch1Introduction_b1">
- "file.s" is a command line argument which tells the program rm to remove the file "file.s".
- </p>
- <p id="ch1Introduction_b2">
- Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
- </p>
- <p id="ch1Introduction_b3">
- A command line option or simply
- <span class="emphasis">
- <em>
- option
- </em>
- </span>
- (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
- </p>
- <p id="ch1Introduction_b4">
- Long options are introduced via "--", and are typically whole words. For example,
- <span class="emphasis">
- <em>
- ls --long --classify --all
- </em>
- </span>
- . Arguments to long options are provided with "=", as
- <span class="emphasis">
- <em>
- ls --block-size=1024
- </em>
- </span>
- . Some Unix programs use long options with single dashes, for example MPlayer as in
- <span class="emphasis">
- <em>
- mplayer -nosound
- </em>
- </span>
- .
- </p>
- <p id="ch1Introduction_b5">
- Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- by using
- <span class="emphasis">
- <em>
- rm -file1
- </em>
- </span>
- may produce an error, since rm may interpret
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- as a command line switch. Using
- <span class="emphasis">
- <em>
- rm -- -file1
- </em>
- </span>
- removes ambiguity.
- </p>
- </div>
- <div class="section" title="7.Basic Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2710792">
- </a>
- 7.Basic Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="7.1.head">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2710801">
- </a>
- 7.1.head
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_b6">
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:
- </p>
- <pre class="programlisting">
- $ head [options] <file_name>
- </pre>
- <p id="ch1Introduction_b7">
- By default,
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ head -n 20 filename
- </pre>
- <p id="ch1Introduction_b8">
- This displays the first 5 lines of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ head -n 5 foo*
- </pre>
- <p id="ch1Introduction_b9">
- Some versions omit the n and just let you say -5.
- </p>
- <div class="section" title="7.1.1.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2710852">
- </a>
- 7.1.1.Flags
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- -c <x number of bytes> Copy first x number of bytes.
- </pre>
- <p id="ch1Introduction_ba">
- Other options:
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- </p>
- <p id="ch1Introduction_bb">
- Many early versions of Unix did not have this command, and so documentation and books had
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- do this job:
- </p>
- <pre class="programlisting">
- sed 5q foo
- </pre>
- <p id="ch1Introduction_bc">
- This says to print every line (implicit), and quit after the fifth.
- </p>
- </div>
- </div>
- <div class="section" title="7.2.tail">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2710887">
- </a>
- 7.2.tail
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_bd">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
- </p>
- <p id="ch1Introduction_be">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ tail [options] <file_name>
- </pre>
- <p id="ch1Introduction_bf">
- By default,
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ tail -n 20 filename
- </pre>
- <p id="ch1Introduction_c0">
- This example shows the last 15 bytes of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ tail -c 15 foo*
- </pre>
- <p id="ch1Introduction_c1">
- This example shows all lines of filename from the second line onwards:
- </p>
- <pre class="programlisting">
- $ tail -n +2 filename
- </pre>
- <p id="ch1Introduction_c2">
- Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:
- </p>
- <pre class="programlisting">
- $ tail -20 filename
-$ tail -50c filename
- </pre>
- <p id="ch1Introduction_c3">
- However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
- </p>
- <div class="section" title="7.2.1.File monitoring">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2710965">
- </a>
- 7.2.1.File monitoring
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_c4">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- has a special command line option
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:
- </p>
- <pre class="programlisting">
- $ tail -f /var/adm/messages
- </pre>
- <p id="ch1Introduction_c5">
- To interrupt tail while it is monitoring, break-in with
- <span class="emphasis">
- <em>
- Ctrl+C
- </em>
- </span>
- . This command can be run "in the background" with &, see job control.
- </p>
- <p id="ch1Introduction_c6">
- If you have a command's result to monitor, you can use the
- <span class="emphasis">
- <em>
- watch
- </em>
- </span>
- command.
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_7">
+ automate tasks by writing shell scripts and python scripts,
</p>
- </div>
- </div>
- <div class="section" title="7.3.cut">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2711014">
- </a>
- 7.3.cut
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_c7">
- In computing,
- <span class="emphasis">
- <em>
- cut
- </em>
- </span>
- is a Unix command line utility which is used to extract sections from each line of input usually from a file.
- </p>
- <p id="ch1Introduction_c8">
- Extraction of line segments can typically be done by
- <span class="emphasis">
- <em>
- bytes (-b), characters (-c)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- fields (-f)
- </em>
- </span>
- separated by a
- <span class="emphasis">
- <em>
- delimiter (-d the tab character by default)
- </em>
- </span>
- . A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
- </p>
- <p id="ch1Introduction_c9">
- Assuming a file named file containing the lines:
- </p>
- <pre class="programlisting">
- foo:bar:baz:qux:quux
-one:two:three:four:five:six:seven
-alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- <p id="ch1Introduction_ca">
- To output the fourth through tenth characters of each line:
- </p>
- <pre class="programlisting">
- $ cut -c 4-10 file
- </pre>
- <p id="ch1Introduction_cb">
- This gives the output:
- </p>
- <pre class="programlisting">
- :bar:ba
-:two:th
-ha:beta
- </pre>
- <p id="ch1Introduction_cc">
- To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
- </p>
- <pre class="programlisting">
- $ cut -d : -f 5- file
- </pre>
- <p id="ch1Introduction_cd">
- This gives the output:
- </p>
- <pre class="programlisting">
- quux
-five:six:seven
-epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- </div>
- <div class="section" title="7.4.paste">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2711100">
- </a>
- 7.4.paste
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_ce">
- <span class="emphasis">
- <em>
- paste
- </em>
- </span>
- is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command which operates on the vertical plane of two or more files.
- </p>
- <p id="ch1Introduction_cf">
- To paste several columns of data together into the file
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- from files
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- where
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- when
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ paste who where when > www
- </pre>
- <p id="ch1Introduction_d0">
- If the files contain:
- </p>
- <table summary="paste" border="1">
- <colgroup>
- <col width="11">
- </col>
- <col width="12">
- </col>
- <col width="12">
- </col>
- </colgroup>
- </table>
- <p id="ch1Introduction_dd">
- This creates the file named
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- containing:
- </p>
- <pre class="programlisting">
- Batman GothamCity January 3
-Trillian Andromeda February 4
-Jeeves London March 19
- </pre>
- </div>
- </div>
- <div class="section" title="8.Shell Meta Characters">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2711232">
- </a>
- 8.Shell Meta Characters
- </h2>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_de">
- Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
- </p>
- <p id="ch1Introduction_df">
- The shell meta characters include:
- </p>
- <p id="ch1Introduction_e0">
- / < > ! $ % ^ & * | { } [ ] " ' ` ~ ;
- </p>
- <p id="ch1Introduction_e1">
- Different shells may differ in the meta characters recognized.
- </p>
- <p id="ch1Introduction_e2">
- As an example,
- </p>
- <pre class="programlisting">
- $ ls file.*
- </pre>
- <p id="ch1Introduction_e3">
- run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
- </p>
- <pre class="programlisting">
- $ ls file.?
- </pre>
- <p id="ch1Introduction_e4">
- run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:
- </p>
- <pre class="programlisting">
- $ more c*
- </pre>
- <p id="ch1Introduction_e5">
- because the c* matches that long file name.
- </p>
- <p id="ch1Introduction_e6">
- Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named "``*`|more"` can be accomplished with:
- </p>
- <pre class="programlisting">
- $ rm ??more
- </pre>
- <p id="ch1Introduction_e7">
- or:
- </p>
- <pre class="programlisting">
- $ rm $\backslash$*$\backslash$|more
- </pre>
- <p id="ch1Introduction_e8">
- or:
- </p>
- <pre class="programlisting">
- $ rm ''*|more''
- </pre>
- </div>
- <div class="section" title="9.Looking At Files">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2711344">
- </a>
- 9.Looking At Files
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="9.1.cat">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2711353">
- </a>
- 9.1.cat
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_e9">
- The
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
- <span class="emphasis">
- <em>
- concatenate
- </em>
- </span>
- .
- </p>
- <p id="ch1Introduction_ea">
- The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
- </p>
- <p id="ch1Introduction_eb">
- If the filename is specified as -, then
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input at that point in the sequence. If no files are specified,
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input entered.
- </p>
- <div class="section" title="9.1.1.Jargon File Definition">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2711396">
- </a>
- 9.1.1.Jargon File Definition
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_ec">
- The Jargon File version 4.4.7 lists this as the definition of
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- 1. To spew an entire file to the screen or some other output sink without
- pause (syn. blast).
-
-2. By extension, to dump large amounts of data at an unprepared target or
- with no intention of browsing it carefully. Usage: considered silly.
- Rare outside Unix sites. See also dd, BLT.
-
- Among Unix fans, *cat(1)* is considered an excellent example of
- user-interface design, because it delivers the file contents without
- such verbosity as spacing or headers between the files, and because
- it does not require the files to consist of lines of text, but works
- with any sort of data.
-
- Among Unix critics, *cat(1)* is considered the canonical example of
- bad user-interface design, because of its woefully unobvious name.
- It is far more often used to blast a single file to standard output
- than to concatenate two or more files. The name cat for the former
- operation is just as unintuitive as, say, LISP's cdr.
-
- Of such oppositions are holy wars made...
- </pre>
- </div>
- <div class="section" title="9.1.2.Useless Use of 'cat'">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2711452">
- </a>
- 9.1.2.Useless Use of 'cat'
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_ed">
- UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
- <span class="emphasis">
- <em>
- comp.unix.shell
- </em>
- </span>
- , The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
- </p>
- <p id="ch1Introduction_ee">
- Nevertheless one sees people doing:
- </p>
- <pre class="programlisting">
- $ cat file | some_command and its args ...
- </pre>
- <p id="ch1Introduction_ef">
- instead of the equivalent and cheaper:
- </p>
- <pre class="programlisting">
- <file some_command and its args ...
- </pre>
- <p id="ch1Introduction_f0">
- or (equivalently and more classically):
- </p>
- <pre class="programlisting">
- some_command and its args ... <file
- </pre>
- <p id="ch1Introduction_f1">
- Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
- </p>
- <p id="ch1Introduction_f2">
- Amongst many, it is still considered safer to use
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
- </p>
- </div>
- <div class="section" title="9.1.3.zcat">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2711522">
- </a>
- 9.1.3.zcat
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_f3">
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- is a Unix program similar to
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- , that decompresses individual files and concatenates them to standard output. Traditionally
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- operated on files compressed by compress but today it is usually able to operate on
- <span class="emphasis">
- <em>
- gzip
- </em>
- </span>
- or even
- <span class="emphasis">
- <em>
- bzip2
- </em>
- </span>
- archives. On such systems, it is equivalent to
- <span class="emphasis">
- <em>
- gunzip -c
- </em>
- </span>
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_8">
+ realise the impact of coding style and readbility on quality,
</p>
- </div>
- </div>
- <div class="section" title="9.2.more">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2711556">
- </a>
- 9.2.more
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_f4">
- In computing,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
- </p>
- <div class="section" title="9.2.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2711575">
- </a>
- 9.2.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_f5">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ more [options] [file_name]
- </pre>
- <p id="ch1Introduction_f6">
- If no file name is provided,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- looks for input from stdin.
- </p>
- <p id="ch1Introduction_f7">
- Once
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has paged through. (This percentage includes the text displayed on the current screen.) When
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- , which advances the output by one line, and
- <span class="emphasis">
- <em>
- Space
- </em>
- </span>
- , which advances the output by one screen.
- </p>
- <p id="ch1Introduction_f8">
- There are also other commands that can be used while navigating through the document; consult
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- 's
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page for more details.
- </p>
- <p id="ch1Introduction_f9">
- <span class="emphasis">
- <em>
- Options
- </em>
- </span>
- are typically entered before the file name, but can also be entered in the environment variable
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- . Options entered in the actual command line will override those entered in the
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- environment variable. Available options may vary between Unix systems.
- </p>
- </div>
- </div>
- <div class="section" title="9.3.less">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2711666">
- </a>
- 9.3.less
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_fa">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- does not need to read the entire file before starting, resulting in faster load times with large files.
- </p>
- <div class="section" title="9.3.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2711695">
- </a>
- 9.3.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_fb">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- vi
- </em>
- </span>
- . It is also possible to search for character patterns in the file.
- </p>
- <p id="ch1Introduction_fc">
- By default,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
- </p>
- <p id="ch1Introduction_fd">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ less [options] file_name
- </pre>
- </div>
- <div class="section" title="9.3.2.Frequently Used Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2711749">
- </a>
- 9.3.2.Frequently Used Options
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_fe">
- -g: Highlights just the current match of any searched string.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_ff">
- -I: Case-insensitive searches.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_100">
- -M: Shows more detailed prompt, including file position.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_101">
- -N: Shows line numbers (useful for source code viewing).
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_102">
- -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_103">
- -?: Shows help.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.3.Frequently Used Commands">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2711800">
- </a>
- 9.3.3.Frequently Used Commands
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_104">
- [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_105">
- [Space bar]: Next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_106">
- b: Previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_107">
- ng: Jump to line number n. Default is the start of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_108">
- nG: Jump to line number n. Default is the end of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_109">
- /pattern: Search for pattern. Regular expressions can be used.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_10a">
- '^ or g: Go to start of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_10b">
- '$ or G: Go to end of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_10c">
- s: Save current content (got from another program like grep) in a file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_10d">
- =: File information.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_10e">
- h: Help.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_10f">
- q: Quit.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.4.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2711889">
- </a>
- 9.3.4.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ less -M readme.txt #Read "readme.txt."
-$ less +F /var/log/mail.log #Follow mode for log
-$ file * | less #Easier file analysis.
-$ grep -i void *.c | less -I -p void #Case insensitive search for "void" in all .c files
- </pre>
- </div>
- </div>
- </div>
- <div class="section" title="10.Directory Structure">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2711904">
- </a>
- 10.Directory Structure
- </h2>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_110">
- In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
- </p>
- <p id="ch1Introduction_111">
- The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
- </p>
- <table summary="Directory Structure" border="1">
- <colgroup>
- <col width="15">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <div class="section" title="10.1.man hier">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2712174">
- </a>
- 10.1.man hier
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_136">
- This is the manual page on the UNIX filesystem. The syntax for this is:
- </p>
- <pre class="programlisting">
- $ man hier
- </pre>
- </div>
- <div class="section" title="10.2.ls -l">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2712190">
- </a>
- 10.2.ls -l
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_137">
- Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
- </p>
- <pre class="programlisting">
- $ ls -l
- </pre>
- <p id="ch1Introduction_138">
- This can be done after entering the required directory.
- </p>
- </div>
- </div>
- <div class="section" title="11.Permissions and Ownership">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2712213">
- </a>
- 11.Permissions and Ownership
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="11.1.chmod">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2712221">
- </a>
- 11.1.chmod
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_139">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.
- </p>
- <div class="section" title="11.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2712247">
- </a>
- 11.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_13a">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command options are specified like this:
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_9">
+ write mid-sized programs that carry out typical engineering / numerical computations such as those that involve (basic) manipulation of large arrays in an efficient manner,
</p>
- <pre class="programlisting">
- $ chmod [options] mode[,mode] file1 [file2 ...]
- </pre>
- <p id="ch1Introduction_13b">
- To view what the permissions currently are, type:
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_a">
+ generate 2D and simple 3D plots,
</p>
- <pre class="programlisting">
- $ ls -l file
- </pre>
- </div>
- <div class="section" title="11.1.2.Command line options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2712275">
- </a>
- 11.1.2.Command line options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_13c">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command has a number of command line options that affect its behavior. The most common options are:
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_b">
+ debug programs using a standardised approach,
</p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_13d">
- -R: Changes the modes of directories and files recursively
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch1Introduction_13e">
- -v: Verbose mode; lists all files as they are being processed
- </p>
- </li>
- </ul>
- </div>
- <div class="section" title="11.1.2.1.Symbolic modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2712310">
- </a>
- 11.1.2.1.Symbolic modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_13f">
- To the
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
- </p>
- <pre class="programlisting">
- $ chmod [references][operator][modes] file1 ...
- </pre>
- <p id="ch1Introduction_140">
- The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="8">
- </col>
- <col width="45">
- </col>
- </colgroup>
- </table>
- <p id="ch1Introduction_150">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="54">
- </col>
- </colgroup>
- </table>
- <p id="ch1Introduction_157">
- The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="5">
- </col>
- <col width="14">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <p id="ch1Introduction_16d">
- The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
- </p>
- </div>
- <div class="section" title="11.1.2.2.Symbolic examples">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2708121">
- </a>
- 11.1.2.2.Symbolic examples
- </h5>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_16e">
- Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
- </p>
- <pre class="programlisting">
- $ chmod ug+rw mydir
-$ ls -ld mydir
-drw-rw---- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- <p id="ch1Introduction_16f">
- For a file, remove
- <span class="emphasis">
- <em>
- write
- </em>
- </span>
- permissions for all classes:
- </p>
- <pre class="programlisting">
- $ chmod a-w myfile
-$ ls -l myfile
--r-xr-xr-x 2 starwars yoda 96 Dec 8 12:53 myfile
- </pre>
- <p id="ch1Introduction_170">
- Set the permissions for the
- <span class="emphasis">
- <em>
- u*ser and the *g*roup to read and execute only (no write permission) on *mydir
- </em>
- </span>
- .
- </p>
- <pre class="programlisting">
- $ chmod ug=rx mydir
-$ ls -ld mydir
-dr-xr-x--- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- </div>
- <div class="section" title="11.1.2.3.Octal numbers">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2708163">
- </a>
- 11.1.2.3.Octal numbers
- </h5>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_171">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
- </p>
- <pre class="programlisting">
- $ chmod 664 myfile
-$ ls -l myfile
--rw-rw-r-- 1 57 Jul 3 10:13 myfile
- </pre>
- <p id="ch1Introduction_172">
- Since the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- sticky
- </em>
- </span>
- bits are not set, this is equivalent to:
- </p>
- <pre class="programlisting">
- $ chmod 0664 myfile
- </pre>
- </div>
- <div class="section" title="11.1.2.4.Special modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2708202">
- </a>
- 11.1.2.4.Special modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_173">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
- <span class="strong">
- <strong>
- s
- </strong>
- </span>
- to represent the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- modes, and
- <span class="strong">
- <strong>
- t
- </strong>
- </span>
- to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
- </p>
- <p id="ch1Introduction_174">
- Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
- </p>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="12.Redirection and Piping">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2713123">
- </a>
- 12.Redirection and Piping
- </h2>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_175">
- In computing,
- <span class="emphasis">
- <em>
- redirection
- </em>
- </span>
- is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
- </p>
- <p id="ch1Introduction_176">
- Programs do redirection with the
- <span class="emphasis">
- <em>
- dup2(2)
- </em>
- </span>
- system call, or its less-flexible but higher-level stdio analogues,
- <span class="emphasis">
- <em>
- freopen(3)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- popen(3)
- </em>
- </span>
- .
- </p>
- <div class="section" title="12.1.Redirecting standard input and standard output">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2713159">
- </a>
- 12.1.Redirecting standard input and standard output
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_177">
- Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
- </p>
- <pre class="programlisting">
- $ command1 > file1
- </pre>
- <p id="ch1Introduction_178">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , placing the output in file1. Note that this will truncate any existing data in
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- . To append output to the end of the file, use the >> operator.:
- </p>
- <pre class="programlisting">
- $ command1 < file1
- </pre>
- <p id="ch1Introduction_179">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- as the source of input (as opposed to the keyboard).:
- </p>
- <pre class="programlisting">
- $ command1 < infile > outfile
- </pre>
- <p id="ch1Introduction_17a">
- combines the two capabilities:
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- reads from
- <span class="emphasis">
- <em>
- infile
- </em>
- </span>
- and writes to
- <span class="emphasis">
- <em>
- outfile
- </em>
- </span>
- </p>
- </div>
- <div class="section" title="12.2.Piping">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2713228">
- </a>
- 12.2.Piping
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_17b">
- Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
-A pipeline of three programs run on a text terminal:
- </p>
- <pre class="programlisting">
- $ command1 | command2
- </pre>
- <p id="ch1Introduction_17c">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using its output as the input for
- <span class="emphasis">
- <em>
- command2
- </em>
- </span>
- (commonly called piping, since the "|" character is known as a "pipe").
- </p>
- <p id="ch1Introduction_17d">
- This is equivalent to using two redirects and a temporary file:
- </p>
- <pre class="programlisting">
- $ command1 > tempfile
-$ command2 < tempfile
-$ rm tempfile
- </pre>
- <p id="ch1Introduction_17e">
- A good example for command piping is combining
- <span class="emphasis">
- <em>
- echo
- </em>
- </span>
- with another command to achieve something interactive in a non-interactive shell, e.g.:
- </p>
- <pre class="programlisting">
- $ echo -e "user\npass" | ftp localhost
- </pre>
- <p id="ch1Introduction_17f">
- This runs the ftp client with input user, press return, then pass.
- </p>
- </div>
- <div class="section" title="12.3.Redirecting to and from the standard file handles">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2713289">
- </a>
- 12.3.Redirecting to and from the standard file handles
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_180">
- In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
- </p>
- <table summary="Redirecting to and from the standard file handles" border="1">
- <colgroup>
- <col width="12">
- </col>
- <col width="13">
- </col>
- <col width="24">
- </col>
- </colgroup>
- </table>
- <p id="ch1Introduction_18d">
- For example:
- </p>
- <pre class="programlisting">
- $ command1 2> file1
- </pre>
- <p id="ch1Introduction_18e">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , directing the standard error stream to
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- .
- </p>
- <p id="ch1Introduction_18f">
- In shells derived from
- <span class="emphasis">
- <em>
- csh
- </em>
- </span>
- (the C shell), the syntax instead appends the & character to the redirect characters, thus achieving a similar result.
- </p>
- <p id="ch1Introduction_190">
- Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
- </p>
- <pre class="programlisting">
- $ find / -name .profile > results 2>&1
- </pre>
- <p id="ch1Introduction_191">
- will try to find all files named
- <span class="emphasis">
- <em>
- .profile
- </em>
- </span>
- . Executed without redirection, it will output hits to
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- and errors (e.g. for lack of privilege to traverse protected directories) to
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- . If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- (handle 2) into
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- (handle 1) using 2>&1 .
- </p>
- <p id="ch1Introduction_192">
- It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
- </p>
- <p id="ch1Introduction_193">
- If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus:
- </p>
- <pre class="programlisting">
- $ find / -name .profile 2>&1 | less
- </pre>
- <p id="ch1Introduction_194">
- A simplified form of the command:
- </p>
- <pre class="programlisting">
- $ command > file 2>&1
- </pre>
- <p id="ch1Introduction_195">
- is:
- </p>
- <pre class="programlisting">
- $ command &>file
- </pre>
- <p id="ch1Introduction_196">
- or:
- </p>
- <pre class="programlisting">
- $command >&file
- </pre>
- </div>
- <div class="section" title="12.4.Chained pipelines">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2713494">
- </a>
- 12.4.Chained pipelines
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_197">
- The redirection and piping tokens can be chained together to create complex commands. For example:
- </p>
- <pre class="programlisting">
- $ ls | grep '\.sh' | sort > shlist
- </pre>
- <p id="ch1Introduction_198">
- lists the contents of the current directory, where this output is filtered to only contain lines which contain
- <span class="emphasis">
- <em>
- .sh
- </em>
- </span>
- , sort this resultant output lexicographically, and place the final output in
- <span class="emphasis">
- <em>
- shlist
- </em>
- </span>
- . This type of construction is used very commonly in shell scripts and batch files.
- </p>
- </div>
- <div class="section" title="12.5.Redirect to multiple outputs">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2713528">
- </a>
- 12.5.Redirect to multiple outputs
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_199">
- The standard command
- <span class="emphasis">
- <em>
- tee
- </em>
- </span>
- can redirect output from a command to several destinations.
- </p>
- <pre class="programlisting">
- $ ls -lrt | tee xyz
- </pre>
- <p id="ch1Introduction_19a">
- This directs the file list output to both standard output as well as to the file
- <span class="emphasis">
- <em>
- xyz
- </em>
- </span>
- .
- </p>
- </div>
- </div>
- <div class="section" title="13.More Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2713558">
- </a>
- 13.More Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="13.1.grep">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2713567">
- </a>
- 13.1.grep
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_19b">
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- is a command line text search utility originally written for Unix. The name is taken from the first letters in
- <span class="emphasis">
- <em>
- global / regular expression / print
- </em>
- </span>
- , a series of instructions for the
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- text editor. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
- </p>
- <div class="section" title="13.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2713598">
- </a>
- 13.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_19c">
- This is an example of a common
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- usage:
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_c">
+ understand the importance of tests and the philosophy of Test Driven Development,
</p>
- <pre class="programlisting">
- $ grep apple fruitlist.txt
- </pre>
- <p id="ch1Introduction_19d">
- In this case,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- prints all lines containing 'apple' from the file
- <span class="emphasis">
- <em>
- fruitlist.txt
- </em>
- </span>
- , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
- </p>
- <p id="ch1Introduction_19e">
- Like most Unix commands,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- accepts command line arguments to change this and many other behaviors. For example:
- </p>
- <pre class="programlisting">
- $ grep -i apple fruitlist.txt
- </pre>
- <p id="ch1Introduction_19f">
- This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be case insensitive, or to ignore case.
- </p>
- <p id="ch1Introduction_1a0">
- To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
- </p>
- <pre class="programlisting">
- $ grep -w apple fruitlist.txt
- </pre>
- <p id="ch1Introduction_1a1">
- Regular expressions can be used to match more complicated queries.
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch1Introduction_d">
+ write unit tests and improve the quality of code.
</p>
- <div class="section" title="13.1.1.1.Variations">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2713677">
- </a>
- 13.1.1.1.Variations
- </h5>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_1a2">
- There are countless implementations and derivatives of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- available for many operating systems. Early variants of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- included
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- . The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- may also behave differently depending on the name by which it is invoked, allowing
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be links to the same program.
- </p>
- <p id="ch1Introduction_1a3">
- <span class="emphasis">
- <em>
- pcregrep
- </em>
- </span>
- is an implementation of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- that uses Perl regular expression syntax.
- </p>
- <p id="ch1Introduction_1a4">
- Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
- <span class="emphasis">
- <em>
- pgrep
- </em>
- </span>
- utility, for instance, displays the processes whose names match a given regular expression.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="13.2.tr">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2713756">
- </a>
- 13.2.tr
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_1a5">
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- (abbreviated from
- <span class="emphasis">
- <em>
- translate
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- transliterate
- </em>
- </span>
- ) is a command in Unix-like operating systems.
- </p>
- <p id="ch1Introduction_1a6">
- When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
- </p>
- <pre class="programlisting">
- $ tr 'abcd' 'jkmn'
- </pre>
- <p id="ch1Introduction_1a7">
- maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
- </p>
- <p id="ch1Introduction_1a8">
- Sets of characters may be abbreviated by using character ranges. The previous example could be written:
- </p>
- <pre class="programlisting">
- $ tr 'a-d' 'jkmn'
- </pre>
- <p id="ch1Introduction_1a9">
- In POSIX compliant versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
- </p>
- <p id="ch1Introduction_1aa">
- The
- <span class="emphasis">
- <em>
- -c
- </em>
- </span>
- flag complements the first set of characters.
- </p>
- <pre class="programlisting">
- $ tr -cd '[:alnum:]'
- </pre>
- <p id="ch1Introduction_1ab">
- therefore removes all non-alphanumeric characters.
- </p>
- <p id="ch1Introduction_1ac">
- The
- <span class="emphasis">
- <em>
- -s
- </em>
- </span>
- flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
- </p>
- <pre class="programlisting">
- $ tr -s '\n' '\n'
- </pre>
- <p id="ch1Introduction_1ad">
- replaces sequences of one or more newline characters with a single newline.
- </p>
- <p id="ch1Introduction_1ae">
- The
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
- </p>
- <pre class="programlisting">
- $ tr -d '\r'
- </pre>
- <p id="ch1Introduction_1af">
- Most versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , including GNU
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- and classic Unix
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
- </p>
- <p id="ch1Introduction_1b0">
- Ruby and Perl also have an internal
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- operator, which operates analogously. Tcl's
- <span class="emphasis">
- <em>
- string map
- </em>
- </span>
- command is more general in that it maps strings to strings while
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- maps characters to characters.
- </p>
- </div>
- </div>
- <div class="section" title="14.Elementary Regex">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2713906">
- </a>
- 14.Elementary Regex
- </h2>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_1b1">
- In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
- </p>
- <p id="ch1Introduction_1b2">
- Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributionsincluding the editor
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- and the filter
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- were the first to popularize the concept of regular expressions.
- </p>
- <p id="ch1Introduction_1b3">
- Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
- <span class="emphasis">
- <em>
- Basic Regular Expressions
- </em>
- </span>
- (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
- </p>
- <p id="ch1Introduction_1b4">
- In the BRE syntax, most characters are treated as literals they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
- </p>
- <table summary="Elementary Regex" border="1">
- <colgroup>
- <col width="13">
- </col>
- <col width="60">
- </col>
- </colgroup>
- </table>
- <div class="section" title="14.1.Lazy quantification">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2714115">
- </a>
- 14.1.Lazy quantification
- </h3>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_1c9">
- The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example:
- </p>
- <pre class="programlisting">
- Another whale explosion occurred on <January 26>, <2004>.
- </pre>
- <p id="ch1Introduction_1ca">
- ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the * quantifier is greedy it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
- </p>
- <p id="ch1Introduction_1cb">
- Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as
- <span class="emphasis">
- <em>
- lazy
- </em>
- </span>
- (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
- </p>
- </div>
- </div>
- <div class="section" title="15.One Liners">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2714191">
- </a>
- 15.One Liners
- </h2>
- </div>
- </div>
- </div>
- <p id="ch1Introduction_1cc">
- A
- <span class="emphasis">
- <em>
- one-liner
- </em>
- </span>
- is textual input to the command-line of an operating system shell that performs some function in just one line of input.
- </p>
- <p id="ch1Introduction_1cd">
- The one liner can be
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch1Introduction_1ce">
- An expression written in the language of the shell.
- </p>
- </li>
- <li class="listitem">
- <p id="ch1Introduction_1cf">
- The invocation of an interpreter together with program source for the interpreter to run.
- </p>
- </li>
- <li class="listitem">
- <p id="ch1Introduction_1d0">
- The invocation of a compiler together with source to compile and
-instructions for executing the compiled program.
- </p>
- </li>
- </ol>
- </div>
- <p id="ch1Introduction_1d1">
- Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
- </p>
- <p id="ch1Introduction_1d2">
- The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
- </p>
- <p id="ch1Introduction_1d3">
- The word
- <span class="emphasis">
- <em>
- One-liner
- </em>
- </span>
- has two references in the index of the book
- <span class="emphasis">
- <em>
- The AWK Programming Language
- </em>
- </span>
- (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
- </p>
- <pre class="programlisting">
- The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.
- </pre>
- <p id="ch1Introduction_1d4">
- Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
- </p>
- <p id="ch1Introduction_1d5">
- The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
- </p>
- <p id="ch1Introduction_1d6">
- Here are the first few of them:
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch1Introduction_1d7">
- Print the total number of input lines:
- </p>
- <p id="ch1Introduction_1d8">
- END { print NR }
- </p>
- </li>
- <li class="listitem">
- <p id="ch1Introduction_1d9">
- Print the tenth input line:
- </p>
- <p id="ch1Introduction_1da">
- NR == 10
- </p>
- </li>
- <li class="listitem">
- <p id="ch1Introduction_1db">
- Print the last field of every input line:
- </p>
- <p id="ch1Introduction_1dc">
- { print $NF }
- </p>
- </li>
- </ol>
- </div>
- <p id="ch1Introduction_1dd">
- One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
- </p>
- <p id="ch1Introduction_1de">
- The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:
- </p>
- <pre class="programlisting">
- main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
-*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
- </pre>
- <p id="ch1Introduction_1df">
- This one-liner program is a
- <span class="emphasis">
- <em>
- glob pattern matcher
- </em>
- </span>
- . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
- </p>
- <p id="ch1Introduction_1e0">
- Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:
- </p>
- <pre class="programlisting">
- $ prog foo 'f??'; echo $?
-
-$ prog 'best short program' '??st*o**p?*'; echo $?
- </pre>
- <p id="ch1Introduction_1e1">
- Here is a one line shell script to show directories:
- </p>
- <pre class="programlisting">
- $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
- </pre>
+ </li>
+ </ul>
</div>
</div>
</div>
--- a/SEESenv/web/html/ch2intro.html Mon Feb 22 18:46:07 2010 +0530
+++ b/SEESenv/web/html/ch2intro.html Mon Feb 22 22:38:51 2010 +0530
@@ -1,5 +1,5 @@
<html>
- <head>
+<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Chapter. intro
@@ -14,5242 +14,624 @@
<script type="text/javascript" src="/review/support/hsbook.js">
</script>
</head>
- <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
- <div class="chapter" id="ch2intro">
- <div class="titlepage">
- </div>
- <div class="toc">
- <p>
- <b>
- Table of Contents
- </b>
- </p>
- <dl>
- <dt>
- <span class="article">
- <a href="#id2781973">
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2592098">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2779792">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2833032">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2833297">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2833423">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2833432">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2833704">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2833712">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2833868">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2833926">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834021">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834101">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2834262">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2834270">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834353">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834539">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834625">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2834678">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2834687">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834996">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835142">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2835308">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835401">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2835409">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835497">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835624">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835710">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2835844">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835957">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2835965">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2836153">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2836267">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2836505">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2836775">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2836791">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2836814">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2836823">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2837587">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2837624">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2837693">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2837754">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2837959">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2837993">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2838023">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2838032">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2838221">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2838370">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2838588">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2838664">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- </dl>
- </div>
- <div class="article">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" id="id2781973">
- </h2>
- </div>
- </div>
- <hr />
- </div>
- <div class="toc">
- <p>
- <b>
- Table of Contents
- </b>
- </p>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2592098">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2779792">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2833032">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2833297">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2833423">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2833432">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2833704">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2833712">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2833868">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2833926">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834021">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834101">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2834262">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2834270">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834353">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834539">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834625">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2834678">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2834687">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2834996">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835142">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2835308">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835401">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2835409">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835497">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835624">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835710">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2835844">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2835957">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2835965">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2836153">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2836267">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2836505">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2836775">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2836791">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2836814">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2836823">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2837587">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2837624">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2837693">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2837754">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2837959">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2837993">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2838023">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2838032">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2838221">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2838370">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2838588">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2838664">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </div>
- <div class="section" title="1.Introducing Linux">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2592098">
- </a>
- 1.Introducing Linux
- </h2>
- </div>
- </div>
- </div>
- <p id="ch2intro_1">
- (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
- </p>
- <p id="ch2intro_2">
- Linux (usually pronounced lnks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
- </p>
- <p id="ch2intro_3">
- Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
- </p>
- <p id="ch2intro_4">
- The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
- </p>
- <div class="section" title="1.1.Historical Background">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2779792">
- </a>
- 1.1.Historical Background
- </h3>
- </div>
- </div>
- </div>
- <div class="section" title="1.1.1.Events leading to the creation">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2779666">
- </a>
- 1.1.1.Events leading to the creation
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_5">
- The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_6">
- In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="1.1.2.The Creation of Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2832987">
- </a>
- 1.1.2.The Creation of Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_7">
- In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
- </p>
- <p id="ch2intro_8">
- Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
- </p>
- </div>
- </div>
- <div class="section" title="1.2.Design and Implications">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2833032">
- </a>
- 1.2.Design and Implications
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_9">
- A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
- </p>
- <div class="section" title="1.2.1.User Interface">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2833056">
- </a>
- 1.2.1.User Interface
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_a">
- Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
- </p>
- <p id="ch2intro_b">
- A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
- </p>
- </div>
- <div class="section" title="1.2.2.Development">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2833108">
- </a>
- 1.2.2.Development
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_c">
- The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
- </p>
- <p id="ch2intro_d">
- Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
- </p>
- <p id="ch2intro_e">
- A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
- </p>
- </div>
- <div class="section" title="1.2.3.Community">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2833164">
- </a>
- 1.2.3.Community
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_f">
- A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
- </p>
- <p id="ch2intro_10">
- In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
- </p>
- <p id="ch2intro_11">
- Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
- </p>
- </div>
- <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2833207">
- </a>
- 1.2.4.Can I make a profit out of running a business involving Linux?
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_12">
- The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
- </p>
- </div>
- <div class="section" title="1.2.5.Programming on Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2833252">
- </a>
- 1.2.5.Programming on Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_13">
- Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
- </p>
- <p id="ch2intro_14">
- Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
- </p>
- <p id="ch2intro_15">
- The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
- </p>
- </div>
- </div>
- <div class="section" title="1.3.Reasons for Using Linux">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2833297">
- </a>
- 1.3.Reasons for Using Linux
- </h3>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_16">
- Linux is free:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_17">
- As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
-Most of all, Linux is free as in "free speech":
-The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_18">
- Linux is portable to any hardware platform:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_19">
- A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_1a">
- Linux was made to keep on running:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_1b">
- As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_1c">
- Linux is secure and versatile:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_1d">
- The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_1e">
- Linux is scalable:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_1f">
- From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_20">
- The Linux OS and Linux applications have very short debugtimes:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_21">
- Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
- </p>
- </div>
- </div>
- <div class="section" title="2.Getting Started">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2833423">
- </a>
- 2.Getting Started
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="2.1.Logging in, activating the user interface and logging out">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2833432">
- </a>
- 2.1.Logging in, activating the user interface and logging out
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_22">
- In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PCbased Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multiuser features, or in graphical console mode, which looks better but eats more system resources.
- </p>
- <div class="section" title="2.1.1.Graphical Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2833462">
- </a>
- 2.1.1.Graphical Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_23">
- This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
- </p>
- <p id="ch2intro_24">
- To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
- <span class="emphasis">
- <em>
- OK
- </em>
- </span>
- or press
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- .
-It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
- </p>
- <p id="ch2intro_25">
- After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
- </p>
- <p id="ch2intro_26">
- To continue, you will need to open a
- <span class="emphasis">
- <em>
- terminal window
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
- <span class="emphasis">
- <em>
- Applications>Utilities->System Tools
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- Internet menu
- </em>
- </span>
- , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
- </p>
- <p id="ch2intro_27">
- While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old pointnclick method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
- </p>
- <p id="ch2intro_28">
- A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
- </p>
- <p id="ch2intro_29">
- Another common form for a prompt is this one:
-[
- </p>
- <div class="reference">
- <div class="titlepage">
- <hr />
- </div>
- user@host
- </div>
- <p>
- dir]
- </p>
- <p id="ch2intro_2a">
- In the above example,
- <span class="emphasis">
- <em>
- user
- </em>
- </span>
- will be your login name,
- <span class="emphasis">
- <em>
- hosts
- </em>
- </span>
- the name of the machine you are working on, and
- <span class="emphasis">
- <em>
- dir
- </em>
- </span>
- an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- icon or find
- <span class="emphasis">
- <em>
- Log Out
- </em>
- </span>
- in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
- </p>
- <p id="ch2intro_2b">
- When you see the login screen again, asking to enter user name and password, logout was successful.
- </p>
- </div>
- <div class="section" title="2.1.2.Text Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2833616">
- </a>
- 2.1.2.Text Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_2c">
- One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
- </p>
- <p id="ch2intro_2d">
- The login is different from a graphical login, in that you have to hit the
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- . You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
-reasons.
- </p>
- <p id="ch2intro_2e">
- When the system has accepted you as a valid user, you may get some more information, called the
- <span class="emphasis">
- <em>
- message of the day
- </em>
- </span>
- , which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
- </p>
- <p id="ch2intro_2f">
- Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a nonprivileged user.
- </p>
- <p id="ch2intro_30">
- Logging out is done by entering the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't poweroff the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="3.Basic Commands">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2833704">
- </a>
- 3.Basic Commands
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="3.1.ls">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2833712">
- </a>
- 3.1.ls
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_31">
- When invoked without any arguments,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- is derived from
- <span class="emphasis">
- <em>
- list segments
- </em>
- </span>
- which was used in earlier systems.
- </p>
- <p id="ch2intro_32">
- Files whose names start with "." are not listed, unless the
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- flag is specified or the files are specified explicitly.
- </p>
- <p id="ch2intro_33">
- Without options,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_34">
- <span class="emphasis">
- <em>
- -l
- </em>
- </span>
- long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_35">
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_36">
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_37">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- recursively lists subdirectories. The command ls -R / would therefore list all files.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_38">
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_39">
- <span class="emphasis">
- <em>
- -t
- </em>
- </span>
- sort the list of files by modification time.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_3a">
- <span class="emphasis">
- <em>
- -h
- </em>
- </span>
- print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_3b">
- In some environments, providing the option
- <span class="emphasis">
- <em>
- --color
- </em>
- </span>
- (for GNU ls) or
- <span class="emphasis">
- <em>
- -G
- </em>
- </span>
- (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- would. To determine what color to use for a file, GNU
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks the Unix file type, the file permissions, and the file extension, while FreeBSD
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks only the Unix file type and file permissions.:
- </p>
- <pre class="programlisting">
- $ ls
-jeeves.rst psmith.html blandings.html
-$ ls -l
-drwxr--r-- 1 plum editors 4096 jeeves
--rw-r--r-- 1 plum editors 30405 psmith
--r-xr-xr-x 1 plum plum 8460 blandings
- </pre>
- <p id="ch2intro_3c">
- Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
- </p>
- </div>
- <div class="section" title="3.2.date">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2833868">
- </a>
- 3.2.date
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_3d">
- The Unix date command displays the time and date. The super-user can use it to set the system clock.
- </p>
- <p id="ch2intro_3e">
- With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:
- </p>
- <pre class="programlisting">
- $date
-Tue Sep 8 12:01:45 IST 2009
- </pre>
- <p id="ch2intro_3f">
- On some systems to set the current date and time to September 8, 2004 01:22 you type:
- </p>
- <pre class="programlisting">
- $date --set="20040908 01:22"
- </pre>
- <p id="ch2intro_40">
- In order to view the various options for the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command, type:
- </p>
- <pre class="programlisting">
- $man date
- </pre>
- <p id="ch2intro_41">
- This will take you to the "Manual" page comprising of all the details on the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command. You can return to the terminal from the "man" page by pressing the
- <span class="emphasis">
- <em>
- Esc
- </em>
- </span>
- key in the keyboard and typing ":q" in that order.
- </p>
- </div>
- <div class="section" title="3.3.cd">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2833926">
- </a>
- 3.3.cd
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_42">
- This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, cd .. can be used.
- </p>
- <p id="ch2intro_43">
- One dot '.' represents the current directory while two dots '..' represent the parent directory.
- </p>
- <p id="ch2intro_44">
- cd - will return you to the previous directory (a bit like an undo).
- </p>
- <p id="ch2intro_45">
- You can also use cd absolute path or cd relative path (see below):
- </p>
- <p id="ch2intro_46">
- Absolute paths:
- </p>
- <p id="ch2intro_47">
- An absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
- </p>
- <p id="ch2intro_48">
- For example to get to /boot/grub you would type:
- </p>
- <pre class="programlisting">
- $cd /boot/grub
- </pre>
- <p id="ch2intro_49">
- This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
- </p>
- <p id="ch2intro_4a">
- Relative paths:
- </p>
- <p id="ch2intro_4b">
- A relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
- </p>
- <p id="ch2intro_4c">
- For example if you are in root's home directory and want to get to /root/music, you type:
- </p>
- <pre class="programlisting">
- $ cd music
- </pre>
- <p id="ch2intro_4d">
- Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
- </p>
- </div>
- <div class="section" title="3.4.who">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2834021">
- </a>
- 3.4.who
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_4e">
- The standard Unix command
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- displays a list of users who are currently logged into a computer.
- </p>
- <p id="ch2intro_4f">
- The
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command is related to the command
- <span class="emphasis">
- <em>
- w
- </em>
- </span>
- , which provides the same information but also displays additional data and statistics.:
- </p>
- <pre class="programlisting">
- $who
-beeblebrox tty7 2009-09-08 10:50 (:0)
-beeblebrox pts/0 2009-09-08 11:25 (:0.0)
-dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in)
-beeblebrox pts/2 2009-09-08 18:53 (:0.0)
- </pre>
- <p id="ch2intro_50">
- The command can be invoked with the arguments
- <span class="emphasis">
- <em>
- am i
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- am I
- </em>
- </span>
- (so it is invoked as
- <span class="emphasis">
- <em>
- who am i
- </em>
- </span>
- or * who am I*), showing information about the current terminal only (see the
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- option below, of which this invocation is equivalent).
- </p>
- <p id="ch2intro_51">
- In order to find out the various options that can be appended to the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command, check the
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page by typing out the following in the terminal:
- </p>
- <pre class="programlisting">
- $man who
- </pre>
- <p id="ch2intro_52">
- This will take you to the "Manual" page containing details about the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command
- </p>
- </div>
- <div class="section" title="3.5.mkdir">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2834101">
- </a>
- 3.5.mkdir
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_53">
- This command is used to make a new directory. Normal usage is as straightforward as follows:
- </p>
- <pre class="programlisting">
- $mkdir name_of_directory
- </pre>
- <p id="ch2intro_54">
- Where
- <span class="emphasis">
- <em>
- name_of_directory
- </em>
- </span>
- is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- will try to create all of them.
- </p>
- <div class="section" title="3.5.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2834132">
- </a>
- 3.5.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_55">
- On Unix-like operating systems,
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- takes options. Three of the most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_56">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- : will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_57">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- : display each directory that mkdir creates. Most often used with -p.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_58">
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- : specify the octal permissions of directories created by mkdir.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_59">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
- </p>
- </div>
- <div class="section" title="3.5.2.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2834189">
- </a>
- 3.5.2.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_5a">
- An example of
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- in action is:
- </p>
- <pre class="programlisting">
- $mkdir -p /tmp/a/b/c
- </pre>
- <p id="ch2intro_5b">
- If
- <span class="emphasis">
- <em>
- /tmp/a
- </em>
- </span>
- exists but
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- does not, mkdir will create
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- before creating
- <span class="emphasis">
- <em>
- /tmp/a/b/c
- </em>
- </span>
- .
- </p>
- <p id="ch2intro_5c">
- And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
- </p>
- <pre class="programlisting">
- $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
- </pre>
- <p id="ch2intro_5d">
- This will create:
- </p>
- tmpdir - branches
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_5e">
- tag
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- trunk - sources - includes
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_5f">
- docs
- </p>
- </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="4.Getting Help">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2834262">
- </a>
- 4.Getting Help
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="4.1.apropos and whatis">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2834270">
- </a>
- 4.1.apropos and whatis
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_60">
- This is a command to search the manual pages files in Unix and Unix-like operating systems.
- </p>
- <pre class="programlisting">
- $ apropos grep
-egrep egrep (1) Search a file for a pattern using full regular expressions
-fgrep fgrep (1) Search a file for a fixed-character string
-fmlgrep fmlgrep (1) Search a file for a pattern
-grep grep (1) Search a file for a pattern
-gzgrep gzgrep (1) Search a possibly compressed file for a regular expression
-nisgrep nismatch (1) Utilities for searching NIS+ tables
-pgrep pgrep (1) Find or signal a process by name or other attribute
-zgrep zgrep (1) Search a possibly compressed file for a regular expression
-...
- </pre>
- <p id="ch2intro_61">
- In this example, the user uses
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- to search for the string "grep", and apropos returns the indicated
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- pages that include the term "grep".
- </p>
- <p id="ch2intro_62">
- A short index of explanations for commands is available using the
- <span class="emphasis">
- <em>
- whatis
- </em>
- </span>
- command, like in the examples below:
- </p>
- <pre class="programlisting">
- $whatis ls
-ls (1) - list directory contents
- </pre>
- <p id="ch2intro_63">
- This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
- </p>
- <p id="ch2intro_64">
- If you don't know where to get started and which man page to read,
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- gives more information. Say that you do not know how to start a browser, then you could enter the following command:
- </p>
- <pre class="programlisting">
- $apropos browser
-gmusicbrowser (1) - Jukebox for large collections of audio files
-infobrowser (1) - read Info documents
-libsmbclient (7) - An extension library for browsers and that can be used...
-opera (1) - a standards-compliant graphical Web browser
-sensible-browser (1) - sensible editing, paging, and web browsing
-smbtree (1) - A text based smb network browser
-tvtk_doc (1) - A GUI based TVTK documentation search browser.
-viewres (1) - graphical class browser for Xt
-w3m (1) - a text based Web browser and pager
-www-browser (1) - a text based Web browser and pager
-...
- </pre>
- </div>
- <div class="section" title="4.2.man">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2834353">
- </a>
- 4.2.man
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_65">
- Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- . Each page is a self-contained document.
- </p>
- <p id="ch2intro_66">
- To read a manual page for a Unix command, one can use:
- </p>
- <pre class="programlisting">
- $ man <command_name>
- </pre>
- <p id="ch2intro_67">
- at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- generally uses the less terminal pager.
- </p>
- <p id="ch2intro_68">
- Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are
- <span class="emphasis">
- <em>
- man(1)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- man(7)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- exit(2)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- exit(3)
- </em>
- </span>
- . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
- <span class="emphasis">
- <em>
- BSD, for example, the syntax for reading *printf(3)
- </em>
- </span>
- is:
- </p>
- <pre class="programlisting">
- $man 3 printf
- </pre>
- <p id="ch2intro_69">
- Another example:
- </p>
- <pre class="programlisting">
- $man man
- </pre>
- <p id="ch2intro_6a">
- The previous example will take you to the "Manual" page entry about manual pages!
- </p>
- <div class="section" title="4.2.1.Layout">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2834432">
- </a>
- 4.2.1.Layout
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_6b">
- All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
- </p>
- NAME
- <p id="ch2intro_6c">
- The name of the command or function, followed by a one-line description of what it does.
- </p>
- SYNOPSIS
- <p id="ch2intro_6d">
- In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
- </p>
- DESCRIPTION
- <p id="ch2intro_6e">
- A textual description of the functioning of the command or function.
- </p>
- EXAMPLES
- <p id="ch2intro_6f">
- Some examples of common usage.
- </p>
- SEE ALSO
- <p id="ch2intro_70">
- A list of related commands or functions.
- </p>
- <p id="ch2intro_71">
- Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
- </p>
- <p id="ch2intro_72">
- These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
- </p>
- <p id="ch2intro_73">
- However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
- </p>
- <p id="ch2intro_74">
- Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
- </p>
- <p id="ch2intro_75">
- Usually the man pages are written in English. Translations into other languages can be also available on the system.
- </p>
- <p id="ch2intro_76">
- The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
- </p>
- </div>
- </div>
- <div class="section" title="4.3.info">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2834539">
- </a>
- 4.3.info
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_77">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
- </p>
- <p id="ch2intro_78">
- The syntax is
- </p>
- <pre class="programlisting">
- $ info <command_name>
- </pre>
- <p id="ch2intro_79">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_7a">
- <span class="emphasis">
- <em>
- n
- </em>
- </span>
- goes to the next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_7b">
- <span class="emphasis">
- <em>
- p
- </em>
- </span>
- goes to the previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_7c">
- <span class="emphasis">
- <em>
- u
- </em>
- </span>
- goes to the upper page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_7d">
- <span class="emphasis">
- <em>
- l
- </em>
- </span>
- goes to the last(visited) node
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_7e">
- To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_7f">
- info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
- </p>
- </div>
- <div class="section" title="4.4.--help">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2834625">
- </a>
- 4.4.--help
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_80">
- Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command:
- </p>
- <pre class="programlisting">
- $ userprompt@host: cat --help
-Usage: cat [OPTION] [FILE]...
-Concatenate FILE(s), or standard input, to standard output.
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="chapter" title="Chapter 1. ">
+<div class="titlepage"></div>
+<div class="toc">
+<p><b>Table of Contents</b></p>
+<dl>
+<dt><span class="article"><a href="#id2580245">Basic Python</a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="#id2388008">1. Introduction</a></span></dt>
+<dt><span class="section"><a href="#id2631374">2. The Python Interpreter</a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="#id2631383">2.1. The Interactive Interpreter</a></span></dt>
+<dt><span class="section"><a href="#id2631556">2.2. <span class="emphasis"><em>ipython</em></span> - An enhanced interactive Python interpreter</a></span></dt>
+</dl></dd>
+<dt><span class="section"><a href="#id2631681">3. Editing and running a python file</a></span></dt>
+<dt><span class="section"><a href="#id2631788">4. Basic Datatypes and operators in Python</a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="#id2631822">4.1. Numbers</a></span></dt>
+<dt><span class="section"><a href="#id2631952">4.2. Variables</a></span></dt>
+<dt><span class="section"><a href="#id2632000">4.3. Strings</a></span></dt>
+<dt><span class="section"><a href="#id2632194">4.4. Boolean</a></span></dt>
+</dl></dd>
+<dt><span class="section"><a href="#id2632223">5. The <span class="strong"><strong>while</strong></span> loop</a></span></dt>
+<dt><span class="section"><a href="#id2632260">6. The <span class="strong"><strong>if</strong></span> conditional</a></span></dt>
+<dt><span class="section"><a href="#id2632330">7. <span class="strong"><strong>raw_input()</strong></span></a></span></dt>
+<dt><span class="section"><a href="#id2632484">8. <span class="strong"><strong>int()</strong></span> method</a></span></dt>
+</dl></dd>
+</dl>
+</div>
+<div class="article" title="Basic Python">
+<div class="titlepage">
+<div><div><h2 class="title">
+<a name="id2580245"></a>Basic Python</h2></div></div>
+<hr>
+</div>
+<div class="toc">
+<p><b>Table of Contents</b></p>
+<dl>
+<dt><span class="section"><a href="#id2388008">1. Introduction</a></span></dt>
+<dt><span class="section"><a href="#id2631374">2. The Python Interpreter</a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="#id2631383">2.1. The Interactive Interpreter</a></span></dt>
+<dt><span class="section"><a href="#id2631556">2.2. <span class="emphasis"><em>ipython</em></span> - An enhanced interactive Python interpreter</a></span></dt>
+</dl></dd>
+<dt><span class="section"><a href="#id2631681">3. Editing and running a python file</a></span></dt>
+<dt><span class="section"><a href="#id2631788">4. Basic Datatypes and operators in Python</a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="#id2631822">4.1. Numbers</a></span></dt>
+<dt><span class="section"><a href="#id2631952">4.2. Variables</a></span></dt>
+<dt><span class="section"><a href="#id2632000">4.3. Strings</a></span></dt>
+<dt><span class="section"><a href="#id2632194">4.4. Boolean</a></span></dt>
+</dl></dd>
+<dt><span class="section"><a href="#id2632223">5. The <span class="strong"><strong>while</strong></span> loop</a></span></dt>
+<dt><span class="section"><a href="#id2632260">6. The <span class="strong"><strong>if</strong></span> conditional</a></span></dt>
+<dt><span class="section"><a href="#id2632330">7. <span class="strong"><strong>raw_input()</strong></span></a></span></dt>
+<dt><span class="section"><a href="#id2632484">8. <span class="strong"><strong>int()</strong></span> method</a></span></dt>
+</dl>
+</div>
+<p><a name="ch2intro_1"></a>This document is intended to be handed out at the end of the workshop. It has
+been designed for Engineering students who are Python beginners and have basic
+programming skills. The focus is on basic numerics and plotting using Python.</p>The system requirements:<div class="itemizedlist"><ul class="itemizedlist" type="*">
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_2"></a>Python - version 2.5.x or newer.</p></li>
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_3"></a>IPython</p></li>
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_4"></a>Text editor - scite, vim, emacs or whatever you are comfortable with.</p></li>
+</ul></div>
+<div class="section" title="1. Introduction">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="id2388008"></a>1. Introduction</h2></div></div></div>
+<p><a name="ch2intro_5"></a>The Python programming language was created by a dutch named Guido van Rossum.
+The idea of Python was conceived in December 1989. The name Python has nothing
+to do with the reptilian, but its been named after the 70s comedy series
+"Monty Python's Flying Circus", since it happens to be Guido's favourite
+TV series.</p>
+<p><a name="ch2intro_6"></a>Current stable version of Python is 2.6.x, although Python 3.0 is also the stable
+version, it is not backwards compatible with the previous versions and is hence
+not entirely popular at the moment. This material will focus on the 2.6.x series.</p>
+<p><a name="ch2intro_7"></a>Python is licensed under the Python Software Foundation License (PSF License)
+which is GPL compatible Free Software license (excepting license version 1.6 and 2.0)
+It is a no strings attached license, which means the source code is free to modify
+and redistribute.</p>
+<p><a name="ch2intro_8"></a>The Python docs define Python as "Python is an interpreted, object-oriented,
+high-level programming language with dynamic semantics." A more detailed summary
+can be found at </p>
+<div class="reference">
+<div class="titlepage"><hr></div>http://www.python.org/doc/essays/blurb.html</div>
+<p>. Python is a language that
+has been designed to help the programmer concentrate on solving the problem at hand
+and not worry about the programming language idiosyncrasies.</p>
+<p><a name="ch2intro_9"></a>Python is a highly cross platform compatible language on account of it being an
+interpreted language. It is highly scalable and hence has been adapted to run on
+the Nokia 60 series phones. Python has been designed to be readable and easy to use</p>
+<p><a name="ch2intro_a"></a><span class="strong"><strong>Resources available for reference</strong></span></p>
+<div class="itemizedlist"><ul class="itemizedlist" type="*">
+<li class="listitem" style="list-style-type: *">
+<p><a name="ch2intro_b"></a>Web: </p>
+<div class="reference">
+<div class="titlepage"><hr></div>http://www.python.org</div>
+</li>
+<li class="listitem" style="list-style-type: *">
+<p><a name="ch2intro_c"></a>Doc: </p>
+<div class="reference">
+<div class="titlepage"><hr></div>http://www.python.org/doc</div>
+</li>
+<li class="listitem" style="list-style-type: *">Free Tutorials:<div class="itemizedlist"><ul class="itemizedlist" type="*">
+<li class="listitem" style="list-style-type: *">
+<p><a name="ch2intro_d"></a>Official Python Tutorial: </p>
+<div class="reference">
+<div class="titlepage"><hr></div>http://docs.python.org/tut/tut.html</div>
+</li>
+<li class="listitem" style="list-style-type: *">
+<p><a name="ch2intro_e"></a>Byte of Python: </p>
+<div class="reference">
+<div class="titlepage"><hr></div>http://www.byteofpython.info/</div>
+</li>
+<li class="listitem" style="list-style-type: *">
+<p><a name="ch2intro_f"></a>Dive into Python: </p>
+<div class="reference">
+<div class="titlepage"><hr></div>http://diveintopython.org/</div>
+</li>
+</ul></div>
+</li>
+</ul></div>
+<p><a name="ch2intro_10"></a><span class="strong"><strong>Advantages of Python - Why Python??</strong></span></p>
+<div class="itemizedlist"><ul class="itemizedlist" type="*">
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_11"></a>Python has been designed for readability and ease of use. Its been designed in
+such a fashion that it imposes readability on the programmer. Python does away
+with the braces and the semicolons and instead implements code blocks based on
+indentation, thus enhancing readability.</p></li>
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_12"></a>Python is a high level, interpreted, modular and object oriented language.
+Python performs memory management on its own, thus the programmer need not bother
+about allocating and deallocating memory to variables. Python provides extensibility
+by providing modules which can be easily imported similar to headers in C and
+packages in Java. Python is object oriented and hence provides all the object oriented
+characteristics such as inheritance, encapsulation and polymorphism.</p></li>
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_13"></a>Python offers a highly powerful interactive programming interface in the form
+of the 'Interactive Interpreter' which will be discussed in more detail in the
+following sections.</p></li>
+<li class="listitem" style="list-style-type: *">
+<p><a name="ch2intro_14"></a>Python provides a rich standard library and an extensive set of modules. The
+power of Python modules can be seen in this slightly exaggerated cartoon
+</p>
+<div class="reference">
+<div class="titlepage"><hr></div>http://xkcd.com/353/</div>
+</li>
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_15"></a>Python interfaces well with most other programming languages such as C, C++
+and FORTRAN.</p></li>
+</ul></div>
+<p><a name="ch2intro_16"></a>Although, Python has one setback. Python is not fast as some of the compiled
+languages like C or C++. Yet, the amount of flexibility and power more than make
+up for this setback.</p>
+</div>
+<div class="section" title="2. The Python Interpreter">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="id2631374"></a>2. The Python Interpreter</h2></div></div></div>
+<div class="section" title="2.1. The Interactive Interpreter">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id2631383"></a>2.1. The Interactive Interpreter</h3></div></div></div>
+<p><a name="ch2intro_17"></a>Typing <span class="emphasis"><em>python</em></span> at the shell prompt on any standard Unix/Gnu-Linux system and
+hitting the enter key fires up the Python 'Interactive Interpreter'. The Python
+interpreter is one of the most integral features of Python. The prompt obtained
+when the interactive interpreter is similar to what is shown below. The exact
+appearance might differ based on the version of Python being used. The <code class="literal">>>></code>
+thing shown is the python prompt. When something is typed at the prompt and the
+enter key is hit, the python interpreter interprets the command entered and
+performs the appropriate action. All the examples presented in this document are
+to be tried hands on, on the interactive interpreter.</p>
+<pre class="programlisting">Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
+[GCC 4.3.2] on linux2
+Type "help", "copyright", "credits" or "license" for more information.
+>>></pre>
+<p><a name="ch2intro_18"></a>Lets try with an example, type <code class="literal">print 'Hello, World!'</code> at the prompt and hit
+the enter key.</p>
+<pre class="programlisting">>>> print 'Hello, World!'
+Hello, World!</pre>
+<p><a name="ch2intro_19"></a>This example was quite straight forward, and thus we have written our first
+line of Python code. Now let us try typing something arbitrary at the prompt.
+For example:</p>
+<pre class="programlisting">>>> arbit word
+ File "<stdin>", line 1
+ arbit word
+ ^
+SyntaxError: invalid syntax
+>>></pre>
+<p><a name="ch2intro_1a"></a>The interpreter gave an error message saying that 'arbit word' was invalid
+syntax which is valid. The interpreter is an amazing tool when learning to
+program in Python. The interpreter provides a help function that provides the
+necessary documentation regarding all Python syntax, constructs, modules and
+objects. Typing <span class="emphasis"><em>help()</em></span> at the prompt gives the following output:</p>
+<pre class="programlisting">>>> help()
- -A, --show-all equivalent to -vET
- -b, --number-nonblank number nonempty output lines
- -e equivalent to -vE
- -E, --show-ends display $ at end of each line
- -n, --number number all output lines
- -s, --squeeze-blank suppress repeated empty output lines
- -t equivalent to -vT
- -T, --show-tabs display TAB characters as ^I
- -u (ignored)
- -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
- --help display this help and exit
- --version output version information and exit
+Welcome to Python 2.5! This is the online help utility.
+
+If this is your first time using Python, you should definitely check out
+the tutorial on the Internet at http://www.python.org/doc/tut/.
+
+Enter the name of any module, keyword, or topic to get help on writing
+Python programs and using Python modules. To quit this help utility and
+return to the interpreter, just type "quit".
+
+To get a list of available modules, keywords, or topics, type "modules",
+"keywords", or "topics". Each module also comes with a one-line summary
+of what it does; to list the modules whose summaries contain a given word
+such as "spam", type "modules spam".
-With no FILE, or when FILE is -, read standard input.
+help></pre>
+<p><a name="ch2intro_1b"></a>As mentioned in the output, entering the name of any module, keyword or topic
+will provide the documentation and help regarding the same through the online
+help utility. Pressing <span class="emphasis"><em>Ctrl+d</em></span> exits the help prompt and returns to the
+python prompt.</p>
+<p><a name="ch2intro_1c"></a>Let us now try a few examples at the python interpreter.</p>
+<p><a name="ch2intro_1d"></a>Eg 1:</p>
+<pre class="programlisting">>>> print 'Hello, python!'
+Hello, python!
+>>></pre>
+<p><a name="ch2intro_1e"></a>Eg 2:</p>
+<pre class="programlisting">>>> print 4321*567890
+2453852690
+>>></pre>
+<p><a name="ch2intro_1f"></a>Eg 3:</p>
+<pre class="programlisting">>>> 4321*567890
+2453852690L
+>>></pre>
+<pre class="programlisting">Note: Notice the 'L' at the end of the output. The 'L' signifies that the
+output of the operation is of type *long*. It was absent in the previous
+example because we used the print statement. This is because *print* formats
+the output before displaying.</pre>
+<p><a name="ch2intro_20"></a>Eg 4:</p>
+<pre class="programlisting">>>> big = 12345678901234567890 ** 3
+>>> print big
+1881676372353657772490265749424677022198701224860897069000
+>>></pre>
+<pre class="programlisting">This example is to show that unlike in C or C++ there is no limit on the
+value of an integer.</pre>
+<p><a name="ch2intro_21"></a>Try this on the interactive interpreter:
+<code class="literal">import this</code></p>
+<p><a name="ch2intro_22"></a><span class="emphasis"><em>Hint: The output gives an idea of Power of Python</em></span></p>
+</div>
+<div class="section" title="2.2. ipython - An enhanced interactive Python interpreter">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id2631556"></a>2.2. <span class="emphasis"><em>ipython</em></span> - An enhanced interactive Python interpreter</h3></div></div></div>
+<p><a name="ch2intro_23"></a>The power and the importance of the interactive interpreter was the highlight
+of the previous section. This section provides insight into the enhanced
+interpreter with more advanced set of features called <span class="strong"><strong>ipython</strong></span>. Entering
+<span class="emphasis"><em>ipython</em></span> at the shell prompt fires up the interactive interpreter.</p>
+<pre class="programlisting">$ ipython
+Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
+Type "copyright", "credits" or "license" for more information.
-Examples:
- cat f - g Output f's contents, then standard input, then g's contents.
- cat Copy standard input to standard output.
+IPython 0.8.4 -- An enhanced Interactive Python.
+? -> Introduction and overview of IPython's features.
+%quickref -> Quick reference.
+help -> Python's own help system.
+object? -> Details about 'object'. ?object also works, ?? prints more.
+
+In [1]:</pre>
+<p><a name="ch2intro_24"></a>This is the output obtained upon firing ipython. The exact appearance may
+change based on the Python version installed. The following are some of the
+various features provided by <span class="strong"><strong>ipython</strong></span>:</p>
+<p><a name="ch2intro_25"></a>Suggestions - ipython provides suggestions of the possible methods and
+operations available for the given python object.</p>
+<p><a name="ch2intro_26"></a>Eg 5:</p>
+<pre class="programlisting">In [4]: a = 6
+
+In [5]: a.
+a.__abs__ a.__divmod__ a.__index__ a.__neg__ a.__rand__ a.__rmod__ a.__rxor__
+a.__add__ a.__doc__ a.__init__ a.__new__ a.__rdiv__ a.__rmul__ a.__setattr__
+a.__and__ a.__float__ a.__int__ a.__nonzero__ a.__rdivmod__ a.__ror__ a.__str__
+a.__class__ a.__floordiv__ a.__invert__ a.__oct__ a.__reduce__ a.__rpow__ a.__sub__
+a.__cmp__ a.__getattribute__ a.__long__ a.__or__ a.__reduce_ex__ a.__rrshift__ a.__truediv__
+a.__coerce__ a.__getnewargs__ a.__lshift__ a.__pos__ a.__repr__ a.__rshift__ a.__xor__
+a.__delattr__ a.__hash__ a.__mod__ a.__pow__ a.__rfloordiv__ a.__rsub__
+a.__div__ a.__hex__ a.__mul__ a.__radd__ a.__rlshift__ a.__rtruediv__</pre>
+<p><a name="ch2intro_27"></a>In this example, we initialized 'a' (a variable - a concept that will be
+discussed in the subsequent sections.) to 6. In the next line when the <span class="emphasis"><em>tab</em></span> key
+is pressed after typing '<span class="emphasis"><em>a.</em></span>' ipython displays the set of all possible methods
+that are applicable on the object 'a' (an integer in this context). Ipython
+provides many such datatype specific features which will be presented in the
+further sections as and when the datatypes are introduced.</p>
+</div>
+</div>
+<div class="section" title="3. Editing and running a python file">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="id2631681"></a>3. Editing and running a python file</h2></div></div></div>
+<p><a name="ch2intro_28"></a>The previous sections focused on the use of the interpreter to run python code.
+While the interpeter is an excellent tool to test simple solutions and
+experiment with small code snippets, its main disadvantage is that everything
+written in the interpreter is lost once its quit. Most of the times a program is
+used by people other than the author. So the programs have to be available in
+some form suitable for distribution, and hence they are written in files. This
+section will focus on editing and running python files. Start by opening a text
+editor ( it is recommended you choose one from the list at the top of this page ).
+In the editor type down python code and save the file with an extension <span class="strong"><strong>.py</strong></span>
+(python files have an extension of .py). Once done with the editing, save the
+file and exit the editor.</p>
+<p><a name="ch2intro_29"></a>Let us look at a simple example of calculating the gcd of 2 numbers using Python:</p>
+<p><a name="ch2intro_2a"></a><span class="strong"><strong>Creating the first python script(file)</strong></span></p>
+<pre class="programlisting">$ emacs gcd.py
+ def gcd(x,y):
+ if x % y == 0:
+ return y
+ return gcd(y, x%y)
-Report bugs to <bug-coreutils@gnu.org>.
- </pre>
- </div>
- </div>
- <div class="section" title="5.Basic file handling">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2834678">
- </a>
- 5.Basic file handling
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="5.1.cp">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2834687">
- </a>
- 5.1.cp
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_81">
- <span class="emphasis">
- <em>
- cp
- </em>
- </span>
- is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
- </p>
- <div class="section" title="5.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2834704">
- </a>
- 5.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_82">
- To copy a file to another file:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
- </pre>
- <p id="ch2intro_83">
- To copy a file to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
- </pre>
- <p id="ch2intro_84">
- To copy a directory to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
-SourceDirectory ... TargetDirectory
- </pre>
- </div>
- <div class="section" title="5.1.2.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2834738">
- </a>
- 5.1.2.Flags
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_85">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (force) specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
- </p>
- <p id="ch2intro_86">
- <span class="emphasis">
- <em>
- -P
- </em>
- </span>
- makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
- </p>
- <p id="ch2intro_87">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- (interactive) prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
- </p>
- <p id="ch2intro_88">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- (preserve) duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_89">
- The time of the last data modification and the time of the last access.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_8a">
- The user ID and group ID (only if it has permissions to do this)
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_8b">
- The file permission bits and the SUID and SGID bits.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_8c">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- (recursive) copy directories (recursively copying all the contents)
- </p>
- </div>
- <div class="section" title="5.1.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2834835">
- </a>
- 5.1.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_8d">
- To make a copy of a file in the current directory, enter:
- </p>
- <pre class="programlisting">
- $ cp prog.c prog.bak
- </pre>
- <p id="ch2intro_8e">
- This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
- </p>
- <p id="ch2intro_8f">
- To copy a file in your current directory into another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod /home/books/hhgg
- </pre>
- <p id="ch2intro_90">
- This copies the jones file to /home/books/hhgg/zaphod.
- </p>
- <p id="ch2intro_91">
- To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
- </p>
- <pre class="programlisting">
- $ cp -p martin_luther_king martin_luther_king.jr
- </pre>
- <p id="ch2intro_92">
- This copies the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file to the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file. Instead of creating the file with the current date and time stamp, the system gives the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file the same date and time as the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file. The
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file also inherits the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file's access control protection.
- </p>
- <p id="ch2intro_93">
- To copy all the files in a directory to a new directory, enter:
- </p>
- <pre class="programlisting">
- $ cp /home/galactica/clients/* /home/hhgg/customers
- </pre>
- <p id="ch2intro_94">
- This copies only the files in the clients directory to the customers directory.
- </p>
- <p id="ch2intro_95">
- To copy a directory, including all its files and subdirectories, to another directory, enter:
- </p>
- <p id="ch2intro_96">
- $ cp -R /home/hhgg/clients /home/hhgg/customers
- </p>
- <p id="ch2intro_97">
- This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
- </p>
- <p id="ch2intro_98">
- To copy a specific set of files of any extension to another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod arthur ford /home/hhgg/clients
- </pre>
- <p id="ch2intro_99">
- This copies the
- <span class="emphasis">
- <em>
- zaphod
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- arthur
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- ford
- </em>
- </span>
- files in your current working directory to the /home/hhgg/clients directory.
- </p>
- <p id="ch2intro_9a">
- To use pattern-matching characters to copy files, enter:
- </p>
- <pre class="programlisting">
- $ cp programs/*.py .
- </pre>
- <p id="ch2intro_9b">
- This copies the files in the programs directory that end with
- <span class="emphasis">
- <em>
- .py
- </em>
- </span>
- to the current directory, signified by the single "." (dot). You must type a space between the
- <span class="emphasis">
- <em>
- py
- </em>
- </span>
- and the final dot.
- </p>
- </div>
- </div>
- <div class="section" title="5.2.mv">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2834996">
- </a>
- 5.2.mv
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_9c">
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system),
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- will rename the file instead. Write permission is required on all directories being modified.
- </p>
- <div class="section" title="5.2.1.Conflicting existing file">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2835020">
- </a>
- 5.2.1.Conflicting existing file
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_9d">
- In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
- </p>
- </div>
- <div class="section" title="5.2.2.Differences with copy and delete">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2835039">
- </a>
- 5.2.2.Differences with copy and delete
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_9e">
- Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
- </p>
- </div>
- <div class="section" title="5.2.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2835069">
- </a>
- 5.2.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ mv myfile mynewfilename renames a file
-$ mv myfile otherfilename renames a file and deletes the existing file "myfile"
-$ mv myfile /myfile moves 'myfile' from the current directory to the root directory
-$ mv myfile dir/myfile moves 'myfile' to 'dir/myfile' relative to the current directory
-$ mv myfile dir same as the previous command (the filename is implied to be the same)
-$ mv myfile dir/myfile2 moves 'myfile' to dir and renames it to 'myfile2'
-$ mv foo bar baz dir moves multiple files to directory dir
-$ mv --help shows a very concise help about the syntax of the command
-$ man mv prints an extensive user manual for 'mv' in the terminal
- </pre>
- <p id="ch2intro_9f">
- In all cases, the file or files being moved or renamed can be a directory.
- </p>
- <p id="ch2intro_a0">
- Note that when the command is called with two arguments (as
- <span class="emphasis">
- <em>
- mv name1 name2
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- mv name1 /dir/name2
- </em>
- </span>
- ), it can have three different effects, depending on whether
- <span class="emphasis">
- <em>
- name2
- </em>
- </span>
- does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
- <span class="emphasis">
- <em>
- /.
- </em>
- </span>
- (or in some Unix versions
- <span class="emphasis">
- <em>
- /
- </em>
- </span>
- is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
- </p>
- </div>
- </div>
- <div class="section" title="5.3.rm">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2835142">
- </a>
- 5.3.rm
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_a1">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
- </p>
- <p id="ch2intro_a2">
- Here's example to remove a file named "foo" from a directory, here shown with the -i option:
- </p>
- <pre class="programlisting">
- $ rm -i foo
-remove foo? y
- </pre>
- <div class="section" title="5.3.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2835171">
- </a>
- 5.3.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_a3">
- Common options that rm accepts include:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_a4">
- <span class="emphasis">
- <em>
- -r
- </em>
- </span>
- , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_a5">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- , which asks for every deletion to be confirmed ("interactive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_a6">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- , which ignores non-existent files and overrides any confirmation prompts ("force")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_a7">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- , which shows what is being removed as it happens ("verbose")
- </p>
- </li>
- </ul>
- </div>
- <p id="ch2intro_a8">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
- </p>
- <p id="ch2intro_a9">
- <span class="emphasis">
- <em>
- rm -rf
- </em>
- </span>
- (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
- </p>
- <p id="ch2intro_aa">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often used in conjunction with xargs to supply a list of files to delete:
- </p>
- <pre class="programlisting">
- xargs rm < filelist
- </pre>
- <p id="ch2intro_ab">
- When
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is used on a symbolic link, it deletes the link, but does not affect the target of the link.
- </p>
- </div>
- <div class="section" title="5.3.2.Permissions">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2835268">
- </a>
- 5.3.2.Permissions
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_ac">
- Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
- </p>
- <p id="ch2intro_ad">
- To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
- </p>
- <p id="ch2intro_ae">
- If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="6.Command Line Arguments">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2835308">
- </a>
- 6.Command Line Arguments
- </h2>
- </div>
- </div>
- </div>
- <p id="ch2intro_af">
- In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
- </p>
- <p id="ch2intro_b0">
- For example, in Unix and Unix-like environments, an example of a command-line argument is:
- </p>
- <pre class="programlisting">
- rm file.s
- </pre>
- <p id="ch2intro_b1">
- "file.s" is a command line argument which tells the program rm to remove the file "file.s".
- </p>
- <p id="ch2intro_b2">
- Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
- </p>
- <p id="ch2intro_b3">
- A command line option or simply
- <span class="emphasis">
- <em>
- option
- </em>
- </span>
- (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
- </p>
- <p id="ch2intro_b4">
- Long options are introduced via "--", and are typically whole words. For example,
- <span class="emphasis">
- <em>
- ls --long --classify --all
- </em>
- </span>
- . Arguments to long options are provided with "=", as
- <span class="emphasis">
- <em>
- ls --block-size=1024
- </em>
- </span>
- . Some Unix programs use long options with single dashes, for example MPlayer as in
- <span class="emphasis">
- <em>
- mplayer -nosound
- </em>
- </span>
- .
- </p>
- <p id="ch2intro_b5">
- Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- by using
- <span class="emphasis">
- <em>
- rm -file1
- </em>
- </span>
- may produce an error, since rm may interpret
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- as a command line switch. Using
- <span class="emphasis">
- <em>
- rm -- -file1
- </em>
- </span>
- removes ambiguity.
- </p>
- </div>
- <div class="section" title="7.Basic Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2835401">
- </a>
- 7.Basic Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="7.1.head">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2835409">
- </a>
- 7.1.head
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_b6">
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:
- </p>
- <pre class="programlisting">
- $ head [options] <file_name>
- </pre>
- <p id="ch2intro_b7">
- By default,
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ head -n 20 filename
- </pre>
- <p id="ch2intro_b8">
- This displays the first 5 lines of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ head -n 5 foo*
- </pre>
- <p id="ch2intro_b9">
- Some versions omit the n and just let you say -5.
- </p>
- <div class="section" title="7.1.1.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2835461">
- </a>
- 7.1.1.Flags
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- -c <x number of bytes> Copy first x number of bytes.
- </pre>
- <p id="ch2intro_ba">
- Other options:
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- </p>
- <p id="ch2intro_bb">
- Many early versions of Unix did not have this command, and so documentation and books had
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- do this job:
- </p>
- <pre class="programlisting">
- sed 5q foo
- </pre>
- <p id="ch2intro_bc">
- This says to print every line (implicit), and quit after the fifth.
- </p>
- </div>
- </div>
- <div class="section" title="7.2.tail">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2835497">
- </a>
- 7.2.tail
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_bd">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
- </p>
- <p id="ch2intro_be">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ tail [options] <file_name>
- </pre>
- <p id="ch2intro_bf">
- By default,
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ tail -n 20 filename
- </pre>
- <p id="ch2intro_c0">
- This example shows the last 15 bytes of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ tail -c 15 foo*
- </pre>
- <p id="ch2intro_c1">
- This example shows all lines of filename from the second line onwards:
- </p>
- <pre class="programlisting">
- $ tail -n +2 filename
- </pre>
- <p id="ch2intro_c2">
- Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:
- </p>
- <pre class="programlisting">
- $ tail -20 filename
-$ tail -50c filename
- </pre>
- <p id="ch2intro_c3">
- However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
- </p>
- <div class="section" title="7.2.1.File monitoring">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2835575">
- </a>
- 7.2.1.File monitoring
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_c4">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- has a special command line option
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:
- </p>
- <pre class="programlisting">
- $ tail -f /var/adm/messages
- </pre>
- <p id="ch2intro_c5">
- To interrupt tail while it is monitoring, break-in with
- <span class="emphasis">
- <em>
- Ctrl+C
- </em>
- </span>
- . This command can be run "in the background" with &, see job control.
- </p>
- <p id="ch2intro_c6">
- If you have a command's result to monitor, you can use the
- <span class="emphasis">
- <em>
- watch
- </em>
- </span>
- command.
- </p>
- </div>
- </div>
- <div class="section" title="7.3.cut">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2835624">
- </a>
- 7.3.cut
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_c7">
- In computing,
- <span class="emphasis">
- <em>
- cut
- </em>
- </span>
- is a Unix command line utility which is used to extract sections from each line of input usually from a file.
- </p>
- <p id="ch2intro_c8">
- Extraction of line segments can typically be done by
- <span class="emphasis">
- <em>
- bytes (-b), characters (-c)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- fields (-f)
- </em>
- </span>
- separated by a
- <span class="emphasis">
- <em>
- delimiter (-d the tab character by default)
- </em>
- </span>
- . A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
- </p>
- <p id="ch2intro_c9">
- Assuming a file named file containing the lines:
- </p>
- <pre class="programlisting">
- foo:bar:baz:qux:quux
-one:two:three:four:five:six:seven
-alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- <p id="ch2intro_ca">
- To output the fourth through tenth characters of each line:
- </p>
- <pre class="programlisting">
- $ cut -c 4-10 file
- </pre>
- <p id="ch2intro_cb">
- This gives the output:
- </p>
- <pre class="programlisting">
- :bar:ba
-:two:th
-ha:beta
- </pre>
- <p id="ch2intro_cc">
- To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
- </p>
- <pre class="programlisting">
- $ cut -d : -f 5- file
- </pre>
- <p id="ch2intro_cd">
- This gives the output:
- </p>
- <pre class="programlisting">
- quux
-five:six:seven
-epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- </div>
- <div class="section" title="7.4.paste">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2835710">
- </a>
- 7.4.paste
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_ce">
- <span class="emphasis">
- <em>
- paste
- </em>
- </span>
- is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command which operates on the vertical plane of two or more files.
- </p>
- <p id="ch2intro_cf">
- To paste several columns of data together into the file
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- from files
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- where
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- when
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ paste who where when > www
- </pre>
- <p id="ch2intro_d0">
- If the files contain:
- </p>
- <table summary="paste" border="1">
- <colgroup>
- <col width="11">
- </col>
- <col width="12">
- </col>
- <col width="12">
- </col>
- </colgroup>
- </table>
- <p id="ch2intro_dd">
- This creates the file named
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- containing:
- </p>
- <pre class="programlisting">
- Batman GothamCity January 3
-Trillian Andromeda February 4
-Jeeves London March 19
- </pre>
- </div>
- </div>
- <div class="section" title="8.Shell Meta Characters">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2835844">
- </a>
- 8.Shell Meta Characters
- </h2>
- </div>
- </div>
- </div>
- <p id="ch2intro_de">
- Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
- </p>
- <p id="ch2intro_df">
- The shell meta characters include:
- </p>
- <p id="ch2intro_e0">
- / < > ! $ % ^ & * | { } [ ] " ' ` ~ ;
- </p>
- <p id="ch2intro_e1">
- Different shells may differ in the meta characters recognized.
- </p>
- <p id="ch2intro_e2">
- As an example,
- </p>
- <pre class="programlisting">
- $ ls file.*
- </pre>
- <p id="ch2intro_e3">
- run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
- </p>
- <pre class="programlisting">
- $ ls file.?
- </pre>
- <p id="ch2intro_e4">
- run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:
- </p>
- <pre class="programlisting">
- $ more c*
- </pre>
- <p id="ch2intro_e5">
- because the c* matches that long file name.
- </p>
- <p id="ch2intro_e6">
- Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named "``*`|more"` can be accomplished with:
- </p>
- <pre class="programlisting">
- $ rm ??more
- </pre>
- <p id="ch2intro_e7">
- or:
- </p>
- <pre class="programlisting">
- $ rm $\backslash$*$\backslash$|more
- </pre>
- <p id="ch2intro_e8">
- or:
- </p>
- <pre class="programlisting">
- $ rm ''*|more''
- </pre>
- </div>
- <div class="section" title="9.Looking At Files">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2835957">
- </a>
- 9.Looking At Files
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="9.1.cat">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2835965">
- </a>
- 9.1.cat
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_e9">
- The
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
- <span class="emphasis">
- <em>
- concatenate
- </em>
- </span>
- .
- </p>
- <p id="ch2intro_ea">
- The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
- </p>
- <p id="ch2intro_eb">
- If the filename is specified as -, then
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input at that point in the sequence. If no files are specified,
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input entered.
- </p>
- <div class="section" title="9.1.1.Jargon File Definition">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2836009">
- </a>
- 9.1.1.Jargon File Definition
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_ec">
- The Jargon File version 4.4.7 lists this as the definition of
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- 1. To spew an entire file to the screen or some other output sink without
- pause (syn. blast).
-
-2. By extension, to dump large amounts of data at an unprepared target or
- with no intention of browsing it carefully. Usage: considered silly.
- Rare outside Unix sites. See also dd, BLT.
-
- Among Unix fans, *cat(1)* is considered an excellent example of
- user-interface design, because it delivers the file contents without
- such verbosity as spacing or headers between the files, and because
- it does not require the files to consist of lines of text, but works
- with any sort of data.
-
- Among Unix critics, *cat(1)* is considered the canonical example of
- bad user-interface design, because of its woefully unobvious name.
- It is far more often used to blast a single file to standard output
- than to concatenate two or more files. The name cat for the former
- operation is just as unintuitive as, say, LISP's cdr.
+ print gcd(72, 92)</pre>
+<p><a name="ch2intro_2b"></a>To run the script, open the shell prompt, navigate to the directory that
+contains the python file and run <code class="literal">python <filename.py></code> at the prompt ( in this
+case filename is gcd.py )</p>
+<p><a name="ch2intro_2c"></a><span class="strong"><strong>Running the python script</strong></span></p>
+<pre class="programlisting">$ python gcd.py
+4
+$</pre>
+<p><a name="ch2intro_2d"></a>Another method to run a python script would be to include the line</p>
+<p><a name="ch2intro_2e"></a><code class="literal">#! /usr/bin/python</code></p>
+<p><a name="ch2intro_2f"></a>at the beginning of the python file and then make the file executable by</p>
+<p><a name="ch2intro_30"></a>$ chmod a+x <span class="emphasis"><em>filename.py</em></span></p>
+<p><a name="ch2intro_31"></a>Once this is done, the script can be run as a standalone program as follows:</p>
+<p><a name="ch2intro_32"></a>$ ./<span class="emphasis"><em>filename.py</em></span></p>
+</div>
+<div class="section" title="4. Basic Datatypes and operators in Python">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="id2631788"></a>4. Basic Datatypes and operators in Python</h2></div></div></div>
+<p><a name="ch2intro_33"></a>Python provides the following set of basic datatypes.</p>
+<div class="itemizedlist"><ul class="itemizedlist" type="*">
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_34"></a>Numbers: int, float, long, complex</p></li>
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_35"></a>Strings</p></li>
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_36"></a>Boolean</p></li>
+</ul></div>
+<div class="section" title="4.1. Numbers">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id2631822"></a>4.1. Numbers</h3></div></div></div>
+<p><a name="ch2intro_37"></a>Numbers were introduced in the examples presented in the interactive interpreter
+section. Numbers include types as mentioned earlier viz., int (integers), float
+(floating point numbers), long (large integers), complex (complex numbers with
+real and imaginary parts). Python is not a strongly typed language, which means
+the type of a variable need not mentioned during its initialization. Let us look
+at a few examples.</p>
+<p><a name="ch2intro_38"></a>Eg 6:</p>
+<pre class="programlisting">>>> a = 1 #here a is an integer variable</pre>
+<p><a name="ch2intro_39"></a>Eg 7:</p>
+<pre class="programlisting">>>> lng = 122333444455555666666777777788888888999999999 #here lng is a variable of type long
+>>> lng
+122333444455555666666777777788888888999999999L #notice the trailing 'L'
+>>> print lng
+122333444455555666666777777788888888999999999 #notice the absence of the trailing 'L'
+>>> lng+1
+122333444455555666666777777788888889000000000L</pre>
+<p><a name="ch2intro_3a"></a>Long numbers are the same as integers in almost all aspects. They can be used in
+operations just like integers and along with integers without any distinction.
+The only distinction comes during type checking (which is not a healthy practice).
+Long numbers are tucked with a trailing 'L' just to signify that they are long.
+Notice that in the example just lng at the prompt displays the value of the variable
+with the 'L' whereas <code class="literal">print lng</code> displays without the 'L'. This is because print
+formats the output before printing. Also in the example, notice that adding an
+integer to a long does not give any errors and the result is as expected. So for
+all practical purposes longs can be treated as ints.</p>
+<p><a name="ch2intro_3b"></a>Eg 8:</p>
+<pre class="programlisting">>>> fl = 3.14159 #fl is a float variable
+>>> e = 1.234e-4 #e is also a float variable, specified in the exponential form
+>>> a = 1
+>>> b = 2
+>>> a/b #integer division
+0
+>>> a/fl #floating point division
+0.31831015504887655
+>>> e/fl
+3.9279473133031364e-05</pre>
+<p><a name="ch2intro_3c"></a>Floating point numbers, simply called floats are real numbers with a decimal point.
+The example above shows the initialization of a float variable. Shown also in this
+example is the difference between integer division and floating point division.
+'a' and 'b' here are integer variables and hence the division gives 0 as the quotient.
+When either of the operands is a float, the operation is a floating point division,
+and the result is also a float as illustrated.</p>
+<p><a name="ch2intro_3d"></a>Eg 9:</p>
+<pre class="programlisting">>>> cplx = 3 + 4j #cplx is a complex variable
+>>> cplx
+(3+4j)
+>>> print cplx.real #prints the real part of the complex number
+3.0
+>>> print cplx.imag #prints the imaginary part of the complex number
+4.0
+>>> print cplx*fl #multiplies the real and imag parts of the complex number with the multiplier
+(9.42477+12.56636j)
+>>> abs(cplx) #returns the absolute value of the complex number
+5.0</pre>
+<p><a name="ch2intro_3e"></a>Python provides a datatype for complex numbers. Complex numbers are initialized
+as shown in the example above. The <span class="emphasis"><em>real</em></span> and <span class="emphasis"><em>imag</em></span> operators return the real and
+imaginary parts of the complex number as shown. The <span class="emphasis"><em>abs()</em></span> returns the absolute
+value of the complex number.</p>
+</div>
+<div class="section" title="4.2. Variables">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id2631952"></a>4.2. Variables</h3></div></div></div>
+<p><a name="ch2intro_3f"></a>Variables are just names that represent a value. Variables have already been
+introduced in the various examples from the previous sections. Certain rules about
+using variables:</p>
+<div class="itemizedlist"><ul class="itemizedlist" type="*">
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_40"></a>Variables have to be initialized or assigned a value before being used.</p></li>
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_41"></a>Variable names can consist of letters, digits and underscores(_).</p></li>
+<li class="listitem" style="list-style-type: *"><p><a name="ch2intro_42"></a>Variable names cannot begin with digits, but can contain digits in them.</p></li>
+</ul></div>
+<p><a name="ch2intro_43"></a>In reference to the previous section examples, 'a', 'b', 'lng', 'fl', 'e' and 'cplx'
+are all variables of various datatypes.</p>
+<pre class="programlisting">Note: Python is not a strongly typed language and hence an integer variable can at a
+later stage be used as a float variable as well.</pre>
+</div>
+<div class="section" title="4.3. Strings">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id2632000"></a>4.3. Strings</h3></div></div></div>
+<p><a name="ch2intro_44"></a>Strings are one of the essential data structures of any programming language.
+The <code class="literal">print "Hello, World!"</code> program was introduced in the earlier section, and
+the <span class="emphasis"><em>"Hello, World!"</em></span> in the print statement is a string. A string is basically
+a set of characters. Strings can be represented in various ways shown below:</p>
+<pre class="programlisting">s = 'this is a string' # a string variable can be represented using single quotes
+s = 'This one has "quotes" inside!' # The string can have quotes inside it as shown
+s = "I have 'single-quotes' inside!"
+l = "A string spanning many lines\
+one more line\
+yet another" # a string can span more than a single line.
+t = """A triple quoted string does # another way of representing multiline strings.
+not need to be escaped at the end and
+"can have nested quotes" etc."""</pre>
+<p><a name="ch2intro_45"></a>Try the following on the interpreter:
+<code class="literal">s = 'this is a string with 'quotes' of similar kind'</code></p>
+<p><a name="ch2intro_46"></a><span class="strong"><strong>Exercise: How to use single quotes within single quotes in a string as shown
+in the above example without getting an error?</strong></span></p>
+<div class="section" title="4.3.1. String operations">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="id2632051"></a>4.3.1. String operations</h4></div></div></div>
+<p><a name="ch2intro_47"></a>A few basic string operations are presented here.</p>
+<p><a name="ch2intro_48"></a><span class="strong"><strong>String concatenation</strong></span>
+String concatenation is done by simple addition of two strings.</p>
+<pre class="programlisting">>>> x = 'Hello'
+>>> y = ' Python'
+>>> print x+y
+Hello Python</pre>
+<p><a name="ch2intro_49"></a><span class="emphasis"><em>Try this yourself:</em></span></p>
+<pre class="programlisting">>>> somenum = 13
+>>> print x+somenum</pre>
+<p><a name="ch2intro_4a"></a>The problem with the above example is that here a string variable and an integer
+variable are trying to be concantenated. To obtain the desired result from the
+above example the str(), repr() and the `` can be used.</p>
+<p><a name="ch2intro_4b"></a><span class="strong"><strong>str()</strong></span> simply converts a value to a string in a reasonable form.
+<span class="strong"><strong>repr()</strong></span> creates a string that is a representation of the value.</p>
+<p><a name="ch2intro_4c"></a>The difference can be seen in the example shown below:</p>
+<pre class="programlisting">>>> str(1000000000000000000000000000000000000000000000000L)
+'1000000000000000000000000000000000000000000000000'
+>>> repr(1000000000000000000000000000000000000000000000000L)
+'1000000000000000000000000000000000000000000000000L'</pre>
+<p><a name="ch2intro_4d"></a>It can be observed that the 'L' in the long value shown was omitted by str(),
+whereas repr() converted that into a string too. An alternative way of using
+repr(value) is <code class="literal">`value`</code>.</p>
+<p><a name="ch2intro_4e"></a>A few more examples:</p>
+<pre class="programlisting">>>> x = "Let's go \nto Pycon"
+>>> print x
+Let's go
+to Pycon</pre>
+<p><a name="ch2intro_4f"></a>In the above example, notice that the 'n'(newline) character is formatted and
+the string is printed on two lines. The strings discussed until now were normal
+strings. Other than these there are two other types of strings namely, raw strings
+and unicode strings.</p>
+<p><a name="ch2intro_50"></a><span class="strong"><strong>Raw strings</strong></span> are strings which are unformatted, that is the backslashes() are
+not parsed and are left as it is in the string. Raw strings are represented with
+an 'r' at the start of a string.
+Let us look at an example</p>
+<pre class="programlisting">>>> x = r"Let's go \nto Pycon"
+>>> print x
+Let's go \nto Pycon</pre>
+<p><a name="ch2intro_51"></a>Note: The 'n' is not being parsed into a new line and is left as it is.</p>
+<p><a name="ch2intro_52"></a><span class="emphasis"><em>Try this yourself:</em></span></p>
+<pre class="programlisting">>>> x = r"Let's go to Pycon\"</pre>
+<p><a name="ch2intro_53"></a><span class="strong"><strong>Unicode strings</strong></span> are strings where the characters are Unicode characters as
+opposed to ASCII characters. Unicode strings are represented with a 'u' at the
+start of the string.
+Let us look at an example:</p>
+<pre class="programlisting">>>> x = u"Let's go to Pycon!"
+>>> print x
+Let's go to Pycon!</pre>
+</div>
+</div>
+<div class="section" title="4.4. Boolean">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="id2632194"></a>4.4. Boolean</h3></div></div></div>
+<p><a name="ch2intro_54"></a>Python also provides special Boolean datatype. A boolean variable can assume a
+value of either <span class="emphasis"><em>True</em></span> or <span class="emphasis"><em>False</em></span> (Note the capitalizations).</p>
+<p><a name="ch2intro_55"></a>Let us look at examples:</p>
+<pre class="programlisting">>>> t = True
+>>> f = not t
+>>> print f
+False
+>>> f or t
+True
+>>> f and t
+False</pre>
+</div>
+</div>
+<div class="section" title="5. The while loop">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="id2632223"></a>5. The <span class="strong"><strong>while</strong></span> loop</h2></div></div></div>
+<p><a name="ch2intro_56"></a>The Python <span class="strong"><strong>while</strong></span> loop is similar to the C/C++ while loop. The syntax is as
+follows:</p>
+<pre class="programlisting">statement 0
+while condition:
+ statement 1 #while block
+ statement 2 #while block
+statement 3 #outside the while block.</pre>
+<p><a name="ch2intro_57"></a>Let us look at an example:</p>
+<pre class="programlisting">>>> x = 1
+>>> while x <= 5:
+... print x
+... x += 1
+...
+1
+2
+3
+4
+5</pre>
+</div>
+<div class="section" title="6. The if conditional">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="id2632260"></a>6. The <span class="strong"><strong>if</strong></span> conditional</h2></div></div></div>
+<p><a name="ch2intro_58"></a>The Python <span class="strong"><strong>if</strong></span> block provides the conditional execution of statements.
+If the condition evaluates as true the block of statements defined under the if
+block are executed.</p>
+<p><a name="ch2intro_59"></a>If the first block is not executed on account of the condition not being satisfied,
+the set of statements in the <span class="strong"><strong>else</strong></span> block are executed.</p>
+<p><a name="ch2intro_5a"></a>The <span class="strong"><strong>elif</strong></span> block provides the functionality of evaluation of multiple conditions
+as shown in the example.</p>
+<p><a name="ch2intro_5b"></a>The syntax is as follows:</p>
+<pre class="programlisting">if condition :
+ statement_1
+ statement_2
- Of such oppositions are holy wars made...
- </pre>
- </div>
- <div class="section" title="9.1.2.Useless Use of 'cat'">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2836048">
- </a>
- 9.1.2.Useless Use of 'cat'
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_ed">
- UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
- <span class="emphasis">
- <em>
- comp.unix.shell
- </em>
- </span>
- , The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
- </p>
- <p id="ch2intro_ee">
- Nevertheless one sees people doing:
- </p>
- <pre class="programlisting">
- $ cat file | some_command and its args ...
- </pre>
- <p id="ch2intro_ef">
- instead of the equivalent and cheaper:
- </p>
- <pre class="programlisting">
- <file some_command and its args ...
- </pre>
- <p id="ch2intro_f0">
- or (equivalently and more classically):
- </p>
- <pre class="programlisting">
- some_command and its args ... <file
- </pre>
- <p id="ch2intro_f1">
- Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
- </p>
- <p id="ch2intro_f2">
- Amongst many, it is still considered safer to use
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
- </p>
- </div>
- <div class="section" title="9.1.3.zcat">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2836117">
- </a>
- 9.1.3.zcat
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_f3">
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- is a Unix program similar to
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- , that decompresses individual files and concatenates them to standard output. Traditionally
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- operated on files compressed by compress but today it is usually able to operate on
- <span class="emphasis">
- <em>
- gzip
- </em>
- </span>
- or even
- <span class="emphasis">
- <em>
- bzip2
- </em>
- </span>
- archives. On such systems, it is equivalent to
- <span class="emphasis">
- <em>
- gunzip -c
- </em>
- </span>
- </p>
- </div>
- </div>
- <div class="section" title="9.2.more">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2836153">
- </a>
- 9.2.more
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_f4">
- In computing,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
- </p>
- <div class="section" title="9.2.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2836174">
- </a>
- 9.2.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_f5">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ more [options] [file_name]
- </pre>
- <p id="ch2intro_f6">
- If no file name is provided,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- looks for input from stdin.
- </p>
- <p id="ch2intro_f7">
- Once
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has paged through. (This percentage includes the text displayed on the current screen.) When
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- , which advances the output by one line, and
- <span class="emphasis">
- <em>
- Space
- </em>
- </span>
- , which advances the output by one screen.
- </p>
- <p id="ch2intro_f8">
- There are also other commands that can be used while navigating through the document; consult
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- 's
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page for more details.
- </p>
- <p id="ch2intro_f9">
- <span class="emphasis">
- <em>
- Options
- </em>
- </span>
- are typically entered before the file name, but can also be entered in the environment variable
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- . Options entered in the actual command line will override those entered in the
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- environment variable. Available options may vary between Unix systems.
- </p>
- </div>
- </div>
- <div class="section" title="9.3.less">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2836267">
- </a>
- 9.3.less
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_fa">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- does not need to read the entire file before starting, resulting in faster load times with large files.
- </p>
- <div class="section" title="9.3.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2836296">
- </a>
- 9.3.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_fb">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- vi
- </em>
- </span>
- . It is also possible to search for character patterns in the file.
- </p>
- <p id="ch2intro_fc">
- By default,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
- </p>
- <p id="ch2intro_fd">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ less [options] file_name
- </pre>
- </div>
- <div class="section" title="9.3.2.Frequently Used Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2836350">
- </a>
- 9.3.2.Frequently Used Options
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_fe">
- -g: Highlights just the current match of any searched string.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_ff">
- -I: Case-insensitive searches.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_100">
- -M: Shows more detailed prompt, including file position.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_101">
- -N: Shows line numbers (useful for source code viewing).
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_102">
- -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_103">
- -?: Shows help.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.3.Frequently Used Commands">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2836402">
- </a>
- 9.3.3.Frequently Used Commands
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_104">
- [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_105">
- [Space bar]: Next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_106">
- b: Previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_107">
- ng: Jump to line number n. Default is the start of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_108">
- nG: Jump to line number n. Default is the end of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_109">
- /pattern: Search for pattern. Regular expressions can be used.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_10a">
- '^ or g: Go to start of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_10b">
- '$ or G: Go to end of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_10c">
- s: Save current content (got from another program like grep) in a file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_10d">
- =: File information.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_10e">
- h: Help.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_10f">
- q: Quit.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.4.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2836490">
- </a>
- 9.3.4.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ less -M readme.txt #Read "readme.txt."
-$ less +F /var/log/mail.log #Follow mode for log
-$ file * | less #Easier file analysis.
-$ grep -i void *.c | less -I -p void #Case insensitive search for "void" in all .c files
- </pre>
- </div>
- </div>
- </div>
- <div class="section" title="10.Directory Structure">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2836505">
- </a>
- 10.Directory Structure
- </h2>
- </div>
- </div>
- </div>
- <p id="ch2intro_110">
- In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
- </p>
- <p id="ch2intro_111">
- The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
- </p>
- <table summary="Directory Structure" border="1">
- <colgroup>
- <col width="15">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <div class="section" title="10.1.man hier">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2836775">
- </a>
- 10.1.man hier
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_136">
- This is the manual page on the UNIX filesystem. The syntax for this is:
- </p>
- <pre class="programlisting">
- $ man hier
- </pre>
- </div>
- <div class="section" title="10.2.ls -l">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2836791">
- </a>
- 10.2.ls -l
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_137">
- Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
- </p>
- <pre class="programlisting">
- $ ls -l
- </pre>
- <p id="ch2intro_138">
- This can be done after entering the required directory.
- </p>
- </div>
- </div>
- <div class="section" title="11.Permissions and Ownership">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2836814">
- </a>
- 11.Permissions and Ownership
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="11.1.chmod">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2836823">
- </a>
- 11.1.chmod
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_139">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.
- </p>
- <div class="section" title="11.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2836848">
- </a>
- 11.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_13a">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command options are specified like this:
- </p>
- <pre class="programlisting">
- $ chmod [options] mode[,mode] file1 [file2 ...]
- </pre>
- <p id="ch2intro_13b">
- To view what the permissions currently are, type:
- </p>
- <pre class="programlisting">
- $ ls -l file
- </pre>
- </div>
- <div class="section" title="11.1.2.Command line options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2836876">
- </a>
- 11.1.2.Command line options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_13c">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command has a number of command line options that affect its behavior. The most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_13d">
- -R: Changes the modes of directories and files recursively
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch2intro_13e">
- -v: Verbose mode; lists all files as they are being processed
- </p>
- </li>
- </ul>
- </div>
- <div class="section" title="11.1.2.1.Symbolic modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2836912">
- </a>
- 11.1.2.1.Symbolic modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch2intro_13f">
- To the
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
- </p>
- <pre class="programlisting">
- $ chmod [references][operator][modes] file1 ...
- </pre>
- <p id="ch2intro_140">
- The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="8">
- </col>
- <col width="45">
- </col>
- </colgroup>
- </table>
- <p id="ch2intro_150">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="54">
- </col>
- </colgroup>
- </table>
- <p id="ch2intro_157">
- The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="5">
- </col>
- <col width="14">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <p id="ch2intro_16d">
- The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
- </p>
- </div>
- <div class="section" title="11.1.2.2.Symbolic examples">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2837458">
- </a>
- 11.1.2.2.Symbolic examples
- </h5>
- </div>
- </div>
- </div>
- <p id="ch2intro_16e">
- Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
- </p>
- <pre class="programlisting">
- $ chmod ug+rw mydir
-$ ls -ld mydir
-drw-rw---- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- <p id="ch2intro_16f">
- For a file, remove
- <span class="emphasis">
- <em>
- write
- </em>
- </span>
- permissions for all classes:
- </p>
- <pre class="programlisting">
- $ chmod a-w myfile
-$ ls -l myfile
--r-xr-xr-x 2 starwars yoda 96 Dec 8 12:53 myfile
- </pre>
- <p id="ch2intro_170">
- Set the permissions for the
- <span class="emphasis">
- <em>
- u*ser and the *g*roup to read and execute only (no write permission) on *mydir
- </em>
- </span>
- .
- </p>
- <pre class="programlisting">
- $ chmod ug=rx mydir
-$ ls -ld mydir
-dr-xr-x--- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- </div>
- <div class="section" title="11.1.2.3.Octal numbers">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2837499">
- </a>
- 11.1.2.3.Octal numbers
- </h5>
- </div>
- </div>
- </div>
- <p id="ch2intro_171">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
- </p>
- <pre class="programlisting">
- $ chmod 664 myfile
-$ ls -l myfile
--rw-rw-r-- 1 57 Jul 3 10:13 myfile
- </pre>
- <p id="ch2intro_172">
- Since the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- sticky
- </em>
- </span>
- bits are not set, this is equivalent to:
- </p>
- <pre class="programlisting">
- $ chmod 0664 myfile
- </pre>
- </div>
- <div class="section" title="11.1.2.4.Special modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2837539">
- </a>
- 11.1.2.4.Special modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch2intro_173">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
- <span class="strong">
- <strong>
- s
- </strong>
- </span>
- to represent the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- modes, and
- <span class="strong">
- <strong>
- t
- </strong>
- </span>
- to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
- </p>
- <p id="ch2intro_174">
- Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
- </p>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="12.Redirection and Piping">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2837587">
- </a>
- 12.Redirection and Piping
- </h2>
- </div>
- </div>
- </div>
- <p id="ch2intro_175">
- In computing,
- <span class="emphasis">
- <em>
- redirection
- </em>
- </span>
- is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
- </p>
- <p id="ch2intro_176">
- Programs do redirection with the
- <span class="emphasis">
- <em>
- dup2(2)
- </em>
- </span>
- system call, or its less-flexible but higher-level stdio analogues,
- <span class="emphasis">
- <em>
- freopen(3)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- popen(3)
- </em>
- </span>
- .
- </p>
- <div class="section" title="12.1.Redirecting standard input and standard output">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2837624">
- </a>
- 12.1.Redirecting standard input and standard output
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_177">
- Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
- </p>
- <pre class="programlisting">
- $ command1 > file1
- </pre>
- <p id="ch2intro_178">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , placing the output in file1. Note that this will truncate any existing data in
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- . To append output to the end of the file, use the >> operator.:
- </p>
- <pre class="programlisting">
- $ command1 < file1
- </pre>
- <p id="ch2intro_179">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- as the source of input (as opposed to the keyboard).:
- </p>
- <pre class="programlisting">
- $ command1 < infile > outfile
- </pre>
- <p id="ch2intro_17a">
- combines the two capabilities:
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- reads from
- <span class="emphasis">
- <em>
- infile
- </em>
- </span>
- and writes to
- <span class="emphasis">
- <em>
- outfile
- </em>
- </span>
- </p>
- </div>
- <div class="section" title="12.2.Piping">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2837693">
- </a>
- 12.2.Piping
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_17b">
- Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
-A pipeline of three programs run on a text terminal:
- </p>
- <pre class="programlisting">
- $ command1 | command2
- </pre>
- <p id="ch2intro_17c">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using its output as the input for
- <span class="emphasis">
- <em>
- command2
- </em>
- </span>
- (commonly called piping, since the "|" character is known as a "pipe").
- </p>
- <p id="ch2intro_17d">
- This is equivalent to using two redirects and a temporary file:
- </p>
- <pre class="programlisting">
- $ command1 > tempfile
-$ command2 < tempfile
-$ rm tempfile
- </pre>
- <p id="ch2intro_17e">
- A good example for command piping is combining
- <span class="emphasis">
- <em>
- echo
- </em>
- </span>
- with another command to achieve something interactive in a non-interactive shell, e.g.:
- </p>
- <pre class="programlisting">
- $ echo -e "user\npass" | ftp localhost
- </pre>
- <p id="ch2intro_17f">
- This runs the ftp client with input user, press return, then pass.
- </p>
- </div>
- <div class="section" title="12.3.Redirecting to and from the standard file handles">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2837754">
- </a>
- 12.3.Redirecting to and from the standard file handles
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_180">
- In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
- </p>
- <table summary="Redirecting to and from the standard file handles" border="1">
- <colgroup>
- <col width="12">
- </col>
- <col width="13">
- </col>
- <col width="24">
- </col>
- </colgroup>
- </table>
- <p id="ch2intro_18d">
- For example:
- </p>
- <pre class="programlisting">
- $ command1 2> file1
- </pre>
- <p id="ch2intro_18e">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , directing the standard error stream to
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- .
- </p>
- <p id="ch2intro_18f">
- In shells derived from
- <span class="emphasis">
- <em>
- csh
- </em>
- </span>
- (the C shell), the syntax instead appends the & character to the redirect characters, thus achieving a similar result.
- </p>
- <p id="ch2intro_190">
- Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
- </p>
- <pre class="programlisting">
- $ find / -name .profile > results 2>&1
- </pre>
- <p id="ch2intro_191">
- will try to find all files named
- <span class="emphasis">
- <em>
- .profile
- </em>
- </span>
- . Executed without redirection, it will output hits to
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- and errors (e.g. for lack of privilege to traverse protected directories) to
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- . If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- (handle 2) into
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- (handle 1) using 2>&1 .
- </p>
- <p id="ch2intro_192">
- It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
- </p>
- <p id="ch2intro_193">
- If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus:
- </p>
- <pre class="programlisting">
- $ find / -name .profile 2>&1 | less
- </pre>
- <p id="ch2intro_194">
- A simplified form of the command:
- </p>
- <pre class="programlisting">
- $ command > file 2>&1
- </pre>
- <p id="ch2intro_195">
- is:
- </p>
- <pre class="programlisting">
- $ command &>file
- </pre>
- <p id="ch2intro_196">
- or:
- </p>
- <pre class="programlisting">
- $command >&file
- </pre>
- </div>
- <div class="section" title="12.4.Chained pipelines">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2837959">
- </a>
- 12.4.Chained pipelines
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_197">
- The redirection and piping tokens can be chained together to create complex commands. For example:
- </p>
- <pre class="programlisting">
- $ ls | grep '\.sh' | sort > shlist
- </pre>
- <p id="ch2intro_198">
- lists the contents of the current directory, where this output is filtered to only contain lines which contain
- <span class="emphasis">
- <em>
- .sh
- </em>
- </span>
- , sort this resultant output lexicographically, and place the final output in
- <span class="emphasis">
- <em>
- shlist
- </em>
- </span>
- . This type of construction is used very commonly in shell scripts and batch files.
- </p>
- </div>
- <div class="section" title="12.5.Redirect to multiple outputs">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2837993">
- </a>
- 12.5.Redirect to multiple outputs
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_199">
- The standard command
- <span class="emphasis">
- <em>
- tee
- </em>
- </span>
- can redirect output from a command to several destinations.
- </p>
- <pre class="programlisting">
- $ ls -lrt | tee xyz
- </pre>
- <p id="ch2intro_19a">
- This directs the file list output to both standard output as well as to the file
- <span class="emphasis">
- <em>
- xyz
- </em>
- </span>
- .
- </p>
- </div>
- </div>
- <div class="section" title="13.More Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2838023">
- </a>
- 13.More Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="13.1.grep">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2838032">
- </a>
- 13.1.grep
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_19b">
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- is a command line text search utility originally written for Unix. The name is taken from the first letters in
- <span class="emphasis">
- <em>
- global / regular expression / print
- </em>
- </span>
- , a series of instructions for the
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- text editor. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
- </p>
- <div class="section" title="13.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2838063">
- </a>
- 13.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch2intro_19c">
- This is an example of a common
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- usage:
- </p>
- <pre class="programlisting">
- $ grep apple fruitlist.txt
- </pre>
- <p id="ch2intro_19d">
- In this case,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- prints all lines containing 'apple' from the file
- <span class="emphasis">
- <em>
- fruitlist.txt
- </em>
- </span>
- , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
- </p>
- <p id="ch2intro_19e">
- Like most Unix commands,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- accepts command line arguments to change this and many other behaviors. For example:
- </p>
- <pre class="programlisting">
- $ grep -i apple fruitlist.txt
- </pre>
- <p id="ch2intro_19f">
- This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be case insensitive, or to ignore case.
- </p>
- <p id="ch2intro_1a0">
- To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
- </p>
- <pre class="programlisting">
- $ grep -w apple fruitlist.txt
- </pre>
- <p id="ch2intro_1a1">
- Regular expressions can be used to match more complicated queries.
- </p>
- <div class="section" title="13.1.1.1.Variations">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2838142">
- </a>
- 13.1.1.1.Variations
- </h5>
- </div>
- </div>
- </div>
- <p id="ch2intro_1a2">
- There are countless implementations and derivatives of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- available for many operating systems. Early variants of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- included
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- . The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- may also behave differently depending on the name by which it is invoked, allowing
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be links to the same program.
- </p>
- <p id="ch2intro_1a3">
- <span class="emphasis">
- <em>
- pcregrep
- </em>
- </span>
- is an implementation of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- that uses Perl regular expression syntax.
- </p>
- <p id="ch2intro_1a4">
- Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
- <span class="emphasis">
- <em>
- pgrep
- </em>
- </span>
- utility, for instance, displays the processes whose names match a given regular expression.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="13.2.tr">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2838221">
- </a>
- 13.2.tr
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_1a5">
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- (abbreviated from
- <span class="emphasis">
- <em>
- translate
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- transliterate
- </em>
- </span>
- ) is a command in Unix-like operating systems.
- </p>
- <p id="ch2intro_1a6">
- When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
- </p>
- <pre class="programlisting">
- $ tr 'abcd' 'jkmn'
- </pre>
- <p id="ch2intro_1a7">
- maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
- </p>
- <p id="ch2intro_1a8">
- Sets of characters may be abbreviated by using character ranges. The previous example could be written:
- </p>
- <pre class="programlisting">
- $ tr 'a-d' 'jkmn'
- </pre>
- <p id="ch2intro_1a9">
- In POSIX compliant versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
- </p>
- <p id="ch2intro_1aa">
- The
- <span class="emphasis">
- <em>
- -c
- </em>
- </span>
- flag complements the first set of characters.
- </p>
- <pre class="programlisting">
- $ tr -cd '[:alnum:]'
- </pre>
- <p id="ch2intro_1ab">
- therefore removes all non-alphanumeric characters.
- </p>
- <p id="ch2intro_1ac">
- The
- <span class="emphasis">
- <em>
- -s
- </em>
- </span>
- flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
- </p>
- <pre class="programlisting">
- $ tr -s '\n' '\n'
- </pre>
- <p id="ch2intro_1ad">
- replaces sequences of one or more newline characters with a single newline.
- </p>
- <p id="ch2intro_1ae">
- The
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
- </p>
- <pre class="programlisting">
- $ tr -d '\r'
- </pre>
- <p id="ch2intro_1af">
- Most versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , including GNU
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- and classic Unix
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
- </p>
- <p id="ch2intro_1b0">
- Ruby and Perl also have an internal
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- operator, which operates analogously. Tcl's
- <span class="emphasis">
- <em>
- string map
- </em>
- </span>
- command is more general in that it maps strings to strings while
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- maps characters to characters.
- </p>
- </div>
- </div>
- <div class="section" title="14.Elementary Regex">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2838370">
- </a>
- 14.Elementary Regex
- </h2>
- </div>
- </div>
- </div>
- <p id="ch2intro_1b1">
- In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
- </p>
- <p id="ch2intro_1b2">
- Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributionsincluding the editor
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- and the filter
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- were the first to popularize the concept of regular expressions.
- </p>
- <p id="ch2intro_1b3">
- Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
- <span class="emphasis">
- <em>
- Basic Regular Expressions
- </em>
- </span>
- (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
- </p>
- <p id="ch2intro_1b4">
- In the BRE syntax, most characters are treated as literals they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
- </p>
- <table summary="Elementary Regex" border="1">
- <colgroup>
- <col width="13">
- </col>
- <col width="60">
- </col>
- </colgroup>
- </table>
- <div class="section" title="14.1.Lazy quantification">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2838588">
- </a>
- 14.1.Lazy quantification
- </h3>
- </div>
- </div>
- </div>
- <p id="ch2intro_1c9">
- The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example:
- </p>
- <pre class="programlisting">
- Another whale explosion occurred on <January 26>, <2004>.
- </pre>
- <p id="ch2intro_1ca">
- ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the * quantifier is greedy it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
- </p>
- <p id="ch2intro_1cb">
- Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as
- <span class="emphasis">
- <em>
- lazy
- </em>
- </span>
- (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
- </p>
- </div>
- </div>
- <div class="section" title="15.One Liners">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2838664">
- </a>
- 15.One Liners
- </h2>
- </div>
- </div>
- </div>
- <p id="ch2intro_1cc">
- A
- <span class="emphasis">
- <em>
- one-liner
- </em>
- </span>
- is textual input to the command-line of an operating system shell that performs some function in just one line of input.
- </p>
- <p id="ch2intro_1cd">
- The one liner can be
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch2intro_1ce">
- An expression written in the language of the shell.
- </p>
- </li>
- <li class="listitem">
- <p id="ch2intro_1cf">
- The invocation of an interpreter together with program source for the interpreter to run.
- </p>
- </li>
- <li class="listitem">
- <p id="ch2intro_1d0">
- The invocation of a compiler together with source to compile and
-instructions for executing the compiled program.
- </p>
- </li>
- </ol>
- </div>
- <p id="ch2intro_1d1">
- Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
- </p>
- <p id="ch2intro_1d2">
- The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
- </p>
- <p id="ch2intro_1d3">
- The word
- <span class="emphasis">
- <em>
- One-liner
- </em>
- </span>
- has two references in the index of the book
- <span class="emphasis">
- <em>
- The AWK Programming Language
- </em>
- </span>
- (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
- </p>
- <pre class="programlisting">
- The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.
- </pre>
- <p id="ch2intro_1d4">
- Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
- </p>
- <p id="ch2intro_1d5">
- The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
- </p>
- <p id="ch2intro_1d6">
- Here are the first few of them:
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch2intro_1d7">
- Print the total number of input lines:
- </p>
- <p id="ch2intro_1d8">
- END { print NR }
- </p>
- </li>
- <li class="listitem">
- <p id="ch2intro_1d9">
- Print the tenth input line:
- </p>
- <p id="ch2intro_1da">
- NR == 10
- </p>
- </li>
- <li class="listitem">
- <p id="ch2intro_1db">
- Print the last field of every input line:
- </p>
- <p id="ch2intro_1dc">
- { print $NF }
- </p>
- </li>
- </ol>
- </div>
- <p id="ch2intro_1dd">
- One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
- </p>
- <p id="ch2intro_1de">
- The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:
- </p>
- <pre class="programlisting">
- main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
-*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
- </pre>
- <p id="ch2intro_1df">
- This one-liner program is a
- <span class="emphasis">
- <em>
- glob pattern matcher
- </em>
- </span>
- . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
- </p>
- <p id="ch2intro_1e0">
- Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:
- </p>
- <pre class="programlisting">
- $ prog foo 'f??'; echo $?
+elif condition:
+ statement_3
+ statement_4
+else:
+ statement_5
+ statement_6</pre>
+<p><a name="ch2intro_5c"></a>Let us look at an example:</p>
+<pre class="programlisting">>>> n = raw_input("Input a number:")
+>>> if n < 0:
+ print n," is negative"
+ elif n > 0:
+ print n," is positive"
+ else:
+ print n, " is 0"</pre>
+</div>
+<div class="section" title="7. raw_input()">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="id2632330"></a>7. <span class="strong"><strong>raw_input()</strong></span>
+</h2></div></div></div>
+<p><a name="ch2intro_5d"></a>In the previous example we saw the call to the raw_input() subroutine.
+The <span class="strong"><strong>raw_input()</strong></span> method is used to take user inputs through the console.
+Unlike <span class="strong"><strong>input()</strong></span> which assumes the data entered by the user as a standard python
+expression, <span class="strong"><strong>raw_input()</strong></span> treats all the input data as raw data and converts
+everything into a string. To illustrate this let us look at an example.</p>
+<pre class="programlisting">>>> input("Enter a number thats a palindrome:")
+Enter a number thats a palindrome:121
+121
-$ prog 'best short program' '??st*o**p?*'; echo $?
- </pre>
- <p id="ch2intro_1e1">
- Here is a one line shell script to show directories:
- </p>
- <pre class="programlisting">
- $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
- </pre>
- </div>
- </div>
- </div>
- </body>
+>>> input("Enter your name:")
+Enter your name:PythonFreak
+Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ File "<string>", line 1, in <module>
+NameError: name 'PythonFreak' is not defined</pre>
+<p><a name="ch2intro_5e"></a>As shown above the <span class="strong"><strong>input()</strong></span> assumes that the data entered is a valid Python
+expression. In the first call it prompts for an integer input and when entered
+it accepts the integer as an integer, whereas in the second call, when the string
+is entered without the quotes, <span class="strong"><strong>input()</strong></span> assumes that the entered data is a valid
+Python expression and hence it raises and exception saying PythonFreak is not
+defined.</p>
+<pre class="programlisting">>>> input("Enter your name:")
+Enter your name:'PythonFreak'
+'PythonFreak'
+>>></pre>
+<p><a name="ch2intro_5f"></a>Here the name is accepted because its entered as a string (within quotes). But
+its unreasonable to go on using quotes each time a string is entered. Hence the
+alternative is to use <span class="strong"><strong>raw_input()</strong></span>.</p>
+<p><a name="ch2intro_60"></a>Let us now look at how <span class="strong"><strong>raw_input()</strong></span> operates with an example.</p>
+<pre class="programlisting">>>> raw_input("Enter your name:")
+Enter your name:PythonFreak
+'PythonFreak'</pre>
+<p><a name="ch2intro_61"></a>Observe that the <span class="strong"><strong>raw_input()</strong></span> is converting it into a string all by itself.</p>
+<pre class="programlisting">>>> pal = raw_input("Enter a number thats a palindrome:")
+Enter a number thats a palindrome:121
+'121'</pre>
+<p><a name="ch2intro_62"></a>Observe that <span class="strong"><strong>raw_input()</strong></span> is converting the integer 121 also to a string as
+'121'. Let us look at another example:</p>
+<pre class="programlisting">>>> pal = raw_input("Enter a number thats a palindrome:")
+Enter a number thats a palindrome:121
+>>> pal + 2
+Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+TypeError: cannot concatenate 'str' and 'int' objects
+>>> pal
+'121'</pre>
+<p><a name="ch2intro_63"></a>Observe here that the variable <span class="emphasis"><em>pal</em></span> is a string and hence integer operations
+cannot be performed on it. Hence the exception is raised.</p>
+</div>
+<div class="section" title="8. int() method">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="id2632484"></a>8. <span class="strong"><strong>int()</strong></span> method</h2></div></div></div>
+<p><a name="ch2intro_64"></a>Generally for computing purposes, the data used is not strings or raw data but
+on integers, floats and similar mathematical data structures. The data obtained
+from <span class="strong"><strong>raw_input()</strong></span> is raw data in the form of strings. In order to obtain integers
+from strings we use the method <span class="strong"><strong>int()</strong></span>.</p>
+<p><a name="ch2intro_65"></a>Let us look at an example.</p>
+<pre class="programlisting">>>> intpal = int(pal)
+>>> intpal
+121</pre>
+<p><a name="ch2intro_66"></a>In the previous example it was observed that <span class="emphasis"><em>pal</em></span> was a string variable. Here
+using the <span class="strong"><strong>int()</strong></span> method the string <span class="emphasis"><em>pal</em></span> was converted to an integer variable.</p>
+<p><a name="ch2intro_67"></a><span class="emphasis"><em>Try This Yourself:</em></span></p>
+<pre class="programlisting">>>> stringvar = raw_input("Enter a name:")
+Enter a name:Guido Van Rossum
+>>> stringvar
+'Guido Van Rossum'
+>>> numvar = int(stringvar)</pre>
+</div>
+</div>
+</div></body>
</html>
--- a/SEESenv/web/html/ch3list_tuples.html Mon Feb 22 18:46:07 2010 +0530
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,5255 +0,0 @@
-<html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>
- Chapter. list_tuples
- </title>
- <link rel="stylesheet" href="/review/support/styles.css" type="text/css" />
- <meta name="generator" content="DocBook XSL Stylesheets V1.74.3" />
- <link rel="shortcut icon" type="image/png" href="/review/support/figs/favicon.png" />
- <script type="text/javascript" src="/review/support/jquery-min.js">
- </script>
- <script type="text/javascript" src="/review/support/form.js">
- </script>
- <script type="text/javascript" src="/review/support/hsbook.js">
- </script>
- </head>
- <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
- <div class="chapter" id="ch3list_tuples">
- <div class="titlepage">
- </div>
- <div class="toc">
- <p>
- <b>
- Table of Contents
- </b>
- </p>
- <dl>
- <dt>
- <span class="article">
- <a href="#id2514845">
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2324970">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2512665">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2565906">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2566178">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2566310">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2566318">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2566596">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2566604">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2566766">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2566826">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2566925">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2567008">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2567173">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2567182">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2567266">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2567457">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2567543">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2567596">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2567604">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2567913">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2568062">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2568228">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2568320">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2568329">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2568415">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2568541">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2568627">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2568759">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2565724">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2565732">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2569195">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2569305">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2569543">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2569812">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2569828">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2569851">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2569860">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2570624">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2570662">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2570731">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2570792">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2570996">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2571030">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2571061">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2571069">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2571258">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2571408">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2571625">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2571701">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- </dl>
- </div>
- <div class="article">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" id="id2514845">
- </h2>
- </div>
- </div>
- <hr />
- </div>
- <div class="toc">
- <p>
- <b>
- Table of Contents
- </b>
- </p>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2324970">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2512665">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2565906">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2566178">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2566310">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2566318">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2566596">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2566604">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2566766">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2566826">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2566925">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2567008">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2567173">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2567182">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2567266">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2567457">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2567543">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2567596">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2567604">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2567913">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2568062">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2568228">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2568320">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2568329">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2568415">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2568541">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2568627">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2568759">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2565724">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2565732">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2569195">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2569305">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2569543">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2569812">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2569828">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2569851">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2569860">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2570624">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2570662">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2570731">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2570792">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2570996">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2571030">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2571061">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2571069">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2571258">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2571408">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2571625">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2571701">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </div>
- <div class="section" title="1.Introducing Linux">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2324970">
- </a>
- 1.Introducing Linux
- </h2>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_1">
- (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
- </p>
- <p id="ch3list_tuples_2">
- Linux (usually pronounced lnks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
- </p>
- <p id="ch3list_tuples_3">
- Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
- </p>
- <p id="ch3list_tuples_4">
- The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
- </p>
- <div class="section" title="1.1.Historical Background">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2512665">
- </a>
- 1.1.Historical Background
- </h3>
- </div>
- </div>
- </div>
- <div class="section" title="1.1.1.Events leading to the creation">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2512631">
- </a>
- 1.1.1.Events leading to the creation
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_5">
- The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_6">
- In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="1.1.2.The Creation of Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2565861">
- </a>
- 1.1.2.The Creation of Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_7">
- In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
- </p>
- <p id="ch3list_tuples_8">
- Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
- </p>
- </div>
- </div>
- <div class="section" title="1.2.Design and Implications">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2565906">
- </a>
- 1.2.Design and Implications
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_9">
- A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
- </p>
- <div class="section" title="1.2.1.User Interface">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2565930">
- </a>
- 1.2.1.User Interface
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_a">
- Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
- </p>
- <p id="ch3list_tuples_b">
- A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
- </p>
- </div>
- <div class="section" title="1.2.2.Development">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2565984">
- </a>
- 1.2.2.Development
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_c">
- The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
- </p>
- <p id="ch3list_tuples_d">
- Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
- </p>
- <p id="ch3list_tuples_e">
- A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
- </p>
- </div>
- <div class="section" title="1.2.3.Community">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2566040">
- </a>
- 1.2.3.Community
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_f">
- A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
- </p>
- <p id="ch3list_tuples_10">
- In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
- </p>
- <p id="ch3list_tuples_11">
- Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
- </p>
- </div>
- <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2566085">
- </a>
- 1.2.4.Can I make a profit out of running a business involving Linux?
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_12">
- The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
- </p>
- </div>
- <div class="section" title="1.2.5.Programming on Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2566131">
- </a>
- 1.2.5.Programming on Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_13">
- Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
- </p>
- <p id="ch3list_tuples_14">
- Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
- </p>
- <p id="ch3list_tuples_15">
- The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
- </p>
- </div>
- </div>
- <div class="section" title="1.3.Reasons for Using Linux">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2566178">
- </a>
- 1.3.Reasons for Using Linux
- </h3>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_16">
- Linux is free:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_17">
- As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
-Most of all, Linux is free as in "free speech":
-The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_18">
- Linux is portable to any hardware platform:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_19">
- A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_1a">
- Linux was made to keep on running:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_1b">
- As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_1c">
- Linux is secure and versatile:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_1d">
- The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_1e">
- Linux is scalable:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_1f">
- From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_20">
- The Linux OS and Linux applications have very short debugtimes:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_21">
- Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
- </p>
- </div>
- </div>
- <div class="section" title="2.Getting Started">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2566310">
- </a>
- 2.Getting Started
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="2.1.Logging in, activating the user interface and logging out">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2566318">
- </a>
- 2.1.Logging in, activating the user interface and logging out
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_22">
- In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PCbased Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multiuser features, or in graphical console mode, which looks better but eats more system resources.
- </p>
- <div class="section" title="2.1.1.Graphical Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2566349">
- </a>
- 2.1.1.Graphical Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_23">
- This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
- </p>
- <p id="ch3list_tuples_24">
- To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
- <span class="emphasis">
- <em>
- OK
- </em>
- </span>
- or press
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- .
-It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
- </p>
- <p id="ch3list_tuples_25">
- After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
- </p>
- <p id="ch3list_tuples_26">
- To continue, you will need to open a
- <span class="emphasis">
- <em>
- terminal window
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
- <span class="emphasis">
- <em>
- Applications>Utilities->System Tools
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- Internet menu
- </em>
- </span>
- , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
- </p>
- <p id="ch3list_tuples_27">
- While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old pointnclick method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
- </p>
- <p id="ch3list_tuples_28">
- A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
- </p>
- <p id="ch3list_tuples_29">
- Another common form for a prompt is this one:
-[
- </p>
- <div class="reference">
- <div class="titlepage">
- <hr />
- </div>
- user@host
- </div>
- <p>
- dir]
- </p>
- <p id="ch3list_tuples_2a">
- In the above example,
- <span class="emphasis">
- <em>
- user
- </em>
- </span>
- will be your login name,
- <span class="emphasis">
- <em>
- hosts
- </em>
- </span>
- the name of the machine you are working on, and
- <span class="emphasis">
- <em>
- dir
- </em>
- </span>
- an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- icon or find
- <span class="emphasis">
- <em>
- Log Out
- </em>
- </span>
- in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
- </p>
- <p id="ch3list_tuples_2b">
- When you see the login screen again, asking to enter user name and password, logout was successful.
- </p>
- </div>
- <div class="section" title="2.1.2.Text Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2566507">
- </a>
- 2.1.2.Text Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_2c">
- One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
- </p>
- <p id="ch3list_tuples_2d">
- The login is different from a graphical login, in that you have to hit the
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- . You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
-reasons.
- </p>
- <p id="ch3list_tuples_2e">
- When the system has accepted you as a valid user, you may get some more information, called the
- <span class="emphasis">
- <em>
- message of the day
- </em>
- </span>
- , which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
- </p>
- <p id="ch3list_tuples_2f">
- Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a nonprivileged user.
- </p>
- <p id="ch3list_tuples_30">
- Logging out is done by entering the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't poweroff the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="3.Basic Commands">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2566596">
- </a>
- 3.Basic Commands
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="3.1.ls">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2566604">
- </a>
- 3.1.ls
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_31">
- When invoked without any arguments,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- is derived from
- <span class="emphasis">
- <em>
- list segments
- </em>
- </span>
- which was used in earlier systems.
- </p>
- <p id="ch3list_tuples_32">
- Files whose names start with "." are not listed, unless the
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- flag is specified or the files are specified explicitly.
- </p>
- <p id="ch3list_tuples_33">
- Without options,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_34">
- <span class="emphasis">
- <em>
- -l
- </em>
- </span>
- long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_35">
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_36">
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_37">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- recursively lists subdirectories. The command ls -R / would therefore list all files.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_38">
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_39">
- <span class="emphasis">
- <em>
- -t
- </em>
- </span>
- sort the list of files by modification time.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_3a">
- <span class="emphasis">
- <em>
- -h
- </em>
- </span>
- print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_3b">
- In some environments, providing the option
- <span class="emphasis">
- <em>
- --color
- </em>
- </span>
- (for GNU ls) or
- <span class="emphasis">
- <em>
- -G
- </em>
- </span>
- (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- would. To determine what color to use for a file, GNU
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks the Unix file type, the file permissions, and the file extension, while FreeBSD
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks only the Unix file type and file permissions.:
- </p>
- <pre class="programlisting">
- $ ls
-jeeves.rst psmith.html blandings.html
-$ ls -l
-drwxr--r-- 1 plum editors 4096 jeeves
--rw-r--r-- 1 plum editors 30405 psmith
--r-xr-xr-x 1 plum plum 8460 blandings
- </pre>
- <p id="ch3list_tuples_3c">
- Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
- </p>
- </div>
- <div class="section" title="3.2.date">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2566766">
- </a>
- 3.2.date
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_3d">
- The Unix date command displays the time and date. The super-user can use it to set the system clock.
- </p>
- <p id="ch3list_tuples_3e">
- With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:
- </p>
- <pre class="programlisting">
- $date
-Tue Sep 8 12:01:45 IST 2009
- </pre>
- <p id="ch3list_tuples_3f">
- On some systems to set the current date and time to September 8, 2004 01:22 you type:
- </p>
- <pre class="programlisting">
- $date --set="20040908 01:22"
- </pre>
- <p id="ch3list_tuples_40">
- In order to view the various options for the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command, type:
- </p>
- <pre class="programlisting">
- $man date
- </pre>
- <p id="ch3list_tuples_41">
- This will take you to the "Manual" page comprising of all the details on the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command. You can return to the terminal from the "man" page by pressing the
- <span class="emphasis">
- <em>
- Esc
- </em>
- </span>
- key in the keyboard and typing ":q" in that order.
- </p>
- </div>
- <div class="section" title="3.3.cd">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2566826">
- </a>
- 3.3.cd
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_42">
- This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, cd .. can be used.
- </p>
- <p id="ch3list_tuples_43">
- One dot '.' represents the current directory while two dots '..' represent the parent directory.
- </p>
- <p id="ch3list_tuples_44">
- cd - will return you to the previous directory (a bit like an undo).
- </p>
- <p id="ch3list_tuples_45">
- You can also use cd absolute path or cd relative path (see below):
- </p>
- <p id="ch3list_tuples_46">
- Absolute paths:
- </p>
- <p id="ch3list_tuples_47">
- An absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
- </p>
- <p id="ch3list_tuples_48">
- For example to get to /boot/grub you would type:
- </p>
- <pre class="programlisting">
- $cd /boot/grub
- </pre>
- <p id="ch3list_tuples_49">
- This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
- </p>
- <p id="ch3list_tuples_4a">
- Relative paths:
- </p>
- <p id="ch3list_tuples_4b">
- A relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
- </p>
- <p id="ch3list_tuples_4c">
- For example if you are in root's home directory and want to get to /root/music, you type:
- </p>
- <pre class="programlisting">
- $ cd music
- </pre>
- <p id="ch3list_tuples_4d">
- Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
- </p>
- </div>
- <div class="section" title="3.4.who">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2566925">
- </a>
- 3.4.who
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_4e">
- The standard Unix command
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- displays a list of users who are currently logged into a computer.
- </p>
- <p id="ch3list_tuples_4f">
- The
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command is related to the command
- <span class="emphasis">
- <em>
- w
- </em>
- </span>
- , which provides the same information but also displays additional data and statistics.:
- </p>
- <pre class="programlisting">
- $who
-beeblebrox tty7 2009-09-08 10:50 (:0)
-beeblebrox pts/0 2009-09-08 11:25 (:0.0)
-dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in)
-beeblebrox pts/2 2009-09-08 18:53 (:0.0)
- </pre>
- <p id="ch3list_tuples_50">
- The command can be invoked with the arguments
- <span class="emphasis">
- <em>
- am i
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- am I
- </em>
- </span>
- (so it is invoked as
- <span class="emphasis">
- <em>
- who am i
- </em>
- </span>
- or * who am I*), showing information about the current terminal only (see the
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- option below, of which this invocation is equivalent).
- </p>
- <p id="ch3list_tuples_51">
- In order to find out the various options that can be appended to the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command, check the
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page by typing out the following in the terminal:
- </p>
- <pre class="programlisting">
- $man who
- </pre>
- <p id="ch3list_tuples_52">
- This will take you to the "Manual" page containing details about the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command
- </p>
- </div>
- <div class="section" title="3.5.mkdir">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2567008">
- </a>
- 3.5.mkdir
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_53">
- This command is used to make a new directory. Normal usage is as straightforward as follows:
- </p>
- <pre class="programlisting">
- $mkdir name_of_directory
- </pre>
- <p id="ch3list_tuples_54">
- Where
- <span class="emphasis">
- <em>
- name_of_directory
- </em>
- </span>
- is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- will try to create all of them.
- </p>
- <div class="section" title="3.5.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2567039">
- </a>
- 3.5.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_55">
- On Unix-like operating systems,
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- takes options. Three of the most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_56">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- : will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_57">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- : display each directory that mkdir creates. Most often used with -p.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_58">
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- : specify the octal permissions of directories created by mkdir.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_59">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
- </p>
- </div>
- <div class="section" title="3.5.2.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2567098">
- </a>
- 3.5.2.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_5a">
- An example of
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- in action is:
- </p>
- <pre class="programlisting">
- $mkdir -p /tmp/a/b/c
- </pre>
- <p id="ch3list_tuples_5b">
- If
- <span class="emphasis">
- <em>
- /tmp/a
- </em>
- </span>
- exists but
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- does not, mkdir will create
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- before creating
- <span class="emphasis">
- <em>
- /tmp/a/b/c
- </em>
- </span>
- .
- </p>
- <p id="ch3list_tuples_5c">
- And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
- </p>
- <pre class="programlisting">
- $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
- </pre>
- <p id="ch3list_tuples_5d">
- This will create:
- </p>
- tmpdir - branches
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_5e">
- tag
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- trunk - sources - includes
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_5f">
- docs
- </p>
- </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="4.Getting Help">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2567173">
- </a>
- 4.Getting Help
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="4.1.apropos and whatis">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2567182">
- </a>
- 4.1.apropos and whatis
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_60">
- This is a command to search the manual pages files in Unix and Unix-like operating systems.
- </p>
- <pre class="programlisting">
- $ apropos grep
-egrep egrep (1) Search a file for a pattern using full regular expressions
-fgrep fgrep (1) Search a file for a fixed-character string
-fmlgrep fmlgrep (1) Search a file for a pattern
-grep grep (1) Search a file for a pattern
-gzgrep gzgrep (1) Search a possibly compressed file for a regular expression
-nisgrep nismatch (1) Utilities for searching NIS+ tables
-pgrep pgrep (1) Find or signal a process by name or other attribute
-zgrep zgrep (1) Search a possibly compressed file for a regular expression
-...
- </pre>
- <p id="ch3list_tuples_61">
- In this example, the user uses
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- to search for the string "grep", and apropos returns the indicated
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- pages that include the term "grep".
- </p>
- <p id="ch3list_tuples_62">
- A short index of explanations for commands is available using the
- <span class="emphasis">
- <em>
- whatis
- </em>
- </span>
- command, like in the examples below:
- </p>
- <pre class="programlisting">
- $whatis ls
-ls (1) - list directory contents
- </pre>
- <p id="ch3list_tuples_63">
- This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
- </p>
- <p id="ch3list_tuples_64">
- If you don't know where to get started and which man page to read,
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- gives more information. Say that you do not know how to start a browser, then you could enter the following command:
- </p>
- <pre class="programlisting">
- $apropos browser
-gmusicbrowser (1) - Jukebox for large collections of audio files
-infobrowser (1) - read Info documents
-libsmbclient (7) - An extension library for browsers and that can be used...
-opera (1) - a standards-compliant graphical Web browser
-sensible-browser (1) - sensible editing, paging, and web browsing
-smbtree (1) - A text based smb network browser
-tvtk_doc (1) - A GUI based TVTK documentation search browser.
-viewres (1) - graphical class browser for Xt
-w3m (1) - a text based Web browser and pager
-www-browser (1) - a text based Web browser and pager
-...
- </pre>
- </div>
- <div class="section" title="4.2.man">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2567266">
- </a>
- 4.2.man
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_65">
- Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- . Each page is a self-contained document.
- </p>
- <p id="ch3list_tuples_66">
- To read a manual page for a Unix command, one can use:
- </p>
- <pre class="programlisting">
- $ man <command_name>
- </pre>
- <p id="ch3list_tuples_67">
- at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- generally uses the less terminal pager.
- </p>
- <p id="ch3list_tuples_68">
- Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are
- <span class="emphasis">
- <em>
- man(1)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- man(7)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- exit(2)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- exit(3)
- </em>
- </span>
- . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
- <span class="emphasis">
- <em>
- BSD, for example, the syntax for reading *printf(3)
- </em>
- </span>
- is:
- </p>
- <pre class="programlisting">
- $man 3 printf
- </pre>
- <p id="ch3list_tuples_69">
- Another example:
- </p>
- <pre class="programlisting">
- $man man
- </pre>
- <p id="ch3list_tuples_6a">
- The previous example will take you to the "Manual" page entry about manual pages!
- </p>
- <div class="section" title="4.2.1.Layout">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2567348">
- </a>
- 4.2.1.Layout
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_6b">
- All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
- </p>
- NAME
- <p id="ch3list_tuples_6c">
- The name of the command or function, followed by a one-line description of what it does.
- </p>
- SYNOPSIS
- <p id="ch3list_tuples_6d">
- In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
- </p>
- DESCRIPTION
- <p id="ch3list_tuples_6e">
- A textual description of the functioning of the command or function.
- </p>
- EXAMPLES
- <p id="ch3list_tuples_6f">
- Some examples of common usage.
- </p>
- SEE ALSO
- <p id="ch3list_tuples_70">
- A list of related commands or functions.
- </p>
- <p id="ch3list_tuples_71">
- Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
- </p>
- <p id="ch3list_tuples_72">
- These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
- </p>
- <p id="ch3list_tuples_73">
- However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
- </p>
- <p id="ch3list_tuples_74">
- Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
- </p>
- <p id="ch3list_tuples_75">
- Usually the man pages are written in English. Translations into other languages can be also available on the system.
- </p>
- <p id="ch3list_tuples_76">
- The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
- </p>
- </div>
- </div>
- <div class="section" title="4.3.info">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2567457">
- </a>
- 4.3.info
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_77">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
- </p>
- <p id="ch3list_tuples_78">
- The syntax is
- </p>
- <pre class="programlisting">
- $ info <command_name>
- </pre>
- <p id="ch3list_tuples_79">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_7a">
- <span class="emphasis">
- <em>
- n
- </em>
- </span>
- goes to the next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_7b">
- <span class="emphasis">
- <em>
- p
- </em>
- </span>
- goes to the previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_7c">
- <span class="emphasis">
- <em>
- u
- </em>
- </span>
- goes to the upper page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_7d">
- <span class="emphasis">
- <em>
- l
- </em>
- </span>
- goes to the last(visited) node
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_7e">
- To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_7f">
- info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
- </p>
- </div>
- <div class="section" title="4.4.--help">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2567543">
- </a>
- 4.4.--help
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_80">
- Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command:
- </p>
- <pre class="programlisting">
- $ userprompt@host: cat --help
-Usage: cat [OPTION] [FILE]...
-Concatenate FILE(s), or standard input, to standard output.
-
- -A, --show-all equivalent to -vET
- -b, --number-nonblank number nonempty output lines
- -e equivalent to -vE
- -E, --show-ends display $ at end of each line
- -n, --number number all output lines
- -s, --squeeze-blank suppress repeated empty output lines
- -t equivalent to -vT
- -T, --show-tabs display TAB characters as ^I
- -u (ignored)
- -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
- --help display this help and exit
- --version output version information and exit
-
-With no FILE, or when FILE is -, read standard input.
-
-Examples:
- cat f - g Output f's contents, then standard input, then g's contents.
- cat Copy standard input to standard output.
-
-Report bugs to <bug-coreutils@gnu.org>.
- </pre>
- </div>
- </div>
- <div class="section" title="5.Basic file handling">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2567596">
- </a>
- 5.Basic file handling
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="5.1.cp">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2567604">
- </a>
- 5.1.cp
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_81">
- <span class="emphasis">
- <em>
- cp
- </em>
- </span>
- is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
- </p>
- <div class="section" title="5.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2567622">
- </a>
- 5.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_82">
- To copy a file to another file:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
- </pre>
- <p id="ch3list_tuples_83">
- To copy a file to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
- </pre>
- <p id="ch3list_tuples_84">
- To copy a directory to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
-SourceDirectory ... TargetDirectory
- </pre>
- </div>
- <div class="section" title="5.1.2.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2567656">
- </a>
- 5.1.2.Flags
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_85">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (force) specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
- </p>
- <p id="ch3list_tuples_86">
- <span class="emphasis">
- <em>
- -P
- </em>
- </span>
- makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
- </p>
- <p id="ch3list_tuples_87">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- (interactive) prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
- </p>
- <p id="ch3list_tuples_88">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- (preserve) duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_89">
- The time of the last data modification and the time of the last access.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_8a">
- The user ID and group ID (only if it has permissions to do this)
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_8b">
- The file permission bits and the SUID and SGID bits.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_8c">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- (recursive) copy directories (recursively copying all the contents)
- </p>
- </div>
- <div class="section" title="5.1.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2567752">
- </a>
- 5.1.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_8d">
- To make a copy of a file in the current directory, enter:
- </p>
- <pre class="programlisting">
- $ cp prog.c prog.bak
- </pre>
- <p id="ch3list_tuples_8e">
- This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
- </p>
- <p id="ch3list_tuples_8f">
- To copy a file in your current directory into another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod /home/books/hhgg
- </pre>
- <p id="ch3list_tuples_90">
- This copies the jones file to /home/books/hhgg/zaphod.
- </p>
- <p id="ch3list_tuples_91">
- To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
- </p>
- <pre class="programlisting">
- $ cp -p martin_luther_king martin_luther_king.jr
- </pre>
- <p id="ch3list_tuples_92">
- This copies the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file to the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file. Instead of creating the file with the current date and time stamp, the system gives the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file the same date and time as the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file. The
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file also inherits the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file's access control protection.
- </p>
- <p id="ch3list_tuples_93">
- To copy all the files in a directory to a new directory, enter:
- </p>
- <pre class="programlisting">
- $ cp /home/galactica/clients/* /home/hhgg/customers
- </pre>
- <p id="ch3list_tuples_94">
- This copies only the files in the clients directory to the customers directory.
- </p>
- <p id="ch3list_tuples_95">
- To copy a directory, including all its files and subdirectories, to another directory, enter:
- </p>
- <p id="ch3list_tuples_96">
- $ cp -R /home/hhgg/clients /home/hhgg/customers
- </p>
- <p id="ch3list_tuples_97">
- This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
- </p>
- <p id="ch3list_tuples_98">
- To copy a specific set of files of any extension to another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod arthur ford /home/hhgg/clients
- </pre>
- <p id="ch3list_tuples_99">
- This copies the
- <span class="emphasis">
- <em>
- zaphod
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- arthur
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- ford
- </em>
- </span>
- files in your current working directory to the /home/hhgg/clients directory.
- </p>
- <p id="ch3list_tuples_9a">
- To use pattern-matching characters to copy files, enter:
- </p>
- <pre class="programlisting">
- $ cp programs/*.py .
- </pre>
- <p id="ch3list_tuples_9b">
- This copies the files in the programs directory that end with
- <span class="emphasis">
- <em>
- .py
- </em>
- </span>
- to the current directory, signified by the single "." (dot). You must type a space between the
- <span class="emphasis">
- <em>
- py
- </em>
- </span>
- and the final dot.
- </p>
- </div>
- </div>
- <div class="section" title="5.2.mv">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2567913">
- </a>
- 5.2.mv
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_9c">
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system),
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- will rename the file instead. Write permission is required on all directories being modified.
- </p>
- <div class="section" title="5.2.1.Conflicting existing file">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2567937">
- </a>
- 5.2.1.Conflicting existing file
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_9d">
- In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
- </p>
- </div>
- <div class="section" title="5.2.2.Differences with copy and delete">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2567956">
- </a>
- 5.2.2.Differences with copy and delete
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_9e">
- Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
- </p>
- </div>
- <div class="section" title="5.2.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2568003">
- </a>
- 5.2.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ mv myfile mynewfilename renames a file
-$ mv myfile otherfilename renames a file and deletes the existing file "myfile"
-$ mv myfile /myfile moves 'myfile' from the current directory to the root directory
-$ mv myfile dir/myfile moves 'myfile' to 'dir/myfile' relative to the current directory
-$ mv myfile dir same as the previous command (the filename is implied to be the same)
-$ mv myfile dir/myfile2 moves 'myfile' to dir and renames it to 'myfile2'
-$ mv foo bar baz dir moves multiple files to directory dir
-$ mv --help shows a very concise help about the syntax of the command
-$ man mv prints an extensive user manual for 'mv' in the terminal
- </pre>
- <p id="ch3list_tuples_9f">
- In all cases, the file or files being moved or renamed can be a directory.
- </p>
- <p id="ch3list_tuples_a0">
- Note that when the command is called with two arguments (as
- <span class="emphasis">
- <em>
- mv name1 name2
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- mv name1 /dir/name2
- </em>
- </span>
- ), it can have three different effects, depending on whether
- <span class="emphasis">
- <em>
- name2
- </em>
- </span>
- does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
- <span class="emphasis">
- <em>
- /.
- </em>
- </span>
- (or in some Unix versions
- <span class="emphasis">
- <em>
- /
- </em>
- </span>
- is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
- </p>
- </div>
- </div>
- <div class="section" title="5.3.rm">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2568062">
- </a>
- 5.3.rm
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_a1">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
- </p>
- <p id="ch3list_tuples_a2">
- Here's example to remove a file named "foo" from a directory, here shown with the -i option:
- </p>
- <pre class="programlisting">
- $ rm -i foo
-remove foo? y
- </pre>
- <div class="section" title="5.3.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2568091">
- </a>
- 5.3.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_a3">
- Common options that rm accepts include:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_a4">
- <span class="emphasis">
- <em>
- -r
- </em>
- </span>
- , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_a5">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- , which asks for every deletion to be confirmed ("interactive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_a6">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- , which ignores non-existent files and overrides any confirmation prompts ("force")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_a7">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- , which shows what is being removed as it happens ("verbose")
- </p>
- </li>
- </ul>
- </div>
- <p id="ch3list_tuples_a8">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
- </p>
- <p id="ch3list_tuples_a9">
- <span class="emphasis">
- <em>
- rm -rf
- </em>
- </span>
- (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
- </p>
- <p id="ch3list_tuples_aa">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often used in conjunction with xargs to supply a list of files to delete:
- </p>
- <pre class="programlisting">
- xargs rm < filelist
- </pre>
- <p id="ch3list_tuples_ab">
- When
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is used on a symbolic link, it deletes the link, but does not affect the target of the link.
- </p>
- </div>
- <div class="section" title="5.3.2.Permissions">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2568188">
- </a>
- 5.3.2.Permissions
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_ac">
- Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
- </p>
- <p id="ch3list_tuples_ad">
- To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
- </p>
- <p id="ch3list_tuples_ae">
- If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="6.Command Line Arguments">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2568228">
- </a>
- 6.Command Line Arguments
- </h2>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_af">
- In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
- </p>
- <p id="ch3list_tuples_b0">
- For example, in Unix and Unix-like environments, an example of a command-line argument is:
- </p>
- <pre class="programlisting">
- rm file.s
- </pre>
- <p id="ch3list_tuples_b1">
- "file.s" is a command line argument which tells the program rm to remove the file "file.s".
- </p>
- <p id="ch3list_tuples_b2">
- Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
- </p>
- <p id="ch3list_tuples_b3">
- A command line option or simply
- <span class="emphasis">
- <em>
- option
- </em>
- </span>
- (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
- </p>
- <p id="ch3list_tuples_b4">
- Long options are introduced via "--", and are typically whole words. For example,
- <span class="emphasis">
- <em>
- ls --long --classify --all
- </em>
- </span>
- . Arguments to long options are provided with "=", as
- <span class="emphasis">
- <em>
- ls --block-size=1024
- </em>
- </span>
- . Some Unix programs use long options with single dashes, for example MPlayer as in
- <span class="emphasis">
- <em>
- mplayer -nosound
- </em>
- </span>
- .
- </p>
- <p id="ch3list_tuples_b5">
- Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- by using
- <span class="emphasis">
- <em>
- rm -file1
- </em>
- </span>
- may produce an error, since rm may interpret
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- as a command line switch. Using
- <span class="emphasis">
- <em>
- rm -- -file1
- </em>
- </span>
- removes ambiguity.
- </p>
- </div>
- <div class="section" title="7.Basic Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2568320">
- </a>
- 7.Basic Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="7.1.head">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2568329">
- </a>
- 7.1.head
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_b6">
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:
- </p>
- <pre class="programlisting">
- $ head [options] <file_name>
- </pre>
- <p id="ch3list_tuples_b7">
- By default,
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ head -n 20 filename
- </pre>
- <p id="ch3list_tuples_b8">
- This displays the first 5 lines of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ head -n 5 foo*
- </pre>
- <p id="ch3list_tuples_b9">
- Some versions omit the n and just let you say -5.
- </p>
- <div class="section" title="7.1.1.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2568379">
- </a>
- 7.1.1.Flags
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- -c <x number of bytes> Copy first x number of bytes.
- </pre>
- <p id="ch3list_tuples_ba">
- Other options:
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- </p>
- <p id="ch3list_tuples_bb">
- Many early versions of Unix did not have this command, and so documentation and books had
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- do this job:
- </p>
- <pre class="programlisting">
- sed 5q foo
- </pre>
- <p id="ch3list_tuples_bc">
- This says to print every line (implicit), and quit after the fifth.
- </p>
- </div>
- </div>
- <div class="section" title="7.2.tail">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2568415">
- </a>
- 7.2.tail
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_bd">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
- </p>
- <p id="ch3list_tuples_be">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ tail [options] <file_name>
- </pre>
- <p id="ch3list_tuples_bf">
- By default,
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ tail -n 20 filename
- </pre>
- <p id="ch3list_tuples_c0">
- This example shows the last 15 bytes of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ tail -c 15 foo*
- </pre>
- <p id="ch3list_tuples_c1">
- This example shows all lines of filename from the second line onwards:
- </p>
- <pre class="programlisting">
- $ tail -n +2 filename
- </pre>
- <p id="ch3list_tuples_c2">
- Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:
- </p>
- <pre class="programlisting">
- $ tail -20 filename
-$ tail -50c filename
- </pre>
- <p id="ch3list_tuples_c3">
- However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
- </p>
- <div class="section" title="7.2.1.File monitoring">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2568493">
- </a>
- 7.2.1.File monitoring
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_c4">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- has a special command line option
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:
- </p>
- <pre class="programlisting">
- $ tail -f /var/adm/messages
- </pre>
- <p id="ch3list_tuples_c5">
- To interrupt tail while it is monitoring, break-in with
- <span class="emphasis">
- <em>
- Ctrl+C
- </em>
- </span>
- . This command can be run "in the background" with &, see job control.
- </p>
- <p id="ch3list_tuples_c6">
- If you have a command's result to monitor, you can use the
- <span class="emphasis">
- <em>
- watch
- </em>
- </span>
- command.
- </p>
- </div>
- </div>
- <div class="section" title="7.3.cut">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2568541">
- </a>
- 7.3.cut
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_c7">
- In computing,
- <span class="emphasis">
- <em>
- cut
- </em>
- </span>
- is a Unix command line utility which is used to extract sections from each line of input usually from a file.
- </p>
- <p id="ch3list_tuples_c8">
- Extraction of line segments can typically be done by
- <span class="emphasis">
- <em>
- bytes (-b), characters (-c)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- fields (-f)
- </em>
- </span>
- separated by a
- <span class="emphasis">
- <em>
- delimiter (-d the tab character by default)
- </em>
- </span>
- . A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
- </p>
- <p id="ch3list_tuples_c9">
- Assuming a file named file containing the lines:
- </p>
- <pre class="programlisting">
- foo:bar:baz:qux:quux
-one:two:three:four:five:six:seven
-alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- <p id="ch3list_tuples_ca">
- To output the fourth through tenth characters of each line:
- </p>
- <pre class="programlisting">
- $ cut -c 4-10 file
- </pre>
- <p id="ch3list_tuples_cb">
- This gives the output:
- </p>
- <pre class="programlisting">
- :bar:ba
-:two:th
-ha:beta
- </pre>
- <p id="ch3list_tuples_cc">
- To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
- </p>
- <pre class="programlisting">
- $ cut -d : -f 5- file
- </pre>
- <p id="ch3list_tuples_cd">
- This gives the output:
- </p>
- <pre class="programlisting">
- quux
-five:six:seven
-epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- </div>
- <div class="section" title="7.4.paste">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2568627">
- </a>
- 7.4.paste
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_ce">
- <span class="emphasis">
- <em>
- paste
- </em>
- </span>
- is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command which operates on the vertical plane of two or more files.
- </p>
- <p id="ch3list_tuples_cf">
- To paste several columns of data together into the file
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- from files
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- where
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- when
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ paste who where when > www
- </pre>
- <p id="ch3list_tuples_d0">
- If the files contain:
- </p>
- <table summary="paste" border="1">
- <colgroup>
- <col width="11">
- </col>
- <col width="12">
- </col>
- <col width="12">
- </col>
- </colgroup>
- </table>
- <p id="ch3list_tuples_dd">
- This creates the file named
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- containing:
- </p>
- <pre class="programlisting">
- Batman GothamCity January 3
-Trillian Andromeda February 4
-Jeeves London March 19
- </pre>
- </div>
- </div>
- <div class="section" title="8.Shell Meta Characters">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2568759">
- </a>
- 8.Shell Meta Characters
- </h2>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_de">
- Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
- </p>
- <p id="ch3list_tuples_df">
- The shell meta characters include:
- </p>
- <p id="ch3list_tuples_e0">
- / < > ! $ % ^ & * | { } [ ] " ' ` ~ ;
- </p>
- <p id="ch3list_tuples_e1">
- Different shells may differ in the meta characters recognized.
- </p>
- <p id="ch3list_tuples_e2">
- As an example,
- </p>
- <pre class="programlisting">
- $ ls file.*
- </pre>
- <p id="ch3list_tuples_e3">
- run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
- </p>
- <pre class="programlisting">
- $ ls file.?
- </pre>
- <p id="ch3list_tuples_e4">
- run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:
- </p>
- <pre class="programlisting">
- $ more c*
- </pre>
- <p id="ch3list_tuples_e5">
- because the c* matches that long file name.
- </p>
- <p id="ch3list_tuples_e6">
- Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named "``*`|more"` can be accomplished with:
- </p>
- <pre class="programlisting">
- $ rm ??more
- </pre>
- <p id="ch3list_tuples_e7">
- or:
- </p>
- <pre class="programlisting">
- $ rm $\backslash$*$\backslash$|more
- </pre>
- <p id="ch3list_tuples_e8">
- or:
- </p>
- <pre class="programlisting">
- $ rm ''*|more''
- </pre>
- </div>
- <div class="section" title="9.Looking At Files">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2565724">
- </a>
- 9.Looking At Files
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="9.1.cat">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2565732">
- </a>
- 9.1.cat
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_e9">
- The
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
- <span class="emphasis">
- <em>
- concatenate
- </em>
- </span>
- .
- </p>
- <p id="ch3list_tuples_ea">
- The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
- </p>
- <p id="ch3list_tuples_eb">
- If the filename is specified as -, then
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input at that point in the sequence. If no files are specified,
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input entered.
- </p>
- <div class="section" title="9.1.1.Jargon File Definition">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2565775">
- </a>
- 9.1.1.Jargon File Definition
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_ec">
- The Jargon File version 4.4.7 lists this as the definition of
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- 1. To spew an entire file to the screen or some other output sink without
- pause (syn. blast).
-
-2. By extension, to dump large amounts of data at an unprepared target or
- with no intention of browsing it carefully. Usage: considered silly.
- Rare outside Unix sites. See also dd, BLT.
-
- Among Unix fans, *cat(1)* is considered an excellent example of
- user-interface design, because it delivers the file contents without
- such verbosity as spacing or headers between the files, and because
- it does not require the files to consist of lines of text, but works
- with any sort of data.
-
- Among Unix critics, *cat(1)* is considered the canonical example of
- bad user-interface design, because of its woefully unobvious name.
- It is far more often used to blast a single file to standard output
- than to concatenate two or more files. The name cat for the former
- operation is just as unintuitive as, say, LISP's cdr.
-
- Of such oppositions are holy wars made...
- </pre>
- </div>
- <div class="section" title="9.1.2.Useless Use of 'cat'">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2569091">
- </a>
- 9.1.2.Useless Use of 'cat'
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_ed">
- UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
- <span class="emphasis">
- <em>
- comp.unix.shell
- </em>
- </span>
- , The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
- </p>
- <p id="ch3list_tuples_ee">
- Nevertheless one sees people doing:
- </p>
- <pre class="programlisting">
- $ cat file | some_command and its args ...
- </pre>
- <p id="ch3list_tuples_ef">
- instead of the equivalent and cheaper:
- </p>
- <pre class="programlisting">
- <file some_command and its args ...
- </pre>
- <p id="ch3list_tuples_f0">
- or (equivalently and more classically):
- </p>
- <pre class="programlisting">
- some_command and its args ... <file
- </pre>
- <p id="ch3list_tuples_f1">
- Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
- </p>
- <p id="ch3list_tuples_f2">
- Amongst many, it is still considered safer to use
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
- </p>
- </div>
- <div class="section" title="9.1.3.zcat">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2569161">
- </a>
- 9.1.3.zcat
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_f3">
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- is a Unix program similar to
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- , that decompresses individual files and concatenates them to standard output. Traditionally
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- operated on files compressed by compress but today it is usually able to operate on
- <span class="emphasis">
- <em>
- gzip
- </em>
- </span>
- or even
- <span class="emphasis">
- <em>
- bzip2
- </em>
- </span>
- archives. On such systems, it is equivalent to
- <span class="emphasis">
- <em>
- gunzip -c
- </em>
- </span>
- </p>
- </div>
- </div>
- <div class="section" title="9.2.more">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2569195">
- </a>
- 9.2.more
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_f4">
- In computing,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
- </p>
- <div class="section" title="9.2.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2569214">
- </a>
- 9.2.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_f5">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ more [options] [file_name]
- </pre>
- <p id="ch3list_tuples_f6">
- If no file name is provided,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- looks for input from stdin.
- </p>
- <p id="ch3list_tuples_f7">
- Once
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has paged through. (This percentage includes the text displayed on the current screen.) When
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- , which advances the output by one line, and
- <span class="emphasis">
- <em>
- Space
- </em>
- </span>
- , which advances the output by one screen.
- </p>
- <p id="ch3list_tuples_f8">
- There are also other commands that can be used while navigating through the document; consult
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- 's
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page for more details.
- </p>
- <p id="ch3list_tuples_f9">
- <span class="emphasis">
- <em>
- Options
- </em>
- </span>
- are typically entered before the file name, but can also be entered in the environment variable
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- . Options entered in the actual command line will override those entered in the
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- environment variable. Available options may vary between Unix systems.
- </p>
- </div>
- </div>
- <div class="section" title="9.3.less">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2569305">
- </a>
- 9.3.less
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_fa">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- does not need to read the entire file before starting, resulting in faster load times with large files.
- </p>
- <div class="section" title="9.3.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2569333">
- </a>
- 9.3.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_fb">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- vi
- </em>
- </span>
- . It is also possible to search for character patterns in the file.
- </p>
- <p id="ch3list_tuples_fc">
- By default,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
- </p>
- <p id="ch3list_tuples_fd">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ less [options] file_name
- </pre>
- </div>
- <div class="section" title="9.3.2.Frequently Used Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2569388">
- </a>
- 9.3.2.Frequently Used Options
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_fe">
- -g: Highlights just the current match of any searched string.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_ff">
- -I: Case-insensitive searches.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_100">
- -M: Shows more detailed prompt, including file position.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_101">
- -N: Shows line numbers (useful for source code viewing).
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_102">
- -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_103">
- -?: Shows help.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.3.Frequently Used Commands">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2569439">
- </a>
- 9.3.3.Frequently Used Commands
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_104">
- [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_105">
- [Space bar]: Next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_106">
- b: Previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_107">
- ng: Jump to line number n. Default is the start of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_108">
- nG: Jump to line number n. Default is the end of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_109">
- /pattern: Search for pattern. Regular expressions can be used.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_10a">
- '^ or g: Go to start of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_10b">
- '$ or G: Go to end of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_10c">
- s: Save current content (got from another program like grep) in a file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_10d">
- =: File information.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_10e">
- h: Help.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_10f">
- q: Quit.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.4.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2569527">
- </a>
- 9.3.4.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ less -M readme.txt #Read "readme.txt."
-$ less +F /var/log/mail.log #Follow mode for log
-$ file * | less #Easier file analysis.
-$ grep -i void *.c | less -I -p void #Case insensitive search for "void" in all .c files
- </pre>
- </div>
- </div>
- </div>
- <div class="section" title="10.Directory Structure">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2569543">
- </a>
- 10.Directory Structure
- </h2>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_110">
- In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
- </p>
- <p id="ch3list_tuples_111">
- The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
- </p>
- <table summary="Directory Structure" border="1">
- <colgroup>
- <col width="15">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <div class="section" title="10.1.man hier">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2569812">
- </a>
- 10.1.man hier
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_136">
- This is the manual page on the UNIX filesystem. The syntax for this is:
- </p>
- <pre class="programlisting">
- $ man hier
- </pre>
- </div>
- <div class="section" title="10.2.ls -l">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2569828">
- </a>
- 10.2.ls -l
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_137">
- Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
- </p>
- <pre class="programlisting">
- $ ls -l
- </pre>
- <p id="ch3list_tuples_138">
- This can be done after entering the required directory.
- </p>
- </div>
- </div>
- <div class="section" title="11.Permissions and Ownership">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2569851">
- </a>
- 11.Permissions and Ownership
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="11.1.chmod">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2569860">
- </a>
- 11.1.chmod
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_139">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.
- </p>
- <div class="section" title="11.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2569886">
- </a>
- 11.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_13a">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command options are specified like this:
- </p>
- <pre class="programlisting">
- $ chmod [options] mode[,mode] file1 [file2 ...]
- </pre>
- <p id="ch3list_tuples_13b">
- To view what the permissions currently are, type:
- </p>
- <pre class="programlisting">
- $ ls -l file
- </pre>
- </div>
- <div class="section" title="11.1.2.Command line options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2569914">
- </a>
- 11.1.2.Command line options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_13c">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command has a number of command line options that affect its behavior. The most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_13d">
- -R: Changes the modes of directories and files recursively
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch3list_tuples_13e">
- -v: Verbose mode; lists all files as they are being processed
- </p>
- </li>
- </ul>
- </div>
- <div class="section" title="11.1.2.1.Symbolic modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2569949">
- </a>
- 11.1.2.1.Symbolic modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_13f">
- To the
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
- </p>
- <pre class="programlisting">
- $ chmod [references][operator][modes] file1 ...
- </pre>
- <p id="ch3list_tuples_140">
- The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="8">
- </col>
- <col width="45">
- </col>
- </colgroup>
- </table>
- <p id="ch3list_tuples_150">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="54">
- </col>
- </colgroup>
- </table>
- <p id="ch3list_tuples_157">
- The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="5">
- </col>
- <col width="14">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <p id="ch3list_tuples_16d">
- The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
- </p>
- </div>
- <div class="section" title="11.1.2.2.Symbolic examples">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2570495">
- </a>
- 11.1.2.2.Symbolic examples
- </h5>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_16e">
- Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
- </p>
- <pre class="programlisting">
- $ chmod ug+rw mydir
-$ ls -ld mydir
-drw-rw---- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- <p id="ch3list_tuples_16f">
- For a file, remove
- <span class="emphasis">
- <em>
- write
- </em>
- </span>
- permissions for all classes:
- </p>
- <pre class="programlisting">
- $ chmod a-w myfile
-$ ls -l myfile
--r-xr-xr-x 2 starwars yoda 96 Dec 8 12:53 myfile
- </pre>
- <p id="ch3list_tuples_170">
- Set the permissions for the
- <span class="emphasis">
- <em>
- u*ser and the *g*roup to read and execute only (no write permission) on *mydir
- </em>
- </span>
- .
- </p>
- <pre class="programlisting">
- $ chmod ug=rx mydir
-$ ls -ld mydir
-dr-xr-x--- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- </div>
- <div class="section" title="11.1.2.3.Octal numbers">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2570536">
- </a>
- 11.1.2.3.Octal numbers
- </h5>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_171">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
- </p>
- <pre class="programlisting">
- $ chmod 664 myfile
-$ ls -l myfile
--rw-rw-r-- 1 57 Jul 3 10:13 myfile
- </pre>
- <p id="ch3list_tuples_172">
- Since the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- sticky
- </em>
- </span>
- bits are not set, this is equivalent to:
- </p>
- <pre class="programlisting">
- $ chmod 0664 myfile
- </pre>
- </div>
- <div class="section" title="11.1.2.4.Special modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2570577">
- </a>
- 11.1.2.4.Special modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_173">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
- <span class="strong">
- <strong>
- s
- </strong>
- </span>
- to represent the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- modes, and
- <span class="strong">
- <strong>
- t
- </strong>
- </span>
- to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
- </p>
- <p id="ch3list_tuples_174">
- Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
- </p>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="12.Redirection and Piping">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2570624">
- </a>
- 12.Redirection and Piping
- </h2>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_175">
- In computing,
- <span class="emphasis">
- <em>
- redirection
- </em>
- </span>
- is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
- </p>
- <p id="ch3list_tuples_176">
- Programs do redirection with the
- <span class="emphasis">
- <em>
- dup2(2)
- </em>
- </span>
- system call, or its less-flexible but higher-level stdio analogues,
- <span class="emphasis">
- <em>
- freopen(3)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- popen(3)
- </em>
- </span>
- .
- </p>
- <div class="section" title="12.1.Redirecting standard input and standard output">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2570662">
- </a>
- 12.1.Redirecting standard input and standard output
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_177">
- Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
- </p>
- <pre class="programlisting">
- $ command1 > file1
- </pre>
- <p id="ch3list_tuples_178">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , placing the output in file1. Note that this will truncate any existing data in
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- . To append output to the end of the file, use the >> operator.:
- </p>
- <pre class="programlisting">
- $ command1 < file1
- </pre>
- <p id="ch3list_tuples_179">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- as the source of input (as opposed to the keyboard).:
- </p>
- <pre class="programlisting">
- $ command1 < infile > outfile
- </pre>
- <p id="ch3list_tuples_17a">
- combines the two capabilities:
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- reads from
- <span class="emphasis">
- <em>
- infile
- </em>
- </span>
- and writes to
- <span class="emphasis">
- <em>
- outfile
- </em>
- </span>
- </p>
- </div>
- <div class="section" title="12.2.Piping">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2570731">
- </a>
- 12.2.Piping
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_17b">
- Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
-A pipeline of three programs run on a text terminal:
- </p>
- <pre class="programlisting">
- $ command1 | command2
- </pre>
- <p id="ch3list_tuples_17c">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using its output as the input for
- <span class="emphasis">
- <em>
- command2
- </em>
- </span>
- (commonly called piping, since the "|" character is known as a "pipe").
- </p>
- <p id="ch3list_tuples_17d">
- This is equivalent to using two redirects and a temporary file:
- </p>
- <pre class="programlisting">
- $ command1 > tempfile
-$ command2 < tempfile
-$ rm tempfile
- </pre>
- <p id="ch3list_tuples_17e">
- A good example for command piping is combining
- <span class="emphasis">
- <em>
- echo
- </em>
- </span>
- with another command to achieve something interactive in a non-interactive shell, e.g.:
- </p>
- <pre class="programlisting">
- $ echo -e "user\npass" | ftp localhost
- </pre>
- <p id="ch3list_tuples_17f">
- This runs the ftp client with input user, press return, then pass.
- </p>
- </div>
- <div class="section" title="12.3.Redirecting to and from the standard file handles">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2570792">
- </a>
- 12.3.Redirecting to and from the standard file handles
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_180">
- In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
- </p>
- <table summary="Redirecting to and from the standard file handles" border="1">
- <colgroup>
- <col width="12">
- </col>
- <col width="13">
- </col>
- <col width="24">
- </col>
- </colgroup>
- </table>
- <p id="ch3list_tuples_18d">
- For example:
- </p>
- <pre class="programlisting">
- $ command1 2> file1
- </pre>
- <p id="ch3list_tuples_18e">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , directing the standard error stream to
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- .
- </p>
- <p id="ch3list_tuples_18f">
- In shells derived from
- <span class="emphasis">
- <em>
- csh
- </em>
- </span>
- (the C shell), the syntax instead appends the & character to the redirect characters, thus achieving a similar result.
- </p>
- <p id="ch3list_tuples_190">
- Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
- </p>
- <pre class="programlisting">
- $ find / -name .profile > results 2>&1
- </pre>
- <p id="ch3list_tuples_191">
- will try to find all files named
- <span class="emphasis">
- <em>
- .profile
- </em>
- </span>
- . Executed without redirection, it will output hits to
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- and errors (e.g. for lack of privilege to traverse protected directories) to
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- . If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- (handle 2) into
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- (handle 1) using 2>&1 .
- </p>
- <p id="ch3list_tuples_192">
- It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
- </p>
- <p id="ch3list_tuples_193">
- If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus:
- </p>
- <pre class="programlisting">
- $ find / -name .profile 2>&1 | less
- </pre>
- <p id="ch3list_tuples_194">
- A simplified form of the command:
- </p>
- <pre class="programlisting">
- $ command > file 2>&1
- </pre>
- <p id="ch3list_tuples_195">
- is:
- </p>
- <pre class="programlisting">
- $ command &>file
- </pre>
- <p id="ch3list_tuples_196">
- or:
- </p>
- <pre class="programlisting">
- $command >&file
- </pre>
- </div>
- <div class="section" title="12.4.Chained pipelines">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2570996">
- </a>
- 12.4.Chained pipelines
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_197">
- The redirection and piping tokens can be chained together to create complex commands. For example:
- </p>
- <pre class="programlisting">
- $ ls | grep '\.sh' | sort > shlist
- </pre>
- <p id="ch3list_tuples_198">
- lists the contents of the current directory, where this output is filtered to only contain lines which contain
- <span class="emphasis">
- <em>
- .sh
- </em>
- </span>
- , sort this resultant output lexicographically, and place the final output in
- <span class="emphasis">
- <em>
- shlist
- </em>
- </span>
- . This type of construction is used very commonly in shell scripts and batch files.
- </p>
- </div>
- <div class="section" title="12.5.Redirect to multiple outputs">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2571030">
- </a>
- 12.5.Redirect to multiple outputs
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_199">
- The standard command
- <span class="emphasis">
- <em>
- tee
- </em>
- </span>
- can redirect output from a command to several destinations.
- </p>
- <pre class="programlisting">
- $ ls -lrt | tee xyz
- </pre>
- <p id="ch3list_tuples_19a">
- This directs the file list output to both standard output as well as to the file
- <span class="emphasis">
- <em>
- xyz
- </em>
- </span>
- .
- </p>
- </div>
- </div>
- <div class="section" title="13.More Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2571061">
- </a>
- 13.More Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="13.1.grep">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2571069">
- </a>
- 13.1.grep
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_19b">
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- is a command line text search utility originally written for Unix. The name is taken from the first letters in
- <span class="emphasis">
- <em>
- global / regular expression / print
- </em>
- </span>
- , a series of instructions for the
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- text editor. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
- </p>
- <div class="section" title="13.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2571100">
- </a>
- 13.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_19c">
- This is an example of a common
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- usage:
- </p>
- <pre class="programlisting">
- $ grep apple fruitlist.txt
- </pre>
- <p id="ch3list_tuples_19d">
- In this case,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- prints all lines containing 'apple' from the file
- <span class="emphasis">
- <em>
- fruitlist.txt
- </em>
- </span>
- , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
- </p>
- <p id="ch3list_tuples_19e">
- Like most Unix commands,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- accepts command line arguments to change this and many other behaviors. For example:
- </p>
- <pre class="programlisting">
- $ grep -i apple fruitlist.txt
- </pre>
- <p id="ch3list_tuples_19f">
- This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be case insensitive, or to ignore case.
- </p>
- <p id="ch3list_tuples_1a0">
- To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
- </p>
- <pre class="programlisting">
- $ grep -w apple fruitlist.txt
- </pre>
- <p id="ch3list_tuples_1a1">
- Regular expressions can be used to match more complicated queries.
- </p>
- <div class="section" title="13.1.1.1.Variations">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2571179">
- </a>
- 13.1.1.1.Variations
- </h5>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_1a2">
- There are countless implementations and derivatives of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- available for many operating systems. Early variants of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- included
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- . The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- may also behave differently depending on the name by which it is invoked, allowing
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be links to the same program.
- </p>
- <p id="ch3list_tuples_1a3">
- <span class="emphasis">
- <em>
- pcregrep
- </em>
- </span>
- is an implementation of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- that uses Perl regular expression syntax.
- </p>
- <p id="ch3list_tuples_1a4">
- Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
- <span class="emphasis">
- <em>
- pgrep
- </em>
- </span>
- utility, for instance, displays the processes whose names match a given regular expression.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="13.2.tr">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2571258">
- </a>
- 13.2.tr
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_1a5">
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- (abbreviated from
- <span class="emphasis">
- <em>
- translate
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- transliterate
- </em>
- </span>
- ) is a command in Unix-like operating systems.
- </p>
- <p id="ch3list_tuples_1a6">
- When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
- </p>
- <pre class="programlisting">
- $ tr 'abcd' 'jkmn'
- </pre>
- <p id="ch3list_tuples_1a7">
- maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
- </p>
- <p id="ch3list_tuples_1a8">
- Sets of characters may be abbreviated by using character ranges. The previous example could be written:
- </p>
- <pre class="programlisting">
- $ tr 'a-d' 'jkmn'
- </pre>
- <p id="ch3list_tuples_1a9">
- In POSIX compliant versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
- </p>
- <p id="ch3list_tuples_1aa">
- The
- <span class="emphasis">
- <em>
- -c
- </em>
- </span>
- flag complements the first set of characters.
- </p>
- <pre class="programlisting">
- $ tr -cd '[:alnum:]'
- </pre>
- <p id="ch3list_tuples_1ab">
- therefore removes all non-alphanumeric characters.
- </p>
- <p id="ch3list_tuples_1ac">
- The
- <span class="emphasis">
- <em>
- -s
- </em>
- </span>
- flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
- </p>
- <pre class="programlisting">
- $ tr -s '\n' '\n'
- </pre>
- <p id="ch3list_tuples_1ad">
- replaces sequences of one or more newline characters with a single newline.
- </p>
- <p id="ch3list_tuples_1ae">
- The
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
- </p>
- <pre class="programlisting">
- $ tr -d '\r'
- </pre>
- <p id="ch3list_tuples_1af">
- Most versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , including GNU
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- and classic Unix
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
- </p>
- <p id="ch3list_tuples_1b0">
- Ruby and Perl also have an internal
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- operator, which operates analogously. Tcl's
- <span class="emphasis">
- <em>
- string map
- </em>
- </span>
- command is more general in that it maps strings to strings while
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- maps characters to characters.
- </p>
- </div>
- </div>
- <div class="section" title="14.Elementary Regex">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2571408">
- </a>
- 14.Elementary Regex
- </h2>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_1b1">
- In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
- </p>
- <p id="ch3list_tuples_1b2">
- Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributionsincluding the editor
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- and the filter
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- were the first to popularize the concept of regular expressions.
- </p>
- <p id="ch3list_tuples_1b3">
- Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
- <span class="emphasis">
- <em>
- Basic Regular Expressions
- </em>
- </span>
- (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
- </p>
- <p id="ch3list_tuples_1b4">
- In the BRE syntax, most characters are treated as literals they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
- </p>
- <table summary="Elementary Regex" border="1">
- <colgroup>
- <col width="13">
- </col>
- <col width="60">
- </col>
- </colgroup>
- </table>
- <div class="section" title="14.1.Lazy quantification">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2571625">
- </a>
- 14.1.Lazy quantification
- </h3>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_1c9">
- The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example:
- </p>
- <pre class="programlisting">
- Another whale explosion occurred on <January 26>, <2004>.
- </pre>
- <p id="ch3list_tuples_1ca">
- ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the * quantifier is greedy it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
- </p>
- <p id="ch3list_tuples_1cb">
- Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as
- <span class="emphasis">
- <em>
- lazy
- </em>
- </span>
- (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
- </p>
- </div>
- </div>
- <div class="section" title="15.One Liners">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2571701">
- </a>
- 15.One Liners
- </h2>
- </div>
- </div>
- </div>
- <p id="ch3list_tuples_1cc">
- A
- <span class="emphasis">
- <em>
- one-liner
- </em>
- </span>
- is textual input to the command-line of an operating system shell that performs some function in just one line of input.
- </p>
- <p id="ch3list_tuples_1cd">
- The one liner can be
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch3list_tuples_1ce">
- An expression written in the language of the shell.
- </p>
- </li>
- <li class="listitem">
- <p id="ch3list_tuples_1cf">
- The invocation of an interpreter together with program source for the interpreter to run.
- </p>
- </li>
- <li class="listitem">
- <p id="ch3list_tuples_1d0">
- The invocation of a compiler together with source to compile and
-instructions for executing the compiled program.
- </p>
- </li>
- </ol>
- </div>
- <p id="ch3list_tuples_1d1">
- Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
- </p>
- <p id="ch3list_tuples_1d2">
- The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
- </p>
- <p id="ch3list_tuples_1d3">
- The word
- <span class="emphasis">
- <em>
- One-liner
- </em>
- </span>
- has two references in the index of the book
- <span class="emphasis">
- <em>
- The AWK Programming Language
- </em>
- </span>
- (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
- </p>
- <pre class="programlisting">
- The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.
- </pre>
- <p id="ch3list_tuples_1d4">
- Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
- </p>
- <p id="ch3list_tuples_1d5">
- The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
- </p>
- <p id="ch3list_tuples_1d6">
- Here are the first few of them:
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch3list_tuples_1d7">
- Print the total number of input lines:
- </p>
- <p id="ch3list_tuples_1d8">
- END { print NR }
- </p>
- </li>
- <li class="listitem">
- <p id="ch3list_tuples_1d9">
- Print the tenth input line:
- </p>
- <p id="ch3list_tuples_1da">
- NR == 10
- </p>
- </li>
- <li class="listitem">
- <p id="ch3list_tuples_1db">
- Print the last field of every input line:
- </p>
- <p id="ch3list_tuples_1dc">
- { print $NF }
- </p>
- </li>
- </ol>
- </div>
- <p id="ch3list_tuples_1dd">
- One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
- </p>
- <p id="ch3list_tuples_1de">
- The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:
- </p>
- <pre class="programlisting">
- main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
-*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
- </pre>
- <p id="ch3list_tuples_1df">
- This one-liner program is a
- <span class="emphasis">
- <em>
- glob pattern matcher
- </em>
- </span>
- . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
- </p>
- <p id="ch3list_tuples_1e0">
- Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:
- </p>
- <pre class="programlisting">
- $ prog foo 'f??'; echo $?
-
-$ prog 'best short program' '??st*o**p?*'; echo $?
- </pre>
- <p id="ch3list_tuples_1e1">
- Here is a one line shell script to show directories:
- </p>
- <pre class="programlisting">
- $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
- </pre>
- </div>
- </div>
- </div>
- </body>
-</html>
--- a/SEESenv/web/html/ch4strings_dicts.html Mon Feb 22 18:46:07 2010 +0530
+++ b/SEESenv/web/html/ch4strings_dicts.html Mon Feb 22 22:38:51 2010 +0530
@@ -27,7 +27,8 @@
<dl>
<dt>
<span class="article">
- <a href="#id2566592">
+ <a href="#id2625574">
+ Strings
</a>
</span>
</dt>
@@ -35,182 +36,15 @@
<dl>
<dt>
<span class="section">
- <a href="#id2376716">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2564411">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2617652">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2617924">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2618056">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2618064">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2617418">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2617426">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2618649">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2618708">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2618808">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2618890">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2619056">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2619065">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2619149">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2619340">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2619426">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2619479">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2619487">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2619796">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2619944">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2620116">
- 6. Command Line Arguments
+ <a href="#id2624161">
+ 1. String Formatting
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2620208">
- 7. Basic Text Processing
+ <a href="#id2676578">
+ 2. String Methods
</a>
</span>
</dt>
@@ -218,29 +52,73 @@
<dl>
<dt>
<span class="section">
- <a href="#id2620217">
- 7.1. head
+ <a href="#id2676592">
+ 2.1.
+ <span class="strong">
+ <strong>
+ find
+ </strong>
+ </span>
+ </a>
+ </span>
+ </dt>
+ <dt>
+ <span class="section">
+ <a href="#id2676623">
+ 2.2.
+ <span class="strong">
+ <strong>
+ join
+ </strong>
+ </span>
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2620303">
- 7.2. tail
+ <a href="#id2676661">
+ 2.3.
+ <span class="strong">
+ <strong>
+ lower
+ </strong>
+ </span>
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2620429">
- 7.3. cut
+ <a href="#id2676688">
+ 2.4.
+ <span class="strong">
+ <strong>
+ replace
+ </strong>
+ </span>
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2620515">
- 7.4. paste
+ <a href="#id2676744">
+ 2.5.
+ <span class="strong">
+ <strong>
+ split
+ </strong>
+ </span>
+ </a>
+ </span>
+ </dt>
+ <dt>
+ <span class="section">
+ <a href="#id2676803">
+ 2.6.
+ <span class="strong">
+ <strong>
+ strip
+ </strong>
+ </span>
</a>
</span>
</dt>
@@ -248,72 +126,15 @@
</dd>
<dt>
<span class="section">
- <a href="#id2620647">
- 8. Shell Meta Characters
+ <a href="#id2676848">
+ 3. Introduction to the standard library
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2620751">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2620760">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2620963">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2621073">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2621313">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2621588">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2621604">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2621627">
- 11. Permissions and Ownership
+ <a href="#id2676924">
+ 4. I/O: Reading and Writing Files
</a>
</span>
</dt>
@@ -321,54 +142,15 @@
<dl>
<dt>
<span class="section">
- <a href="#id2621636">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2622412">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2622448">
- 12.1. Redirecting standard input and standard output
+ <a href="#id2676954">
+ 4.1. Opening Files
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2622518">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2622579">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2622787">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2622821">
- 12.5. Redirect to multiple outputs
+ <a href="#id2676411">
+ 4.2. Reading and Writing files
</a>
</span>
</dt>
@@ -376,8 +158,8 @@
</dd>
<dt>
<span class="section">
- <a href="#id2622852">
- 13. More Text Processing
+ <a href="#id2677418">
+ 5. Dictionaries
</a>
</span>
</dt>
@@ -385,54 +167,37 @@
<dl>
<dt>
<span class="section">
- <a href="#id2622861">
- 13.1. grep
+ <a href="#id2677474">
+ 5.1.
+ <span class="strong">
+ <strong>
+ dict()
+ </strong>
+ </span>
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2623051">
- 13.2. tr
+ <a href="#id2677539">
+ 5.2. Dictionary Methods
</a>
</span>
</dt>
</dl>
</dd>
- <dt>
- <span class="section">
- <a href="#id2623202">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2623415">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2623491">
- 15. One Liners
- </a>
- </span>
- </dt>
</dl>
</dd>
</dl>
</div>
- <div class="article">
+ <div class="article" title="Strings">
<div class="titlepage">
<div>
<div>
- <h2 class="title" id="id2566592">
+ <h2 class="title">
+ <a name="id2625574">
+ </a>
+ Strings
</h2>
</div>
</div>
@@ -447,182 +212,15 @@
<dl>
<dt>
<span class="section">
- <a href="#id2376716">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2564411">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2617652">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2617924">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2618056">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2618064">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2617418">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2617426">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2618649">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2618708">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2618808">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2618890">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2619056">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2619065">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2619149">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2619340">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2619426">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2619479">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2619487">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2619796">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2619944">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2620116">
- 6. Command Line Arguments
+ <a href="#id2624161">
+ 1. String Formatting
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2620208">
- 7. Basic Text Processing
+ <a href="#id2676578">
+ 2. String Methods
</a>
</span>
</dt>
@@ -630,93 +228,73 @@
<dl>
<dt>
<span class="section">
- <a href="#id2620217">
- 7.1. head
+ <a href="#id2676592">
+ 2.1.
+ <span class="strong">
+ <strong>
+ find
+ </strong>
+ </span>
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2620303">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2620429">
- 7.3. cut
+ <a href="#id2676623">
+ 2.2.
+ <span class="strong">
+ <strong>
+ join
+ </strong>
+ </span>
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2620515">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2620647">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2620751">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2620760">
- 9.1. cat
+ <a href="#id2676661">
+ 2.3.
+ <span class="strong">
+ <strong>
+ lower
+ </strong>
+ </span>
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2620963">
- 9.2. more
+ <a href="#id2676688">
+ 2.4.
+ <span class="strong">
+ <strong>
+ replace
+ </strong>
+ </span>
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2621073">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2621313">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2621588">
- 10.1. man hier
+ <a href="#id2676744">
+ 2.5.
+ <span class="strong">
+ <strong>
+ split
+ </strong>
+ </span>
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2621604">
- 10.2. ls -l
+ <a href="#id2676803">
+ 2.6.
+ <span class="strong">
+ <strong>
+ strip
+ </strong>
+ </span>
</a>
</span>
</dt>
@@ -724,26 +302,15 @@
</dd>
<dt>
<span class="section">
- <a href="#id2621627">
- 11. Permissions and Ownership
+ <a href="#id2676848">
+ 3. Introduction to the standard library
</a>
</span>
</dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2621636">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
<dt>
<span class="section">
- <a href="#id2622412">
- 12. Redirection and Piping
+ <a href="#id2676924">
+ 4. I/O: Reading and Writing Files
</a>
</span>
</dt>
@@ -751,79 +318,15 @@
<dl>
<dt>
<span class="section">
- <a href="#id2622448">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2622518">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2622579">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2622787">
- 12.4. Chained pipelines
+ <a href="#id2676954">
+ 4.1. Opening Files
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2622821">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2622852">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2622861">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2623051">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2623202">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2623415">
- 14.1. Lazy quantification
+ <a href="#id2676411">
+ 4.2. Reading and Writing files
</a>
</span>
</dt>
@@ -831,4423 +334,1388 @@
</dd>
<dt>
<span class="section">
- <a href="#id2623491">
- 15. One Liners
+ <a href="#id2677418">
+ 5. Dictionaries
</a>
</span>
</dt>
+ <dd>
+ <dl>
+ <dt>
+ <span class="section">
+ <a href="#id2677474">
+ 5.1.
+ <span class="strong">
+ <strong>
+ dict()
+ </strong>
+ </span>
+ </a>
+ </span>
+ </dt>
+ <dt>
+ <span class="section">
+ <a href="#id2677539">
+ 5.2. Dictionary Methods
+ </a>
+ </span>
+ </dt>
+ </dl>
+ </dd>
</dl>
</div>
- <div class="section" title="1.Introducing Linux">
+ <p id="ch4strings_dicts_1">
+ Strings were briefly introduced previously in the introduction document. In this
+section strings will be presented in greater detail. All the standard operations
+that can be performed on sequences such as indexing, slicing, multiplication, length
+minimum and maximum can be performed on string variables as well. One thing to
+be noted is that strings are immutable, which means that string variables are
+unchangeable. Hence, all item and slice assignments on strings are illegal.
+Let us look at a few example.
+ </p>
+ <pre class="programlisting">
+ >>> name = 'PythonFreak'
+>>> print name[3]
+h
+>>> print name[-1]
+k
+>>> print name[6:]
+Freak
+>>> name[6:0] = 'Maniac'
+Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+TypeError: 'str' object does not support item assignment
+ </pre>
+ <p id="ch4strings_dicts_2">
+ This is quite expected, since string objects are immutable as already mentioned.
+The error message is clear in mentioning that 'str' object does not support item
+assignment.
+ </p>
+ <div class="section" title="1.String Formatting">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
- <a name="id2376716">
+ <a name="id2624161">
</a>
- 1.Introducing Linux
+ 1.String Formatting
</h2>
</div>
</div>
</div>
- <p id="ch4strings_dicts_1">
- (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
+ <p id="ch4strings_dicts_3">
+ String formatting can be performed using the string formatting operator represented
+as the percent (%) sign. The string placed before the % sign is formatted with
+the value placed to the right of it. Let us look at a simple example.
</p>
- <p id="ch4strings_dicts_2">
- Linux (usually pronounced lnks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
+ <pre class="programlisting">
+ >>> format = 'Hello %s, from PythonFreak'
+>>> str1 = 'world!'
+>>> print format % str1
+Hello world!, from PythonFreak
+ </pre>
+ <p id="ch4strings_dicts_4">
+ The %s parts of the format string are called the coversion specifiers. The coversion
+specifiers mark the places where the formatting has to be performed in a string.
+In the example the %s is replaced by the value of str1. More than one value can
+also be formatted at a time by specifying the values to be formatted using tuples
+and dictionaries (explained in later sections). Let us look at an example.
+ </p>
+ <pre class="programlisting">
+ >>> format = 'Hello %s, from %s'
+>>> values = ('world!', 'PythonFreak')
+>>> print format % values
+Hello world!, from PythonFreak
+ </pre>
+ <p id="ch4strings_dicts_5">
+ In this example it can be observed that the format string contains two conversion
+specifiers and they are formatted using the tuple of values as shown.
</p>
- <p id="ch4strings_dicts_3">
- Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
+ <p id="ch4strings_dicts_6">
+ The s in %s specifies that the value to be replaced is of type string. Values of
+other types can be specified as well such as integers and floats. Integers are
+specified as %d and floats as %f. The precision with which the integer or the
+float values are to be represented can also be specified using a
+ <span class="strong">
+ <strong>
+ .
+ </strong>
+ </span>
+ (
+ <span class="strong">
+ <strong>
+ dot
+ </strong>
+ </span>
+ )
+followed by the precision value.
</p>
- <p id="ch4strings_dicts_4">
- The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
+ </div>
+ <div class="section" title="2.String Methods">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h2 class="title" style="clear: both">
+ <a name="id2676578">
+ </a>
+ 2.String Methods
+ </h2>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_7">
+ Similar to list methods, strings also have a rich set of methods to perform various
+operations on strings. Some of the most important and popular ones are presented
+in this section.
</p>
- <div class="section" title="1.1.Historical Background">
+ <div class="section" title="2.1.find">
<div class="titlepage">
<div>
<div>
<h3 class="title">
- <a name="id2564411">
+ <a name="id2676592">
</a>
- 1.1.Historical Background
+ 2.1.
+ <span class="strong">
+ <strong>
+ find
+ </strong>
+ </span>
</h3>
</div>
</div>
</div>
- <div class="section" title="1.1.1.Events leading to the creation">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2564377">
- </a>
- 1.1.1.Events leading to the creation
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_5">
- The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_6">
- In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="1.1.2.The Creation of Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2617607">
- </a>
- 1.1.2.The Creation of Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_7">
- In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
- </p>
- <p id="ch4strings_dicts_8">
- Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
- </p>
- </div>
+ <p id="ch4strings_dicts_8">
+ The
+ <span class="strong">
+ <strong>
+ find
+ </strong>
+ </span>
+ method is used to search for a substring within a given string. It
+returns the left most index of the first occurence of the substring. If the
+substring is not found in the string then it returns -1. Let us look at a few
+examples.
+ </p>
+ <pre class="programlisting">
+ >>> longstring = 'Hello world!, from PythonFreak'
+>>> longstring.find('Python')
+19
+>>> longstring.find('Perl')
+-1
+ </pre>
</div>
- <div class="section" title="1.2.Design and Implications">
+ <div class="section" title="2.2.join">
<div class="titlepage">
<div>
<div>
<h3 class="title">
- <a name="id2617652">
+ <a name="id2676623">
</a>
- 1.2.Design and Implications
+ 2.2.
+ <span class="strong">
+ <strong>
+ join
+ </strong>
+ </span>
</h3>
</div>
</div>
</div>
<p id="ch4strings_dicts_9">
- A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
+ The
+ <span class="strong">
+ <strong>
+ join
+ </strong>
+ </span>
+ method is used to join the elements of a sequence. The sequence
+elements that are to be join ed should all be strings. Let us look at a few
+examples.
</p>
- <div class="section" title="1.2.1.User Interface">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2617676">
- </a>
- 1.2.1.User Interface
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_a">
- Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
- </p>
- <p id="ch4strings_dicts_b">
- A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
- </p>
- </div>
- <div class="section" title="1.2.2.Development">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2617730">
- </a>
- 1.2.2.Development
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_c">
- The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
- </p>
- <p id="ch4strings_dicts_d">
- Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
- </p>
- <p id="ch4strings_dicts_e">
- A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
- </p>
- </div>
- <div class="section" title="1.2.3.Community">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2617787">
- </a>
- 1.2.3.Community
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_f">
- A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
- </p>
- <p id="ch4strings_dicts_10">
- In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
- </p>
- <p id="ch4strings_dicts_11">
- Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
- </p>
- </div>
- <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2617831">
- </a>
- 1.2.4.Can I make a profit out of running a business involving Linux?
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_12">
- The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
- </p>
- </div>
- <div class="section" title="1.2.5.Programming on Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2617877">
- </a>
- 1.2.5.Programming on Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_13">
- Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
- </p>
- <p id="ch4strings_dicts_14">
- Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
- </p>
- <p id="ch4strings_dicts_15">
- The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
- </p>
- </div>
+ <pre class="programlisting">
+ >>> seq = ['With', 'great', 'power', 'comes', 'great', 'responsibility']
+>>> sep = ' '
+>>> sep.join(seq)
+'With great power comes great responsibility'
+>>> sep = ',!'
+>>> sep.join(seq)
+'With,!great,!power,!comes,!great,!responsibility'
+ </pre>
+ <p id="ch4strings_dicts_a">
+ <span class="emphasis">
+ <em>
+ Try this yourself
+ </em>
+ </span>
+ </p>
+ <pre class="programlisting">
+ >>> seq = [12,34,56,78]
+>>> sep.join(seq)
+ </pre>
</div>
- <div class="section" title="1.3.Reasons for Using Linux">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2617924">
- </a>
- 1.3.Reasons for Using Linux
- </h3>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_16">
- Linux is free:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_17">
- As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
-Most of all, Linux is free as in "free speech":
-The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_18">
- Linux is portable to any hardware platform:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_19">
- A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_1a">
- Linux was made to keep on running:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_1b">
- As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_1c">
- Linux is secure and versatile:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_1d">
- The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_1e">
- Linux is scalable:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_1f">
- From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_20">
- The Linux OS and Linux applications have very short debugtimes:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_21">
- Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
- </p>
- </div>
- </div>
- <div class="section" title="2.Getting Started">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2618056">
- </a>
- 2.Getting Started
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="2.1.Logging in, activating the user interface and logging out">
+ <div class="section" title="2.3.lower">
<div class="titlepage">
<div>
<div>
<h3 class="title">
- <a name="id2618064">
+ <a name="id2676661">
</a>
- 2.1.Logging in, activating the user interface and logging out
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_22">
- In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PCbased Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multiuser features, or in graphical console mode, which looks better but eats more system resources.
- </p>
- <div class="section" title="2.1.1.Graphical Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2618095">
- </a>
- 2.1.1.Graphical Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_23">
- This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
- </p>
- <p id="ch4strings_dicts_24">
- To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
- <span class="emphasis">
- <em>
- OK
- </em>
- </span>
- or press
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- .
-It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
- </p>
- <p id="ch4strings_dicts_25">
- After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
- </p>
- <p id="ch4strings_dicts_26">
- To continue, you will need to open a
- <span class="emphasis">
- <em>
- terminal window
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
- <span class="emphasis">
- <em>
- Applications>Utilities->System Tools
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- Internet menu
- </em>
- </span>
- , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
- </p>
- <p id="ch4strings_dicts_27">
- While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old pointnclick method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
- </p>
- <p id="ch4strings_dicts_28">
- A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
- </p>
- <p id="ch4strings_dicts_29">
- Another common form for a prompt is this one:
-[
- </p>
- <div class="reference">
- <div class="titlepage">
- <hr />
- </div>
- user@host
- </div>
- <p>
- dir]
- </p>
- <p id="ch4strings_dicts_2a">
- In the above example,
- <span class="emphasis">
- <em>
- user
- </em>
- </span>
- will be your login name,
- <span class="emphasis">
- <em>
- hosts
- </em>
- </span>
- the name of the machine you are working on, and
- <span class="emphasis">
- <em>
- dir
- </em>
- </span>
- an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- icon or find
- <span class="emphasis">
- <em>
- Log Out
- </em>
- </span>
- in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
- </p>
- <p id="ch4strings_dicts_2b">
- When you see the login screen again, asking to enter user name and password, logout was successful.
- </p>
- </div>
- <div class="section" title="2.1.2.Text Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2618253">
- </a>
- 2.1.2.Text Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_2c">
- One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
- </p>
- <p id="ch4strings_dicts_2d">
- The login is different from a graphical login, in that you have to hit the
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- . You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
-reasons.
- </p>
- <p id="ch4strings_dicts_2e">
- When the system has accepted you as a valid user, you may get some more information, called the
- <span class="emphasis">
- <em>
- message of the day
- </em>
- </span>
- , which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
- </p>
- <p id="ch4strings_dicts_2f">
- Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a nonprivileged user.
- </p>
- <p id="ch4strings_dicts_30">
- Logging out is done by entering the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't poweroff the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="3.Basic Commands">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2617418">
- </a>
- 3.Basic Commands
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="3.1.ls">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2617426">
- </a>
- 3.1.ls
+ 2.3.
+ <span class="strong">
+ <strong>
+ lower
+ </strong>
+ </span>
</h3>
</div>
</div>
</div>
- <p id="ch4strings_dicts_31">
- When invoked without any arguments,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- is derived from
- <span class="emphasis">
- <em>
- list segments
- </em>
- </span>
- which was used in earlier systems.
- </p>
- <p id="ch4strings_dicts_32">
- Files whose names start with "." are not listed, unless the
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- flag is specified or the files are specified explicitly.
- </p>
- <p id="ch4strings_dicts_33">
- Without options,
- <span class="emphasis">
- <em>
- ls
- </em>
+ <p id="ch4strings_dicts_b">
+ The
+ <span class="strong">
+ <strong>
+ lower
+ </strong>
</span>
- displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_34">
- <span class="emphasis">
- <em>
- -l
- </em>
- </span>
- long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_35">
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_36">
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_37">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- recursively lists subdirectories. The command ls -R / would therefore list all files.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_38">
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_39">
- <span class="emphasis">
- <em>
- -t
- </em>
- </span>
- sort the list of files by modification time.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_3a">
- <span class="emphasis">
- <em>
- -h
- </em>
- </span>
- print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_3b">
- In some environments, providing the option
- <span class="emphasis">
- <em>
- --color
- </em>
- </span>
- (for GNU ls) or
- <span class="emphasis">
- <em>
- -G
- </em>
- </span>
- (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- would. To determine what color to use for a file, GNU
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks the Unix file type, the file permissions, and the file extension, while FreeBSD
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks only the Unix file type and file permissions.:
+ method, as the name indicates, converts the entire text of a string
+to lower case. It is specially useful in cases where the programmers deal with case
+insensitive data. Let us look at a few examples.
</p>
<pre class="programlisting">
- $ ls
-jeeves.rst psmith.html blandings.html
-$ ls -l
-drwxr--r-- 1 plum editors 4096 jeeves
--rw-r--r-- 1 plum editors 30405 psmith
--r-xr-xr-x 1 plum plum 8460 blandings
+ >>> sometext = 'Hello world!, from PythonFreak'
+>>> sometext.lower()
+'hello world!, from pythonfreak'
</pre>
- <p id="ch4strings_dicts_3c">
- Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
- </p>
</div>
- <div class="section" title="3.2.date">
+ <div class="section" title="2.4.replace">
<div class="titlepage">
<div>
<div>
<h3 class="title">
- <a name="id2618649">
+ <a name="id2676688">
</a>
- 3.2.date
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_3d">
- The Unix date command displays the time and date. The super-user can use it to set the system clock.
- </p>
- <p id="ch4strings_dicts_3e">
- With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:
- </p>
- <pre class="programlisting">
- $date
-Tue Sep 8 12:01:45 IST 2009
- </pre>
- <p id="ch4strings_dicts_3f">
- On some systems to set the current date and time to September 8, 2004 01:22 you type:
- </p>
- <pre class="programlisting">
- $date --set="20040908 01:22"
- </pre>
- <p id="ch4strings_dicts_40">
- In order to view the various options for the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command, type:
- </p>
- <pre class="programlisting">
- $man date
- </pre>
- <p id="ch4strings_dicts_41">
- This will take you to the "Manual" page comprising of all the details on the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command. You can return to the terminal from the "man" page by pressing the
- <span class="emphasis">
- <em>
- Esc
- </em>
- </span>
- key in the keyboard and typing ":q" in that order.
- </p>
- </div>
- <div class="section" title="3.3.cd">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2618708">
- </a>
- 3.3.cd
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_42">
- This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, cd .. can be used.
- </p>
- <p id="ch4strings_dicts_43">
- One dot '.' represents the current directory while two dots '..' represent the parent directory.
- </p>
- <p id="ch4strings_dicts_44">
- cd - will return you to the previous directory (a bit like an undo).
- </p>
- <p id="ch4strings_dicts_45">
- You can also use cd absolute path or cd relative path (see below):
- </p>
- <p id="ch4strings_dicts_46">
- Absolute paths:
- </p>
- <p id="ch4strings_dicts_47">
- An absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
- </p>
- <p id="ch4strings_dicts_48">
- For example to get to /boot/grub you would type:
- </p>
- <pre class="programlisting">
- $cd /boot/grub
- </pre>
- <p id="ch4strings_dicts_49">
- This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
- </p>
- <p id="ch4strings_dicts_4a">
- Relative paths:
- </p>
- <p id="ch4strings_dicts_4b">
- A relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
- </p>
- <p id="ch4strings_dicts_4c">
- For example if you are in root's home directory and want to get to /root/music, you type:
- </p>
- <pre class="programlisting">
- $ cd music
- </pre>
- <p id="ch4strings_dicts_4d">
- Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
- </p>
- </div>
- <div class="section" title="3.4.who">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2618808">
- </a>
- 3.4.who
+ 2.4.
+ <span class="strong">
+ <strong>
+ replace
+ </strong>
+ </span>
</h3>
</div>
</div>
</div>
- <p id="ch4strings_dicts_4e">
- The standard Unix command
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- displays a list of users who are currently logged into a computer.
- </p>
- <p id="ch4strings_dicts_4f">
+ <p id="ch4strings_dicts_c">
The
- <span class="emphasis">
- <em>
- who
- </em>
+ <span class="strong">
+ <strong>
+ replace
+ </strong>
</span>
- command is related to the command
- <span class="emphasis">
- <em>
- w
- </em>
- </span>
- , which provides the same information but also displays additional data and statistics.:
+ method replaces a substring with another substring within
+a given string and returns the new string. Let us look at an example.
</p>
<pre class="programlisting">
- $who
-beeblebrox tty7 2009-09-08 10:50 (:0)
-beeblebrox pts/0 2009-09-08 11:25 (:0.0)
-dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in)
-beeblebrox pts/2 2009-09-08 18:53 (:0.0)
+ >>> sometext = 'Concise, precise and criticise is some of the words that end with ise'
+>>> sometext.replace('is', 'are')
+'Concaree, precaree and criticaree are some of the words that end with aree'
</pre>
- <p id="ch4strings_dicts_50">
- The command can be invoked with the arguments
- <span class="emphasis">
- <em>
- am i
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- am I
- </em>
- </span>
- (so it is invoked as
- <span class="emphasis">
- <em>
- who am i
- </em>
- </span>
- or * who am I*), showing information about the current terminal only (see the
+ <p id="ch4strings_dicts_d">
+ Observe here that all the occurences of the substring
<span class="emphasis">
<em>
- -m
- </em>
- </span>
- option below, of which this invocation is equivalent).
- </p>
- <p id="ch4strings_dicts_51">
- In order to find out the various options that can be appended to the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command, check the
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page by typing out the following in the terminal:
- </p>
- <pre class="programlisting">
- $man who
- </pre>
- <p id="ch4strings_dicts_52">
- This will take you to the "Manual" page containing details about the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command
- </p>
- </div>
- <div class="section" title="3.5.mkdir">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2618890">
- </a>
- 3.5.mkdir
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_53">
- This command is used to make a new directory. Normal usage is as straightforward as follows:
- </p>
- <pre class="programlisting">
- $mkdir name_of_directory
- </pre>
- <p id="ch4strings_dicts_54">
- Where
- <span class="emphasis">
- <em>
- name_of_directory
- </em>
- </span>
- is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and
- <span class="emphasis">
- <em>
- mkdir
+ is
</em>
</span>
- will try to create all of them.
- </p>
- <div class="section" title="3.5.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2618922">
- </a>
- 3.5.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_55">
- On Unix-like operating systems,
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- takes options. Three of the most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_56">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- : will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_57">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- : display each directory that mkdir creates. Most often used with -p.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_58">
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- : specify the octal permissions of directories created by mkdir.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_59">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
- </p>
- </div>
- <div class="section" title="3.5.2.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2618981">
- </a>
- 3.5.2.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_5a">
- An example of
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- in action is:
- </p>
- <pre class="programlisting">
- $mkdir -p /tmp/a/b/c
- </pre>
- <p id="ch4strings_dicts_5b">
- If
- <span class="emphasis">
- <em>
- /tmp/a
- </em>
- </span>
- exists but
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- does not, mkdir will create
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- before creating
- <span class="emphasis">
- <em>
- /tmp/a/b/c
- </em>
- </span>
- .
- </p>
- <p id="ch4strings_dicts_5c">
- And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
- </p>
- <pre class="programlisting">
- $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
- </pre>
- <p id="ch4strings_dicts_5d">
- This will create:
- </p>
- tmpdir - branches
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_5e">
- tag
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- trunk - sources - includes
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_5f">
- docs
- </p>
- </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="4.Getting Help">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2619056">
- </a>
- 4.Getting Help
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="4.1.apropos and whatis">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2619065">
- </a>
- 4.1.apropos and whatis
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_60">
- This is a command to search the manual pages files in Unix and Unix-like operating systems.
- </p>
- <pre class="programlisting">
- $ apropos grep
-egrep egrep (1) Search a file for a pattern using full regular expressions
-fgrep fgrep (1) Search a file for a fixed-character string
-fmlgrep fmlgrep (1) Search a file for a pattern
-grep grep (1) Search a file for a pattern
-gzgrep gzgrep (1) Search a possibly compressed file for a regular expression
-nisgrep nismatch (1) Utilities for searching NIS+ tables
-pgrep pgrep (1) Find or signal a process by name or other attribute
-zgrep zgrep (1) Search a possibly compressed file for a regular expression
-...
- </pre>
- <p id="ch4strings_dicts_61">
- In this example, the user uses
+ have been replaced,
+even the
<span class="emphasis">
<em>
- apropos
- </em>
- </span>
- to search for the string "grep", and apropos returns the indicated
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- pages that include the term "grep".
- </p>
- <p id="ch4strings_dicts_62">
- A short index of explanations for commands is available using the
- <span class="emphasis">
- <em>
- whatis
- </em>
- </span>
- command, like in the examples below:
- </p>
- <pre class="programlisting">
- $whatis ls
-ls (1) - list directory contents
- </pre>
- <p id="ch4strings_dicts_63">
- This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
- </p>
- <p id="ch4strings_dicts_64">
- If you don't know where to get started and which man page to read,
- <span class="emphasis">
- <em>
- apropos
+ is
</em>
</span>
- gives more information. Say that you do not know how to start a browser, then you could enter the following command:
- </p>
- <pre class="programlisting">
- $apropos browser
-gmusicbrowser (1) - Jukebox for large collections of audio files
-infobrowser (1) - read Info documents
-libsmbclient (7) - An extension library for browsers and that can be used...
-opera (1) - a standards-compliant graphical Web browser
-sensible-browser (1) - sensible editing, paging, and web browsing
-smbtree (1) - A text based smb network browser
-tvtk_doc (1) - A GUI based TVTK documentation search browser.
-viewres (1) - graphical class browser for Xt
-w3m (1) - a text based Web browser and pager
-www-browser (1) - a text based Web browser and pager
-...
- </pre>
- </div>
- <div class="section" title="4.2.man">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2619149">
- </a>
- 4.2.man
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_65">
- Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is
+ in
<span class="emphasis">
<em>
- man
+ concise
</em>
</span>
- . Each page is a self-contained document.
- </p>
- <p id="ch4strings_dicts_66">
- To read a manual page for a Unix command, one can use:
- </p>
- <pre class="programlisting">
- $ man <command_name>
- </pre>
- <p id="ch4strings_dicts_67">
- at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
+ ,
<span class="emphasis">
<em>
- man
- </em>
- </span>
- generally uses the less terminal pager.
- </p>
- <p id="ch4strings_dicts_68">
- Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are
- <span class="emphasis">
- <em>
- man(1)
+ precise
</em>
</span>
and
<span class="emphasis">
<em>
- man(7)
+ criticise
+ </em>
+ </span>
+ have been replaced.
+ </p>
+ </div>
+ <div class="section" title="2.5.split">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h3 class="title">
+ <a name="id2676744">
+ </a>
+ 2.5.
+ <span class="strong">
+ <strong>
+ split
+ </strong>
+ </span>
+ </h3>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_e">
+ The
+ <span class="strong">
+ <strong>
+ split
+ </strong>
+ </span>
+ is one of the very important string methods. split is the opposite of the
+ <span class="strong">
+ <strong>
+ join
+ </strong>
+ </span>
+ method. It is used to split a string based on the argument passed as the
+delimiter. It returns a list of strings. By default when no argument is passed it
+splits with
+ <span class="emphasis">
+ <em>
+ space
+ </em>
+ </span>
+ (' ') as the delimiter. Let us look at an example.
+ </p>
+ <pre class="programlisting">
+ >>> grocerylist = 'butter, cucumber, beer(a grocery item??), wheatbread'
+>>> grocerylist.split(',')
+['butter', ' cucumber', ' beer(a grocery item??)', ' wheatbread']
+>>> grocerylist.split()
+['butter,', 'cucumber,', 'beer(a', 'grocery', 'item??),', 'wheatbread']
+ </pre>
+ <p id="ch4strings_dicts_f">
+ Observe here that in the second case when the delimiter argument was not set
+ <span class="strong">
+ <strong>
+ split
+ </strong>
+ </span>
+ was done with
+ <span class="emphasis">
+ <em>
+ space
</em>
</span>
- , or
+ as the delimiter.
+ </p>
+ </div>
+ <div class="section" title="2.6.strip">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h3 class="title">
+ <a name="id2676803">
+ </a>
+ 2.6.
+ <span class="strong">
+ <strong>
+ strip
+ </strong>
+ </span>
+ </h3>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_10">
+ The
+ <span class="strong">
+ <strong>
+ strip
+ </strong>
+ </span>
+ method is used to remove or
+ <span class="strong">
+ <strong>
+ strip
+ </strong>
+ </span>
+ off any whitespaces that exist
+to the left and right of a string, but not the whitespaces within a string. Let
+us look at an example.
+ </p>
+ <pre class="programlisting">
+ >>> spacedtext = " Where's the text?? "
+>>> spacedtext.strip()
+"Where's the text??"
+ </pre>
+ <p id="ch4strings_dicts_11">
+ Observe that the whitespaces between the words have not been removed.
+ </p>
+ <pre class="programlisting">
+ Note: Very important thing to note is that all the methods shown above do not
+ transform the source string. The source string still remains the same.
+ Remember that **strings are immutable**.
+ </pre>
+ </div>
+ </div>
+ <div class="section" title="3.Introduction to the standard library">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h2 class="title" style="clear: both">
+ <a name="id2676848">
+ </a>
+ 3.Introduction to the standard library
+ </h2>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_12">
+ Python is often referred to as a "Batteries included!" language, mainly because
+of the Python Standard Library. The Python Standard Library provides an extensive
+set of features some of which are available directly for use while some require to
+import a few
+ <span class="strong">
+ <strong>
+ modules
+ </strong>
+ </span>
+ . The Standard Library provides various built-in functions
+like:
+ </p>
+ <div class="itemizedlist">
+ <ul class="itemizedlist" type="*">
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch4strings_dicts_13">
+ <span class="strong">
+ <strong>
+ abs()
+ </strong>
+ </span>
+ </p>
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch4strings_dicts_14">
+ <span class="strong">
+ <strong>
+ dict()
+ </strong>
+ </span>
+ </p>
+ </li>
+ <li class="listitem" style="list-style-type: *">
+ <p id="ch4strings_dicts_15">
+ <span class="strong">
+ <strong>
+ enumerate()
+ </strong>
+ </span>
+ </p>
+ </li>
+ </ul>
+ </div>
+ <p id="ch4strings_dicts_16">
+ The built-in constants like
+ <span class="strong">
+ <strong>
+ True
+ </strong>
+ </span>
+ and
+ <span class="strong">
+ <strong>
+ False
+ </strong>
+ </span>
+ are provided by the Standard Library.
+More information about the Python Standard Library is available
+ </p>
+ <div class="reference">
+ <div class="titlepage">
+ <hr />
+ </div>
+ http://docs.python.org/library/
+ </div>
+ </div>
+ <div class="section" title="4.I/O: Reading and Writing Files">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h2 class="title" style="clear: both">
+ <a name="id2676924">
+ </a>
+ 4.I/O: Reading and Writing Files
+ </h2>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_17">
+ Files are very important aspects when it comes to computing and programming.
+Up until now the focus has been on small programs that interacted with users
+through
+ <span class="strong">
+ <strong>
+ input()
+ </strong>
+ </span>
+ and
+ <span class="strong">
+ <strong>
+ raw_input()
+ </strong>
+ </span>
+ . Generally, for computational purposes
+it becomes necessary to handle files, which are usually large in size as well.
+This section focuses on basics of file handling.
+ </p>
+ <div class="section" title="4.1.Opening Files">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h3 class="title">
+ <a name="id2676954">
+ </a>
+ 4.1.Opening Files
+ </h3>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_18">
+ Files can be opened using the
+ <span class="strong">
+ <strong>
+ open()
+ </strong>
+ </span>
+ method.
+ <span class="strong">
+ <strong>
+ open()
+ </strong>
+ </span>
+ accepts 3 arguments
+out of which 2 are optional. Let us look at the syntax of
+ <span class="strong">
+ <strong>
+ open()
+ </strong>
+ </span>
+ :
+ </p>
+ <p id="ch4strings_dicts_19">
<span class="emphasis">
<em>
- exit(2)
+ f = open( filename, mode, buffering)
+ </em>
+ </span>
+ </p>
+ <p id="ch4strings_dicts_1a">
+ The
+ <span class="emphasis">
+ <em>
+ filename
+ </em>
+ </span>
+ is a compulsory argument while the
+ <span class="emphasis">
+ <em>
+ mode
</em>
</span>
and
<span class="emphasis">
<em>
- exit(3)
- </em>
- </span>
- . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
- <span class="emphasis">
- <em>
- BSD, for example, the syntax for reading *printf(3)
- </em>
- </span>
- is:
- </p>
- <pre class="programlisting">
- $man 3 printf
- </pre>
- <p id="ch4strings_dicts_69">
- Another example:
- </p>
- <pre class="programlisting">
- $man man
- </pre>
- <p id="ch4strings_dicts_6a">
- The previous example will take you to the "Manual" page entry about manual pages!
- </p>
- <div class="section" title="4.2.1.Layout">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2619231">
- </a>
- 4.2.1.Layout
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_6b">
- All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
- </p>
- NAME
- <p id="ch4strings_dicts_6c">
- The name of the command or function, followed by a one-line description of what it does.
- </p>
- SYNOPSIS
- <p id="ch4strings_dicts_6d">
- In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
- </p>
- DESCRIPTION
- <p id="ch4strings_dicts_6e">
- A textual description of the functioning of the command or function.
- </p>
- EXAMPLES
- <p id="ch4strings_dicts_6f">
- Some examples of common usage.
- </p>
- SEE ALSO
- <p id="ch4strings_dicts_70">
- A list of related commands or functions.
- </p>
- <p id="ch4strings_dicts_71">
- Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
- </p>
- <p id="ch4strings_dicts_72">
- These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
- </p>
- <p id="ch4strings_dicts_73">
- However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
- </p>
- <p id="ch4strings_dicts_74">
- Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
- </p>
- <p id="ch4strings_dicts_75">
- Usually the man pages are written in English. Translations into other languages can be also available on the system.
- </p>
- <p id="ch4strings_dicts_76">
- The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
- </p>
- </div>
- </div>
- <div class="section" title="4.3.info">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2619340">
- </a>
- 4.3.info
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_77">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
- </p>
- <p id="ch4strings_dicts_78">
- The syntax is
- </p>
- <pre class="programlisting">
- $ info <command_name>
- </pre>
- <p id="ch4strings_dicts_79">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_7a">
- <span class="emphasis">
- <em>
- n
- </em>
- </span>
- goes to the next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_7b">
- <span class="emphasis">
- <em>
- p
- </em>
- </span>
- goes to the previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_7c">
- <span class="emphasis">
- <em>
- u
- </em>
- </span>
- goes to the upper page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_7d">
- <span class="emphasis">
- <em>
- l
- </em>
- </span>
- goes to the last(visited) node
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_7e">
- To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_7f">
- info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
- </p>
- </div>
- <div class="section" title="4.4.--help">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2619426">
- </a>
- 4.4.--help
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_80">
- Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command:
- </p>
- <pre class="programlisting">
- $ userprompt@host: cat --help
-Usage: cat [OPTION] [FILE]...
-Concatenate FILE(s), or standard input, to standard output.
-
- -A, --show-all equivalent to -vET
- -b, --number-nonblank number nonempty output lines
- -e equivalent to -vE
- -E, --show-ends display $ at end of each line
- -n, --number number all output lines
- -s, --squeeze-blank suppress repeated empty output lines
- -t equivalent to -vT
- -T, --show-tabs display TAB characters as ^I
- -u (ignored)
- -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
- --help display this help and exit
- --version output version information and exit
-
-With no FILE, or when FILE is -, read standard input.
-
-Examples:
- cat f - g Output f's contents, then standard input, then g's contents.
- cat Copy standard input to standard output.
-
-Report bugs to <bug-coreutils@gnu.org>.
- </pre>
- </div>
- </div>
- <div class="section" title="5.Basic file handling">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2619479">
- </a>
- 5.Basic file handling
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="5.1.cp">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2619487">
- </a>
- 5.1.cp
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_81">
- <span class="emphasis">
- <em>
- cp
+ buffering
</em>
</span>
- is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
- </p>
- <div class="section" title="5.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2619505">
- </a>
- 5.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_82">
- To copy a file to another file:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
- </pre>
- <p id="ch4strings_dicts_83">
- To copy a file to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
- </pre>
- <p id="ch4strings_dicts_84">
- To copy a directory to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
-SourceDirectory ... TargetDirectory
- </pre>
- </div>
- <div class="section" title="5.1.2.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2619538">
- </a>
- 5.1.2.Flags
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_85">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (force) specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
- </p>
- <p id="ch4strings_dicts_86">
- <span class="emphasis">
- <em>
- -P
- </em>
- </span>
- makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
- </p>
- <p id="ch4strings_dicts_87">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- (interactive) prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
- </p>
- <p id="ch4strings_dicts_88">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- (preserve) duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_89">
- The time of the last data modification and the time of the last access.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_8a">
- The user ID and group ID (only if it has permissions to do this)
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_8b">
- The file permission bits and the SUID and SGID bits.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_8c">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- (recursive) copy directories (recursively copying all the contents)
- </p>
- </div>
- <div class="section" title="5.1.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2619635">
- </a>
- 5.1.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_8d">
- To make a copy of a file in the current directory, enter:
- </p>
- <pre class="programlisting">
- $ cp prog.c prog.bak
- </pre>
- <p id="ch4strings_dicts_8e">
- This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
- </p>
- <p id="ch4strings_dicts_8f">
- To copy a file in your current directory into another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod /home/books/hhgg
- </pre>
- <p id="ch4strings_dicts_90">
- This copies the jones file to /home/books/hhgg/zaphod.
- </p>
- <p id="ch4strings_dicts_91">
- To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
- </p>
- <pre class="programlisting">
- $ cp -p martin_luther_king martin_luther_king.jr
- </pre>
- <p id="ch4strings_dicts_92">
- This copies the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file to the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file. Instead of creating the file with the current date and time stamp, the system gives the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file the same date and time as the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file. The
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file also inherits the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file's access control protection.
- </p>
- <p id="ch4strings_dicts_93">
- To copy all the files in a directory to a new directory, enter:
- </p>
- <pre class="programlisting">
- $ cp /home/galactica/clients/* /home/hhgg/customers
- </pre>
- <p id="ch4strings_dicts_94">
- This copies only the files in the clients directory to the customers directory.
- </p>
- <p id="ch4strings_dicts_95">
- To copy a directory, including all its files and subdirectories, to another directory, enter:
- </p>
- <p id="ch4strings_dicts_96">
- $ cp -R /home/hhgg/clients /home/hhgg/customers
- </p>
- <p id="ch4strings_dicts_97">
- This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
- </p>
- <p id="ch4strings_dicts_98">
- To copy a specific set of files of any extension to another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod arthur ford /home/hhgg/clients
- </pre>
- <p id="ch4strings_dicts_99">
- This copies the
- <span class="emphasis">
- <em>
- zaphod
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- arthur
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- ford
- </em>
- </span>
- files in your current working directory to the /home/hhgg/clients directory.
- </p>
- <p id="ch4strings_dicts_9a">
- To use pattern-matching characters to copy files, enter:
- </p>
- <pre class="programlisting">
- $ cp programs/*.py .
- </pre>
- <p id="ch4strings_dicts_9b">
- This copies the files in the programs directory that end with
- <span class="emphasis">
- <em>
- .py
- </em>
- </span>
- to the current directory, signified by the single "." (dot). You must type a space between the
- <span class="emphasis">
- <em>
- py
- </em>
- </span>
- and the final dot.
- </p>
- </div>
- </div>
- <div class="section" title="5.2.mv">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2619796">
- </a>
- 5.2.mv
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_9c">
+ are
+optional. The
<span class="emphasis">
<em>
- mv
- </em>
- </span>
- (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system),
- <span class="emphasis">
- <em>
- mv
+ filename
</em>
</span>
- will rename the file instead. Write permission is required on all directories being modified.
- </p>
- <div class="section" title="5.2.1.Conflicting existing file">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2619820">
- </a>
- 5.2.1.Conflicting existing file
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_9d">
- In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
- </p>
- </div>
- <div class="section" title="5.2.2.Differences with copy and delete">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2619839">
- </a>
- 5.2.2.Differences with copy and delete
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_9e">
- Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
- </p>
- </div>
- <div class="section" title="5.2.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2619886">
- </a>
- 5.2.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ mv myfile mynewfilename renames a file
-$ mv myfile otherfilename renames a file and deletes the existing file "myfile"
-$ mv myfile /myfile moves 'myfile' from the current directory to the root directory
-$ mv myfile dir/myfile moves 'myfile' to 'dir/myfile' relative to the current directory
-$ mv myfile dir same as the previous command (the filename is implied to be the same)
-$ mv myfile dir/myfile2 moves 'myfile' to dir and renames it to 'myfile2'
-$ mv foo bar baz dir moves multiple files to directory dir
-$ mv --help shows a very concise help about the syntax of the command
-$ man mv prints an extensive user manual for 'mv' in the terminal
- </pre>
- <p id="ch4strings_dicts_9f">
- In all cases, the file or files being moved or renamed can be a directory.
- </p>
- <p id="ch4strings_dicts_a0">
- Note that when the command is called with two arguments (as
- <span class="emphasis">
- <em>
- mv name1 name2
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- mv name1 /dir/name2
- </em>
- </span>
- ), it can have three different effects, depending on whether
- <span class="emphasis">
- <em>
- name2
- </em>
- </span>
- does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
- <span class="emphasis">
- <em>
- /.
- </em>
- </span>
- (or in some Unix versions
- <span class="emphasis">
- <em>
- /
- </em>
- </span>
- is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
- </p>
- </div>
- </div>
- <div class="section" title="5.3.rm">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2619944">
- </a>
- 5.3.rm
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_a1">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
- </p>
- <p id="ch4strings_dicts_a2">
- Here's example to remove a file named "foo" from a directory, here shown with the -i option:
+ should be a string and it should be the complete path
+to the file to be opened (The path can be absolute or relative). Let us look at
+an example.
</p>
<pre class="programlisting">
- $ rm -i foo
-remove foo? y
- </pre>
- <div class="section" title="5.3.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2619974">
- </a>
- 5.3.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_a3">
- Common options that rm accepts include:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_a4">
- <span class="emphasis">
- <em>
- -r
- </em>
- </span>
- , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_a5">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- , which asks for every deletion to be confirmed ("interactive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_a6">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- , which ignores non-existent files and overrides any confirmation prompts ("force")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_a7">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- , which shows what is being removed as it happens ("verbose")
- </p>
- </li>
- </ul>
- </div>
- <p id="ch4strings_dicts_a8">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
- </p>
- <p id="ch4strings_dicts_a9">
- <span class="emphasis">
- <em>
- rm -rf
- </em>
- </span>
- (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
- </p>
- <p id="ch4strings_dicts_aa">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often used in conjunction with xargs to supply a list of files to delete:
- </p>
- <pre class="programlisting">
- xargs rm < filelist
- </pre>
- <p id="ch4strings_dicts_ab">
- When
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is used on a symbolic link, it deletes the link, but does not affect the target of the link.
- </p>
- </div>
- <div class="section" title="5.3.2.Permissions">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2620076">
- </a>
- 5.3.2.Permissions
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_ac">
- Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
- </p>
- <p id="ch4strings_dicts_ad">
- To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
- </p>
- <p id="ch4strings_dicts_ae">
- If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="6.Command Line Arguments">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2620116">
- </a>
- 6.Command Line Arguments
- </h2>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_af">
- In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
- </p>
- <p id="ch4strings_dicts_b0">
- For example, in Unix and Unix-like environments, an example of a command-line argument is:
- </p>
- <pre class="programlisting">
- rm file.s
- </pre>
- <p id="ch4strings_dicts_b1">
- "file.s" is a command line argument which tells the program rm to remove the file "file.s".
- </p>
- <p id="ch4strings_dicts_b2">
- Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
- </p>
- <p id="ch4strings_dicts_b3">
- A command line option or simply
- <span class="emphasis">
- <em>
- option
- </em>
- </span>
- (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
- </p>
- <p id="ch4strings_dicts_b4">
- Long options are introduced via "--", and are typically whole words. For example,
- <span class="emphasis">
- <em>
- ls --long --classify --all
- </em>
- </span>
- . Arguments to long options are provided with "=", as
- <span class="emphasis">
- <em>
- ls --block-size=1024
- </em>
- </span>
- . Some Unix programs use long options with single dashes, for example MPlayer as in
- <span class="emphasis">
- <em>
- mplayer -nosound
- </em>
- </span>
- .
- </p>
- <p id="ch4strings_dicts_b5">
- Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- by using
- <span class="emphasis">
- <em>
- rm -file1
- </em>
- </span>
- may produce an error, since rm may interpret
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- as a command line switch. Using
- <span class="emphasis">
- <em>
- rm -- -file1
- </em>
- </span>
- removes ambiguity.
- </p>
- </div>
- <div class="section" title="7.Basic Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2620208">
- </a>
- 7.Basic Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="7.1.head">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2620217">
- </a>
- 7.1.head
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_b6">
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:
- </p>
- <pre class="programlisting">
- $ head [options] <file_name>
- </pre>
- <p id="ch4strings_dicts_b7">
- By default,
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ head -n 20 filename
- </pre>
- <p id="ch4strings_dicts_b8">
- This displays the first 5 lines of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ head -n 5 foo*
- </pre>
- <p id="ch4strings_dicts_b9">
- Some versions omit the n and just let you say -5.
- </p>
- <div class="section" title="7.1.1.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2620267">
- </a>
- 7.1.1.Flags
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- -c <x number of bytes> Copy first x number of bytes.
- </pre>
- <p id="ch4strings_dicts_ba">
- Other options:
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- </p>
- <p id="ch4strings_dicts_bb">
- Many early versions of Unix did not have this command, and so documentation and books had
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- do this job:
- </p>
- <pre class="programlisting">
- sed 5q foo
- </pre>
- <p id="ch4strings_dicts_bc">
- This says to print every line (implicit), and quit after the fifth.
- </p>
- </div>
- </div>
- <div class="section" title="7.2.tail">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2620303">
- </a>
- 7.2.tail
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_bd">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
- </p>
- <p id="ch4strings_dicts_be">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ tail [options] <file_name>
+ >>> f = open ('basic_python/interim_assessment.rst')
</pre>
- <p id="ch4strings_dicts_bf">
- By default,
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ tail -n 20 filename
- </pre>
- <p id="ch4strings_dicts_c0">
- This example shows the last 15 bytes of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ tail -c 15 foo*
- </pre>
- <p id="ch4strings_dicts_c1">
- This example shows all lines of filename from the second line onwards:
- </p>
- <pre class="programlisting">
- $ tail -n +2 filename
- </pre>
- <p id="ch4strings_dicts_c2">
- Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:
- </p>
- <pre class="programlisting">
- $ tail -20 filename
-$ tail -50c filename
- </pre>
- <p id="ch4strings_dicts_c3">
- However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
- </p>
- <div class="section" title="7.2.1.File monitoring">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2620381">
- </a>
- 7.2.1.File monitoring
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_c4">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- has a special command line option
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:
- </p>
- <pre class="programlisting">
- $ tail -f /var/adm/messages
- </pre>
- <p id="ch4strings_dicts_c5">
- To interrupt tail while it is monitoring, break-in with
- <span class="emphasis">
- <em>
- Ctrl+C
- </em>
- </span>
- . This command can be run "in the background" with &, see job control.
- </p>
- <p id="ch4strings_dicts_c6">
- If you have a command's result to monitor, you can use the
- <span class="emphasis">
- <em>
- watch
- </em>
- </span>
- command.
- </p>
- </div>
- </div>
- <div class="section" title="7.3.cut">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2620429">
- </a>
- 7.3.cut
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_c7">
- In computing,
- <span class="emphasis">
- <em>
- cut
- </em>
- </span>
- is a Unix command line utility which is used to extract sections from each line of input usually from a file.
- </p>
- <p id="ch4strings_dicts_c8">
- Extraction of line segments can typically be done by
- <span class="emphasis">
- <em>
- bytes (-b), characters (-c)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- fields (-f)
- </em>
- </span>
- separated by a
- <span class="emphasis">
- <em>
- delimiter (-d the tab character by default)
- </em>
- </span>
- . A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
- </p>
- <p id="ch4strings_dicts_c9">
- Assuming a file named file containing the lines:
- </p>
- <pre class="programlisting">
- foo:bar:baz:qux:quux
-one:two:three:four:five:six:seven
-alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- <p id="ch4strings_dicts_ca">
- To output the fourth through tenth characters of each line:
- </p>
- <pre class="programlisting">
- $ cut -c 4-10 file
- </pre>
- <p id="ch4strings_dicts_cb">
- This gives the output:
- </p>
- <pre class="programlisting">
- :bar:ba
-:two:th
-ha:beta
- </pre>
- <p id="ch4strings_dicts_cc">
- To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
- </p>
- <pre class="programlisting">
- $ cut -d : -f 5- file
- </pre>
- <p id="ch4strings_dicts_cd">
- This gives the output:
- </p>
- <pre class="programlisting">
- quux
-five:six:seven
-epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- </div>
- <div class="section" title="7.4.paste">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2620515">
- </a>
- 7.4.paste
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_ce">
- <span class="emphasis">
- <em>
- paste
- </em>
- </span>
- is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command which operates on the vertical plane of two or more files.
- </p>
- <p id="ch4strings_dicts_cf">
- To paste several columns of data together into the file
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- from files
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- where
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- when
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ paste who where when > www
- </pre>
- <p id="ch4strings_dicts_d0">
- If the files contain:
- </p>
- <table summary="paste" border="1">
- <colgroup>
- <col width="11">
- </col>
- <col width="12">
- </col>
- <col width="12">
- </col>
- </colgroup>
- </table>
- <p id="ch4strings_dicts_dd">
- This creates the file named
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- containing:
- </p>
- <pre class="programlisting">
- Batman GothamCity January 3
-Trillian Andromeda February 4
-Jeeves London March 19
- </pre>
- </div>
- </div>
- <div class="section" title="8.Shell Meta Characters">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2620647">
- </a>
- 8.Shell Meta Characters
- </h2>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_de">
- Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
- </p>
- <p id="ch4strings_dicts_df">
- The shell meta characters include:
- </p>
- <p id="ch4strings_dicts_e0">
- / < > ! $ % ^ & * | { } [ ] " ' ` ~ ;
- </p>
- <p id="ch4strings_dicts_e1">
- Different shells may differ in the meta characters recognized.
- </p>
- <p id="ch4strings_dicts_e2">
- As an example,
- </p>
- <pre class="programlisting">
- $ ls file.*
- </pre>
- <p id="ch4strings_dicts_e3">
- run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
- </p>
- <pre class="programlisting">
- $ ls file.?
- </pre>
- <p id="ch4strings_dicts_e4">
- run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:
- </p>
- <pre class="programlisting">
- $ more c*
- </pre>
- <p id="ch4strings_dicts_e5">
- because the c* matches that long file name.
- </p>
- <p id="ch4strings_dicts_e6">
- Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named "``*`|more"` can be accomplished with:
- </p>
- <pre class="programlisting">
- $ rm ??more
- </pre>
- <p id="ch4strings_dicts_e7">
- or:
- </p>
- <pre class="programlisting">
- $ rm $\backslash$*$\backslash$|more
- </pre>
- <p id="ch4strings_dicts_e8">
- or:
- </p>
- <pre class="programlisting">
- $ rm ''*|more''
- </pre>
- </div>
- <div class="section" title="9.Looking At Files">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2620751">
- </a>
- 9.Looking At Files
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="9.1.cat">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2620760">
- </a>
- 9.1.cat
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_e9">
+ <p id="ch4strings_dicts_1b">
The
<span class="emphasis">
<em>
- cat
- </em>
- </span>
- command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
- <span class="emphasis">
- <em>
- concatenate
- </em>
- </span>
- .
- </p>
- <p id="ch4strings_dicts_ea">
- The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
- </p>
- <p id="ch4strings_dicts_eb">
- If the filename is specified as -, then
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input at that point in the sequence. If no files are specified,
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input entered.
- </p>
- <div class="section" title="9.1.1.Jargon File Definition">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2620803">
- </a>
- 9.1.1.Jargon File Definition
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_ec">
- The Jargon File version 4.4.7 lists this as the definition of
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- 1. To spew an entire file to the screen or some other output sink without
- pause (syn. blast).
-
-2. By extension, to dump large amounts of data at an unprepared target or
- with no intention of browsing it carefully. Usage: considered silly.
- Rare outside Unix sites. See also dd, BLT.
-
- Among Unix fans, *cat(1)* is considered an excellent example of
- user-interface design, because it delivers the file contents without
- such verbosity as spacing or headers between the files, and because
- it does not require the files to consist of lines of text, but works
- with any sort of data.
-
- Among Unix critics, *cat(1)* is considered the canonical example of
- bad user-interface design, because of its woefully unobvious name.
- It is far more often used to blast a single file to standard output
- than to concatenate two or more files. The name cat for the former
- operation is just as unintuitive as, say, LISP's cdr.
-
- Of such oppositions are holy wars made...
- </pre>
- </div>
- <div class="section" title="9.1.2.Useless Use of 'cat'">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2620859">
- </a>
- 9.1.2.Useless Use of 'cat'
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_ed">
- UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
- <span class="emphasis">
- <em>
- comp.unix.shell
- </em>
- </span>
- , The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
- </p>
- <p id="ch4strings_dicts_ee">
- Nevertheless one sees people doing:
- </p>
- <pre class="programlisting">
- $ cat file | some_command and its args ...
- </pre>
- <p id="ch4strings_dicts_ef">
- instead of the equivalent and cheaper:
- </p>
- <pre class="programlisting">
- <file some_command and its args ...
- </pre>
- <p id="ch4strings_dicts_f0">
- or (equivalently and more classically):
- </p>
- <pre class="programlisting">
- some_command and its args ... <file
- </pre>
- <p id="ch4strings_dicts_f1">
- Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
- </p>
- <p id="ch4strings_dicts_f2">
- Amongst many, it is still considered safer to use
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
- </p>
- </div>
- <div class="section" title="9.1.3.zcat">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2620929">
- </a>
- 9.1.3.zcat
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_f3">
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- is a Unix program similar to
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- , that decompresses individual files and concatenates them to standard output. Traditionally
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- operated on files compressed by compress but today it is usually able to operate on
- <span class="emphasis">
- <em>
- gzip
- </em>
- </span>
- or even
- <span class="emphasis">
- <em>
- bzip2
- </em>
- </span>
- archives. On such systems, it is equivalent to
- <span class="emphasis">
- <em>
- gunzip -c
- </em>
- </span>
- </p>
- </div>
- </div>
- <div class="section" title="9.2.more">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2620963">
- </a>
- 9.2.more
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_f4">
- In computing,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
- </p>
- <div class="section" title="9.2.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2620982">
- </a>
- 9.2.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_f5">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ more [options] [file_name]
- </pre>
- <p id="ch4strings_dicts_f6">
- If no file name is provided,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- looks for input from stdin.
- </p>
- <p id="ch4strings_dicts_f7">
- Once
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has paged through. (This percentage includes the text displayed on the current screen.) When
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- , which advances the output by one line, and
- <span class="emphasis">
- <em>
- Space
- </em>
- </span>
- , which advances the output by one screen.
- </p>
- <p id="ch4strings_dicts_f8">
- There are also other commands that can be used while navigating through the document; consult
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- 's
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page for more details.
- </p>
- <p id="ch4strings_dicts_f9">
- <span class="emphasis">
- <em>
- Options
- </em>
- </span>
- are typically entered before the file name, but can also be entered in the environment variable
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- . Options entered in the actual command line will override those entered in the
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- environment variable. Available options may vary between Unix systems.
- </p>
- </div>
- </div>
- <div class="section" title="9.3.less">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2621073">
- </a>
- 9.3.less
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_fa">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- does not need to read the entire file before starting, resulting in faster load times with large files.
- </p>
- <div class="section" title="9.3.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2621101">
- </a>
- 9.3.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_fb">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- vi
- </em>
- </span>
- . It is also possible to search for character patterns in the file.
- </p>
- <p id="ch4strings_dicts_fc">
- By default,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
- </p>
- <p id="ch4strings_dicts_fd">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ less [options] file_name
- </pre>
- </div>
- <div class="section" title="9.3.2.Frequently Used Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2621156">
- </a>
- 9.3.2.Frequently Used Options
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_fe">
- -g: Highlights just the current match of any searched string.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_ff">
- -I: Case-insensitive searches.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_100">
- -M: Shows more detailed prompt, including file position.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_101">
- -N: Shows line numbers (useful for source code viewing).
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_102">
- -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_103">
- -?: Shows help.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.3.Frequently Used Commands">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2621208">
- </a>
- 9.3.3.Frequently Used Commands
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_104">
- [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_105">
- [Space bar]: Next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_106">
- b: Previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_107">
- ng: Jump to line number n. Default is the start of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_108">
- nG: Jump to line number n. Default is the end of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_109">
- /pattern: Search for pattern. Regular expressions can be used.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_10a">
- '^ or g: Go to start of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_10b">
- '$ or G: Go to end of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_10c">
- s: Save current content (got from another program like grep) in a file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_10d">
- =: File information.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_10e">
- h: Help.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_10f">
- q: Quit.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.4.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2621298">
- </a>
- 9.3.4.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ less -M readme.txt #Read "readme.txt."
-$ less +F /var/log/mail.log #Follow mode for log
-$ file * | less #Easier file analysis.
-$ grep -i void *.c | less -I -p void #Case insensitive search for "void" in all .c files
- </pre>
- </div>
- </div>
- </div>
- <div class="section" title="10.Directory Structure">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2621313">
- </a>
- 10.Directory Structure
- </h2>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_110">
- In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
- </p>
- <p id="ch4strings_dicts_111">
- The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
- </p>
- <table summary="Directory Structure" border="1">
- <colgroup>
- <col width="15">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <div class="section" title="10.1.man hier">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2621588">
- </a>
- 10.1.man hier
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_136">
- This is the manual page on the UNIX filesystem. The syntax for this is:
- </p>
- <pre class="programlisting">
- $ man hier
- </pre>
- </div>
- <div class="section" title="10.2.ls -l">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2621604">
- </a>
- 10.2.ls -l
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_137">
- Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
- </p>
- <pre class="programlisting">
- $ ls -l
- </pre>
- <p id="ch4strings_dicts_138">
- This can be done after entering the required directory.
- </p>
- </div>
- </div>
- <div class="section" title="11.Permissions and Ownership">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2621627">
- </a>
- 11.Permissions and Ownership
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="11.1.chmod">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2621636">
- </a>
- 11.1.chmod
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_139">
- The
- <span class="emphasis">
- <em>
- chmod
+ mode
</em>
</span>
- command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.
+ argument specifies the mode in which the file has to be opened.
+The following are the valid mode arguments:
</p>
- <div class="section" title="11.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2621662">
- </a>
- 11.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_13a">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command options are specified like this:
- </p>
- <pre class="programlisting">
- $ chmod [options] mode[,mode] file1 [file2 ...]
- </pre>
- <p id="ch4strings_dicts_13b">
- To view what the permissions currently are, type:
- </p>
- <pre class="programlisting">
- $ ls -l file
- </pre>
- </div>
- <div class="section" title="11.1.2.Command line options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2621690">
- </a>
- 11.1.2.Command line options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_13c">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command has a number of command line options that affect its behavior. The most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_13d">
- -R: Changes the modes of directories and files recursively
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch4strings_dicts_13e">
- -v: Verbose mode; lists all files as they are being processed
- </p>
- </li>
- </ul>
- </div>
- <div class="section" title="11.1.2.1.Symbolic modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2621726">
- </a>
- 11.1.2.1.Symbolic modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_13f">
- To the
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
- </p>
- <pre class="programlisting">
- $ chmod [references][operator][modes] file1 ...
- </pre>
- <p id="ch4strings_dicts_140">
- The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="8">
- </col>
- <col width="45">
- </col>
- </colgroup>
- </table>
- <p id="ch4strings_dicts_150">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="54">
- </col>
- </colgroup>
- </table>
- <p id="ch4strings_dicts_157">
- The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="5">
- </col>
- <col width="14">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <p id="ch4strings_dicts_16d">
- The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
- </p>
- </div>
- <div class="section" title="11.1.2.2.Symbolic examples">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2622287">
- </a>
- 11.1.2.2.Symbolic examples
- </h5>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_16e">
- Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
- </p>
- <pre class="programlisting">
- $ chmod ug+rw mydir
-$ ls -ld mydir
-drw-rw---- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- <p id="ch4strings_dicts_16f">
- For a file, remove
- <span class="emphasis">
- <em>
- write
- </em>
- </span>
- permissions for all classes:
- </p>
- <pre class="programlisting">
- $ chmod a-w myfile
-$ ls -l myfile
--r-xr-xr-x 2 starwars yoda 96 Dec 8 12:53 myfile
- </pre>
- <p id="ch4strings_dicts_170">
- Set the permissions for the
- <span class="emphasis">
- <em>
- u*ser and the *g*roup to read and execute only (no write permission) on *mydir
- </em>
- </span>
- .
- </p>
- <pre class="programlisting">
- $ chmod ug=rx mydir
-$ ls -ld mydir
-dr-xr-x--- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- </div>
- <div class="section" title="11.1.2.3.Octal numbers">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2622330">
- </a>
- 11.1.2.3.Octal numbers
- </h5>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_171">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
- </p>
- <pre class="programlisting">
- $ chmod 664 myfile
-$ ls -l myfile
--rw-rw-r-- 1 57 Jul 3 10:13 myfile
- </pre>
- <p id="ch4strings_dicts_172">
- Since the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- sticky
- </em>
- </span>
- bits are not set, this is equivalent to:
- </p>
- <pre class="programlisting">
- $ chmod 0664 myfile
- </pre>
- </div>
- <div class="section" title="11.1.2.4.Special modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2622368">
- </a>
- 11.1.2.4.Special modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_173">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
- <span class="strong">
- <strong>
- s
- </strong>
- </span>
- to represent the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- modes, and
- <span class="strong">
- <strong>
- t
- </strong>
- </span>
- to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
- </p>
- <p id="ch4strings_dicts_174">
- Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
- </p>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="12.Redirection and Piping">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2622412">
- </a>
- 12.Redirection and Piping
- </h2>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_175">
- In computing,
- <span class="emphasis">
- <em>
- redirection
- </em>
- </span>
- is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
- </p>
- <p id="ch4strings_dicts_176">
- Programs do redirection with the
- <span class="emphasis">
- <em>
- dup2(2)
- </em>
- </span>
- system call, or its less-flexible but higher-level stdio analogues,
- <span class="emphasis">
- <em>
- freopen(3)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- popen(3)
- </em>
- </span>
- .
- </p>
- <div class="section" title="12.1.Redirecting standard input and standard output">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2622448">
- </a>
- 12.1.Redirecting standard input and standard output
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_177">
- Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
+ <p id="ch4strings_dicts_1c">
+ <span class="strong">
+ <strong>
+ r
+ </strong>
+ </span>
+ - Read mode
+ <span class="strong">
+ <strong>
+ w
+ </strong>
+ </span>
+ - Write mode
+ <span class="strong">
+ <strong>
+ a
+ </strong>
+ </span>
+ - Append mode
+ <span class="strong">
+ <strong>
+ b
+ </strong>
+ </span>
+ - Binary mode
+ <span class="strong">
+ <strong>
+ +
+ </strong>
+ </span>
+ - Read/Write mode
</p>
- <pre class="programlisting">
- $ command1 > file1
- </pre>
- <p id="ch4strings_dicts_178">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , placing the output in file1. Note that this will truncate any existing data in
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- . To append output to the end of the file, use the >> operator.:
- </p>
- <pre class="programlisting">
- $ command1 < file1
- </pre>
- <p id="ch4strings_dicts_179">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- as the source of input (as opposed to the keyboard).:
- </p>
- <pre class="programlisting">
- $ command1 < infile > outfile
- </pre>
- <p id="ch4strings_dicts_17a">
- combines the two capabilities:
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- reads from
- <span class="emphasis">
- <em>
- infile
- </em>
- </span>
- and writes to
- <span class="emphasis">
- <em>
- outfile
- </em>
- </span>
- </p>
- </div>
- <div class="section" title="12.2.Piping">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2622518">
- </a>
- 12.2.Piping
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_17b">
- Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
-A pipeline of three programs run on a text terminal:
- </p>
- <pre class="programlisting">
- $ command1 | command2
- </pre>
- <p id="ch4strings_dicts_17c">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using its output as the input for
- <span class="emphasis">
- <em>
- command2
- </em>
- </span>
- (commonly called piping, since the "|" character is known as a "pipe").
- </p>
- <p id="ch4strings_dicts_17d">
- This is equivalent to using two redirects and a temporary file:
+ <p id="ch4strings_dicts_1d">
+ The read mode opens the file as a read-only document. The write mode opens the
+file in the Write only mode. In the write mode, if the file existed prior to the
+opening, the previous contents of the file are erased. The append mode opens the
+file in the write mode but the previous contents of the file are not erased and
+the current data is appended onto the file.
+The binary and the read/write modes are special in the sense that they are added
+onto other modes. The read/write mode opens the file in the reading and writing
+mode combined. The binary mode can be used to open a files that do not contain
+text. Binary files such as images should be opened in the binary mode. Let us look
+at a few examples.
</p>
<pre class="programlisting">
- $ command1 > tempfile
-$ command2 < tempfile
-$ rm tempfile
- </pre>
- <p id="ch4strings_dicts_17e">
- A good example for command piping is combining
- <span class="emphasis">
- <em>
- echo
- </em>
- </span>
- with another command to achieve something interactive in a non-interactive shell, e.g.:
- </p>
- <pre class="programlisting">
- $ echo -e "user\npass" | ftp localhost
- </pre>
- <p id="ch4strings_dicts_17f">
- This runs the ftp client with input user, press return, then pass.
- </p>
- </div>
- <div class="section" title="12.3.Redirecting to and from the standard file handles">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2622579">
- </a>
- 12.3.Redirecting to and from the standard file handles
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_180">
- In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
- </p>
- <table summary="Redirecting to and from the standard file handles" border="1">
- <colgroup>
- <col width="12">
- </col>
- <col width="13">
- </col>
- <col width="24">
- </col>
- </colgroup>
- </table>
- <p id="ch4strings_dicts_18d">
- For example:
- </p>
- <pre class="programlisting">
- $ command1 2> file1
+ >>> f = open ('basic_python/interim_assessment.rst', 'r')
+>>> f = open ('armstrong.py', 'r+')
</pre>
- <p id="ch4strings_dicts_18e">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , directing the standard error stream to
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- .
- </p>
- <p id="ch4strings_dicts_18f">
- In shells derived from
- <span class="emphasis">
- <em>
- csh
- </em>
+ <p id="ch4strings_dicts_1e">
+ The third argument to the
+ <span class="strong">
+ <strong>
+ open()
+ </strong>
</span>
- (the C shell), the syntax instead appends the & character to the redirect characters, thus achieving a similar result.
- </p>
- <p id="ch4strings_dicts_190">
- Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
- </p>
- <pre class="programlisting">
- $ find / -name .profile > results 2>&1
- </pre>
- <p id="ch4strings_dicts_191">
- will try to find all files named
- <span class="emphasis">
- <em>
- .profile
- </em>
- </span>
- . Executed without redirection, it will output hits to
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- and errors (e.g. for lack of privilege to traverse protected directories) to
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- . If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge
+ method is the
<span class="emphasis">
<em>
- stderr
- </em>
- </span>
- (handle 2) into
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- (handle 1) using 2>&1 .
- </p>
- <p id="ch4strings_dicts_192">
- It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
- </p>
- <p id="ch4strings_dicts_193">
- If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus:
- </p>
- <pre class="programlisting">
- $ find / -name .profile 2>&1 | less
- </pre>
- <p id="ch4strings_dicts_194">
- A simplified form of the command:
- </p>
- <pre class="programlisting">
- $ command > file 2>&1
- </pre>
- <p id="ch4strings_dicts_195">
- is:
- </p>
- <pre class="programlisting">
- $ command &>file
- </pre>
- <p id="ch4strings_dicts_196">
- or:
- </p>
- <pre class="programlisting">
- $command >&file
- </pre>
- </div>
- <div class="section" title="12.4.Chained pipelines">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2622787">
- </a>
- 12.4.Chained pipelines
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_197">
- The redirection and piping tokens can be chained together to create complex commands. For example:
- </p>
- <pre class="programlisting">
- $ ls | grep '\.sh' | sort > shlist
- </pre>
- <p id="ch4strings_dicts_198">
- lists the contents of the current directory, where this output is filtered to only contain lines which contain
- <span class="emphasis">
- <em>
- .sh
- </em>
- </span>
- , sort this resultant output lexicographically, and place the final output in
- <span class="emphasis">
- <em>
- shlist
- </em>
- </span>
- . This type of construction is used very commonly in shell scripts and batch files.
- </p>
- </div>
- <div class="section" title="12.5.Redirect to multiple outputs">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2622821">
- </a>
- 12.5.Redirect to multiple outputs
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_199">
- The standard command
- <span class="emphasis">
- <em>
- tee
- </em>
- </span>
- can redirect output from a command to several destinations.
- </p>
- <pre class="programlisting">
- $ ls -lrt | tee xyz
- </pre>
- <p id="ch4strings_dicts_19a">
- This directs the file list output to both standard output as well as to the file
- <span class="emphasis">
- <em>
- xyz
+ buffering
</em>
</span>
- .
- </p>
- </div>
- </div>
- <div class="section" title="13.More Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2622852">
- </a>
- 13.More Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="13.1.grep">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2622861">
- </a>
- 13.1.grep
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_19b">
+ argument. This takes
+a boolean value,
<span class="emphasis">
<em>
- grep
- </em>
- </span>
- is a command line text search utility originally written for Unix. The name is taken from the first letters in
- <span class="emphasis">
- <em>
- global / regular expression / print
+ True
</em>
</span>
- , a series of instructions for the
+ or
<span class="emphasis">
<em>
- ed
- </em>
- </span>
- text editor. The
- <span class="emphasis">
- <em>
- grep
+ 1
</em>
</span>
- command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
- </p>
- <div class="section" title="13.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2622892">
- </a>
- 13.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_19c">
- This is an example of a common
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- usage:
- </p>
- <pre class="programlisting">
- $ grep apple fruitlist.txt
- </pre>
- <p id="ch4strings_dicts_19d">
- In this case,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- prints all lines containing 'apple' from the file
- <span class="emphasis">
- <em>
- fruitlist.txt
- </em>
- </span>
- , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
- </p>
- <p id="ch4strings_dicts_19e">
- Like most Unix commands,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- accepts command line arguments to change this and many other behaviors. For example:
- </p>
- <pre class="programlisting">
- $ grep -i apple fruitlist.txt
- </pre>
- <p id="ch4strings_dicts_19f">
- This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be case insensitive, or to ignore case.
- </p>
- <p id="ch4strings_dicts_1a0">
- To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
- </p>
- <pre class="programlisting">
- $ grep -w apple fruitlist.txt
- </pre>
- <p id="ch4strings_dicts_1a1">
- Regular expressions can be used to match more complicated queries.
- </p>
- <div class="section" title="13.1.1.1.Variations">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2622971">
- </a>
- 13.1.1.1.Variations
- </h5>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_1a2">
- There are countless implementations and derivatives of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- available for many operating systems. Early variants of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- included
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- . The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- may also behave differently depending on the name by which it is invoked, allowing
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be links to the same program.
- </p>
- <p id="ch4strings_dicts_1a3">
- <span class="emphasis">
- <em>
- pcregrep
- </em>
- </span>
- is an implementation of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- that uses Perl regular expression syntax.
- </p>
- <p id="ch4strings_dicts_1a4">
- Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
- <span class="emphasis">
- <em>
- pgrep
- </em>
- </span>
- utility, for instance, displays the processes whose names match a given regular expression.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="13.2.tr">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2623051">
- </a>
- 13.2.tr
- </h3>
- </div>
- </div>
- </div>
- <p id="ch4strings_dicts_1a5">
+ indicates that buffering has to be enabled on the file,
+that is the file is loaded on to the main memory and the changes made to the file are
+not immediately written to the disk. If the
<span class="emphasis">
<em>
- tr
+ buffering
</em>
</span>
- (abbreviated from
+ argument is
<span class="emphasis">
<em>
- translate
+ 0
</em>
</span>
or
<span class="emphasis">
<em>
- transliterate
- </em>
- </span>
- ) is a command in Unix-like operating systems.
- </p>
- <p id="ch4strings_dicts_1a6">
- When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
- </p>
- <pre class="programlisting">
- $ tr 'abcd' 'jkmn'
- </pre>
- <p id="ch4strings_dicts_1a7">
- maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
- </p>
- <p id="ch4strings_dicts_1a8">
- Sets of characters may be abbreviated by using character ranges. The previous example could be written:
- </p>
- <pre class="programlisting">
- $ tr 'a-d' 'jkmn'
- </pre>
- <p id="ch4strings_dicts_1a9">
- In POSIX compliant versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
- </p>
- <p id="ch4strings_dicts_1aa">
- The
- <span class="emphasis">
- <em>
- -c
- </em>
- </span>
- flag complements the first set of characters.
- </p>
- <pre class="programlisting">
- $ tr -cd '[:alnum:]'
- </pre>
- <p id="ch4strings_dicts_1ab">
- therefore removes all non-alphanumeric characters.
- </p>
- <p id="ch4strings_dicts_1ac">
- The
- <span class="emphasis">
- <em>
- -s
+ False
</em>
</span>
- flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
- </p>
- <pre class="programlisting">
- $ tr -s '\n' '\n'
- </pre>
- <p id="ch4strings_dicts_1ad">
- replaces sequences of one or more newline characters with a single newline.
- </p>
- <p id="ch4strings_dicts_1ae">
- The
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
- </p>
- <pre class="programlisting">
- $ tr -d '\r'
- </pre>
- <p id="ch4strings_dicts_1af">
- Most versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , including GNU
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- and classic Unix
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
- </p>
- <p id="ch4strings_dicts_1b0">
- Ruby and Perl also have an internal
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- operator, which operates analogously. Tcl's
- <span class="emphasis">
- <em>
- string map
- </em>
- </span>
- command is more general in that it maps strings to strings while
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- maps characters to characters.
+ the
+changes are directly written on to the disk immediately.
</p>
</div>
+ <div class="section" title="4.2.Reading and Writing files">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h3 class="title">
+ <a name="id2676411">
+ </a>
+ 4.2.Reading and Writing files
+ </h3>
+ </div>
+ </div>
+ </div>
+ <div class="section" title="4.2.1.write()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2676420">
+ </a>
+ 4.2.1.
+ <span class="strong">
+ <strong>
+ write()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_1f">
+ <span class="strong">
+ <strong>
+ write()
+ </strong>
+ </span>
+ , evidently, is used to write data onto a file. It takes the data to
+be written as the argument. The data can be a string, an integer, a float or any
+other datatype. In order to be able to write data onto a file, the file has to
+be opened in one of
+ <span class="strong">
+ <strong>
+ w
+ </strong>
+ </span>
+ ,
+ <span class="strong">
+ <strong>
+ a
+ </strong>
+ </span>
+ or
+ <span class="strong">
+ <strong>
+ +
+ </strong>
+ </span>
+ modes.
+ </p>
+ </div>
+ <div class="section" title="4.2.2.read()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2676458">
+ </a>
+ 4.2.2.
+ <span class="strong">
+ <strong>
+ read()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_20">
+ <span class="strong">
+ <strong>
+ read()
+ </strong>
+ </span>
+ is used to read data from a file. It takes the number of bytes of data
+to be read as the argument. If nothing is specified by default it reads the entire
+contents from the current position to the end of file.
+ </p>
+ <p id="ch4strings_dicts_21">
+ Let us look at a few examples:
+ </p>
+ <pre class="programlisting">
+ >>> f = open ('randomtextfile', 'w')
+>>> f.write('Hello all, this is PythonFreak. This is a random text file.')
+>>> f = open ('../randomtextfile', 'r')
+>>> f = open ('../randomtextfile', 'r')
+>>> f.read(5)
+'Hello'
+>>> f.read()
+' all, this is PythonFreak. This is a random text file.'
+>>> f.close()
+ </pre>
+ </div>
+ <div class="section" title="4.2.3.readline()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2676493">
+ </a>
+ 4.2.3.
+ <span class="strong">
+ <strong>
+ readline()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_22">
+ <span class="strong">
+ <strong>
+ readline()
+ </strong>
+ </span>
+ is used to read a file line by line.
+ <span class="strong">
+ <strong>
+ readline()
+ </strong>
+ </span>
+ reads a line
+of a file at a time. When an argument is passed to
+ <span class="strong">
+ <strong>
+ readline()
+ </strong>
+ </span>
+ it reads that
+many bytes from the current line.
+ </p>
+ <p id="ch4strings_dicts_23">
+ One other method to read a file line by line is using the
+ <span class="strong">
+ <strong>
+ read()
+ </strong>
+ </span>
+ and the
+ <span class="strong">
+ <strong>
+ for
+ </strong>
+ </span>
+ construct. Let us look at this block of code as an example.
+ </p>
+ <pre class="programlisting">
+ >>> f = open('../randomtextfile', 'r')
+>>> for line in f:
+... print line
+...
+Hello all!
+
+This is PythonFreak on the second line.
+
+This is a random text file on line 3
+ </pre>
+ </div>
+ <div class="section" title="4.2.4.close()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2677395">
+ </a>
+ 4.2.4.
+ <span class="strong">
+ <strong>
+ close()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_24">
+ One must always close all the files that have been opened. Although, files opened
+will be closed automatically when the program ends. When files opened in read mode
+are not closed it might lead to uselessly locked sometimes. In case of files
+opened in the write mode it is more important to close the files. This is because,
+Python maybe using the file in the buffering mode and when the file is not closed
+the buffer maybe lost completely and the changes made to the file are lost forever.
+ </p>
+ </div>
+ </div>
</div>
- <div class="section" title="14.Elementary Regex">
+ <div class="section" title="5.Dictionaries">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
- <a name="id2623202">
+ <a name="id2677418">
</a>
- 14.Elementary Regex
+ 5.Dictionaries
</h2>
</div>
</div>
</div>
- <p id="ch4strings_dicts_1b1">
- In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
+ <p id="ch4strings_dicts_25">
+ A dictionary in general, are designed to be able to look up meanings of words.
+Similarly, the Python dictionaries are also designed to look up for a specific
+key and retrieve the corresponding value. Dictionaries are data structures that
+provide key-value mappings. Dictionaries are similar to lists except that instead
+of the values having integer indexes, dictionaries have keys or strings as indexes.
+Let us look at an example of how to define dictionaries.
</p>
- <p id="ch4strings_dicts_1b2">
- Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributionsincluding the editor
+ <pre class="programlisting">
+ >>> dct = { 'Sachin': 'Tendulkar', 'Rahul': 'Dravid', 'Anil': 'Kumble'}
+ </pre>
+ <p id="ch4strings_dicts_26">
+ The dictionary consists of pairs of strings, which are called
<span class="emphasis">
<em>
- ed
+ keys
</em>
</span>
- and the filter
+ and their
+corresponding
<span class="emphasis">
<em>
- grep
+ values
</em>
</span>
- were the first to popularize the concept of regular expressions.
- </p>
- <p id="ch4strings_dicts_1b3">
- Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
+ separated by
<span class="emphasis">
<em>
- Basic Regular Expressions
+ :
+ </em>
+ </span>
+ and each of these
+ <span class="emphasis">
+ <em>
+ key-value
</em>
</span>
- (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
- </p>
- <p id="ch4strings_dicts_1b4">
- In the BRE syntax, most characters are treated as literals they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
+ pairs are
+comma(',') separated and the entire structure wrapped in a pair curly braces
+ <span class="emphasis">
+ <em>
+ {}
+ </em>
+ </span>
+ .
</p>
- <table summary="Elementary Regex" border="1">
- <colgroup>
- <col width="13">
- </col>
- <col width="60">
- </col>
- </colgroup>
- </table>
- <div class="section" title="14.1.Lazy quantification">
+ <pre class="programlisting">
+ Note: The data inside a dictionary is not ordered. The order in which you enter
+the key-value pairs is not the order in which they are stored in the dictionary.
+Python has an internal storage mechanism for that which is out of the purview
+of this document.
+ </pre>
+ <div class="section" title="5.1.dict()">
<div class="titlepage">
<div>
<div>
<h3 class="title">
- <a name="id2623415">
+ <a name="id2677474">
</a>
- 14.1.Lazy quantification
+ 5.1.
+ <span class="strong">
+ <strong>
+ dict()
+ </strong>
+ </span>
+ </h3>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_27">
+ The
+ <span class="strong">
+ <strong>
+ dict()
+ </strong>
+ </span>
+ function is used to create dictionaries from other mappings or other
+dictionaries. Let us look at an example.
+ </p>
+ <pre class="programlisting">
+ >>> diction = dict(mat = 133, avg = 52.53)
+ </pre>
+ <p id="ch4strings_dicts_28">
+ <span class="strong">
+ <strong>
+ String Formatting with Dictionaries:
+ </strong>
+ </span>
+ </p>
+ <p id="ch4strings_dicts_29">
+ String formatting was discussed in the previous section and it was mentioned that
+dictionaries can also be used for formatting more than one value. This section
+focuses on the formatting of strings using dictionaries. String formatting using
+dictionaries is more appealing than doing the same with tuples. Here the
+ <span class="emphasis">
+ <em>
+ keyword
+ </em>
+ </span>
+ can be used as a place holder and the
+ <span class="emphasis">
+ <em>
+ value
+ </em>
+ </span>
+ corresponding to it is replaced in
+the formatted string. Let us look at an example.
+ </p>
+ <pre class="programlisting">
+ >>> player = { 'Name':'Rahul Dravid', 'Matches':133, 'Avg':52.53, '100s':26 }
+>>> strng = '%(Name)s has played %(Matches)d with an average of %(Avg).2f and has %(100s)d hundreds to his name.'
+>>> print strng % player
+Rahul Dravid has played 133 with an average of 52.53 and has 26 hundreds to his name.
+ </pre>
+ </div>
+ <div class="section" title="5.2.Dictionary Methods">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h3 class="title">
+ <a name="id2677539">
+ </a>
+ 5.2.Dictionary Methods
</h3>
</div>
</div>
</div>
- <p id="ch4strings_dicts_1c9">
- The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example:
- </p>
- <pre class="programlisting">
- Another whale explosion occurred on <January 26>, <2004>.
- </pre>
- <p id="ch4strings_dicts_1ca">
- ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the * quantifier is greedy it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
- </p>
- <p id="ch4strings_dicts_1cb">
- Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as
- <span class="emphasis">
- <em>
- lazy
- </em>
- </span>
- (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
- </p>
- </div>
- </div>
- <div class="section" title="15.One Liners">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2623491">
- </a>
- 15.One Liners
- </h2>
+ <div class="section" title="5.2.1.clear()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2677547">
+ </a>
+ 5.2.1.
+ <span class="strong">
+ <strong>
+ clear()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_2a">
+ The
+ <span class="strong">
+ <strong>
+ clear()
+ </strong>
+ </span>
+ method removes all the existing
+ <span class="emphasis">
+ <em>
+ key-value
+ </em>
+ </span>
+ pairs from a dictionary.
+It returns
+ <span class="emphasis">
+ <em>
+ None
+ </em>
+ </span>
+ or rather does not return anything. It is a method that changes
+the object. It has to be noted here that dictionaries are not immutable. Let us
+look at an example.
+ </p>
+ <pre class="programlisting">
+ >>> dct
+{'Anil': 'Kumble', 'Sachin': 'Tendulkar', 'Rahul': 'Dravid'}
+>>> dct.clear()
+>>> dct
+{}
+ </pre>
+ </div>
+ <div class="section" title="5.2.2.copy()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2677582">
+ </a>
+ 5.2.2.
+ <span class="strong">
+ <strong>
+ copy()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_2b">
+ The
+ <span class="strong">
+ <strong>
+ copy()
+ </strong>
+ </span>
+ returns a copy of a given dictionary. Let us look at an example.
+ </p>
+ <pre class="programlisting">
+ >>> dct = {'Anil': 'Kumble', 'Sachin': 'Tendulkar', 'Rahul': 'Dravid'}
+>>> dctcopy = dct.copy()
+>>> dctcopy
+{'Anil': 'Kumble', 'Sachin': 'Tendulkar', 'Rahul': 'Dravid'}
+ </pre>
+ </div>
+ <div class="section" title="5.2.3.get()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2677613">
+ </a>
+ 5.2.3.
+ <span class="strong">
+ <strong>
+ get()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_2c">
+ <span class="strong">
+ <strong>
+ get()
+ </strong>
+ </span>
+ returns the
+ <span class="emphasis">
+ <em>
+ value
+ </em>
+ </span>
+ for the
+ <span class="emphasis">
+ <em>
+ key
+ </em>
+ </span>
+ passed as the argument and if the
+ <span class="emphasis">
+ <em>
+ key
+ </em>
+ </span>
+ does not exist in the dictionary, it returns
+ <span class="emphasis">
+ <em>
+ None
+ </em>
+ </span>
+ . Let us look at an
+example.
+ </p>
+ <pre class="programlisting">
+ >>> print dctcopy.get('Saurav')
+None
+>>> print dctcopy.get('Anil')
+Kumble
+ </pre>
+ </div>
+ <div class="section" title="5.2.4.has_key()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2677651">
+ </a>
+ 5.2.4.
+ <span class="strong">
+ <strong>
+ has_key()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
</div>
+ <p id="ch4strings_dicts_2d">
+ This method returns
+ <span class="emphasis">
+ <em>
+ True
+ </em>
+ </span>
+ if the given
+ <span class="emphasis">
+ <em>
+ key
+ </em>
+ </span>
+ is in the dictionary, else it returns
+ <span class="emphasis">
+ <em>
+ False
+ </em>
+ </span>
+ .
+ </p>
+ <pre class="programlisting">
+ >>> dctcopy.has_key('Saurav')
+False
+>>> dctcopy.has_key('Sachin')
+True
+ </pre>
+ </div>
+ <div class="section" title="5.2.5.pop()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2677681">
+ </a>
+ 5.2.5.
+ <span class="strong">
+ <strong>
+ pop()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_2e">
+ This method is used to retrieve the
+ <span class="emphasis">
+ <em>
+ value
+ </em>
+ </span>
+ of a given
+ <span class="emphasis">
+ <em>
+ key
+ </em>
+ </span>
+ and subsequently
+remove the
+ <span class="emphasis">
+ <em>
+ key-value
+ </em>
+ </span>
+ pair from the dictionary. Let us look at an example.
+ </p>
+ <pre class="programlisting">
+ >>> print dctcopy.pop('Sachin')
+Tendulkar
+>>> dctcopy
+{'Anil': 'Kumble', 'Rahul': 'Dravid'}
+ </pre>
+ </div>
+ <div class="section" title="5.2.6.popitem()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2677715">
+ </a>
+ 5.2.6.
+ <span class="strong">
+ <strong>
+ popitem()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_2f">
+ This method randomly pops a
+ <span class="emphasis">
+ <em>
+ key-value
+ </em>
+ </span>
+ pair from a dictionary and returns it.
+The
+ <span class="emphasis">
+ <em>
+ key-value
+ </em>
+ </span>
+ pair returned is removed from the dictionary. Let us look at an
+example.
+ </p>
+ <pre class="programlisting">
+ >>> print dctcopy.popitem()
+('Anil', 'Kumble')
+>>> dctcopy
+{'Rahul': 'Dravid'}
+
+Note that the item chosen is completely random since dictionaries are unordered
+as mentioned earlier.
+ </pre>
+ </div>
+ <div class="section" title="5.2.7.update()">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h4 class="title">
+ <a name="id2677751">
+ </a>
+ 5.2.7.
+ <span class="strong">
+ <strong>
+ update()
+ </strong>
+ </span>
+ </h4>
+ </div>
+ </div>
+ </div>
+ <p id="ch4strings_dicts_30">
+ The
+ <span class="strong">
+ <strong>
+ update()
+ </strong>
+ </span>
+ method updates the contents of one dictionary with the contents
+of another dictionary. For items with existing
+ <span class="emphasis">
+ <em>
+ keys
+ </em>
+ </span>
+ their
+ <span class="emphasis">
+ <em>
+ values
+ </em>
+ </span>
+ are updated,
+and the rest of the items are added. Let us look at an example.
+ </p>
+ <pre class="programlisting">
+ >>> dctcopy.update(dct)
+>>> dct
+{'Anil': 'Kumble', 'Sachin': 'Tendulkar', 'Rahul': 'Dravid'}
+>>> dctcopy
+{'Anil': 'Kumble', 'Sachin': 'Tendulkar', 'Rahul': 'Dravid'}
+ </pre>
</div>
</div>
- <p id="ch4strings_dicts_1cc">
- A
- <span class="emphasis">
- <em>
- one-liner
- </em>
- </span>
- is textual input to the command-line of an operating system shell that performs some function in just one line of input.
- </p>
- <p id="ch4strings_dicts_1cd">
- The one liner can be
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch4strings_dicts_1ce">
- An expression written in the language of the shell.
- </p>
- </li>
- <li class="listitem">
- <p id="ch4strings_dicts_1cf">
- The invocation of an interpreter together with program source for the interpreter to run.
- </p>
- </li>
- <li class="listitem">
- <p id="ch4strings_dicts_1d0">
- The invocation of a compiler together with source to compile and
-instructions for executing the compiled program.
- </p>
- </li>
- </ol>
- </div>
- <p id="ch4strings_dicts_1d1">
- Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
- </p>
- <p id="ch4strings_dicts_1d2">
- The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
- </p>
- <p id="ch4strings_dicts_1d3">
- The word
- <span class="emphasis">
- <em>
- One-liner
- </em>
- </span>
- has two references in the index of the book
- <span class="emphasis">
- <em>
- The AWK Programming Language
- </em>
- </span>
- (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
- </p>
- <pre class="programlisting">
- The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.
- </pre>
- <p id="ch4strings_dicts_1d4">
- Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
- </p>
- <p id="ch4strings_dicts_1d5">
- The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
- </p>
- <p id="ch4strings_dicts_1d6">
- Here are the first few of them:
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch4strings_dicts_1d7">
- Print the total number of input lines:
- </p>
- <p id="ch4strings_dicts_1d8">
- END { print NR }
- </p>
- </li>
- <li class="listitem">
- <p id="ch4strings_dicts_1d9">
- Print the tenth input line:
- </p>
- <p id="ch4strings_dicts_1da">
- NR == 10
- </p>
- </li>
- <li class="listitem">
- <p id="ch4strings_dicts_1db">
- Print the last field of every input line:
- </p>
- <p id="ch4strings_dicts_1dc">
- { print $NF }
- </p>
- </li>
- </ol>
- </div>
- <p id="ch4strings_dicts_1dd">
- One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
- </p>
- <p id="ch4strings_dicts_1de">
- The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:
- </p>
- <pre class="programlisting">
- main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
-*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
- </pre>
- <p id="ch4strings_dicts_1df">
- This one-liner program is a
- <span class="emphasis">
- <em>
- glob pattern matcher
- </em>
- </span>
- . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
- </p>
- <p id="ch4strings_dicts_1e0">
- Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:
- </p>
- <pre class="programlisting">
- $ prog foo 'f??'; echo $?
-
-$ prog 'best short program' '??st*o**p?*'; echo $?
- </pre>
- <p id="ch4strings_dicts_1e1">
- Here is a one line shell script to show directories:
- </p>
- <pre class="programlisting">
- $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
- </pre>
</div>
</div>
</div>
--- a/SEESenv/web/html/ch5func.html Mon Feb 22 18:46:07 2010 +0530
+++ b/SEESenv/web/html/ch5func.html Mon Feb 22 22:38:51 2010 +0530
@@ -27,7 +27,8 @@
<dl>
<dt>
<span class="article">
- <a href="#id2832695">
+ <a href="#id2813580">
+ Functional Approach
</a>
</span>
</dt>
@@ -35,182 +36,43 @@
<dl>
<dt>
<span class="section">
- <a href="#id2642820">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2830514">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2883754">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2884019">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2884146">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2884154">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2884426">
- 3. Basic Commands
+ <a href="#id2864618">
+ 1. Function scope
</a>
</span>
</dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2884434">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2884591">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2884648">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2884743">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2884824">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
<dt>
<span class="section">
- <a href="#id2884984">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2884993">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2885075">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2885261">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2885347">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2885401">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2885409">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2885718">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2883527">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2886163">
- 6. Command Line Arguments
+ <a href="#id2864676">
+ 2. Default Arguments
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2886256">
- 7. Basic Text Processing
+ <a href="#id2864716">
+ 3. Keyword Arguments
+ </a>
+ </span>
+ </dt>
+ <dt>
+ <span class="section">
+ <a href="#id2864832">
+ 4. Parameter Packing and Unpacking
+ </a>
+ </span>
+ </dt>
+ <dt>
+ <span class="section">
+ <a href="#id2864932">
+ 5. Nested Functions and Scopes
+ </a>
+ </span>
+ </dt>
+ <dt>
+ <span class="section">
+ <a href="#id2864984">
+ 6. map, reduce and filter functions
</a>
</span>
</dt>
@@ -218,221 +80,25 @@
<dl>
<dt>
<span class="section">
- <a href="#id2886264">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2886352">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2886479">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2886565">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2886699">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2886803">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2886811">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2886999">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2887113">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2887349">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2887614">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2887630">
- 10.2. ls -l
+ <a href="#id2865174">
+ 6.1. List Comprehensions
</a>
</span>
</dt>
</dl>
</dd>
- <dt>
- <span class="section">
- <a href="#id2887652">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2887661">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2888420">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2888457">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2888526">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2888586">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2888787">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2888821">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2888851">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2888860">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2889048">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2889196">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2889402">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2889478">
- 15. One Liners
- </a>
- </span>
- </dt>
</dl>
</dd>
</dl>
</div>
- <div class="article">
+ <div class="article" title="Functional Approach">
<div class="titlepage">
<div>
<div>
- <h2 class="title" id="id2832695">
+ <h2 class="title">
+ <a name="id2813580">
+ </a>
+ Functional Approach
</h2>
</div>
</div>
@@ -447,374 +113,43 @@
<dl>
<dt>
<span class="section">
- <a href="#id2642820">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2830514">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2883754">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2884019">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2884146">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2884154">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2884426">
- 3. Basic Commands
+ <a href="#id2864618">
+ 1. Function scope
</a>
</span>
</dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2884434">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2884591">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2884648">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2884743">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2884824">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
<dt>
<span class="section">
- <a href="#id2884984">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2884993">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2885075">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2885261">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2885347">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2885401">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2885409">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2885718">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2883527">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2886163">
- 6. Command Line Arguments
+ <a href="#id2864676">
+ 2. Default Arguments
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2886256">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2886264">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2886352">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2886479">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2886565">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2886699">
- 8. Shell Meta Characters
+ <a href="#id2864716">
+ 3. Keyword Arguments
</a>
</span>
</dt>
<dt>
<span class="section">
- <a href="#id2886803">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2886811">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2886999">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2887113">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2887349">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2887614">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2887630">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2887652">
- 11. Permissions and Ownership
+ <a href="#id2864832">
+ 4. Parameter Packing and Unpacking
</a>
</span>
</dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2887661">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
<dt>
<span class="section">
- <a href="#id2888420">
- 12. Redirection and Piping
+ <a href="#id2864932">
+ 5. Nested Functions and Scopes
</a>
</span>
</dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2888457">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2888526">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2888586">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2888787">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2888821">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
<dt>
<span class="section">
- <a href="#id2888851">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2888860">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2889048">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2889196">
- 14. Elementary Regex
+ <a href="#id2864984">
+ 6. map, reduce and filter functions
</a>
</span>
</dt>
@@ -822,4433 +157,946 @@
<dl>
<dt>
<span class="section">
- <a href="#id2889402">
- 14.1. Lazy quantification
+ <a href="#id2865174">
+ 6.1. List Comprehensions
</a>
</span>
</dt>
</dl>
</dd>
- <dt>
- <span class="section">
- <a href="#id2889478">
- 15. One Liners
- </a>
- </span>
- </dt>
</dl>
</div>
- <div class="section" title="1.Introducing Linux">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2642820">
- </a>
- 1.Introducing Linux
- </h2>
- </div>
- </div>
- </div>
- <p id="ch5func_1">
- (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
- </p>
- <p id="ch5func_2">
- Linux (usually pronounced lnks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
- </p>
- <p id="ch5func_3">
- Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
- </p>
- <p id="ch5func_4">
- The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
- </p>
- <div class="section" title="1.1.Historical Background">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2830514">
- </a>
- 1.1.Historical Background
- </h3>
- </div>
- </div>
- </div>
- <div class="section" title="1.1.1.Events leading to the creation">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2830388">
- </a>
- 1.1.1.Events leading to the creation
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_5">
- The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_6">
- In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="1.1.2.The Creation of Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2883709">
- </a>
- 1.1.2.The Creation of Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_7">
- In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
- </p>
- <p id="ch5func_8">
- Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
- </p>
- </div>
- </div>
- <div class="section" title="1.2.Design and Implications">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2883754">
- </a>
- 1.2.Design and Implications
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_9">
- A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
- </p>
- <div class="section" title="1.2.1.User Interface">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2883778">
- </a>
- 1.2.1.User Interface
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_a">
- Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
- </p>
- <p id="ch5func_b">
- A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
- </p>
- </div>
- <div class="section" title="1.2.2.Development">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2883830">
- </a>
- 1.2.2.Development
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_c">
- The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
- </p>
- <p id="ch5func_d">
- Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
- </p>
- <p id="ch5func_e">
- A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
- </p>
- </div>
- <div class="section" title="1.2.3.Community">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2883886">
- </a>
- 1.2.3.Community
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_f">
- A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
- </p>
- <p id="ch5func_10">
- In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
- </p>
- <p id="ch5func_11">
- Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
- </p>
- </div>
- <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2883929">
- </a>
- 1.2.4.Can I make a profit out of running a business involving Linux?
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_12">
- The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
- </p>
- </div>
- <div class="section" title="1.2.5.Programming on Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2883975">
- </a>
- 1.2.5.Programming on Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_13">
- Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
- </p>
- <p id="ch5func_14">
- Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
- </p>
- <p id="ch5func_15">
- The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
- </p>
- </div>
- </div>
- <div class="section" title="1.3.Reasons for Using Linux">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2884019">
- </a>
- 1.3.Reasons for Using Linux
- </h3>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_16">
- Linux is free:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_17">
- As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
-Most of all, Linux is free as in "free speech":
-The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_18">
- Linux is portable to any hardware platform:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_19">
- A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_1a">
- Linux was made to keep on running:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_1b">
- As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_1c">
- Linux is secure and versatile:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_1d">
- The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_1e">
- Linux is scalable:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_1f">
- From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_20">
- The Linux OS and Linux applications have very short debugtimes:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_21">
- Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
- </p>
- </div>
- </div>
- <div class="section" title="2.Getting Started">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2884146">
- </a>
- 2.Getting Started
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="2.1.Logging in, activating the user interface and logging out">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2884154">
- </a>
- 2.1.Logging in, activating the user interface and logging out
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_22">
- In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PCbased Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multiuser features, or in graphical console mode, which looks better but eats more system resources.
- </p>
- <div class="section" title="2.1.1.Graphical Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2884184">
- </a>
- 2.1.1.Graphical Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_23">
- This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
- </p>
- <p id="ch5func_24">
- To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
- <span class="emphasis">
- <em>
- OK
- </em>
- </span>
- or press
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- .
-It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
- </p>
- <p id="ch5func_25">
- After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
- </p>
- <p id="ch5func_26">
- To continue, you will need to open a
- <span class="emphasis">
- <em>
- terminal window
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
- <span class="emphasis">
- <em>
- Applications>Utilities->System Tools
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- Internet menu
- </em>
- </span>
- , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
- </p>
- <p id="ch5func_27">
- While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old pointnclick method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
- </p>
- <p id="ch5func_28">
- A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
- </p>
- <p id="ch5func_29">
- Another common form for a prompt is this one:
-[
- </p>
- <div class="reference">
- <div class="titlepage">
- <hr />
- </div>
- user@host
- </div>
- <p>
- dir]
- </p>
- <p id="ch5func_2a">
- In the above example,
- <span class="emphasis">
- <em>
- user
- </em>
- </span>
- will be your login name,
- <span class="emphasis">
- <em>
- hosts
- </em>
- </span>
- the name of the machine you are working on, and
- <span class="emphasis">
- <em>
- dir
- </em>
- </span>
- an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- icon or find
- <span class="emphasis">
- <em>
- Log Out
- </em>
- </span>
- in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
- </p>
- <p id="ch5func_2b">
- When you see the login screen again, asking to enter user name and password, logout was successful.
- </p>
- </div>
- <div class="section" title="2.1.2.Text Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2884338">
- </a>
- 2.1.2.Text Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_2c">
- One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
- </p>
- <p id="ch5func_2d">
- The login is different from a graphical login, in that you have to hit the
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- . You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
-reasons.
- </p>
- <p id="ch5func_2e">
- When the system has accepted you as a valid user, you may get some more information, called the
- <span class="emphasis">
- <em>
- message of the day
- </em>
- </span>
- , which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
- </p>
- <p id="ch5func_2f">
- Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a nonprivileged user.
- </p>
- <p id="ch5func_30">
- Logging out is done by entering the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't poweroff the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="3.Basic Commands">
+ <p id="ch5func_1">
+ <span class="emphasis">
+ <em>
+ Functions
+ </em>
+ </span>
+ allow us to enclose a set of statements and call the function again
+and again instead of repeating the group of statements everytime. Functions also
+allow us to isolate a piece of code from all the other code and provides the
+convenience of not polluting the global variables.
+ </p>
+ <p id="ch5func_2">
+ <span class="emphasis">
+ <em>
+ Function
+ </em>
+ </span>
+ in python is defined with the keyword
+ <span class="strong">
+ <strong>
+ def
+ </strong>
+ </span>
+ followed by the name
+of the function, in turn followed by a pair of parenthesis which encloses the
+list of parameters to the function. The definition line ends with a ':'. The
+definition line is followed by the body of the function intended by one block.
+The
+ <span class="emphasis">
+ <em>
+ Function
+ </em>
+ </span>
+ must return a value:
+ </p>
+ <pre class="programlisting">
+ def factorial(n):
+ fact = 1
+ for i in range(2, n):
+ fact *= i
+
+ return fact
+ </pre>
+ <p id="ch5func_3">
+ The code snippet above defines a function with the name factorial, takes the
+number for which the factorial must be computed, computes the factorial and
+returns the value.
+ </p>
+ <p id="ch5func_4">
+ A
+ <span class="emphasis">
+ <em>
+ Function
+ </em>
+ </span>
+ once defined can be used or called anywhere else in the program. We
+call a fucntion with its name followed by a pair of parenthesis which encloses
+the arguments to the function.
+ </p>
+ <p id="ch5func_5">
+ The value that function returns can be assigned to a variable. Let's call the
+above function and store the factorial in a variable:
+ </p>
+ <pre class="programlisting">
+ fact5 = factorial(5)
+ </pre>
+ <p id="ch5func_6">
+ The value of fact5 will now be 120, which is the factorial of 5. Note that we
+passed 5 as the argument to the function.
+ </p>
+ <p id="ch5func_7">
+ It may be necessary to document what the function does, for each of the function
+to help the person who reads our code to understand it better. In order to do
+this Python allows the first line of the function body to be a string. This
+string is called as
+ <span class="emphasis">
+ <em>
+ Documentation String
+ </em>
+ </span>
+ or
+ <span class="emphasis">
+ <em>
+ docstring
+ </em>
+ </span>
+ .
+ <span class="emphasis">
+ <em>
+ docstrings
+ </em>
+ </span>
+ prove
+to be very handy since there are number of tools which can pull out all the
+docstrings from Python functions and generate the documentation automatically
+from it.
+ <span class="emphasis">
+ <em>
+ docstrings
+ </em>
+ </span>
+ for functions can be written as follows:
+ </p>
+ <pre class="programlisting">
+ def factorial(n):
+ 'Returns the factorial for the number n.'
+ fact = 1
+ for i in range(2, n):
+ fact *= i
+
+ return fact
+ </pre>
+ <p id="ch5func_8">
+ An important point to note at this point is that, a function can return any
+Python value or a Python object, which also includes a
+ <span class="emphasis">
+ <em>
+ Tuple
+ </em>
+ </span>
+ . A
+ <span class="emphasis">
+ <em>
+ Tuple
+ </em>
+ </span>
+ is
+just a collection of values and those values themselves can be of any other
+valid Python datatypes, including
+ <span class="emphasis">
+ <em>
+ Lists
+ </em>
+ </span>
+ ,
+ <span class="emphasis">
+ <em>
+ Tuples
+ </em>
+ </span>
+ ,
+ <span class="emphasis">
+ <em>
+ Dictionaries
+ </em>
+ </span>
+ among other
+things. So effectively, if a function can return a tuple, it can return any
+number of values through a tuple
+ </p>
+ <p id="ch5func_9">
+ Let us write a small function to swap two values:
+ </p>
+ <pre class="programlisting">
+ def swap(a, b):
+ return b, a
+
+c, d = swap(a, b)
+ </pre>
+ <div class="section" title="1.Function scope">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
- <a name="id2884426">
+ <a name="id2864618">
</a>
- 3.Basic Commands
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="3.1.ls">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2884434">
- </a>
- 3.1.ls
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_31">
- When invoked without any arguments,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- is derived from
- <span class="emphasis">
- <em>
- list segments
- </em>
- </span>
- which was used in earlier systems.
- </p>
- <p id="ch5func_32">
- Files whose names start with "." are not listed, unless the
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- flag is specified or the files are specified explicitly.
- </p>
- <p id="ch5func_33">
- Without options,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_34">
- <span class="emphasis">
- <em>
- -l
- </em>
- </span>
- long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_35">
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_36">
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_37">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- recursively lists subdirectories. The command ls -R / would therefore list all files.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_38">
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_39">
- <span class="emphasis">
- <em>
- -t
- </em>
- </span>
- sort the list of files by modification time.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_3a">
- <span class="emphasis">
- <em>
- -h
- </em>
- </span>
- print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_3b">
- In some environments, providing the option
- <span class="emphasis">
- <em>
- --color
- </em>
- </span>
- (for GNU ls) or
- <span class="emphasis">
- <em>
- -G
- </em>
- </span>
- (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- would. To determine what color to use for a file, GNU
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks the Unix file type, the file permissions, and the file extension, while FreeBSD
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks only the Unix file type and file permissions.:
- </p>
- <pre class="programlisting">
- $ ls
-jeeves.rst psmith.html blandings.html
-$ ls -l
-drwxr--r-- 1 plum editors 4096 jeeves
--rw-r--r-- 1 plum editors 30405 psmith
--r-xr-xr-x 1 plum plum 8460 blandings
- </pre>
- <p id="ch5func_3c">
- Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
- </p>
- </div>
- <div class="section" title="3.2.date">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2884591">
- </a>
- 3.2.date
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_3d">
- The Unix date command displays the time and date. The super-user can use it to set the system clock.
- </p>
- <p id="ch5func_3e">
- With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:
- </p>
- <pre class="programlisting">
- $date
-Tue Sep 8 12:01:45 IST 2009
- </pre>
- <p id="ch5func_3f">
- On some systems to set the current date and time to September 8, 2004 01:22 you type:
- </p>
- <pre class="programlisting">
- $date --set="20040908 01:22"
- </pre>
- <p id="ch5func_40">
- In order to view the various options for the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command, type:
- </p>
- <pre class="programlisting">
- $man date
- </pre>
- <p id="ch5func_41">
- This will take you to the "Manual" page comprising of all the details on the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command. You can return to the terminal from the "man" page by pressing the
- <span class="emphasis">
- <em>
- Esc
- </em>
- </span>
- key in the keyboard and typing ":q" in that order.
- </p>
- </div>
- <div class="section" title="3.3.cd">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2884648">
- </a>
- 3.3.cd
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_42">
- This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, cd .. can be used.
- </p>
- <p id="ch5func_43">
- One dot '.' represents the current directory while two dots '..' represent the parent directory.
- </p>
- <p id="ch5func_44">
- cd - will return you to the previous directory (a bit like an undo).
- </p>
- <p id="ch5func_45">
- You can also use cd absolute path or cd relative path (see below):
- </p>
- <p id="ch5func_46">
- Absolute paths:
- </p>
- <p id="ch5func_47">
- An absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
- </p>
- <p id="ch5func_48">
- For example to get to /boot/grub you would type:
- </p>
- <pre class="programlisting">
- $cd /boot/grub
- </pre>
- <p id="ch5func_49">
- This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
- </p>
- <p id="ch5func_4a">
- Relative paths:
- </p>
- <p id="ch5func_4b">
- A relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
- </p>
- <p id="ch5func_4c">
- For example if you are in root's home directory and want to get to /root/music, you type:
- </p>
- <pre class="programlisting">
- $ cd music
- </pre>
- <p id="ch5func_4d">
- Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
- </p>
- </div>
- <div class="section" title="3.4.who">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2884743">
- </a>
- 3.4.who
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_4e">
- The standard Unix command
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- displays a list of users who are currently logged into a computer.
- </p>
- <p id="ch5func_4f">
- The
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command is related to the command
- <span class="emphasis">
- <em>
- w
- </em>
- </span>
- , which provides the same information but also displays additional data and statistics.:
- </p>
- <pre class="programlisting">
- $who
-beeblebrox tty7 2009-09-08 10:50 (:0)
-beeblebrox pts/0 2009-09-08 11:25 (:0.0)
-dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in)
-beeblebrox pts/2 2009-09-08 18:53 (:0.0)
- </pre>
- <p id="ch5func_50">
- The command can be invoked with the arguments
- <span class="emphasis">
- <em>
- am i
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- am I
- </em>
- </span>
- (so it is invoked as
- <span class="emphasis">
- <em>
- who am i
- </em>
- </span>
- or * who am I*), showing information about the current terminal only (see the
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- option below, of which this invocation is equivalent).
- </p>
- <p id="ch5func_51">
- In order to find out the various options that can be appended to the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command, check the
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page by typing out the following in the terminal:
- </p>
- <pre class="programlisting">
- $man who
- </pre>
- <p id="ch5func_52">
- This will take you to the "Manual" page containing details about the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command
- </p>
- </div>
- <div class="section" title="3.5.mkdir">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2884824">
- </a>
- 3.5.mkdir
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_53">
- This command is used to make a new directory. Normal usage is as straightforward as follows:
- </p>
- <pre class="programlisting">
- $mkdir name_of_directory
- </pre>
- <p id="ch5func_54">
- Where
- <span class="emphasis">
- <em>
- name_of_directory
- </em>
- </span>
- is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- will try to create all of them.
- </p>
- <div class="section" title="3.5.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2884854">
- </a>
- 3.5.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_55">
- On Unix-like operating systems,
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- takes options. Three of the most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_56">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- : will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_57">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- : display each directory that mkdir creates. Most often used with -p.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_58">
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- : specify the octal permissions of directories created by mkdir.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_59">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
- </p>
- </div>
- <div class="section" title="3.5.2.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2884911">
- </a>
- 3.5.2.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_5a">
- An example of
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- in action is:
- </p>
- <pre class="programlisting">
- $mkdir -p /tmp/a/b/c
- </pre>
- <p id="ch5func_5b">
- If
- <span class="emphasis">
- <em>
- /tmp/a
- </em>
- </span>
- exists but
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- does not, mkdir will create
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- before creating
- <span class="emphasis">
- <em>
- /tmp/a/b/c
- </em>
- </span>
- .
- </p>
- <p id="ch5func_5c">
- And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
- </p>
- <pre class="programlisting">
- $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
- </pre>
- <p id="ch5func_5d">
- This will create:
- </p>
- tmpdir - branches
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_5e">
- tag
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- trunk - sources - includes
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_5f">
- docs
- </p>
- </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="4.Getting Help">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2884984">
- </a>
- 4.Getting Help
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="4.1.apropos and whatis">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2884993">
- </a>
- 4.1.apropos and whatis
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_60">
- This is a command to search the manual pages files in Unix and Unix-like operating systems.
- </p>
- <pre class="programlisting">
- $ apropos grep
-egrep egrep (1) Search a file for a pattern using full regular expressions
-fgrep fgrep (1) Search a file for a fixed-character string
-fmlgrep fmlgrep (1) Search a file for a pattern
-grep grep (1) Search a file for a pattern
-gzgrep gzgrep (1) Search a possibly compressed file for a regular expression
-nisgrep nismatch (1) Utilities for searching NIS+ tables
-pgrep pgrep (1) Find or signal a process by name or other attribute
-zgrep zgrep (1) Search a possibly compressed file for a regular expression
-...
- </pre>
- <p id="ch5func_61">
- In this example, the user uses
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- to search for the string "grep", and apropos returns the indicated
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- pages that include the term "grep".
- </p>
- <p id="ch5func_62">
- A short index of explanations for commands is available using the
- <span class="emphasis">
- <em>
- whatis
- </em>
- </span>
- command, like in the examples below:
- </p>
- <pre class="programlisting">
- $whatis ls
-ls (1) - list directory contents
- </pre>
- <p id="ch5func_63">
- This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
- </p>
- <p id="ch5func_64">
- If you don't know where to get started and which man page to read,
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- gives more information. Say that you do not know how to start a browser, then you could enter the following command:
- </p>
- <pre class="programlisting">
- $apropos browser
-gmusicbrowser (1) - Jukebox for large collections of audio files
-infobrowser (1) - read Info documents
-libsmbclient (7) - An extension library for browsers and that can be used...
-opera (1) - a standards-compliant graphical Web browser
-sensible-browser (1) - sensible editing, paging, and web browsing
-smbtree (1) - A text based smb network browser
-tvtk_doc (1) - A GUI based TVTK documentation search browser.
-viewres (1) - graphical class browser for Xt
-w3m (1) - a text based Web browser and pager
-www-browser (1) - a text based Web browser and pager
-...
- </pre>
- </div>
- <div class="section" title="4.2.man">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2885075">
- </a>
- 4.2.man
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_65">
- Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- . Each page is a self-contained document.
- </p>
- <p id="ch5func_66">
- To read a manual page for a Unix command, one can use:
- </p>
- <pre class="programlisting">
- $ man <command_name>
- </pre>
- <p id="ch5func_67">
- at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- generally uses the less terminal pager.
- </p>
- <p id="ch5func_68">
- Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are
- <span class="emphasis">
- <em>
- man(1)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- man(7)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- exit(2)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- exit(3)
- </em>
- </span>
- . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
- <span class="emphasis">
- <em>
- BSD, for example, the syntax for reading *printf(3)
- </em>
- </span>
- is:
- </p>
- <pre class="programlisting">
- $man 3 printf
- </pre>
- <p id="ch5func_69">
- Another example:
- </p>
- <pre class="programlisting">
- $man man
- </pre>
- <p id="ch5func_6a">
- The previous example will take you to the "Manual" page entry about manual pages!
- </p>
- <div class="section" title="4.2.1.Layout">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2885155">
- </a>
- 4.2.1.Layout
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_6b">
- All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
- </p>
- NAME
- <p id="ch5func_6c">
- The name of the command or function, followed by a one-line description of what it does.
- </p>
- SYNOPSIS
- <p id="ch5func_6d">
- In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
- </p>
- DESCRIPTION
- <p id="ch5func_6e">
- A textual description of the functioning of the command or function.
- </p>
- EXAMPLES
- <p id="ch5func_6f">
- Some examples of common usage.
- </p>
- SEE ALSO
- <p id="ch5func_70">
- A list of related commands or functions.
- </p>
- <p id="ch5func_71">
- Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
- </p>
- <p id="ch5func_72">
- These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
- </p>
- <p id="ch5func_73">
- However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
- </p>
- <p id="ch5func_74">
- Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
- </p>
- <p id="ch5func_75">
- Usually the man pages are written in English. Translations into other languages can be also available on the system.
- </p>
- <p id="ch5func_76">
- The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
- </p>
- </div>
- </div>
- <div class="section" title="4.3.info">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2885261">
- </a>
- 4.3.info
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_77">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
- </p>
- <p id="ch5func_78">
- The syntax is
- </p>
- <pre class="programlisting">
- $ info <command_name>
- </pre>
- <p id="ch5func_79">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_7a">
- <span class="emphasis">
- <em>
- n
- </em>
- </span>
- goes to the next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_7b">
- <span class="emphasis">
- <em>
- p
- </em>
- </span>
- goes to the previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_7c">
- <span class="emphasis">
- <em>
- u
- </em>
- </span>
- goes to the upper page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_7d">
- <span class="emphasis">
- <em>
- l
- </em>
- </span>
- goes to the last(visited) node
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_7e">
- To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_7f">
- info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
- </p>
- </div>
- <div class="section" title="4.4.--help">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2885347">
- </a>
- 4.4.--help
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_80">
- Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command:
- </p>
- <pre class="programlisting">
- $ userprompt@host: cat --help
-Usage: cat [OPTION] [FILE]...
-Concatenate FILE(s), or standard input, to standard output.
-
- -A, --show-all equivalent to -vET
- -b, --number-nonblank number nonempty output lines
- -e equivalent to -vE
- -E, --show-ends display $ at end of each line
- -n, --number number all output lines
- -s, --squeeze-blank suppress repeated empty output lines
- -t equivalent to -vT
- -T, --show-tabs display TAB characters as ^I
- -u (ignored)
- -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
- --help display this help and exit
- --version output version information and exit
-
-With no FILE, or when FILE is -, read standard input.
-
-Examples:
- cat f - g Output f's contents, then standard input, then g's contents.
- cat Copy standard input to standard output.
-
-Report bugs to <bug-coreutils@gnu.org>.
- </pre>
- </div>
- </div>
- <div class="section" title="5.Basic file handling">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2885401">
- </a>
- 5.Basic file handling
+ 1.Function scope
</h2>
</div>
</div>
</div>
- <div class="section" title="5.1.cp">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2885409">
- </a>
- 5.1.cp
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_81">
- <span class="emphasis">
- <em>
- cp
- </em>
- </span>
- is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
- </p>
- <div class="section" title="5.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2885426">
- </a>
- 5.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_82">
- To copy a file to another file:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
- </pre>
- <p id="ch5func_83">
- To copy a file to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
- </pre>
- <p id="ch5func_84">
- To copy a directory to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
-SourceDirectory ... TargetDirectory
- </pre>
- </div>
- <div class="section" title="5.1.2.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2885461">
- </a>
- 5.1.2.Flags
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_85">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (force) specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
- </p>
- <p id="ch5func_86">
- <span class="emphasis">
- <em>
- -P
- </em>
- </span>
- makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
- </p>
- <p id="ch5func_87">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- (interactive) prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
- </p>
- <p id="ch5func_88">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- (preserve) duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_89">
- The time of the last data modification and the time of the last access.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_8a">
- The user ID and group ID (only if it has permissions to do this)
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_8b">
- The file permission bits and the SUID and SGID bits.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_8c">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- (recursive) copy directories (recursively copying all the contents)
- </p>
- </div>
- <div class="section" title="5.1.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2885557">
- </a>
- 5.1.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_8d">
- To make a copy of a file in the current directory, enter:
- </p>
- <pre class="programlisting">
- $ cp prog.c prog.bak
- </pre>
- <p id="ch5func_8e">
- This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
- </p>
- <p id="ch5func_8f">
- To copy a file in your current directory into another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod /home/books/hhgg
- </pre>
- <p id="ch5func_90">
- This copies the jones file to /home/books/hhgg/zaphod.
- </p>
- <p id="ch5func_91">
- To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
- </p>
- <pre class="programlisting">
- $ cp -p martin_luther_king martin_luther_king.jr
- </pre>
- <p id="ch5func_92">
- This copies the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file to the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file. Instead of creating the file with the current date and time stamp, the system gives the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file the same date and time as the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file. The
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file also inherits the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file's access control protection.
- </p>
- <p id="ch5func_93">
- To copy all the files in a directory to a new directory, enter:
- </p>
- <pre class="programlisting">
- $ cp /home/galactica/clients/* /home/hhgg/customers
- </pre>
- <p id="ch5func_94">
- This copies only the files in the clients directory to the customers directory.
- </p>
- <p id="ch5func_95">
- To copy a directory, including all its files and subdirectories, to another directory, enter:
- </p>
- <p id="ch5func_96">
- $ cp -R /home/hhgg/clients /home/hhgg/customers
- </p>
- <p id="ch5func_97">
- This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
- </p>
- <p id="ch5func_98">
- To copy a specific set of files of any extension to another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod arthur ford /home/hhgg/clients
- </pre>
- <p id="ch5func_99">
- This copies the
- <span class="emphasis">
- <em>
- zaphod
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- arthur
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- ford
- </em>
- </span>
- files in your current working directory to the /home/hhgg/clients directory.
- </p>
- <p id="ch5func_9a">
- To use pattern-matching characters to copy files, enter:
- </p>
- <pre class="programlisting">
- $ cp programs/*.py .
- </pre>
- <p id="ch5func_9b">
- This copies the files in the programs directory that end with
- <span class="emphasis">
- <em>
- .py
- </em>
- </span>
- to the current directory, signified by the single "." (dot). You must type a space between the
- <span class="emphasis">
- <em>
- py
- </em>
- </span>
- and the final dot.
- </p>
- </div>
- </div>
- <div class="section" title="5.2.mv">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2885718">
- </a>
- 5.2.mv
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_9c">
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system),
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- will rename the file instead. Write permission is required on all directories being modified.
- </p>
- <div class="section" title="5.2.1.Conflicting existing file">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2885742">
- </a>
- 5.2.1.Conflicting existing file
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_9d">
- In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
- </p>
- </div>
- <div class="section" title="5.2.2.Differences with copy and delete">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2885761">
- </a>
- 5.2.2.Differences with copy and delete
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_9e">
- Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
- </p>
- </div>
- <div class="section" title="5.2.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2885791">
- </a>
- 5.2.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ mv myfile mynewfilename renames a file
-$ mv myfile otherfilename renames a file and deletes the existing file "myfile"
-$ mv myfile /myfile moves 'myfile' from the current directory to the root directory
-$ mv myfile dir/myfile moves 'myfile' to 'dir/myfile' relative to the current directory
-$ mv myfile dir same as the previous command (the filename is implied to be the same)
-$ mv myfile dir/myfile2 moves 'myfile' to dir and renames it to 'myfile2'
-$ mv foo bar baz dir moves multiple files to directory dir
-$ mv --help shows a very concise help about the syntax of the command
-$ man mv prints an extensive user manual for 'mv' in the terminal
- </pre>
- <p id="ch5func_9f">
- In all cases, the file or files being moved or renamed can be a directory.
- </p>
- <p id="ch5func_a0">
- Note that when the command is called with two arguments (as
- <span class="emphasis">
- <em>
- mv name1 name2
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- mv name1 /dir/name2
- </em>
- </span>
- ), it can have three different effects, depending on whether
- <span class="emphasis">
- <em>
- name2
- </em>
- </span>
- does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
- <span class="emphasis">
- <em>
- /.
- </em>
- </span>
- (or in some Unix versions
- <span class="emphasis">
- <em>
- /
- </em>
- </span>
- is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
- </p>
- </div>
- </div>
- <div class="section" title="5.3.rm">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2883527">
- </a>
- 5.3.rm
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_a1">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
- </p>
- <p id="ch5func_a2">
- Here's example to remove a file named "foo" from a directory, here shown with the -i option:
- </p>
- <pre class="programlisting">
- $ rm -i foo
-remove foo? y
- </pre>
- <div class="section" title="5.3.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2883556">
- </a>
- 5.3.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_a3">
- Common options that rm accepts include:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_a4">
- <span class="emphasis">
- <em>
- -r
- </em>
- </span>
- , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_a5">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- , which asks for every deletion to be confirmed ("interactive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_a6">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- , which ignores non-existent files and overrides any confirmation prompts ("force")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_a7">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- , which shows what is being removed as it happens ("verbose")
- </p>
- </li>
- </ul>
- </div>
- <p id="ch5func_a8">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
- </p>
- <p id="ch5func_a9">
- <span class="emphasis">
- <em>
- rm -rf
- </em>
- </span>
- (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
- </p>
- <p id="ch5func_aa">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often used in conjunction with xargs to supply a list of files to delete:
- </p>
- <pre class="programlisting">
- xargs rm < filelist
- </pre>
- <p id="ch5func_ab">
- When
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is used on a symbolic link, it deletes the link, but does not affect the target of the link.
- </p>
- </div>
- <div class="section" title="5.3.2.Permissions">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2886113">
- </a>
- 5.3.2.Permissions
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_ac">
- Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
- </p>
- <p id="ch5func_ad">
- To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
- </p>
- <p id="ch5func_ae">
- If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
- </p>
- </div>
- </div>
+ <p id="ch5func_a">
+ The variables used inside the function are confined to the function's scope
+and doesn't pollute the variables of the same name outside the scope of the
+function. Also the arguments passed to the function are passed by-value if
+it is of basic Python data type:
+ </p>
+ <pre class="programlisting">
+ def cant_change(n):
+ n = 10
+
+n = 5
+cant_change(n)
+ </pre>
+ <p id="ch5func_b">
+ Upon running this code, what do you think would have happened to value of n
+which was assigned 5 before the function call? If you have already tried out
+that snippet on the interpreter you already know that the value of n is not
+changed. This is true of any immutable types of Python like
+ <span class="emphasis">
+ <em>
+ Numbers
+ </em>
+ </span>
+ ,
+ <span class="emphasis">
+ <em>
+ Strings
+ </em>
+ </span>
+ and
+ <span class="emphasis">
+ <em>
+ Tuples
+ </em>
+ </span>
+ . But when you pass mutable objects like
+ <span class="emphasis">
+ <em>
+ Lists
+ </em>
+ </span>
+ and
+ <span class="emphasis">
+ <em>
+ Dictionaries
+ </em>
+ </span>
+ the values are manipulated even outside the function:
+ </p>
+ <pre class="programlisting">
+ >>> def can_change(n):
+... n[1] = James
+...
+
+>>> name = ['Mr.', 'Steve', 'Gosling']
+>>> can_change(name)
+>>> name
+['Mr.', 'James', 'Gosling']
+ </pre>
+ <p id="ch5func_c">
+ If nothing is returned by the function explicitly, Python takes care to return
+None when the funnction is called.
+ </p>
</div>
- <div class="section" title="6.Command Line Arguments">
+ <div class="section" title="2.Default Arguments">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
- <a name="id2886163">
- </a>
- 6.Command Line Arguments
- </h2>
- </div>
- </div>
- </div>
- <p id="ch5func_af">
- In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
- </p>
- <p id="ch5func_b0">
- For example, in Unix and Unix-like environments, an example of a command-line argument is:
- </p>
- <pre class="programlisting">
- rm file.s
- </pre>
- <p id="ch5func_b1">
- "file.s" is a command line argument which tells the program rm to remove the file "file.s".
- </p>
- <p id="ch5func_b2">
- Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
- </p>
- <p id="ch5func_b3">
- A command line option or simply
- <span class="emphasis">
- <em>
- option
- </em>
- </span>
- (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
- </p>
- <p id="ch5func_b4">
- Long options are introduced via "--", and are typically whole words. For example,
- <span class="emphasis">
- <em>
- ls --long --classify --all
- </em>
- </span>
- . Arguments to long options are provided with "=", as
- <span class="emphasis">
- <em>
- ls --block-size=1024
- </em>
- </span>
- . Some Unix programs use long options with single dashes, for example MPlayer as in
- <span class="emphasis">
- <em>
- mplayer -nosound
- </em>
- </span>
- .
- </p>
- <p id="ch5func_b5">
- Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- by using
- <span class="emphasis">
- <em>
- rm -file1
- </em>
- </span>
- may produce an error, since rm may interpret
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- as a command line switch. Using
- <span class="emphasis">
- <em>
- rm -- -file1
- </em>
- </span>
- removes ambiguity.
- </p>
- </div>
- <div class="section" title="7.Basic Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2886256">
+ <a name="id2864676">
</a>
- 7.Basic Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="7.1.head">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2886264">
- </a>
- 7.1.head
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_b6">
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:
- </p>
- <pre class="programlisting">
- $ head [options] <file_name>
- </pre>
- <p id="ch5func_b7">
- By default,
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ head -n 20 filename
- </pre>
- <p id="ch5func_b8">
- This displays the first 5 lines of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ head -n 5 foo*
- </pre>
- <p id="ch5func_b9">
- Some versions omit the n and just let you say -5.
- </p>
- <div class="section" title="7.1.1.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2886316">
- </a>
- 7.1.1.Flags
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- -c <x number of bytes> Copy first x number of bytes.
- </pre>
- <p id="ch5func_ba">
- Other options:
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- </p>
- <p id="ch5func_bb">
- Many early versions of Unix did not have this command, and so documentation and books had
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- do this job:
- </p>
- <pre class="programlisting">
- sed 5q foo
- </pre>
- <p id="ch5func_bc">
- This says to print every line (implicit), and quit after the fifth.
- </p>
- </div>
- </div>
- <div class="section" title="7.2.tail">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2886352">
- </a>
- 7.2.tail
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_bd">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
- </p>
- <p id="ch5func_be">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ tail [options] <file_name>
- </pre>
- <p id="ch5func_bf">
- By default,
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ tail -n 20 filename
- </pre>
- <p id="ch5func_c0">
- This example shows the last 15 bytes of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ tail -c 15 foo*
- </pre>
- <p id="ch5func_c1">
- This example shows all lines of filename from the second line onwards:
- </p>
- <pre class="programlisting">
- $ tail -n +2 filename
- </pre>
- <p id="ch5func_c2">
- Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:
- </p>
- <pre class="programlisting">
- $ tail -20 filename
-$ tail -50c filename
- </pre>
- <p id="ch5func_c3">
- However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
- </p>
- <div class="section" title="7.2.1.File monitoring">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2886430">
- </a>
- 7.2.1.File monitoring
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_c4">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- has a special command line option
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:
- </p>
- <pre class="programlisting">
- $ tail -f /var/adm/messages
- </pre>
- <p id="ch5func_c5">
- To interrupt tail while it is monitoring, break-in with
- <span class="emphasis">
- <em>
- Ctrl+C
- </em>
- </span>
- . This command can be run "in the background" with &, see job control.
- </p>
- <p id="ch5func_c6">
- If you have a command's result to monitor, you can use the
- <span class="emphasis">
- <em>
- watch
- </em>
- </span>
- command.
- </p>
- </div>
- </div>
- <div class="section" title="7.3.cut">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2886479">
- </a>
- 7.3.cut
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_c7">
- In computing,
- <span class="emphasis">
- <em>
- cut
- </em>
- </span>
- is a Unix command line utility which is used to extract sections from each line of input usually from a file.
- </p>
- <p id="ch5func_c8">
- Extraction of line segments can typically be done by
- <span class="emphasis">
- <em>
- bytes (-b), characters (-c)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- fields (-f)
- </em>
- </span>
- separated by a
- <span class="emphasis">
- <em>
- delimiter (-d the tab character by default)
- </em>
- </span>
- . A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
- </p>
- <p id="ch5func_c9">
- Assuming a file named file containing the lines:
- </p>
- <pre class="programlisting">
- foo:bar:baz:qux:quux
-one:two:three:four:five:six:seven
-alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- <p id="ch5func_ca">
- To output the fourth through tenth characters of each line:
- </p>
- <pre class="programlisting">
- $ cut -c 4-10 file
- </pre>
- <p id="ch5func_cb">
- This gives the output:
- </p>
- <pre class="programlisting">
- :bar:ba
-:two:th
-ha:beta
- </pre>
- <p id="ch5func_cc">
- To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
- </p>
- <pre class="programlisting">
- $ cut -d : -f 5- file
- </pre>
- <p id="ch5func_cd">
- This gives the output:
- </p>
- <pre class="programlisting">
- quux
-five:six:seven
-epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- </div>
- <div class="section" title="7.4.paste">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2886565">
- </a>
- 7.4.paste
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_ce">
- <span class="emphasis">
- <em>
- paste
- </em>
- </span>
- is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command which operates on the vertical plane of two or more files.
- </p>
- <p id="ch5func_cf">
- To paste several columns of data together into the file
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- from files
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- where
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- when
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ paste who where when > www
- </pre>
- <p id="ch5func_d0">
- If the files contain:
- </p>
- <table summary="paste" border="1">
- <colgroup>
- <col width="11">
- </col>
- <col width="12">
- </col>
- <col width="12">
- </col>
- </colgroup>
- </table>
- <p id="ch5func_dd">
- This creates the file named
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- containing:
- </p>
- <pre class="programlisting">
- Batman GothamCity January 3
-Trillian Andromeda February 4
-Jeeves London March 19
- </pre>
- </div>
- </div>
- <div class="section" title="8.Shell Meta Characters">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2886699">
- </a>
- 8.Shell Meta Characters
+ 2.Default Arguments
</h2>
</div>
</div>
</div>
- <p id="ch5func_de">
- Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
- </p>
- <p id="ch5func_df">
- The shell meta characters include:
- </p>
- <p id="ch5func_e0">
- / < > ! $ % ^ & * | { } [ ] " ' ` ~ ;
- </p>
- <p id="ch5func_e1">
- Different shells may differ in the meta characters recognized.
- </p>
- <p id="ch5func_e2">
- As an example,
- </p>
- <pre class="programlisting">
- $ ls file.*
- </pre>
- <p id="ch5func_e3">
- run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
+ <p id="ch5func_d">
+ There may be situations where we need to allow the functions to take the
+arguments optionally. Python allows us to define function this way by providing
+a facility called
+ <span class="emphasis">
+ <em>
+ Default Arguments
+ </em>
+ </span>
+ . For example, we need to write a function
+that returns a list of fibonacci numbers. Since our function cannot generate an
+infinite list of fibonacci numbers, we need to specify the number of elements
+that the fibonacci sequence must contain. Suppose, additionally, we want to the
+function to return 10 numbers in the sequence if no option is specified we can
+define the function as follows:
</p>
<pre class="programlisting">
- $ ls file.?
+ def fib(n=10):
+ fib_list = [0, 1]
+ for i in range(n - 2):
+ next = fib_list[-2] + fib_list[-1]
+ fib_list.append(next)
+ return fib_list
</pre>
- <p id="ch5func_e4">
- run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:
- </p>
- <pre class="programlisting">
- $ more c*
- </pre>
- <p id="ch5func_e5">
- because the c* matches that long file name.
- </p>
- <p id="ch5func_e6">
- Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named "``*`|more"` can be accomplished with:
+ <p id="ch5func_e">
+ When we call this function, we can optionally specify the value for the
+parameter n, during the call as an argument. Calling with no argument and
+argument with n=5 returns the following fibonacci sequences:
</p>
<pre class="programlisting">
- $ rm ??more
- </pre>
- <p id="ch5func_e7">
- or:
- </p>
- <pre class="programlisting">
- $ rm $\backslash$*$\backslash$|more
- </pre>
- <p id="ch5func_e8">
- or:
- </p>
- <pre class="programlisting">
- $ rm ''*|more''
+ fib()
+[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
+fib(5)
+[0, 1, 1, 2, 3]
</pre>
</div>
- <div class="section" title="9.Looking At Files">
+ <div class="section" title="3.Keyword Arguments">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
- <a name="id2886803">
+ <a name="id2864716">
</a>
- 9.Looking At Files
+ 3.Keyword Arguments
</h2>
</div>
</div>
</div>
- <div class="section" title="9.1.cat">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2886811">
- </a>
- 9.1.cat
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_e9">
- The
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
- <span class="emphasis">
- <em>
- concatenate
- </em>
- </span>
- .
- </p>
- <p id="ch5func_ea">
- The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
- </p>
- <p id="ch5func_eb">
- If the filename is specified as -, then
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input at that point in the sequence. If no files are specified,
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input entered.
- </p>
- <div class="section" title="9.1.1.Jargon File Definition">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2886855">
- </a>
- 9.1.1.Jargon File Definition
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_ec">
- The Jargon File version 4.4.7 lists this as the definition of
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- 1. To spew an entire file to the screen or some other output sink without
- pause (syn. blast).
-
-2. By extension, to dump large amounts of data at an unprepared target or
- with no intention of browsing it carefully. Usage: considered silly.
- Rare outside Unix sites. See also dd, BLT.
-
- Among Unix fans, *cat(1)* is considered an excellent example of
- user-interface design, because it delivers the file contents without
- such verbosity as spacing or headers between the files, and because
- it does not require the files to consist of lines of text, but works
- with any sort of data.
-
- Among Unix critics, *cat(1)* is considered the canonical example of
- bad user-interface design, because of its woefully unobvious name.
- It is far more often used to blast a single file to standard output
- than to concatenate two or more files. The name cat for the former
- operation is just as unintuitive as, say, LISP's cdr.
+ <p id="ch5func_f">
+ When a function takes a large number of arguments, it may be difficult to
+remember the order of the parameters in the function definition or it may
+be necessary to pass values to only certain parameters since others take
+the default value. In either of these cases, Python provides the facility
+of passing arguments by specifying the name of the parameter as defined in
+the function definition. This is known as
+ <span class="emphasis">
+ <em>
+ Keyword Arguments
+ </em>
+ </span>
+ .
+ </p>
+ <p id="ch5func_10">
+ In a function call,
+ <span class="emphasis">
+ <em>
+ Keyword arguments
+ </em>
+ </span>
+ can be used for each argument, in the
+following fashion:
+ </p>
+ <pre class="programlisting">
+ argument_name=argument_value
+Also denoted as: keyword=argument
- Of such oppositions are holy wars made...
- </pre>
- </div>
- <div class="section" title="9.1.2.Useless Use of 'cat'">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2886894">
- </a>
- 9.1.2.Useless Use of 'cat'
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_ed">
- UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
- <span class="emphasis">
- <em>
- comp.unix.shell
- </em>
- </span>
- , The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
- </p>
- <p id="ch5func_ee">
- Nevertheless one sees people doing:
- </p>
- <pre class="programlisting">
- $ cat file | some_command and its args ...
- </pre>
- <p id="ch5func_ef">
- instead of the equivalent and cheaper:
- </p>
- <pre class="programlisting">
- <file some_command and its args ...
- </pre>
- <p id="ch5func_f0">
- or (equivalently and more classically):
- </p>
- <pre class="programlisting">
- some_command and its args ... <file
- </pre>
- <p id="ch5func_f1">
- Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
- </p>
- <p id="ch5func_f2">
- Amongst many, it is still considered safer to use
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
- </p>
- </div>
- <div class="section" title="9.1.3.zcat">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2886963">
- </a>
- 9.1.3.zcat
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_f3">
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- is a Unix program similar to
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- , that decompresses individual files and concatenates them to standard output. Traditionally
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- operated on files compressed by compress but today it is usually able to operate on
- <span class="emphasis">
- <em>
- gzip
- </em>
- </span>
- or even
- <span class="emphasis">
- <em>
- bzip2
- </em>
- </span>
- archives. On such systems, it is equivalent to
- <span class="emphasis">
- <em>
- gunzip -c
- </em>
- </span>
- </p>
- </div>
- </div>
- <div class="section" title="9.2.more">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2886999">
- </a>
- 9.2.more
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_f4">
- In computing,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
- </p>
- <div class="section" title="9.2.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2887020">
- </a>
- 9.2.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_f5">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ more [options] [file_name]
- </pre>
- <p id="ch5func_f6">
- If no file name is provided,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- looks for input from stdin.
- </p>
- <p id="ch5func_f7">
- Once
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has paged through. (This percentage includes the text displayed on the current screen.) When
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- , which advances the output by one line, and
- <span class="emphasis">
- <em>
- Space
- </em>
- </span>
- , which advances the output by one screen.
- </p>
- <p id="ch5func_f8">
- There are also other commands that can be used while navigating through the document; consult
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- 's
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page for more details.
- </p>
- <p id="ch5func_f9">
- <span class="emphasis">
- <em>
- Options
- </em>
- </span>
- are typically entered before the file name, but can also be entered in the environment variable
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- . Options entered in the actual command line will override those entered in the
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- environment variable. Available options may vary between Unix systems.
- </p>
- </div>
- </div>
- <div class="section" title="9.3.less">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2887113">
- </a>
- 9.3.less
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_fa">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- does not need to read the entire file before starting, resulting in faster load times with large files.
- </p>
- <div class="section" title="9.3.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2887142">
- </a>
- 9.3.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_fb">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- vi
- </em>
- </span>
- . It is also possible to search for character patterns in the file.
- </p>
- <p id="ch5func_fc">
- By default,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
- </p>
- <p id="ch5func_fd">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ less [options] file_name
- </pre>
- </div>
- <div class="section" title="9.3.2.Frequently Used Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2887196">
- </a>
- 9.3.2.Frequently Used Options
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_fe">
- -g: Highlights just the current match of any searched string.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_ff">
- -I: Case-insensitive searches.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_100">
- -M: Shows more detailed prompt, including file position.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_101">
- -N: Shows line numbers (useful for source code viewing).
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_102">
- -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_103">
- -?: Shows help.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.3.Frequently Used Commands">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2887247">
- </a>
- 9.3.3.Frequently Used Commands
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_104">
- [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_105">
- [Space bar]: Next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_106">
- b: Previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_107">
- ng: Jump to line number n. Default is the start of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_108">
- nG: Jump to line number n. Default is the end of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_109">
- /pattern: Search for pattern. Regular expressions can be used.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_10a">
- '^ or g: Go to start of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_10b">
- '$ or G: Go to end of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_10c">
- s: Save current content (got from another program like grep) in a file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_10d">
- =: File information.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_10e">
- h: Help.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_10f">
- q: Quit.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.4.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2887334">
- </a>
- 9.3.4.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ less -M readme.txt #Read "readme.txt."
-$ less +F /var/log/mail.log #Follow mode for log
-$ file * | less #Easier file analysis.
-$ grep -i void *.c | less -I -p void #Case insensitive search for "void" in all .c files
- </pre>
- </div>
- </div>
- </div>
- <div class="section" title="10.Directory Structure">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2887349">
- </a>
- 10.Directory Structure
- </h2>
- </div>
- </div>
- </div>
- <p id="ch5func_110">
- In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
- </p>
- <p id="ch5func_111">
- The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
- </p>
- <table summary="Directory Structure" border="1">
- <colgroup>
- <col width="15">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <div class="section" title="10.1.man hier">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2887614">
- </a>
- 10.1.man hier
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_136">
- This is the manual page on the UNIX filesystem. The syntax for this is:
- </p>
- <pre class="programlisting">
- $ man hier
- </pre>
- </div>
- <div class="section" title="10.2.ls -l">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2887630">
- </a>
- 10.2.ls -l
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_137">
- Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
- </p>
- <pre class="programlisting">
- $ ls -l
- </pre>
- <p id="ch5func_138">
- This can be done after entering the required directory.
- </p>
- </div>
- </div>
- <div class="section" title="11.Permissions and Ownership">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2887652">
- </a>
- 11.Permissions and Ownership
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="11.1.chmod">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2887661">
- </a>
- 11.1.chmod
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_139">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.
- </p>
- <div class="section" title="11.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2887687">
- </a>
- 11.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_13a">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command options are specified like this:
- </p>
- <pre class="programlisting">
- $ chmod [options] mode[,mode] file1 [file2 ...]
- </pre>
- <p id="ch5func_13b">
- To view what the permissions currently are, type:
- </p>
- <pre class="programlisting">
- $ ls -l file
- </pre>
- </div>
- <div class="section" title="11.1.2.Command line options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2887714">
- </a>
- 11.1.2.Command line options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_13c">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command has a number of command line options that affect its behavior. The most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_13d">
- -R: Changes the modes of directories and files recursively
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch5func_13e">
- -v: Verbose mode; lists all files as they are being processed
- </p>
- </li>
- </ul>
- </div>
- <div class="section" title="11.1.2.1.Symbolic modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2887749">
- </a>
- 11.1.2.1.Symbolic modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch5func_13f">
- To the
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
- </p>
- <pre class="programlisting">
- $ chmod [references][operator][modes] file1 ...
- </pre>
- <p id="ch5func_140">
- The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="8">
- </col>
- <col width="45">
- </col>
- </colgroup>
- </table>
- <p id="ch5func_150">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="54">
- </col>
- </colgroup>
- </table>
- <p id="ch5func_157">
- The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="5">
- </col>
- <col width="14">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <p id="ch5func_16d">
- The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
- </p>
- </div>
- <div class="section" title="11.1.2.2.Symbolic examples">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2888297">
- </a>
- 11.1.2.2.Symbolic examples
- </h5>
- </div>
- </div>
- </div>
- <p id="ch5func_16e">
- Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
- </p>
- <pre class="programlisting">
- $ chmod ug+rw mydir
-$ ls -ld mydir
-drw-rw---- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- <p id="ch5func_16f">
- For a file, remove
- <span class="emphasis">
- <em>
- write
- </em>
- </span>
- permissions for all classes:
- </p>
- <pre class="programlisting">
- $ chmod a-w myfile
-$ ls -l myfile
--r-xr-xr-x 2 starwars yoda 96 Dec 8 12:53 myfile
- </pre>
- <p id="ch5func_170">
- Set the permissions for the
- <span class="emphasis">
- <em>
- u*ser and the *g*roup to read and execute only (no write permission) on *mydir
- </em>
- </span>
- .
- </p>
- <pre class="programlisting">
- $ chmod ug=rx mydir
-$ ls -ld mydir
-dr-xr-x--- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- </div>
- <div class="section" title="11.1.2.3.Octal numbers">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2888338">
- </a>
- 11.1.2.3.Octal numbers
- </h5>
- </div>
- </div>
- </div>
- <p id="ch5func_171">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
- </p>
- <pre class="programlisting">
- $ chmod 664 myfile
-$ ls -l myfile
--rw-rw-r-- 1 57 Jul 3 10:13 myfile
- </pre>
- <p id="ch5func_172">
- Since the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- sticky
- </em>
- </span>
- bits are not set, this is equivalent to:
- </p>
- <pre class="programlisting">
- $ chmod 0664 myfile
- </pre>
- </div>
- <div class="section" title="11.1.2.4.Special modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2888375">
- </a>
- 11.1.2.4.Special modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch5func_173">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
- <span class="strong">
- <strong>
- s
- </strong>
- </span>
- to represent the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- modes, and
- <span class="strong">
- <strong>
- t
- </strong>
- </span>
- to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
- </p>
- <p id="ch5func_174">
- Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
- </p>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="12.Redirection and Piping">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2888420">
- </a>
- 12.Redirection and Piping
- </h2>
- </div>
- </div>
- </div>
- <p id="ch5func_175">
- In computing,
+def wish(name='World', greetings='Hello'):
+ print "%s, %s!" % (greetings, name)
+ </pre>
+ <p id="ch5func_11">
+ This function can be called in one of the following ways. It is important to
+note that no restriction is imposed in the order in which
<span class="emphasis">
<em>
- redirection
+ Keyword arguments
+ </em>
+ </span>
+ can be specified. Also note, that we have combined
+ <span class="emphasis">
+ <em>
+ Keyword arguments
+ </em>
+ </span>
+ with
+ <span class="emphasis">
+ <em>
+ Default arguments
</em>
</span>
- is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
+ in this example, however it is not necessary:
</p>
- <p id="ch5func_176">
- Programs do redirection with the
+ <pre class="programlisting">
+ wish(name='Guido', greetings='Hey')
+wish(greetings='Hey', name='Guido')
+ </pre>
+ <p id="ch5func_12">
+ Calling functions by specifying arguments in the order of parameters specified
+in the function definition is called as
<span class="emphasis">
<em>
- dup2(2)
+ Positional arguments
</em>
</span>
- system call, or its less-flexible but higher-level stdio analogues,
+ , as opposed to
<span class="emphasis">
<em>
- freopen(3)
+ Keyword arguments
+ </em>
+ </span>
+ . It is possible to use both
+ <span class="emphasis">
+ <em>
+ Positional arguments
</em>
</span>
and
<span class="emphasis">
<em>
- popen(3)
+ Keyword arguments
+ </em>
+ </span>
+ in a single function call. But Python doesn't allow us to
+bungle up both of them. The arguments to the function, in the call, must always
+start with
+ <span class="emphasis">
+ <em>
+ Positional arguments
+ </em>
+ </span>
+ which is in turn followed by
+ <span class="emphasis">
+ <em>
+ Keyword
+arguments
+ </em>
+ </span>
+ :
+ </p>
+ <pre class="programlisting">
+ def my_func(x, y, z, u, v, w):
+ # initialize variables.
+ ...
+ # do some stuff
+ ...
+ # return the value
+ </pre>
+ <p id="ch5func_13">
+ It is valid to call the above functions in the following ways:
+ </p>
+ <pre class="programlisting">
+ my_func(10, 20, 30, u=1.0, v=2.0, w=3.0)
+my_func(10, 20, 30, 1.0, 2.0, w=3.0)
+my_func(10, 20, z=30, u=1.0, v=2.0, w=3.0)
+my_func(x=10, y=20, z=30, u=1.0, v=2.0, w=3.0)
+ </pre>
+ <p id="ch5func_14">
+ Following lists some of the invalid calls:
+ </p>
+ <pre class="programlisting">
+ my_func(10, 20, z=30, 1.0, 2.0, 3.0)
+my_func(x=10, 20, z=30, 1.0, 2.0, 3.0)
+my_func(x=10, y=20, z=30, u=1.0, v=2.0, 3.0)
+ </pre>
+ </div>
+ <div class="section" title="4.Parameter Packing and Unpacking">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h2 class="title" style="clear: both">
+ <a name="id2864832">
+ </a>
+ 4.Parameter Packing and Unpacking
+ </h2>
+ </div>
+ </div>
+ </div>
+ <p id="ch5func_15">
+ The positional arguments passed to a function can be collected in a tuple
+parameter and keyword arguments can be collected in a dictionary. Since keyword
+arguments must always be the last set of arguments passed to a function, the
+keyword dictionary parameter must be the last parameter. The function definition
+must include a list explicit parameters, followed by tuple paramter collecting
+parameter, whose name is preceded by a
+ <span class="strong">
+ <strong>
+ *
+ </strong>
+ </span>
+ , for collecting positional
+parameters, in turn followed by the dictionary collecting parameter, whose name
+is preceded by a
+ <span class="strong">
+ <strong>
+ **
+ </strong>
+ </span>
+ </p>
+ <pre class="programlisting">
+ def print_report(title, *args, **name):
+ """Structure of *args*
+ (age, email-id)
+ Structure of *name*
+ {
+ 'first': First Name
+ 'middle': Middle Name
+ 'last': Last Name
+ }
+ """
+
+ print "Title: %s" % (title)
+ print "Full name: %(first)s %(middle)s %(last)s" % name
+ print "Age: %d\nEmail-ID: %s" % args
+ </pre>
+ <p id="ch5func_16">
+ The above function can be called as. Note, the order of keyword parameters can
+be interchanged:
+ </p>
+ <pre class="programlisting">
+ >>> print_report('Employee Report', 29, 'johny@example.com', first='Johny',
+ last='Charles', middle='Douglas')
+Title: Employee Report
+Full name: Johny Douglas Charles
+Age: 29
+Email-ID: johny@example.com
+ </pre>
+ <p id="ch5func_17">
+ The reverse of this can also be achieved by using a very identical syntax while
+calling the function. A tuple or a dictionary can be passed as arguments in
+place of a list of
+ <span class="emphasis">
+ <em>
+ Positional arguments
+ </em>
+ </span>
+ or
+ <span class="emphasis">
+ <em>
+ Keyword arguments
+ </em>
+ </span>
+ respectively
+using
+ <span class="strong">
+ <strong>
+ *
+ </strong>
+ </span>
+ or
+ <span class="strong">
+ <strong>
+ **
+ </strong>
+ </span>
+ </p>
+ <pre class="programlisting">
+ def print_report(title, age, email, first, middle, last):
+ print "Title: %s" % (title)
+ print "Full name: %s %s %s" % (first, middle, last)
+ print "Age: %d\nEmail-ID: %s" % (age, email)
+
+>>> args = (29, 'johny@example.com')
+>>> name = {
+ 'first': 'Johny',
+ 'middle': 'Charles',
+ 'last': 'Douglas'
+ }
+>>> print_report('Employee Report', *args, **name)
+Title: Employee Report
+Full name: Johny Charles Douglas
+Age: 29
+Email-ID: johny@example.com
+ </pre>
+ </div>
+ <div class="section" title="5.Nested Functions and Scopes">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h2 class="title" style="clear: both">
+ <a name="id2864932">
+ </a>
+ 5.Nested Functions and Scopes
+ </h2>
+ </div>
+ </div>
+ </div>
+ <p id="ch5func_18">
+ Python allows nesting one function inside another. This style of programming
+turns out to be extremely flexible and powerful features when we use
+ <span class="emphasis">
+ <em>
+ Python
+decorators
+ </em>
+ </span>
+ . We will not talk about decorators is beyond the scope of this
+course. If you are interested in knowing more about
+ <span class="emphasis">
+ <em>
+ decorator programming
+ </em>
+ </span>
+ in
+Python you are suggested to read:
+ </p>
+ <span style="color: red">
+ <line_block>
+ <span style="color: red">
+ <line>
+ <div class="reference">
+ <div class="titlepage">
+ <hr />
+ </div>
+ http://avinashv.net/2008/04/python-decorators-syntactic-sugar/
+ </div>
+ </line>
+ </span>
+ <span style="color: red">
+ <line>
+ <div class="reference">
+ <div class="titlepage">
+ <hr />
+ </div>
+ http://personalpages.tds.net/~kent37/kk/00001.html
+ </div>
+ </line>
+ </span>
+ </line_block>
+ </span>
+ <p id="ch5func_19">
+ However, the following is an example for nested functions in Python:
+ </p>
+ <pre class="programlisting">
+ def outer():
+ print "Outer..."
+ def inner():
+ print "Inner..."
+ print "Outer..."
+ inner()
+
+>>> outer()
+ </pre>
+ </div>
+ <div class="section" title="6.map, reduce and filter functions">
+ <div class="titlepage">
+ <div>
+ <div>
+ <h2 class="title" style="clear: both">
+ <a name="id2864984">
+ </a>
+ 6.map, reduce and filter functions
+ </h2>
+ </div>
+ </div>
+ </div>
+ <p id="ch5func_1a">
+ Python provides several built-in functions for convenience. The
+ <span class="strong">
+ <strong>
+ map()
+ </strong>
+ </span>
+ ,
+ <span class="strong">
+ <strong>
+ reduce()
+ </strong>
+ </span>
+ and
+ <span class="strong">
+ <strong>
+ filter()
+ </strong>
+ </span>
+ functions prove to be very useful with sequences like
+ <span class="emphasis">
+ <em>
+ Lists
</em>
</span>
.
</p>
- <div class="section" title="12.1.Redirecting standard input and standard output">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2888457">
- </a>
- 12.1.Redirecting standard input and standard output
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_177">
- Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
- </p>
- <pre class="programlisting">
- $ command1 > file1
- </pre>
- <p id="ch5func_178">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , placing the output in file1. Note that this will truncate any existing data in
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- . To append output to the end of the file, use the >> operator.:
- </p>
- <pre class="programlisting">
- $ command1 < file1
- </pre>
- <p id="ch5func_179">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- as the source of input (as opposed to the keyboard).:
- </p>
- <pre class="programlisting">
- $ command1 < infile > outfile
- </pre>
- <p id="ch5func_17a">
- combines the two capabilities:
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- reads from
- <span class="emphasis">
- <em>
- infile
- </em>
- </span>
- and writes to
- <span class="emphasis">
- <em>
- outfile
- </em>
- </span>
- </p>
- </div>
- <div class="section" title="12.2.Piping">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2888526">
- </a>
- 12.2.Piping
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_17b">
- Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
-A pipeline of three programs run on a text terminal:
- </p>
- <pre class="programlisting">
- $ command1 | command2
- </pre>
- <p id="ch5func_17c">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using its output as the input for
- <span class="emphasis">
- <em>
- command2
- </em>
- </span>
- (commonly called piping, since the "|" character is known as a "pipe").
- </p>
- <p id="ch5func_17d">
- This is equivalent to using two redirects and a temporary file:
- </p>
- <pre class="programlisting">
- $ command1 > tempfile
-$ command2 < tempfile
-$ rm tempfile
- </pre>
- <p id="ch5func_17e">
- A good example for command piping is combining
- <span class="emphasis">
- <em>
- echo
- </em>
- </span>
- with another command to achieve something interactive in a non-interactive shell, e.g.:
- </p>
- <pre class="programlisting">
- $ echo -e "user\npass" | ftp localhost
- </pre>
- <p id="ch5func_17f">
- This runs the ftp client with input user, press return, then pass.
- </p>
- </div>
- <div class="section" title="12.3.Redirecting to and from the standard file handles">
+ <p id="ch5func_1b">
+ The
+ <span class="strong">
+ <strong>
+ map
+ </strong>
+ </span>
+ (
+ <span class="emphasis">
+ <em>
+ function
+ </em>
+ </span>
+ ,
+ <span class="emphasis">
+ <em>
+ sequence
+ </em>
+ </span>
+ ) function takes two arguments:
+ <span class="emphasis">
+ <em>
+ function
+ </em>
+ </span>
+ and a
+ <span class="emphasis">
+ <em>
+ sequence
+ </em>
+ </span>
+ argument. The
+ <span class="emphasis">
+ <em>
+ function
+ </em>
+ </span>
+ argument must be the name of the
+function which in turn takes a single argument, the individual element of the
+ <span class="emphasis">
+ <em>
+ sequence
+ </em>
+ </span>
+ . The
+ <span class="strong">
+ <strong>
+ map
+ </strong>
+ </span>
+ function calls
+ <span class="emphasis">
+ <em>
+ function(item)
+ </em>
+ </span>
+ , for each item in the
+sequence and returns a list of values, where each value is the value returned
+by each call to
+ <span class="emphasis">
+ <em>
+ function(item)
+ </em>
+ </span>
+ .
+ <span class="strong">
+ <strong>
+ map()
+ </strong>
+ </span>
+ function allows to pass more than
+one sequence. In this case, the first argument,
+ <span class="emphasis">
+ <em>
+ function
+ </em>
+ </span>
+ must take as many
+arguments as the number of sequences passed. This function is called with each
+corresponding element in the each of the sequences, or
+ <span class="strong">
+ <strong>
+ None
+ </strong>
+ </span>
+ if one of the
+sequence is exhausted:
+ </p>
+ <pre class="programlisting">
+ def square(x):
+ return x*x
+
+>>> map(square, [1, 2, 3, 4])
+[1, 4, 9, 16]
+
+def mul(x, y):
+ return x*y
+
+>>> map(mul, [1, 2, 3, 4], [6, 7, 8, 9])
+ </pre>
+ <p id="ch5func_1c">
+ The
+ <span class="strong">
+ <strong>
+ filter
+ </strong>
+ </span>
+ (
+ <span class="emphasis">
+ <em>
+ function
+ </em>
+ </span>
+ ,
+ <span class="emphasis">
+ <em>
+ sequence
+ </em>
+ </span>
+ ) function takes two arguments, similar to
+the
+ <span class="strong">
+ <strong>
+ map()
+ </strong>
+ </span>
+ function. The
+ <span class="strong">
+ <strong>
+ filter
+ </strong>
+ </span>
+ function calls
+ <span class="emphasis">
+ <em>
+ function(item)
+ </em>
+ </span>
+ , for each
+item in the sequence and returns all the elements in the sequence for which
+ <span class="emphasis">
+ <em>
+ function(item)
+ </em>
+ </span>
+ returned True:
+ </p>
+ <pre class="programlisting">
+ def even(x):
+ if x % 2:
+ return True
+ else:
+ return False
+
+>>> filter(even, range(1, 10))
+[1, 3, 5, 7, 9]
+ </pre>
+ <p id="ch5func_1d">
+ The
+ <span class="strong">
+ <strong>
+ reduce
+ </strong>
+ </span>
+ (
+ <span class="emphasis">
+ <em>
+ function
+ </em>
+ </span>
+ ,
+ <span class="emphasis">
+ <em>
+ sequence
+ </em>
+ </span>
+ ) function takes two arguments, similar to
+ <span class="strong">
+ <strong>
+ map
+ </strong>
+ </span>
+ function, however multiple sequences are not allowed. The
+ <span class="strong">
+ <strong>
+ reduce
+ </strong>
+ </span>
+ function calls
+ <span class="emphasis">
+ <em>
+ function
+ </em>
+ </span>
+ with first two consecutive elements in the sequence,
+obtains the result, calls
+ <span class="emphasis">
+ <em>
+ function
+ </em>
+ </span>
+ with the result and the subsequent element
+in the sequence and so on until the end of the list and returns the final result:
+ </p>
+ <pre class="programlisting">
+ def mul(x, y):
+ return x*y
+
+>>> reduce(mul, [1, 2, 3, 4])
+24
+ </pre>
+ <div class="section" title="6.1.List Comprehensions">
<div class="titlepage">
<div>
<div>
<h3 class="title">
- <a name="id2888586">
+ <a name="id2865174">
</a>
- 12.3.Redirecting to and from the standard file handles
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_180">
- In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
- </p>
- <table summary="Redirecting to and from the standard file handles" border="1">
- <colgroup>
- <col width="12">
- </col>
- <col width="13">
- </col>
- <col width="24">
- </col>
- </colgroup>
- </table>
- <p id="ch5func_18d">
- For example:
- </p>
- <pre class="programlisting">
- $ command1 2> file1
- </pre>
- <p id="ch5func_18e">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , directing the standard error stream to
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- .
- </p>
- <p id="ch5func_18f">
- In shells derived from
- <span class="emphasis">
- <em>
- csh
- </em>
- </span>
- (the C shell), the syntax instead appends the & character to the redirect characters, thus achieving a similar result.
- </p>
- <p id="ch5func_190">
- Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
- </p>
- <pre class="programlisting">
- $ find / -name .profile > results 2>&1
- </pre>
- <p id="ch5func_191">
- will try to find all files named
- <span class="emphasis">
- <em>
- .profile
- </em>
- </span>
- . Executed without redirection, it will output hits to
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- and errors (e.g. for lack of privilege to traverse protected directories) to
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- . If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- (handle 2) into
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- (handle 1) using 2>&1 .
- </p>
- <p id="ch5func_192">
- It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
- </p>
- <p id="ch5func_193">
- If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus:
- </p>
- <pre class="programlisting">
- $ find / -name .profile 2>&1 | less
- </pre>
- <p id="ch5func_194">
- A simplified form of the command:
- </p>
- <pre class="programlisting">
- $ command > file 2>&1
- </pre>
- <p id="ch5func_195">
- is:
- </p>
- <pre class="programlisting">
- $ command &>file
- </pre>
- <p id="ch5func_196">
- or:
- </p>
- <pre class="programlisting">
- $command >&file
- </pre>
- </div>
- <div class="section" title="12.4.Chained pipelines">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2888787">
- </a>
- 12.4.Chained pipelines
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_197">
- The redirection and piping tokens can be chained together to create complex commands. For example:
- </p>
- <pre class="programlisting">
- $ ls | grep '\.sh' | sort > shlist
- </pre>
- <p id="ch5func_198">
- lists the contents of the current directory, where this output is filtered to only contain lines which contain
- <span class="emphasis">
- <em>
- .sh
- </em>
- </span>
- , sort this resultant output lexicographically, and place the final output in
- <span class="emphasis">
- <em>
- shlist
- </em>
- </span>
- . This type of construction is used very commonly in shell scripts and batch files.
- </p>
- </div>
- <div class="section" title="12.5.Redirect to multiple outputs">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2888821">
- </a>
- 12.5.Redirect to multiple outputs
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_199">
- The standard command
- <span class="emphasis">
- <em>
- tee
- </em>
- </span>
- can redirect output from a command to several destinations.
- </p>
- <pre class="programlisting">
- $ ls -lrt | tee xyz
- </pre>
- <p id="ch5func_19a">
- This directs the file list output to both standard output as well as to the file
- <span class="emphasis">
- <em>
- xyz
- </em>
- </span>
- .
- </p>
- </div>
- </div>
- <div class="section" title="13.More Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2888851">
- </a>
- 13.More Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="13.1.grep">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2888860">
- </a>
- 13.1.grep
+ 6.1.List Comprehensions
</h3>
</div>
</div>
</div>
- <p id="ch5func_19b">
+ <p id="ch5func_1e">
+ List Comprehension is a convenvience utility provided by Python. It is a
+syntatic sugar to create
<span class="emphasis">
<em>
- grep
+ Lists
</em>
</span>
- is a command line text search utility originally written for Unix. The name is taken from the first letters in
+ . Using
<span class="emphasis">
<em>
- global / regular expression / print
+ List Comprehensions
</em>
</span>
- , a series of instructions for the
+ one can create
<span class="emphasis">
<em>
- ed
+ Lists
</em>
</span>
- text editor. The
+ from other type of sequential data structures or other
<span class="emphasis">
<em>
- grep
+ Lists
</em>
</span>
- command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
- </p>
- <div class="section" title="13.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2888891">
- </a>
- 13.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch5func_19c">
- This is an example of a common
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- usage:
- </p>
- <pre class="programlisting">
- $ grep apple fruitlist.txt
- </pre>
- <p id="ch5func_19d">
- In this case,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- prints all lines containing 'apple' from the file
- <span class="emphasis">
- <em>
- fruitlist.txt
- </em>
- </span>
- , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
- </p>
- <p id="ch5func_19e">
- Like most Unix commands,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- accepts command line arguments to change this and many other behaviors. For example:
- </p>
- <pre class="programlisting">
- $ grep -i apple fruitlist.txt
- </pre>
- <p id="ch5func_19f">
- This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be case insensitive, or to ignore case.
- </p>
- <p id="ch5func_1a0">
- To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
- </p>
- <pre class="programlisting">
- $ grep -w apple fruitlist.txt
- </pre>
- <p id="ch5func_1a1">
- Regular expressions can be used to match more complicated queries.
- </p>
- <div class="section" title="13.1.1.1.Variations">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2888969">
- </a>
- 13.1.1.1.Variations
- </h5>
- </div>
- </div>
- </div>
- <p id="ch5func_1a2">
- There are countless implementations and derivatives of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- available for many operating systems. Early variants of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- included
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- . The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- may also behave differently depending on the name by which it is invoked, allowing
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be links to the same program.
- </p>
- <p id="ch5func_1a3">
- <span class="emphasis">
- <em>
- pcregrep
- </em>
- </span>
- is an implementation of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- that uses Perl regular expression syntax.
- </p>
- <p id="ch5func_1a4">
- Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
- <span class="emphasis">
- <em>
- pgrep
- </em>
- </span>
- utility, for instance, displays the processes whose names match a given regular expression.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="13.2.tr">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2889048">
- </a>
- 13.2.tr
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_1a5">
+ itself.
+The syntax of
+ <span class="emphasis">
+ <em>
+ List Comprehensions
+ </em>
+ </span>
+ consists of a square brackets to indicate
+the result is a
<span class="emphasis">
<em>
- tr
- </em>
- </span>
- (abbreviated from
- <span class="emphasis">
- <em>
- translate
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- transliterate
+ List
</em>
</span>
- ) is a command in Unix-like operating systems.
- </p>
- <p id="ch5func_1a6">
- When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
- </p>
- <pre class="programlisting">
- $ tr 'abcd' 'jkmn'
- </pre>
- <p id="ch5func_1a7">
- maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
- </p>
- <p id="ch5func_1a8">
- Sets of characters may be abbreviated by using character ranges. The previous example could be written:
- </p>
- <pre class="programlisting">
- $ tr 'a-d' 'jkmn'
- </pre>
- <p id="ch5func_1a9">
- In POSIX compliant versions of
- <span class="emphasis">
- <em>
- tr
- </em>
+ within which we include at least one
+ <span class="strong">
+ <strong>
+ for
+ </strong>
</span>
- the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
- </p>
- <p id="ch5func_1aa">
- The
- <span class="emphasis">
- <em>
- -c
- </em>
+ clause and
+multiple
+ <span class="strong">
+ <strong>
+ if
+ </strong>
</span>
- flag complements the first set of characters.
- </p>
- <pre class="programlisting">
- $ tr -cd '[:alnum:]'
- </pre>
- <p id="ch5func_1ab">
- therefore removes all non-alphanumeric characters.
- </p>
- <p id="ch5func_1ac">
- The
- <span class="emphasis">
- <em>
- -s
- </em>
- </span>
- flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
+ clauses. It will be more clear with an example:
</p>
<pre class="programlisting">
- $ tr -s '\n' '\n'
- </pre>
- <p id="ch5func_1ad">
- replaces sequences of one or more newline characters with a single newline.
- </p>
- <p id="ch5func_1ae">
- The
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
- </p>
- <pre class="programlisting">
- $ tr -d '\r'
+ >>> num = [1, 2, 3]
+>>> sq = [x*x for x in num]
+>>> sq
+[1, 4, 9]
+>>> all_num = [1, 2, 3, 4, 5, 6, 7, 8, 9]
+>>> even = [x for x in all_num if x%2 == 0]
</pre>
- <p id="ch5func_1af">
- Most versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , including GNU
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- and classic Unix
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
- </p>
- <p id="ch5func_1b0">
- Ruby and Perl also have an internal
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- operator, which operates analogously. Tcl's
- <span class="emphasis">
- <em>
- string map
- </em>
- </span>
- command is more general in that it maps strings to strings while
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- maps characters to characters.
+ <p id="ch5func_1f">
+ The syntax used here is very clear from the way it is written. It can be
+translated into english as, "for each element x in the list all_num,
+if remainder of x divided by 2 is 0, add x to the list."
</p>
</div>
</div>
- <div class="section" title="14.Elementary Regex">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2889196">
- </a>
- 14.Elementary Regex
- </h2>
- </div>
- </div>
- </div>
- <p id="ch5func_1b1">
- In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
- </p>
- <p id="ch5func_1b2">
- Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributionsincluding the editor
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- and the filter
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- were the first to popularize the concept of regular expressions.
- </p>
- <p id="ch5func_1b3">
- Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
- <span class="emphasis">
- <em>
- Basic Regular Expressions
- </em>
- </span>
- (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
- </p>
- <p id="ch5func_1b4">
- In the BRE syntax, most characters are treated as literals they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
- </p>
- <table summary="Elementary Regex" border="1">
- <colgroup>
- <col width="13">
- </col>
- <col width="60">
- </col>
- </colgroup>
- </table>
- <div class="section" title="14.1.Lazy quantification">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2889402">
- </a>
- 14.1.Lazy quantification
- </h3>
- </div>
- </div>
- </div>
- <p id="ch5func_1c9">
- The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example:
- </p>
- <pre class="programlisting">
- Another whale explosion occurred on <January 26>, <2004>.
- </pre>
- <p id="ch5func_1ca">
- ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the * quantifier is greedy it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
- </p>
- <p id="ch5func_1cb">
- Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as
- <span class="emphasis">
- <em>
- lazy
- </em>
- </span>
- (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
- </p>
- </div>
- </div>
- <div class="section" title="15.One Liners">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2889478">
- </a>
- 15.One Liners
- </h2>
- </div>
- </div>
- </div>
- <p id="ch5func_1cc">
- A
- <span class="emphasis">
- <em>
- one-liner
- </em>
- </span>
- is textual input to the command-line of an operating system shell that performs some function in just one line of input.
- </p>
- <p id="ch5func_1cd">
- The one liner can be
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch5func_1ce">
- An expression written in the language of the shell.
- </p>
- </li>
- <li class="listitem">
- <p id="ch5func_1cf">
- The invocation of an interpreter together with program source for the interpreter to run.
- </p>
- </li>
- <li class="listitem">
- <p id="ch5func_1d0">
- The invocation of a compiler together with source to compile and
-instructions for executing the compiled program.
- </p>
- </li>
- </ol>
- </div>
- <p id="ch5func_1d1">
- Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
- </p>
- <p id="ch5func_1d2">
- The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
- </p>
- <p id="ch5func_1d3">
- The word
- <span class="emphasis">
- <em>
- One-liner
- </em>
- </span>
- has two references in the index of the book
- <span class="emphasis">
- <em>
- The AWK Programming Language
- </em>
- </span>
- (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
- </p>
- <pre class="programlisting">
- The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.
- </pre>
- <p id="ch5func_1d4">
- Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
- </p>
- <p id="ch5func_1d5">
- The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
- </p>
- <p id="ch5func_1d6">
- Here are the first few of them:
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch5func_1d7">
- Print the total number of input lines:
- </p>
- <p id="ch5func_1d8">
- END { print NR }
- </p>
- </li>
- <li class="listitem">
- <p id="ch5func_1d9">
- Print the tenth input line:
- </p>
- <p id="ch5func_1da">
- NR == 10
- </p>
- </li>
- <li class="listitem">
- <p id="ch5func_1db">
- Print the last field of every input line:
- </p>
- <p id="ch5func_1dc">
- { print $NF }
- </p>
- </li>
- </ol>
- </div>
- <p id="ch5func_1dd">
- One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
- </p>
- <p id="ch5func_1de">
- The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:
- </p>
- <pre class="programlisting">
- main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
-*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
- </pre>
- <p id="ch5func_1df">
- This one-liner program is a
- <span class="emphasis">
- <em>
- glob pattern matcher
- </em>
- </span>
- . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
- </p>
- <p id="ch5func_1e0">
- Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:
- </p>
- <pre class="programlisting">
- $ prog foo 'f??'; echo $?
-
-$ prog 'best short program' '??st*o**p?*'; echo $?
- </pre>
- <p id="ch5func_1e1">
- Here is a one line shell script to show directories:
- </p>
- <pre class="programlisting">
- $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
- </pre>
- </div>
</div>
</div>
</body>
--- a/SEESenv/web/html/ch6oop.html Mon Feb 22 18:46:07 2010 +0530
+++ b/SEESenv/web/html/ch6oop.html Mon Feb 22 22:38:51 2010 +0530
@@ -27,5228 +27,247 @@
<dl>
<dt>
<span class="article">
- <a href="#id2577036">
+ <a href="#id2864302">
+ Classes and Objects
</a>
</span>
</dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2387161">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2574856">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2628095">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2628360">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2628487">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2628495">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2628767">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2628775">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2628932">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2628990">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2629085">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2629165">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2629326">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2629334">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2629427">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2629613">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2629699">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2629753">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2629761">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2630070">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2627868">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2630515">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2630608">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2630617">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2630704">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2630831">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2630917">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2631052">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2631155">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2631164">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2631352">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2631466">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2631702">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2631966">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2631982">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2632004">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2632013">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2632792">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2632828">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2632896">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2632956">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2633156">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2633188">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2633218">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2633227">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2633413">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2633558">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2633765">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2633840">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </dd>
</dl>
</div>
- <div class="article">
+ <div class="article" title="Classes and Objects">
<div class="titlepage">
<div>
<div>
- <h2 class="title" id="id2577036">
+ <h2 class="title">
+ <a name="id2864302">
+ </a>
+ Classes and Objects
</h2>
</div>
</div>
<hr />
</div>
- <div class="toc">
- <p>
- <b>
- Table of Contents
- </b>
- </p>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2387161">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2574856">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2628095">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2628360">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2628487">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2628495">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2628767">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2628775">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2628932">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2628990">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2629085">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2629165">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2629326">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2629334">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2629427">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2629613">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2629699">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2629753">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2629761">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2630070">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2627868">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2630515">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2630608">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2630617">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2630704">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2630831">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2630917">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2631052">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2631155">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2631164">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2631352">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2631466">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2631702">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2631966">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2631982">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2632004">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2632013">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2632792">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2632828">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2632896">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2632956">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2633156">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2633188">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2633218">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2633227">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2633413">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2633558">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2633765">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2633840">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </div>
- <div class="section" title="1.Introducing Linux">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2387161">
- </a>
- 1.Introducing Linux
- </h2>
- </div>
- </div>
- </div>
- <p id="ch6oop_1">
- (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
- </p>
- <p id="ch6oop_2">
- Linux (usually pronounced lnks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
- </p>
- <p id="ch6oop_3">
- Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
- </p>
- <p id="ch6oop_4">
- The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
- </p>
- <div class="section" title="1.1.Historical Background">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2574856">
- </a>
- 1.1.Historical Background
- </h3>
- </div>
- </div>
- </div>
- <div class="section" title="1.1.1.Events leading to the creation">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2574730">
- </a>
- 1.1.1.Events leading to the creation
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_5">
- The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_6">
- In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="1.1.2.The Creation of Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2628050">
- </a>
- 1.1.2.The Creation of Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_7">
- In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
- </p>
- <p id="ch6oop_8">
- Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
- </p>
- </div>
- </div>
- <div class="section" title="1.2.Design and Implications">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2628095">
- </a>
- 1.2.Design and Implications
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_9">
- A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
- </p>
- <div class="section" title="1.2.1.User Interface">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2628120">
- </a>
- 1.2.1.User Interface
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_a">
- Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
- </p>
- <p id="ch6oop_b">
- A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
- </p>
- </div>
- <div class="section" title="1.2.2.Development">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2628172">
- </a>
- 1.2.2.Development
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_c">
- The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
- </p>
- <p id="ch6oop_d">
- Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
- </p>
- <p id="ch6oop_e">
- A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
- </p>
- </div>
- <div class="section" title="1.2.3.Community">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2628227">
- </a>
- 1.2.3.Community
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_f">
- A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
- </p>
- <p id="ch6oop_10">
- In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
- </p>
- <p id="ch6oop_11">
- Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
- </p>
- </div>
- <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2628270">
- </a>
- 1.2.4.Can I make a profit out of running a business involving Linux?
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_12">
- The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
- </p>
- </div>
- <div class="section" title="1.2.5.Programming on Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2628316">
- </a>
- 1.2.5.Programming on Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_13">
- Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
- </p>
- <p id="ch6oop_14">
- Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
- </p>
- <p id="ch6oop_15">
- The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
- </p>
- </div>
- </div>
- <div class="section" title="1.3.Reasons for Using Linux">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2628360">
- </a>
- 1.3.Reasons for Using Linux
- </h3>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_16">
- Linux is free:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_17">
- As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
-Most of all, Linux is free as in "free speech":
-The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_18">
- Linux is portable to any hardware platform:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_19">
- A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_1a">
- Linux was made to keep on running:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_1b">
- As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_1c">
- Linux is secure and versatile:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_1d">
- The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_1e">
- Linux is scalable:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_1f">
- From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_20">
- The Linux OS and Linux applications have very short debugtimes:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_21">
- Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
- </p>
- </div>
- </div>
- <div class="section" title="2.Getting Started">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2628487">
- </a>
- 2.Getting Started
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="2.1.Logging in, activating the user interface and logging out">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2628495">
- </a>
- 2.1.Logging in, activating the user interface and logging out
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_22">
- In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PCbased Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multiuser features, or in graphical console mode, which looks better but eats more system resources.
- </p>
- <div class="section" title="2.1.1.Graphical Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2628525">
- </a>
- 2.1.1.Graphical Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_23">
- This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
- </p>
- <p id="ch6oop_24">
- To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
- <span class="emphasis">
- <em>
- OK
- </em>
- </span>
- or press
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- .
-It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
- </p>
- <p id="ch6oop_25">
- After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
- </p>
- <p id="ch6oop_26">
- To continue, you will need to open a
- <span class="emphasis">
- <em>
- terminal window
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
- <span class="emphasis">
- <em>
- Applications>Utilities->System Tools
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- Internet menu
- </em>
- </span>
- , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
- </p>
- <p id="ch6oop_27">
- While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old pointnclick method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
- </p>
- <p id="ch6oop_28">
- A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
- </p>
- <p id="ch6oop_29">
- Another common form for a prompt is this one:
-[
- </p>
- <div class="reference">
- <div class="titlepage">
- <hr />
- </div>
- user@host
- </div>
- <p>
- dir]
- </p>
- <p id="ch6oop_2a">
- In the above example,
- <span class="emphasis">
- <em>
- user
- </em>
- </span>
- will be your login name,
- <span class="emphasis">
- <em>
- hosts
- </em>
- </span>
- the name of the machine you are working on, and
- <span class="emphasis">
- <em>
- dir
- </em>
- </span>
- an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- icon or find
- <span class="emphasis">
- <em>
- Log Out
- </em>
- </span>
- in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
- </p>
- <p id="ch6oop_2b">
- When you see the login screen again, asking to enter user name and password, logout was successful.
- </p>
- </div>
- <div class="section" title="2.1.2.Text Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2628680">
- </a>
- 2.1.2.Text Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_2c">
- One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
- </p>
- <p id="ch6oop_2d">
- The login is different from a graphical login, in that you have to hit the
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- . You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
-reasons.
- </p>
- <p id="ch6oop_2e">
- When the system has accepted you as a valid user, you may get some more information, called the
- <span class="emphasis">
- <em>
- message of the day
- </em>
- </span>
- , which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
- </p>
- <p id="ch6oop_2f">
- Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a nonprivileged user.
- </p>
- <p id="ch6oop_30">
- Logging out is done by entering the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't poweroff the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="3.Basic Commands">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2628767">
- </a>
- 3.Basic Commands
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="3.1.ls">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2628775">
- </a>
- 3.1.ls
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_31">
- When invoked without any arguments,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- is derived from
- <span class="emphasis">
- <em>
- list segments
- </em>
- </span>
- which was used in earlier systems.
- </p>
- <p id="ch6oop_32">
- Files whose names start with "." are not listed, unless the
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- flag is specified or the files are specified explicitly.
- </p>
- <p id="ch6oop_33">
- Without options,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_34">
- <span class="emphasis">
- <em>
- -l
- </em>
- </span>
- long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_35">
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_36">
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_37">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- recursively lists subdirectories. The command ls -R / would therefore list all files.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_38">
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_39">
- <span class="emphasis">
- <em>
- -t
- </em>
- </span>
- sort the list of files by modification time.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_3a">
- <span class="emphasis">
- <em>
- -h
- </em>
- </span>
- print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_3b">
- In some environments, providing the option
- <span class="emphasis">
- <em>
- --color
- </em>
- </span>
- (for GNU ls) or
- <span class="emphasis">
- <em>
- -G
- </em>
- </span>
- (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- would. To determine what color to use for a file, GNU
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks the Unix file type, the file permissions, and the file extension, while FreeBSD
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks only the Unix file type and file permissions.:
- </p>
- <pre class="programlisting">
- $ ls
-jeeves.rst psmith.html blandings.html
-$ ls -l
-drwxr--r-- 1 plum editors 4096 jeeves
--rw-r--r-- 1 plum editors 30405 psmith
--r-xr-xr-x 1 plum plum 8460 blandings
- </pre>
- <p id="ch6oop_3c">
- Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
- </p>
- </div>
- <div class="section" title="3.2.date">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2628932">
- </a>
- 3.2.date
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_3d">
- The Unix date command displays the time and date. The super-user can use it to set the system clock.
- </p>
- <p id="ch6oop_3e">
- With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:
- </p>
- <pre class="programlisting">
- $date
-Tue Sep 8 12:01:45 IST 2009
- </pre>
- <p id="ch6oop_3f">
- On some systems to set the current date and time to September 8, 2004 01:22 you type:
- </p>
- <pre class="programlisting">
- $date --set="20040908 01:22"
- </pre>
- <p id="ch6oop_40">
- In order to view the various options for the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command, type:
- </p>
- <pre class="programlisting">
- $man date
- </pre>
- <p id="ch6oop_41">
- This will take you to the "Manual" page comprising of all the details on the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command. You can return to the terminal from the "man" page by pressing the
- <span class="emphasis">
- <em>
- Esc
- </em>
- </span>
- key in the keyboard and typing ":q" in that order.
- </p>
- </div>
- <div class="section" title="3.3.cd">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2628990">
- </a>
- 3.3.cd
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_42">
- This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, cd .. can be used.
- </p>
- <p id="ch6oop_43">
- One dot '.' represents the current directory while two dots '..' represent the parent directory.
- </p>
- <p id="ch6oop_44">
- cd - will return you to the previous directory (a bit like an undo).
- </p>
- <p id="ch6oop_45">
- You can also use cd absolute path or cd relative path (see below):
- </p>
- <p id="ch6oop_46">
- Absolute paths:
- </p>
- <p id="ch6oop_47">
- An absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
- </p>
- <p id="ch6oop_48">
- For example to get to /boot/grub you would type:
- </p>
- <pre class="programlisting">
- $cd /boot/grub
- </pre>
- <p id="ch6oop_49">
- This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
- </p>
- <p id="ch6oop_4a">
- Relative paths:
- </p>
- <p id="ch6oop_4b">
- A relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
- </p>
- <p id="ch6oop_4c">
- For example if you are in root's home directory and want to get to /root/music, you type:
- </p>
- <pre class="programlisting">
- $ cd music
- </pre>
- <p id="ch6oop_4d">
- Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
- </p>
- </div>
- <div class="section" title="3.4.who">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2629085">
- </a>
- 3.4.who
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_4e">
- The standard Unix command
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- displays a list of users who are currently logged into a computer.
- </p>
- <p id="ch6oop_4f">
- The
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command is related to the command
- <span class="emphasis">
- <em>
- w
- </em>
- </span>
- , which provides the same information but also displays additional data and statistics.:
- </p>
- <pre class="programlisting">
- $who
-beeblebrox tty7 2009-09-08 10:50 (:0)
-beeblebrox pts/0 2009-09-08 11:25 (:0.0)
-dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in)
-beeblebrox pts/2 2009-09-08 18:53 (:0.0)
- </pre>
- <p id="ch6oop_50">
- The command can be invoked with the arguments
- <span class="emphasis">
- <em>
- am i
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- am I
- </em>
- </span>
- (so it is invoked as
- <span class="emphasis">
- <em>
- who am i
- </em>
- </span>
- or * who am I*), showing information about the current terminal only (see the
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- option below, of which this invocation is equivalent).
- </p>
- <p id="ch6oop_51">
- In order to find out the various options that can be appended to the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command, check the
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page by typing out the following in the terminal:
- </p>
- <pre class="programlisting">
- $man who
- </pre>
- <p id="ch6oop_52">
- This will take you to the "Manual" page containing details about the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command
- </p>
- </div>
- <div class="section" title="3.5.mkdir">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2629165">
- </a>
- 3.5.mkdir
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_53">
- This command is used to make a new directory. Normal usage is as straightforward as follows:
- </p>
- <pre class="programlisting">
- $mkdir name_of_directory
- </pre>
- <p id="ch6oop_54">
- Where
- <span class="emphasis">
- <em>
- name_of_directory
- </em>
- </span>
- is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- will try to create all of them.
- </p>
- <div class="section" title="3.5.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2629196">
- </a>
- 3.5.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_55">
- On Unix-like operating systems,
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- takes options. Three of the most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_56">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- : will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_57">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- : display each directory that mkdir creates. Most often used with -p.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_58">
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- : specify the octal permissions of directories created by mkdir.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_59">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
- </p>
- </div>
- <div class="section" title="3.5.2.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2629252">
- </a>
- 3.5.2.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_5a">
- An example of
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- in action is:
- </p>
- <pre class="programlisting">
- $mkdir -p /tmp/a/b/c
- </pre>
- <p id="ch6oop_5b">
- If
- <span class="emphasis">
- <em>
- /tmp/a
- </em>
- </span>
- exists but
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- does not, mkdir will create
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- before creating
- <span class="emphasis">
- <em>
- /tmp/a/b/c
- </em>
- </span>
- .
- </p>
- <p id="ch6oop_5c">
- And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
- </p>
- <pre class="programlisting">
- $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
- </pre>
- <p id="ch6oop_5d">
- This will create:
- </p>
- tmpdir - branches
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_5e">
- tag
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- trunk - sources - includes
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_5f">
- docs
- </p>
- </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="4.Getting Help">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2629326">
- </a>
- 4.Getting Help
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="4.1.apropos and whatis">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2629334">
- </a>
- 4.1.apropos and whatis
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_60">
- This is a command to search the manual pages files in Unix and Unix-like operating systems.
- </p>
- <pre class="programlisting">
- $ apropos grep
-egrep egrep (1) Search a file for a pattern using full regular expressions
-fgrep fgrep (1) Search a file for a fixed-character string
-fmlgrep fmlgrep (1) Search a file for a pattern
-grep grep (1) Search a file for a pattern
-gzgrep gzgrep (1) Search a possibly compressed file for a regular expression
-nisgrep nismatch (1) Utilities for searching NIS+ tables
-pgrep pgrep (1) Find or signal a process by name or other attribute
-zgrep zgrep (1) Search a possibly compressed file for a regular expression
-...
- </pre>
- <p id="ch6oop_61">
- In this example, the user uses
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- to search for the string "grep", and apropos returns the indicated
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- pages that include the term "grep".
- </p>
- <p id="ch6oop_62">
- A short index of explanations for commands is available using the
- <span class="emphasis">
- <em>
- whatis
- </em>
- </span>
- command, like in the examples below:
- </p>
- <pre class="programlisting">
- $whatis ls
-ls (1) - list directory contents
- </pre>
- <p id="ch6oop_63">
- This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
- </p>
- <p id="ch6oop_64">
- If you don't know where to get started and which man page to read,
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- gives more information. Say that you do not know how to start a browser, then you could enter the following command:
- </p>
- <pre class="programlisting">
- $apropos browser
-gmusicbrowser (1) - Jukebox for large collections of audio files
-infobrowser (1) - read Info documents
-libsmbclient (7) - An extension library for browsers and that can be used...
-opera (1) - a standards-compliant graphical Web browser
-sensible-browser (1) - sensible editing, paging, and web browsing
-smbtree (1) - A text based smb network browser
-tvtk_doc (1) - A GUI based TVTK documentation search browser.
-viewres (1) - graphical class browser for Xt
-w3m (1) - a text based Web browser and pager
-www-browser (1) - a text based Web browser and pager
-...
- </pre>
- </div>
- <div class="section" title="4.2.man">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2629427">
- </a>
- 4.2.man
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_65">
- Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- . Each page is a self-contained document.
- </p>
- <p id="ch6oop_66">
- To read a manual page for a Unix command, one can use:
- </p>
- <pre class="programlisting">
- $ man <command_name>
- </pre>
- <p id="ch6oop_67">
- at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- generally uses the less terminal pager.
- </p>
- <p id="ch6oop_68">
- Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are
- <span class="emphasis">
- <em>
- man(1)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- man(7)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- exit(2)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- exit(3)
- </em>
- </span>
- . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
- <span class="emphasis">
- <em>
- BSD, for example, the syntax for reading *printf(3)
- </em>
- </span>
- is:
- </p>
- <pre class="programlisting">
- $man 3 printf
- </pre>
- <p id="ch6oop_69">
- Another example:
- </p>
- <pre class="programlisting">
- $man man
- </pre>
- <p id="ch6oop_6a">
- The previous example will take you to the "Manual" page entry about manual pages!
- </p>
- <div class="section" title="4.2.1.Layout">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2629507">
- </a>
- 4.2.1.Layout
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_6b">
- All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
- </p>
- NAME
- <p id="ch6oop_6c">
- The name of the command or function, followed by a one-line description of what it does.
- </p>
- SYNOPSIS
- <p id="ch6oop_6d">
- In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
- </p>
- DESCRIPTION
- <p id="ch6oop_6e">
- A textual description of the functioning of the command or function.
- </p>
- EXAMPLES
- <p id="ch6oop_6f">
- Some examples of common usage.
- </p>
- SEE ALSO
- <p id="ch6oop_70">
- A list of related commands or functions.
- </p>
- <p id="ch6oop_71">
- Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
- </p>
- <p id="ch6oop_72">
- These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
- </p>
- <p id="ch6oop_73">
- However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
- </p>
- <p id="ch6oop_74">
- Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
- </p>
- <p id="ch6oop_75">
- Usually the man pages are written in English. Translations into other languages can be also available on the system.
- </p>
- <p id="ch6oop_76">
- The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
- </p>
- </div>
- </div>
- <div class="section" title="4.3.info">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2629613">
- </a>
- 4.3.info
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_77">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
- </p>
- <p id="ch6oop_78">
- The syntax is
- </p>
- <pre class="programlisting">
- $ info <command_name>
- </pre>
- <p id="ch6oop_79">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_7a">
- <span class="emphasis">
- <em>
- n
- </em>
- </span>
- goes to the next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_7b">
- <span class="emphasis">
- <em>
- p
- </em>
- </span>
- goes to the previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_7c">
- <span class="emphasis">
- <em>
- u
- </em>
- </span>
- goes to the upper page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_7d">
- <span class="emphasis">
- <em>
- l
- </em>
- </span>
- goes to the last(visited) node
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_7e">
- To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_7f">
- info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
- </p>
- </div>
- <div class="section" title="4.4.--help">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2629699">
- </a>
- 4.4.--help
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_80">
- Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command:
- </p>
- <pre class="programlisting">
- $ userprompt@host: cat --help
-Usage: cat [OPTION] [FILE]...
-Concatenate FILE(s), or standard input, to standard output.
-
- -A, --show-all equivalent to -vET
- -b, --number-nonblank number nonempty output lines
- -e equivalent to -vE
- -E, --show-ends display $ at end of each line
- -n, --number number all output lines
- -s, --squeeze-blank suppress repeated empty output lines
- -t equivalent to -vT
- -T, --show-tabs display TAB characters as ^I
- -u (ignored)
- -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
- --help display this help and exit
- --version output version information and exit
-
-With no FILE, or when FILE is -, read standard input.
-
-Examples:
- cat f - g Output f's contents, then standard input, then g's contents.
- cat Copy standard input to standard output.
+ <p id="ch6oop_1">
+ In the previous sections we learnt about functions which provide certain level
+of abstraction to our code by holding the code which performs one or more
+specific functionalities. We were able to use this function as many times as we
+wanted. In addition to functions, Python also higher level of abstractions
+through
+ <span class="emphasis">
+ <em>
+ Classes
+ </em>
+ </span>
+ and
+ <span class="emphasis">
+ <em>
+ Objects
+ </em>
+ </span>
+ .
+ <span class="emphasis">
+ <em>
+ Objects
+ </em>
+ </span>
+ can be loosely defined as a
+collection of a set of data items and a set of methods. The data items can be
+any valid Python variable or any Python object. Functions enclosed within a class
+are called as
+ <span class="emphasis">
+ <em>
+ methods
+ </em>
+ </span>
+ . If you are thinking if methods are functions why is there
+a distinction between the two? The answer to this will be given as we walk through
+the concepts of
+ <span class="emphasis">
+ <em>
+ Classes
+ </em>
+ </span>
+ and
+ <span class="emphasis">
+ <em>
+ Objects
+ </em>
+ </span>
+ .
+ <span class="emphasis">
+ <em>
+ Classes
+ </em>
+ </span>
+ contain the definition for the
+ <span class="emphasis">
+ <em>
+ Objects
+ </em>
+ </span>
+ .
+ <span class="emphasis">
+ <em>
+ Objects
+ </em>
+ </span>
+ are instances of
+ <span class="emphasis">
+ <em>
+ Classes
+ </em>
+ </span>
+ .
+ </p>
+ <p id="ch6oop_2">
+ A class is defined using the keyword
+ <span class="strong">
+ <strong>
+ class
+ </strong>
+ </span>
+ followed by the class name, in
+turn followed by a semicolon. The statements that a
+ <span class="emphasis">
+ <em>
+ Class
+ </em>
+ </span>
+ encloses are written
+in a new block, i.e on the next indentation level:
+ </p>
+ <pre class="programlisting">
+ class Employee:
+ def setName(self, name):
+ self.name = name
-Report bugs to <bug-coreutils@gnu.org>.
- </pre>
- </div>
- </div>
- <div class="section" title="5.Basic file handling">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2629753">
- </a>
- 5.Basic file handling
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="5.1.cp">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2629761">
- </a>
- 5.1.cp
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_81">
- <span class="emphasis">
- <em>
- cp
- </em>
- </span>
- is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
- </p>
- <div class="section" title="5.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2629779">
- </a>
- 5.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_82">
- To copy a file to another file:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
- </pre>
- <p id="ch6oop_83">
- To copy a file to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
- </pre>
- <p id="ch6oop_84">
- To copy a directory to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
-SourceDirectory ... TargetDirectory
- </pre>
- </div>
- <div class="section" title="5.1.2.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2629813">
- </a>
- 5.1.2.Flags
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_85">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (force) specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
- </p>
- <p id="ch6oop_86">
- <span class="emphasis">
- <em>
- -P
- </em>
- </span>
- makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
- </p>
- <p id="ch6oop_87">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- (interactive) prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
- </p>
- <p id="ch6oop_88">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- (preserve) duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_89">
- The time of the last data modification and the time of the last access.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_8a">
- The user ID and group ID (only if it has permissions to do this)
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_8b">
- The file permission bits and the SUID and SGID bits.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_8c">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- (recursive) copy directories (recursively copying all the contents)
- </p>
- </div>
- <div class="section" title="5.1.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2629909">
- </a>
- 5.1.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_8d">
- To make a copy of a file in the current directory, enter:
- </p>
- <pre class="programlisting">
- $ cp prog.c prog.bak
- </pre>
- <p id="ch6oop_8e">
- This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
- </p>
- <p id="ch6oop_8f">
- To copy a file in your current directory into another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod /home/books/hhgg
- </pre>
- <p id="ch6oop_90">
- This copies the jones file to /home/books/hhgg/zaphod.
- </p>
- <p id="ch6oop_91">
- To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
- </p>
- <pre class="programlisting">
- $ cp -p martin_luther_king martin_luther_king.jr
- </pre>
- <p id="ch6oop_92">
- This copies the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file to the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file. Instead of creating the file with the current date and time stamp, the system gives the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file the same date and time as the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file. The
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file also inherits the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file's access control protection.
- </p>
- <p id="ch6oop_93">
- To copy all the files in a directory to a new directory, enter:
- </p>
- <pre class="programlisting">
- $ cp /home/galactica/clients/* /home/hhgg/customers
- </pre>
- <p id="ch6oop_94">
- This copies only the files in the clients directory to the customers directory.
- </p>
- <p id="ch6oop_95">
- To copy a directory, including all its files and subdirectories, to another directory, enter:
- </p>
- <p id="ch6oop_96">
- $ cp -R /home/hhgg/clients /home/hhgg/customers
- </p>
- <p id="ch6oop_97">
- This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
- </p>
- <p id="ch6oop_98">
- To copy a specific set of files of any extension to another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod arthur ford /home/hhgg/clients
- </pre>
- <p id="ch6oop_99">
- This copies the
- <span class="emphasis">
- <em>
- zaphod
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- arthur
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- ford
- </em>
- </span>
- files in your current working directory to the /home/hhgg/clients directory.
- </p>
- <p id="ch6oop_9a">
- To use pattern-matching characters to copy files, enter:
- </p>
- <pre class="programlisting">
- $ cp programs/*.py .
- </pre>
- <p id="ch6oop_9b">
- This copies the files in the programs directory that end with
- <span class="emphasis">
- <em>
- .py
- </em>
- </span>
- to the current directory, signified by the single "." (dot). You must type a space between the
- <span class="emphasis">
- <em>
- py
- </em>
- </span>
- and the final dot.
- </p>
- </div>
- </div>
- <div class="section" title="5.2.mv">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2630070">
- </a>
- 5.2.mv
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_9c">
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system),
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- will rename the file instead. Write permission is required on all directories being modified.
- </p>
- <div class="section" title="5.2.1.Conflicting existing file">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2630094">
- </a>
- 5.2.1.Conflicting existing file
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_9d">
- In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
- </p>
- </div>
- <div class="section" title="5.2.2.Differences with copy and delete">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2630113">
- </a>
- 5.2.2.Differences with copy and delete
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_9e">
- Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
- </p>
- </div>
- <div class="section" title="5.2.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2630143">
- </a>
- 5.2.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ mv myfile mynewfilename renames a file
-$ mv myfile otherfilename renames a file and deletes the existing file "myfile"
-$ mv myfile /myfile moves 'myfile' from the current directory to the root directory
-$ mv myfile dir/myfile moves 'myfile' to 'dir/myfile' relative to the current directory
-$ mv myfile dir same as the previous command (the filename is implied to be the same)
-$ mv myfile dir/myfile2 moves 'myfile' to dir and renames it to 'myfile2'
-$ mv foo bar baz dir moves multiple files to directory dir
-$ mv --help shows a very concise help about the syntax of the command
-$ man mv prints an extensive user manual for 'mv' in the terminal
- </pre>
- <p id="ch6oop_9f">
- In all cases, the file or files being moved or renamed can be a directory.
- </p>
- <p id="ch6oop_a0">
- Note that when the command is called with two arguments (as
- <span class="emphasis">
- <em>
- mv name1 name2
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- mv name1 /dir/name2
- </em>
- </span>
- ), it can have three different effects, depending on whether
- <span class="emphasis">
- <em>
- name2
- </em>
- </span>
- does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
- <span class="emphasis">
- <em>
- /.
- </em>
- </span>
- (or in some Unix versions
- <span class="emphasis">
- <em>
- /
- </em>
- </span>
- is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
- </p>
- </div>
- </div>
- <div class="section" title="5.3.rm">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2627868">
- </a>
- 5.3.rm
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_a1">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
- </p>
- <p id="ch6oop_a2">
- Here's example to remove a file named "foo" from a directory, here shown with the -i option:
- </p>
- <pre class="programlisting">
- $ rm -i foo
-remove foo? y
- </pre>
- <div class="section" title="5.3.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2627898">
- </a>
- 5.3.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_a3">
- Common options that rm accepts include:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_a4">
- <span class="emphasis">
- <em>
- -r
- </em>
- </span>
- , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_a5">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- , which asks for every deletion to be confirmed ("interactive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_a6">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- , which ignores non-existent files and overrides any confirmation prompts ("force")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_a7">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- , which shows what is being removed as it happens ("verbose")
- </p>
- </li>
- </ul>
- </div>
- <p id="ch6oop_a8">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
- </p>
- <p id="ch6oop_a9">
- <span class="emphasis">
- <em>
- rm -rf
- </em>
- </span>
- (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
- </p>
- <p id="ch6oop_aa">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often used in conjunction with xargs to supply a list of files to delete:
- </p>
- <pre class="programlisting">
- xargs rm < filelist
- </pre>
- <p id="ch6oop_ab">
- When
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is used on a symbolic link, it deletes the link, but does not affect the target of the link.
- </p>
- </div>
- <div class="section" title="5.3.2.Permissions">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2630465">
- </a>
- 5.3.2.Permissions
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_ac">
- Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
- </p>
- <p id="ch6oop_ad">
- To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
- </p>
- <p id="ch6oop_ae">
- If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="6.Command Line Arguments">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2630515">
- </a>
- 6.Command Line Arguments
- </h2>
- </div>
- </div>
- </div>
- <p id="ch6oop_af">
- In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
- </p>
- <p id="ch6oop_b0">
- For example, in Unix and Unix-like environments, an example of a command-line argument is:
- </p>
- <pre class="programlisting">
- rm file.s
- </pre>
- <p id="ch6oop_b1">
- "file.s" is a command line argument which tells the program rm to remove the file "file.s".
- </p>
- <p id="ch6oop_b2">
- Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
- </p>
- <p id="ch6oop_b3">
- A command line option or simply
- <span class="emphasis">
- <em>
- option
- </em>
- </span>
- (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
- </p>
- <p id="ch6oop_b4">
- Long options are introduced via "--", and are typically whole words. For example,
- <span class="emphasis">
- <em>
- ls --long --classify --all
- </em>
- </span>
- . Arguments to long options are provided with "=", as
- <span class="emphasis">
- <em>
- ls --block-size=1024
- </em>
- </span>
- . Some Unix programs use long options with single dashes, for example MPlayer as in
- <span class="emphasis">
- <em>
- mplayer -nosound
- </em>
- </span>
- .
- </p>
- <p id="ch6oop_b5">
- Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- by using
- <span class="emphasis">
- <em>
- rm -file1
- </em>
- </span>
- may produce an error, since rm may interpret
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- as a command line switch. Using
- <span class="emphasis">
- <em>
- rm -- -file1
- </em>
- </span>
- removes ambiguity.
- </p>
- </div>
- <div class="section" title="7.Basic Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2630608">
- </a>
- 7.Basic Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="7.1.head">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2630617">
- </a>
- 7.1.head
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_b6">
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:
- </p>
- <pre class="programlisting">
- $ head [options] <file_name>
- </pre>
- <p id="ch6oop_b7">
- By default,
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ head -n 20 filename
- </pre>
- <p id="ch6oop_b8">
- This displays the first 5 lines of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ head -n 5 foo*
- </pre>
- <p id="ch6oop_b9">
- Some versions omit the n and just let you say -5.
- </p>
- <div class="section" title="7.1.1.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2630668">
- </a>
- 7.1.1.Flags
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- -c <x number of bytes> Copy first x number of bytes.
- </pre>
- <p id="ch6oop_ba">
- Other options:
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- </p>
- <p id="ch6oop_bb">
- Many early versions of Unix did not have this command, and so documentation and books had
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- do this job:
- </p>
- <pre class="programlisting">
- sed 5q foo
- </pre>
- <p id="ch6oop_bc">
- This says to print every line (implicit), and quit after the fifth.
- </p>
- </div>
- </div>
- <div class="section" title="7.2.tail">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2630704">
- </a>
- 7.2.tail
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_bd">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
- </p>
- <p id="ch6oop_be">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ tail [options] <file_name>
- </pre>
- <p id="ch6oop_bf">
- By default,
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ tail -n 20 filename
- </pre>
- <p id="ch6oop_c0">
- This example shows the last 15 bytes of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ tail -c 15 foo*
- </pre>
- <p id="ch6oop_c1">
- This example shows all lines of filename from the second line onwards:
- </p>
- <pre class="programlisting">
- $ tail -n +2 filename
- </pre>
- <p id="ch6oop_c2">
- Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:
- </p>
- <pre class="programlisting">
- $ tail -20 filename
-$ tail -50c filename
- </pre>
- <p id="ch6oop_c3">
- However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
- </p>
- <div class="section" title="7.2.1.File monitoring">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2630782">
- </a>
- 7.2.1.File monitoring
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_c4">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- has a special command line option
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:
- </p>
- <pre class="programlisting">
- $ tail -f /var/adm/messages
- </pre>
- <p id="ch6oop_c5">
- To interrupt tail while it is monitoring, break-in with
- <span class="emphasis">
- <em>
- Ctrl+C
- </em>
- </span>
- . This command can be run "in the background" with &, see job control.
- </p>
- <p id="ch6oop_c6">
- If you have a command's result to monitor, you can use the
- <span class="emphasis">
- <em>
- watch
- </em>
- </span>
- command.
- </p>
- </div>
- </div>
- <div class="section" title="7.3.cut">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2630831">
- </a>
- 7.3.cut
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_c7">
- In computing,
- <span class="emphasis">
- <em>
- cut
- </em>
- </span>
- is a Unix command line utility which is used to extract sections from each line of input usually from a file.
- </p>
- <p id="ch6oop_c8">
- Extraction of line segments can typically be done by
- <span class="emphasis">
- <em>
- bytes (-b), characters (-c)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- fields (-f)
- </em>
- </span>
- separated by a
- <span class="emphasis">
- <em>
- delimiter (-d the tab character by default)
- </em>
- </span>
- . A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
- </p>
- <p id="ch6oop_c9">
- Assuming a file named file containing the lines:
- </p>
- <pre class="programlisting">
- foo:bar:baz:qux:quux
-one:two:three:four:five:six:seven
-alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- <p id="ch6oop_ca">
- To output the fourth through tenth characters of each line:
- </p>
- <pre class="programlisting">
- $ cut -c 4-10 file
- </pre>
- <p id="ch6oop_cb">
- This gives the output:
- </p>
- <pre class="programlisting">
- :bar:ba
-:two:th
-ha:beta
- </pre>
- <p id="ch6oop_cc">
- To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
- </p>
- <pre class="programlisting">
- $ cut -d : -f 5- file
- </pre>
- <p id="ch6oop_cd">
- This gives the output:
- </p>
- <pre class="programlisting">
- quux
-five:six:seven
-epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- </div>
- <div class="section" title="7.4.paste">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2630917">
- </a>
- 7.4.paste
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_ce">
- <span class="emphasis">
- <em>
- paste
- </em>
- </span>
- is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command which operates on the vertical plane of two or more files.
- </p>
- <p id="ch6oop_cf">
- To paste several columns of data together into the file
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- from files
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- where
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- when
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ paste who where when > www
- </pre>
- <p id="ch6oop_d0">
- If the files contain:
- </p>
- <table summary="paste" border="1">
- <colgroup>
- <col width="11">
- </col>
- <col width="12">
- </col>
- <col width="12">
- </col>
- </colgroup>
- </table>
- <p id="ch6oop_dd">
- This creates the file named
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- containing:
- </p>
- <pre class="programlisting">
- Batman GothamCity January 3
-Trillian Andromeda February 4
-Jeeves London March 19
- </pre>
- </div>
- </div>
- <div class="section" title="8.Shell Meta Characters">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2631052">
- </a>
- 8.Shell Meta Characters
- </h2>
- </div>
- </div>
- </div>
- <p id="ch6oop_de">
- Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
- </p>
- <p id="ch6oop_df">
- The shell meta characters include:
- </p>
- <p id="ch6oop_e0">
- / < > ! $ % ^ & * | { } [ ] " ' ` ~ ;
- </p>
- <p id="ch6oop_e1">
- Different shells may differ in the meta characters recognized.
- </p>
- <p id="ch6oop_e2">
- As an example,
- </p>
- <pre class="programlisting">
- $ ls file.*
- </pre>
- <p id="ch6oop_e3">
- run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
- </p>
- <pre class="programlisting">
- $ ls file.?
- </pre>
- <p id="ch6oop_e4">
- run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:
- </p>
- <pre class="programlisting">
- $ more c*
- </pre>
- <p id="ch6oop_e5">
- because the c* matches that long file name.
- </p>
- <p id="ch6oop_e6">
- Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named "``*`|more"` can be accomplished with:
- </p>
- <pre class="programlisting">
- $ rm ??more
- </pre>
- <p id="ch6oop_e7">
- or:
- </p>
- <pre class="programlisting">
- $ rm $\backslash$*$\backslash$|more
- </pre>
- <p id="ch6oop_e8">
- or:
- </p>
- <pre class="programlisting">
- $ rm ''*|more''
- </pre>
- </div>
- <div class="section" title="9.Looking At Files">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2631155">
- </a>
- 9.Looking At Files
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="9.1.cat">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2631164">
- </a>
- 9.1.cat
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_e9">
- The
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
- <span class="emphasis">
- <em>
- concatenate
- </em>
- </span>
- .
- </p>
- <p id="ch6oop_ea">
- The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
- </p>
- <p id="ch6oop_eb">
- If the filename is specified as -, then
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input at that point in the sequence. If no files are specified,
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input entered.
- </p>
- <div class="section" title="9.1.1.Jargon File Definition">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2631207">
- </a>
- 9.1.1.Jargon File Definition
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_ec">
- The Jargon File version 4.4.7 lists this as the definition of
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- 1. To spew an entire file to the screen or some other output sink without
- pause (syn. blast).
-
-2. By extension, to dump large amounts of data at an unprepared target or
- with no intention of browsing it carefully. Usage: considered silly.
- Rare outside Unix sites. See also dd, BLT.
-
- Among Unix fans, *cat(1)* is considered an excellent example of
- user-interface design, because it delivers the file contents without
- such verbosity as spacing or headers between the files, and because
- it does not require the files to consist of lines of text, but works
- with any sort of data.
-
- Among Unix critics, *cat(1)* is considered the canonical example of
- bad user-interface design, because of its woefully unobvious name.
- It is far more often used to blast a single file to standard output
- than to concatenate two or more files. The name cat for the former
- operation is just as unintuitive as, say, LISP's cdr.
-
- Of such oppositions are holy wars made...
- </pre>
- </div>
- <div class="section" title="9.1.2.Useless Use of 'cat'">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2631246">
- </a>
- 9.1.2.Useless Use of 'cat'
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_ed">
- UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
- <span class="emphasis">
- <em>
- comp.unix.shell
- </em>
- </span>
- , The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
- </p>
- <p id="ch6oop_ee">
- Nevertheless one sees people doing:
- </p>
- <pre class="programlisting">
- $ cat file | some_command and its args ...
- </pre>
- <p id="ch6oop_ef">
- instead of the equivalent and cheaper:
- </p>
- <pre class="programlisting">
- <file some_command and its args ...
- </pre>
- <p id="ch6oop_f0">
- or (equivalently and more classically):
- </p>
- <pre class="programlisting">
- some_command and its args ... <file
- </pre>
- <p id="ch6oop_f1">
- Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
- </p>
- <p id="ch6oop_f2">
- Amongst many, it is still considered safer to use
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
- </p>
- </div>
- <div class="section" title="9.1.3.zcat">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2631316">
- </a>
- 9.1.3.zcat
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_f3">
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- is a Unix program similar to
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- , that decompresses individual files and concatenates them to standard output. Traditionally
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- operated on files compressed by compress but today it is usually able to operate on
- <span class="emphasis">
- <em>
- gzip
- </em>
- </span>
- or even
- <span class="emphasis">
- <em>
- bzip2
- </em>
- </span>
- archives. On such systems, it is equivalent to
- <span class="emphasis">
- <em>
- gunzip -c
- </em>
- </span>
- </p>
- </div>
- </div>
- <div class="section" title="9.2.more">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2631352">
- </a>
- 9.2.more
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_f4">
- In computing,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
- </p>
- <div class="section" title="9.2.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2631372">
- </a>
- 9.2.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_f5">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ more [options] [file_name]
- </pre>
- <p id="ch6oop_f6">
- If no file name is provided,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- looks for input from stdin.
- </p>
- <p id="ch6oop_f7">
- Once
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has paged through. (This percentage includes the text displayed on the current screen.) When
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- , which advances the output by one line, and
- <span class="emphasis">
- <em>
- Space
- </em>
- </span>
- , which advances the output by one screen.
- </p>
- <p id="ch6oop_f8">
- There are also other commands that can be used while navigating through the document; consult
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- 's
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page for more details.
- </p>
- <p id="ch6oop_f9">
- <span class="emphasis">
- <em>
- Options
- </em>
- </span>
- are typically entered before the file name, but can also be entered in the environment variable
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- . Options entered in the actual command line will override those entered in the
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- environment variable. Available options may vary between Unix systems.
- </p>
- </div>
- </div>
- <div class="section" title="9.3.less">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2631466">
- </a>
- 9.3.less
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_fa">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- does not need to read the entire file before starting, resulting in faster load times with large files.
- </p>
- <div class="section" title="9.3.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2631495">
- </a>
- 9.3.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_fb">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- vi
- </em>
- </span>
- . It is also possible to search for character patterns in the file.
- </p>
- <p id="ch6oop_fc">
- By default,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
- </p>
- <p id="ch6oop_fd">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ less [options] file_name
- </pre>
- </div>
- <div class="section" title="9.3.2.Frequently Used Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2631549">
- </a>
- 9.3.2.Frequently Used Options
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_fe">
- -g: Highlights just the current match of any searched string.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_ff">
- -I: Case-insensitive searches.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_100">
- -M: Shows more detailed prompt, including file position.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_101">
- -N: Shows line numbers (useful for source code viewing).
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_102">
- -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_103">
- -?: Shows help.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.3.Frequently Used Commands">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2631599">
- </a>
- 9.3.3.Frequently Used Commands
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_104">
- [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_105">
- [Space bar]: Next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_106">
- b: Previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_107">
- ng: Jump to line number n. Default is the start of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_108">
- nG: Jump to line number n. Default is the end of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_109">
- /pattern: Search for pattern. Regular expressions can be used.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_10a">
- '^ or g: Go to start of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_10b">
- '$ or G: Go to end of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_10c">
- s: Save current content (got from another program like grep) in a file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_10d">
- =: File information.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_10e">
- h: Help.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_10f">
- q: Quit.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.4.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2631686">
- </a>
- 9.3.4.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ less -M readme.txt #Read "readme.txt."
-$ less +F /var/log/mail.log #Follow mode for log
-$ file * | less #Easier file analysis.
-$ grep -i void *.c | less -I -p void #Case insensitive search for "void" in all .c files
- </pre>
- </div>
- </div>
- </div>
- <div class="section" title="10.Directory Structure">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2631702">
- </a>
- 10.Directory Structure
- </h2>
- </div>
- </div>
- </div>
- <p id="ch6oop_110">
- In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
- </p>
- <p id="ch6oop_111">
- The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
- </p>
- <table summary="Directory Structure" border="1">
- <colgroup>
- <col width="15">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <div class="section" title="10.1.man hier">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2631966">
- </a>
- 10.1.man hier
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_136">
- This is the manual page on the UNIX filesystem. The syntax for this is:
- </p>
- <pre class="programlisting">
- $ man hier
- </pre>
- </div>
- <div class="section" title="10.2.ls -l">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2631982">
- </a>
- 10.2.ls -l
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_137">
- Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
- </p>
- <pre class="programlisting">
- $ ls -l
- </pre>
- <p id="ch6oop_138">
- This can be done after entering the required directory.
- </p>
- </div>
- </div>
- <div class="section" title="11.Permissions and Ownership">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2632004">
- </a>
- 11.Permissions and Ownership
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="11.1.chmod">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2632013">
- </a>
- 11.1.chmod
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_139">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.
- </p>
- <div class="section" title="11.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2632039">
- </a>
- 11.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_13a">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command options are specified like this:
- </p>
- <pre class="programlisting">
- $ chmod [options] mode[,mode] file1 [file2 ...]
- </pre>
- <p id="ch6oop_13b">
- To view what the permissions currently are, type:
- </p>
- <pre class="programlisting">
- $ ls -l file
- </pre>
- </div>
- <div class="section" title="11.1.2.Command line options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2632066">
- </a>
- 11.1.2.Command line options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_13c">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command has a number of command line options that affect its behavior. The most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_13d">
- -R: Changes the modes of directories and files recursively
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch6oop_13e">
- -v: Verbose mode; lists all files as they are being processed
- </p>
- </li>
- </ul>
- </div>
- <div class="section" title="11.1.2.1.Symbolic modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2632102">
- </a>
- 11.1.2.1.Symbolic modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch6oop_13f">
- To the
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
- </p>
- <pre class="programlisting">
- $ chmod [references][operator][modes] file1 ...
- </pre>
- <p id="ch6oop_140">
- The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="8">
- </col>
- <col width="45">
- </col>
- </colgroup>
- </table>
- <p id="ch6oop_150">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="54">
- </col>
- </colgroup>
- </table>
- <p id="ch6oop_157">
- The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="5">
- </col>
- <col width="14">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <p id="ch6oop_16d">
- The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
- </p>
- </div>
- <div class="section" title="11.1.2.2.Symbolic examples">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2632664">
- </a>
- 11.1.2.2.Symbolic examples
- </h5>
- </div>
- </div>
- </div>
- <p id="ch6oop_16e">
- Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
- </p>
- <pre class="programlisting">
- $ chmod ug+rw mydir
-$ ls -ld mydir
-drw-rw---- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- <p id="ch6oop_16f">
- For a file, remove
- <span class="emphasis">
- <em>
- write
- </em>
- </span>
- permissions for all classes:
- </p>
- <pre class="programlisting">
- $ chmod a-w myfile
-$ ls -l myfile
--r-xr-xr-x 2 starwars yoda 96 Dec 8 12:53 myfile
- </pre>
- <p id="ch6oop_170">
- Set the permissions for the
- <span class="emphasis">
- <em>
- u*ser and the *g*roup to read and execute only (no write permission) on *mydir
- </em>
- </span>
- .
- </p>
- <pre class="programlisting">
- $ chmod ug=rx mydir
-$ ls -ld mydir
-dr-xr-x--- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- </div>
- <div class="section" title="11.1.2.3.Octal numbers">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2632707">
- </a>
- 11.1.2.3.Octal numbers
- </h5>
- </div>
- </div>
- </div>
- <p id="ch6oop_171">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
- </p>
- <pre class="programlisting">
- $ chmod 664 myfile
-$ ls -l myfile
--rw-rw-r-- 1 57 Jul 3 10:13 myfile
- </pre>
- <p id="ch6oop_172">
- Since the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- sticky
- </em>
- </span>
- bits are not set, this is equivalent to:
- </p>
- <pre class="programlisting">
- $ chmod 0664 myfile
- </pre>
- </div>
- <div class="section" title="11.1.2.4.Special modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2632746">
- </a>
- 11.1.2.4.Special modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch6oop_173">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
- <span class="strong">
- <strong>
- s
- </strong>
- </span>
- to represent the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- modes, and
- <span class="strong">
- <strong>
- t
- </strong>
- </span>
- to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
- </p>
- <p id="ch6oop_174">
- Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
- </p>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="12.Redirection and Piping">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2632792">
- </a>
- 12.Redirection and Piping
- </h2>
- </div>
- </div>
- </div>
- <p id="ch6oop_175">
- In computing,
- <span class="emphasis">
- <em>
- redirection
- </em>
- </span>
- is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
- </p>
- <p id="ch6oop_176">
- Programs do redirection with the
- <span class="emphasis">
- <em>
- dup2(2)
- </em>
- </span>
- system call, or its less-flexible but higher-level stdio analogues,
- <span class="emphasis">
- <em>
- freopen(3)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- popen(3)
- </em>
- </span>
- .
- </p>
- <div class="section" title="12.1.Redirecting standard input and standard output">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2632828">
- </a>
- 12.1.Redirecting standard input and standard output
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_177">
- Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
- </p>
- <pre class="programlisting">
- $ command1 > file1
- </pre>
- <p id="ch6oop_178">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , placing the output in file1. Note that this will truncate any existing data in
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- . To append output to the end of the file, use the >> operator.:
- </p>
- <pre class="programlisting">
- $ command1 < file1
- </pre>
- <p id="ch6oop_179">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- as the source of input (as opposed to the keyboard).:
- </p>
- <pre class="programlisting">
- $ command1 < infile > outfile
- </pre>
- <p id="ch6oop_17a">
- combines the two capabilities:
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- reads from
- <span class="emphasis">
- <em>
- infile
- </em>
- </span>
- and writes to
- <span class="emphasis">
- <em>
- outfile
- </em>
- </span>
- </p>
- </div>
- <div class="section" title="12.2.Piping">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2632896">
- </a>
- 12.2.Piping
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_17b">
- Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
-A pipeline of three programs run on a text terminal:
- </p>
- <pre class="programlisting">
- $ command1 | command2
- </pre>
- <p id="ch6oop_17c">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using its output as the input for
- <span class="emphasis">
- <em>
- command2
- </em>
- </span>
- (commonly called piping, since the "|" character is known as a "pipe").
- </p>
- <p id="ch6oop_17d">
- This is equivalent to using two redirects and a temporary file:
- </p>
- <pre class="programlisting">
- $ command1 > tempfile
-$ command2 < tempfile
-$ rm tempfile
- </pre>
- <p id="ch6oop_17e">
- A good example for command piping is combining
- <span class="emphasis">
- <em>
- echo
- </em>
- </span>
- with another command to achieve something interactive in a non-interactive shell, e.g.:
- </p>
- <pre class="programlisting">
- $ echo -e "user\npass" | ftp localhost
- </pre>
- <p id="ch6oop_17f">
- This runs the ftp client with input user, press return, then pass.
- </p>
- </div>
- <div class="section" title="12.3.Redirecting to and from the standard file handles">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2632956">
- </a>
- 12.3.Redirecting to and from the standard file handles
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_180">
- In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
- </p>
- <table summary="Redirecting to and from the standard file handles" border="1">
- <colgroup>
- <col width="12">
- </col>
- <col width="13">
- </col>
- <col width="24">
- </col>
- </colgroup>
- </table>
- <p id="ch6oop_18d">
- For example:
- </p>
- <pre class="programlisting">
- $ command1 2> file1
- </pre>
- <p id="ch6oop_18e">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , directing the standard error stream to
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- .
- </p>
- <p id="ch6oop_18f">
- In shells derived from
- <span class="emphasis">
- <em>
- csh
- </em>
- </span>
- (the C shell), the syntax instead appends the & character to the redirect characters, thus achieving a similar result.
- </p>
- <p id="ch6oop_190">
- Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
- </p>
- <pre class="programlisting">
- $ find / -name .profile > results 2>&1
- </pre>
- <p id="ch6oop_191">
- will try to find all files named
- <span class="emphasis">
- <em>
- .profile
- </em>
- </span>
- . Executed without redirection, it will output hits to
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- and errors (e.g. for lack of privilege to traverse protected directories) to
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- . If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- (handle 2) into
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- (handle 1) using 2>&1 .
- </p>
- <p id="ch6oop_192">
- It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
- </p>
- <p id="ch6oop_193">
- If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus:
- </p>
- <pre class="programlisting">
- $ find / -name .profile 2>&1 | less
- </pre>
- <p id="ch6oop_194">
- A simplified form of the command:
- </p>
- <pre class="programlisting">
- $ command > file 2>&1
- </pre>
- <p id="ch6oop_195">
- is:
- </p>
- <pre class="programlisting">
- $ command &>file
- </pre>
- <p id="ch6oop_196">
- or:
- </p>
- <pre class="programlisting">
- $command >&file
- </pre>
- </div>
- <div class="section" title="12.4.Chained pipelines">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2633156">
- </a>
- 12.4.Chained pipelines
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_197">
- The redirection and piping tokens can be chained together to create complex commands. For example:
- </p>
- <pre class="programlisting">
- $ ls | grep '\.sh' | sort > shlist
- </pre>
- <p id="ch6oop_198">
- lists the contents of the current directory, where this output is filtered to only contain lines which contain
- <span class="emphasis">
- <em>
- .sh
- </em>
- </span>
- , sort this resultant output lexicographically, and place the final output in
- <span class="emphasis">
- <em>
- shlist
- </em>
- </span>
- . This type of construction is used very commonly in shell scripts and batch files.
- </p>
- </div>
- <div class="section" title="12.5.Redirect to multiple outputs">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2633188">
- </a>
- 12.5.Redirect to multiple outputs
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_199">
- The standard command
- <span class="emphasis">
- <em>
- tee
- </em>
- </span>
- can redirect output from a command to several destinations.
- </p>
- <pre class="programlisting">
- $ ls -lrt | tee xyz
- </pre>
- <p id="ch6oop_19a">
- This directs the file list output to both standard output as well as to the file
- <span class="emphasis">
- <em>
- xyz
- </em>
- </span>
- .
- </p>
- </div>
- </div>
- <div class="section" title="13.More Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2633218">
- </a>
- 13.More Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="13.1.grep">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2633227">
- </a>
- 13.1.grep
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_19b">
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- is a command line text search utility originally written for Unix. The name is taken from the first letters in
- <span class="emphasis">
- <em>
- global / regular expression / print
- </em>
- </span>
- , a series of instructions for the
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- text editor. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
- </p>
- <div class="section" title="13.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2633257">
- </a>
- 13.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch6oop_19c">
- This is an example of a common
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- usage:
- </p>
- <pre class="programlisting">
- $ grep apple fruitlist.txt
- </pre>
- <p id="ch6oop_19d">
- In this case,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- prints all lines containing 'apple' from the file
- <span class="emphasis">
- <em>
- fruitlist.txt
- </em>
- </span>
- , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
- </p>
- <p id="ch6oop_19e">
- Like most Unix commands,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- accepts command line arguments to change this and many other behaviors. For example:
- </p>
- <pre class="programlisting">
- $ grep -i apple fruitlist.txt
- </pre>
- <p id="ch6oop_19f">
- This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be case insensitive, or to ignore case.
- </p>
- <p id="ch6oop_1a0">
- To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
- </p>
- <pre class="programlisting">
- $ grep -w apple fruitlist.txt
- </pre>
- <p id="ch6oop_1a1">
- Regular expressions can be used to match more complicated queries.
- </p>
- <div class="section" title="13.1.1.1.Variations">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2633334">
- </a>
- 13.1.1.1.Variations
- </h5>
- </div>
- </div>
- </div>
- <p id="ch6oop_1a2">
- There are countless implementations and derivatives of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- available for many operating systems. Early variants of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- included
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- . The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- may also behave differently depending on the name by which it is invoked, allowing
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be links to the same program.
- </p>
- <p id="ch6oop_1a3">
- <span class="emphasis">
- <em>
- pcregrep
- </em>
- </span>
- is an implementation of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- that uses Perl regular expression syntax.
- </p>
- <p id="ch6oop_1a4">
- Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
- <span class="emphasis">
- <em>
- pgrep
- </em>
- </span>
- utility, for instance, displays the processes whose names match a given regular expression.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="13.2.tr">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2633413">
- </a>
- 13.2.tr
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_1a5">
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- (abbreviated from
- <span class="emphasis">
- <em>
- translate
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- transliterate
- </em>
- </span>
- ) is a command in Unix-like operating systems.
- </p>
- <p id="ch6oop_1a6">
- When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
- </p>
- <pre class="programlisting">
- $ tr 'abcd' 'jkmn'
- </pre>
- <p id="ch6oop_1a7">
- maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
- </p>
- <p id="ch6oop_1a8">
- Sets of characters may be abbreviated by using character ranges. The previous example could be written:
- </p>
- <pre class="programlisting">
- $ tr 'a-d' 'jkmn'
- </pre>
- <p id="ch6oop_1a9">
- In POSIX compliant versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
- </p>
- <p id="ch6oop_1aa">
- The
- <span class="emphasis">
- <em>
- -c
- </em>
- </span>
- flag complements the first set of characters.
- </p>
- <pre class="programlisting">
- $ tr -cd '[:alnum:]'
- </pre>
- <p id="ch6oop_1ab">
- therefore removes all non-alphanumeric characters.
- </p>
- <p id="ch6oop_1ac">
- The
- <span class="emphasis">
- <em>
- -s
- </em>
- </span>
- flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
- </p>
- <pre class="programlisting">
- $ tr -s '\n' '\n'
- </pre>
- <p id="ch6oop_1ad">
- replaces sequences of one or more newline characters with a single newline.
- </p>
- <p id="ch6oop_1ae">
- The
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
- </p>
- <pre class="programlisting">
- $ tr -d '\r'
- </pre>
- <p id="ch6oop_1af">
- Most versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , including GNU
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- and classic Unix
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
- </p>
- <p id="ch6oop_1b0">
- Ruby and Perl also have an internal
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- operator, which operates analogously. Tcl's
- <span class="emphasis">
- <em>
- string map
- </em>
- </span>
- command is more general in that it maps strings to strings while
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- maps characters to characters.
- </p>
- </div>
- </div>
- <div class="section" title="14.Elementary Regex">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2633558">
- </a>
- 14.Elementary Regex
- </h2>
- </div>
- </div>
- </div>
- <p id="ch6oop_1b1">
- In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
- </p>
- <p id="ch6oop_1b2">
- Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributionsincluding the editor
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- and the filter
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- were the first to popularize the concept of regular expressions.
- </p>
- <p id="ch6oop_1b3">
- Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
- <span class="emphasis">
- <em>
- Basic Regular Expressions
- </em>
- </span>
- (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
- </p>
- <p id="ch6oop_1b4">
- In the BRE syntax, most characters are treated as literals they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
- </p>
- <table summary="Elementary Regex" border="1">
- <colgroup>
- <col width="13">
- </col>
- <col width="60">
- </col>
- </colgroup>
- </table>
- <div class="section" title="14.1.Lazy quantification">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2633765">
- </a>
- 14.1.Lazy quantification
- </h3>
- </div>
- </div>
- </div>
- <p id="ch6oop_1c9">
- The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example:
- </p>
- <pre class="programlisting">
- Another whale explosion occurred on <January 26>, <2004>.
- </pre>
- <p id="ch6oop_1ca">
- ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the * quantifier is greedy it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
- </p>
- <p id="ch6oop_1cb">
- Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as
- <span class="emphasis">
- <em>
- lazy
- </em>
- </span>
- (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
- </p>
- </div>
- </div>
- <div class="section" title="15.One Liners">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2633840">
- </a>
- 15.One Liners
- </h2>
- </div>
- </div>
- </div>
- <p id="ch6oop_1cc">
- A
- <span class="emphasis">
- <em>
- one-liner
- </em>
- </span>
- is textual input to the command-line of an operating system shell that performs some function in just one line of input.
- </p>
- <p id="ch6oop_1cd">
- The one liner can be
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch6oop_1ce">
- An expression written in the language of the shell.
- </p>
- </li>
- <li class="listitem">
- <p id="ch6oop_1cf">
- The invocation of an interpreter together with program source for the interpreter to run.
- </p>
- </li>
- <li class="listitem">
- <p id="ch6oop_1d0">
- The invocation of a compiler together with source to compile and
-instructions for executing the compiled program.
- </p>
- </li>
- </ol>
- </div>
- <p id="ch6oop_1d1">
- Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
- </p>
- <p id="ch6oop_1d2">
- The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
- </p>
- <p id="ch6oop_1d3">
- The word
- <span class="emphasis">
- <em>
- One-liner
- </em>
- </span>
- has two references in the index of the book
- <span class="emphasis">
- <em>
- The AWK Programming Language
- </em>
- </span>
- (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
- </p>
- <pre class="programlisting">
- The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.
- </pre>
- <p id="ch6oop_1d4">
- Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
- </p>
- <p id="ch6oop_1d5">
- The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
- </p>
- <p id="ch6oop_1d6">
- Here are the first few of them:
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch6oop_1d7">
- Print the total number of input lines:
- </p>
- <p id="ch6oop_1d8">
- END { print NR }
- </p>
- </li>
- <li class="listitem">
- <p id="ch6oop_1d9">
- Print the tenth input line:
- </p>
- <p id="ch6oop_1da">
- NR == 10
- </p>
- </li>
- <li class="listitem">
- <p id="ch6oop_1db">
- Print the last field of every input line:
- </p>
- <p id="ch6oop_1dc">
- { print $NF }
- </p>
- </li>
- </ol>
- </div>
- <p id="ch6oop_1dd">
- One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
- </p>
- <p id="ch6oop_1de">
- The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:
- </p>
- <pre class="programlisting">
- main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
-*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
- </pre>
- <p id="ch6oop_1df">
- This one-liner program is a
- <span class="emphasis">
- <em>
- glob pattern matcher
- </em>
- </span>
- . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
- </p>
- <p id="ch6oop_1e0">
- Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:
- </p>
- <pre class="programlisting">
- $ prog foo 'f??'; echo $?
-
-$ prog 'best short program' '??st*o**p?*'; echo $?
- </pre>
- <p id="ch6oop_1e1">
- Here is a one line shell script to show directories:
- </p>
- <pre class="programlisting">
- $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
- </pre>
- </div>
+ def getName(self):
+ return self.name
+ </pre>
+ <p id="ch6oop_3">
+ In the above example, we defined a class with the name Employee. We also defined
+two methods, setName and getName for this class. It is important to note the
+differences between the normal Python functions and class methods defined above.
+Each method of the class must take the same instance of the class(object) from
+which it was called as the first argument. It is conventionally given the name,
+ <span class="emphasis">
+ <em>
+ self
+ </em>
+ </span>
+ . Note that
+ <span class="emphasis">
+ <em>
+ self
+ </em>
+ </span>
+ is only a convention. You can use any other name, but
+the first argument to the method will always be the same object of the class
+from which the method was called. The data memebers that belong to the class are
+called as
+ <span class="emphasis">
+ <em>
+ class attributes
+ </em>
+ </span>
+ .
+ <span class="emphasis">
+ <em>
+ Class attributes
+ </em>
+ </span>
+ are preceded by the object of
+the class and a dot. In the above example,
+ <span class="emphasis">
+ <em>
+ name
+ </em>
+ </span>
+ is a class attribute since it
+is preceded by the
+ <span class="emphasis">
+ <em>
+ self
+ </em>
+ </span>
+ object.
+ <span class="emphasis">
+ <em>
+ Class attributes
+ </em>
+ </span>
+ can be accessed from
+anywhere within the class.
+ </p>
+ <p id="ch6oop_4">
+ We can create objects of a class outside the class definition by using the same
+syntax we use to call a function with no parameters. We can assign this object
+to a variable:
+ </p>
+ <pre class="programlisting">
+ emp = Employee()
+ </pre>
+ <p id="ch6oop_5">
+ In the above example, we create an object named
+ <span class="emphasis">
+ <em>
+ emp
+ </em>
+ </span>
+ of the class
+ <span class="emphasis">
+ <em>
+ Employee
+ </em>
+ </span>
+ .
+All the attributes and methods of the class can be accessed by the object of the
+class using the standard notation
+ <span class="emphasis">
+ <em>
+ object.attribute
+ </em>
+ </span>
+ or
+ <span class="emphasis">
+ <em>
+ object.method()
+ </em>
+ </span>
+ .
+Although the first parameter of a class method is the self object, it must not
+be passed as an argument when calling the method. The
+ <span class="emphasis">
+ <em>
+ self
+ </em>
+ </span>
+ object is implicitly
+passed to the method by the Python interpreter. All other arguments passing rules
+like default arguments, keyword arguments, argument packing and unpacking follow
+the same rules as those for ordinary Python functions:
+ </p>
+ <pre class="programlisting">
+ >>> emp.setName('John')
+>>> name = emp.getName()
+>>> print name
+John
+>>> print emp.name
+John
+ </pre>
+ <p id="ch6oop_6">
+ If we at all try to access a class attribute before assigning a value to it, i.e
+before creating it, Python raises the same error as it would raise for the
+accessing undefined variable:
+ </p>
+ <pre class="programlisting">
+ >>> emp = Employee()
+>>> emp.name
+Traceback (most recent call last):
+ File "class.py", line 10, in <module>
+ print e.name
+AttributeError: Employee instance has no attribute 'name'
+ </pre>
</div>
</div>
</body>
--- a/SEESenv/web/html/ch7interim_assessment.html Mon Feb 22 18:46:07 2010 +0530
+++ b/SEESenv/web/html/ch7interim_assessment.html Mon Feb 22 22:38:51 2010 +0530
@@ -27,5228 +27,26 @@
<dl>
<dt>
<span class="article">
- <a href="#id2600384">
+ <a href="#id2747157">
+ Interim Assessment
</a>
</span>
</dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2410508">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2600188">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2651434">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2651845">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2651986">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2651994">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2652274">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2652282">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2652445">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2652506">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2652607">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2652690">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2652858">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2652866">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2652961">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2653155">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2653242">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2653295">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2653303">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2653616">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2653754">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2653922">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654015">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2654024">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654111">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654239">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654326">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2654460">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654565">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2654574">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654762">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654872">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2655114">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2655388">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2655404">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2655428">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2655436">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2656213">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2656248">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2656318">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2656380">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2656587">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2656622">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2656652">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2656661">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2656851">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2657002">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2657216">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2657292">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </dd>
</dl>
</div>
- <div class="article">
+ <div class="article" title="Interim Assessment">
<div class="titlepage">
<div>
<div>
- <h2 class="title" id="id2600384">
+ <h2 class="title">
+ <a name="id2747157">
+ </a>
+ Interim Assessment
</h2>
</div>
</div>
<hr />
</div>
- <div class="toc">
- <p>
- <b>
- Table of Contents
- </b>
- </p>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2410508">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2600188">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2651434">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2651845">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2651986">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2651994">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2652274">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2652282">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2652445">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2652506">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2652607">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2652690">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2652858">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2652866">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2652961">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2653155">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2653242">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2653295">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2653303">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2653616">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2653754">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2653922">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654015">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2654024">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654111">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654239">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654326">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2654460">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654565">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2654574">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654762">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2654872">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2655114">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2655388">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2655404">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2655428">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2655436">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2656213">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2656248">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2656318">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2656380">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2656587">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2656622">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2656652">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2656661">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2656851">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2657002">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2657216">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2657292">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </div>
- <div class="section" title="1.Introducing Linux">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2410508">
- </a>
- 1.Introducing Linux
- </h2>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_1">
- (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
- </p>
- <p id="ch7interim_assessment_2">
- Linux (usually pronounced lnks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
- </p>
- <p id="ch7interim_assessment_3">
- Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
- </p>
- <p id="ch7interim_assessment_4">
- The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
- </p>
- <div class="section" title="1.1.Historical Background">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2600188">
- </a>
- 1.1.Historical Background
- </h3>
- </div>
- </div>
- </div>
- <div class="section" title="1.1.1.Events leading to the creation">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2598169">
- </a>
- 1.1.1.Events leading to the creation
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_5">
- The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_6">
- In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="1.1.2.The Creation of Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2651400">
- </a>
- 1.1.2.The Creation of Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_7">
- In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
- </p>
- <p id="ch7interim_assessment_8">
- Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
- </p>
- </div>
- </div>
- <div class="section" title="1.2.Design and Implications">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2651434">
- </a>
- 1.2.Design and Implications
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_9">
- A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
- </p>
- <div class="section" title="1.2.1.User Interface">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2651459">
- </a>
- 1.2.1.User Interface
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_a">
- Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
- </p>
- <p id="ch7interim_assessment_b">
- A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
- </p>
- </div>
- <div class="section" title="1.2.2.Development">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2651513">
- </a>
- 1.2.2.Development
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_c">
- The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
- </p>
- <p id="ch7interim_assessment_d">
- Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
- </p>
- <p id="ch7interim_assessment_e">
- A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
- </p>
- </div>
- <div class="section" title="1.2.3.Community">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2651214">
- </a>
- 1.2.3.Community
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_f">
- A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
- </p>
- <p id="ch7interim_assessment_10">
- In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
- </p>
- <p id="ch7interim_assessment_11">
- Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
- </p>
- </div>
- <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2651259">
- </a>
- 1.2.4.Can I make a profit out of running a business involving Linux?
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_12">
- The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
- </p>
- </div>
- <div class="section" title="1.2.5.Programming on Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2651305">
- </a>
- 1.2.5.Programming on Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_13">
- Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
- </p>
- <p id="ch7interim_assessment_14">
- Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
- </p>
- <p id="ch7interim_assessment_15">
- The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
- </p>
- </div>
- </div>
- <div class="section" title="1.3.Reasons for Using Linux">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2651845">
- </a>
- 1.3.Reasons for Using Linux
- </h3>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_16">
- Linux is free:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_17">
- As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
-Most of all, Linux is free as in "free speech":
-The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_18">
- Linux is portable to any hardware platform:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_19">
- A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_1a">
- Linux was made to keep on running:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_1b">
- As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_1c">
- Linux is secure and versatile:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_1d">
- The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_1e">
- Linux is scalable:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_1f">
- From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_20">
- The Linux OS and Linux applications have very short debugtimes:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_21">
- Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
- </p>
- </div>
- </div>
- <div class="section" title="2.Getting Started">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2651986">
- </a>
- 2.Getting Started
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="2.1.Logging in, activating the user interface and logging out">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2651994">
- </a>
- 2.1.Logging in, activating the user interface and logging out
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_22">
- In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PCbased Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multiuser features, or in graphical console mode, which looks better but eats more system resources.
- </p>
- <div class="section" title="2.1.1.Graphical Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2652025">
- </a>
- 2.1.1.Graphical Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_23">
- This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
- </p>
- <p id="ch7interim_assessment_24">
- To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
- <span class="emphasis">
- <em>
- OK
- </em>
- </span>
- or press
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- .
-It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
- </p>
- <p id="ch7interim_assessment_25">
- After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
- </p>
- <p id="ch7interim_assessment_26">
- To continue, you will need to open a
- <span class="emphasis">
- <em>
- terminal window
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
- <span class="emphasis">
- <em>
- Applications>Utilities->System Tools
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- Internet menu
- </em>
- </span>
- , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
- </p>
- <p id="ch7interim_assessment_27">
- While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old pointnclick method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
- </p>
- <p id="ch7interim_assessment_28">
- A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
- </p>
- <p id="ch7interim_assessment_29">
- Another common form for a prompt is this one:
-[
- </p>
- <div class="reference">
- <div class="titlepage">
- <hr />
- </div>
- user@host
- </div>
- <p>
- dir]
- </p>
- <p id="ch7interim_assessment_2a">
- In the above example,
- <span class="emphasis">
- <em>
- user
- </em>
- </span>
- will be your login name,
- <span class="emphasis">
- <em>
- hosts
- </em>
- </span>
- the name of the machine you are working on, and
- <span class="emphasis">
- <em>
- dir
- </em>
- </span>
- an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- icon or find
- <span class="emphasis">
- <em>
- Log Out
- </em>
- </span>
- in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
- </p>
- <p id="ch7interim_assessment_2b">
- When you see the login screen again, asking to enter user name and password, logout was successful.
- </p>
- </div>
- <div class="section" title="2.1.2.Text Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2652184">
- </a>
- 2.1.2.Text Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_2c">
- One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
- </p>
- <p id="ch7interim_assessment_2d">
- The login is different from a graphical login, in that you have to hit the
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- . You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
-reasons.
- </p>
- <p id="ch7interim_assessment_2e">
- When the system has accepted you as a valid user, you may get some more information, called the
- <span class="emphasis">
- <em>
- message of the day
- </em>
- </span>
- , which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
- </p>
- <p id="ch7interim_assessment_2f">
- Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a nonprivileged user.
- </p>
- <p id="ch7interim_assessment_30">
- Logging out is done by entering the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't poweroff the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="3.Basic Commands">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2652274">
- </a>
- 3.Basic Commands
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="3.1.ls">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2652282">
- </a>
- 3.1.ls
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_31">
- When invoked without any arguments,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- is derived from
- <span class="emphasis">
- <em>
- list segments
- </em>
- </span>
- which was used in earlier systems.
- </p>
- <p id="ch7interim_assessment_32">
- Files whose names start with "." are not listed, unless the
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- flag is specified or the files are specified explicitly.
- </p>
- <p id="ch7interim_assessment_33">
- Without options,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_34">
- <span class="emphasis">
- <em>
- -l
- </em>
- </span>
- long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_35">
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_36">
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_37">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- recursively lists subdirectories. The command ls -R / would therefore list all files.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_38">
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_39">
- <span class="emphasis">
- <em>
- -t
- </em>
- </span>
- sort the list of files by modification time.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_3a">
- <span class="emphasis">
- <em>
- -h
- </em>
- </span>
- print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_3b">
- In some environments, providing the option
- <span class="emphasis">
- <em>
- --color
- </em>
- </span>
- (for GNU ls) or
- <span class="emphasis">
- <em>
- -G
- </em>
- </span>
- (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- would. To determine what color to use for a file, GNU
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks the Unix file type, the file permissions, and the file extension, while FreeBSD
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks only the Unix file type and file permissions.:
- </p>
- <pre class="programlisting">
- $ ls
-jeeves.rst psmith.html blandings.html
-$ ls -l
-drwxr--r-- 1 plum editors 4096 jeeves
--rw-r--r-- 1 plum editors 30405 psmith
--r-xr-xr-x 1 plum plum 8460 blandings
- </pre>
- <p id="ch7interim_assessment_3c">
- Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
- </p>
- </div>
- <div class="section" title="3.2.date">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2652445">
- </a>
- 3.2.date
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_3d">
- The Unix date command displays the time and date. The super-user can use it to set the system clock.
- </p>
- <p id="ch7interim_assessment_3e">
- With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:
- </p>
- <pre class="programlisting">
- $date
-Tue Sep 8 12:01:45 IST 2009
- </pre>
- <p id="ch7interim_assessment_3f">
- On some systems to set the current date and time to September 8, 2004 01:22 you type:
- </p>
- <pre class="programlisting">
- $date --set="20040908 01:22"
- </pre>
- <p id="ch7interim_assessment_40">
- In order to view the various options for the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command, type:
- </p>
- <pre class="programlisting">
- $man date
- </pre>
- <p id="ch7interim_assessment_41">
- This will take you to the "Manual" page comprising of all the details on the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command. You can return to the terminal from the "man" page by pressing the
- <span class="emphasis">
- <em>
- Esc
- </em>
- </span>
- key in the keyboard and typing ":q" in that order.
- </p>
- </div>
- <div class="section" title="3.3.cd">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2652506">
- </a>
- 3.3.cd
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_42">
- This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, cd .. can be used.
- </p>
- <p id="ch7interim_assessment_43">
- One dot '.' represents the current directory while two dots '..' represent the parent directory.
- </p>
- <p id="ch7interim_assessment_44">
- cd - will return you to the previous directory (a bit like an undo).
- </p>
- <p id="ch7interim_assessment_45">
- You can also use cd absolute path or cd relative path (see below):
- </p>
- <p id="ch7interim_assessment_46">
- Absolute paths:
- </p>
- <p id="ch7interim_assessment_47">
- An absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
- </p>
- <p id="ch7interim_assessment_48">
- For example to get to /boot/grub you would type:
- </p>
- <pre class="programlisting">
- $cd /boot/grub
- </pre>
- <p id="ch7interim_assessment_49">
- This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
- </p>
- <p id="ch7interim_assessment_4a">
- Relative paths:
- </p>
- <p id="ch7interim_assessment_4b">
- A relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
- </p>
- <p id="ch7interim_assessment_4c">
- For example if you are in root's home directory and want to get to /root/music, you type:
- </p>
- <pre class="programlisting">
- $ cd music
- </pre>
- <p id="ch7interim_assessment_4d">
- Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
- </p>
- </div>
- <div class="section" title="3.4.who">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2652607">
- </a>
- 3.4.who
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_4e">
- The standard Unix command
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- displays a list of users who are currently logged into a computer.
- </p>
- <p id="ch7interim_assessment_4f">
- The
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command is related to the command
- <span class="emphasis">
- <em>
- w
- </em>
- </span>
- , which provides the same information but also displays additional data and statistics.:
- </p>
- <pre class="programlisting">
- $who
-beeblebrox tty7 2009-09-08 10:50 (:0)
-beeblebrox pts/0 2009-09-08 11:25 (:0.0)
-dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in)
-beeblebrox pts/2 2009-09-08 18:53 (:0.0)
- </pre>
- <p id="ch7interim_assessment_50">
- The command can be invoked with the arguments
- <span class="emphasis">
- <em>
- am i
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- am I
- </em>
- </span>
- (so it is invoked as
- <span class="emphasis">
- <em>
- who am i
- </em>
- </span>
- or * who am I*), showing information about the current terminal only (see the
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- option below, of which this invocation is equivalent).
- </p>
- <p id="ch7interim_assessment_51">
- In order to find out the various options that can be appended to the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command, check the
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page by typing out the following in the terminal:
- </p>
- <pre class="programlisting">
- $man who
- </pre>
- <p id="ch7interim_assessment_52">
- This will take you to the "Manual" page containing details about the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command
- </p>
- </div>
- <div class="section" title="3.5.mkdir">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2652690">
- </a>
- 3.5.mkdir
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_53">
- This command is used to make a new directory. Normal usage is as straightforward as follows:
- </p>
- <pre class="programlisting">
- $mkdir name_of_directory
- </pre>
- <p id="ch7interim_assessment_54">
- Where
- <span class="emphasis">
- <em>
- name_of_directory
- </em>
- </span>
- is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- will try to create all of them.
- </p>
- <div class="section" title="3.5.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2652722">
- </a>
- 3.5.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_55">
- On Unix-like operating systems,
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- takes options. Three of the most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_56">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- : will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_57">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- : display each directory that mkdir creates. Most often used with -p.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_58">
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- : specify the octal permissions of directories created by mkdir.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_59">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
- </p>
- </div>
- <div class="section" title="3.5.2.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2652781">
- </a>
- 3.5.2.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_5a">
- An example of
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- in action is:
- </p>
- <pre class="programlisting">
- $mkdir -p /tmp/a/b/c
- </pre>
- <p id="ch7interim_assessment_5b">
- If
- <span class="emphasis">
- <em>
- /tmp/a
- </em>
- </span>
- exists but
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- does not, mkdir will create
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- before creating
- <span class="emphasis">
- <em>
- /tmp/a/b/c
- </em>
- </span>
- .
- </p>
- <p id="ch7interim_assessment_5c">
- And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
- </p>
- <pre class="programlisting">
- $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
- </pre>
- <p id="ch7interim_assessment_5d">
- This will create:
- </p>
- tmpdir - branches
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_5e">
- tag
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- trunk - sources - includes
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_5f">
- docs
- </p>
- </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="4.Getting Help">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2652858">
- </a>
- 4.Getting Help
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="4.1.apropos and whatis">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2652866">
- </a>
- 4.1.apropos and whatis
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_60">
- This is a command to search the manual pages files in Unix and Unix-like operating systems.
- </p>
- <pre class="programlisting">
- $ apropos grep
-egrep egrep (1) Search a file for a pattern using full regular expressions
-fgrep fgrep (1) Search a file for a fixed-character string
-fmlgrep fmlgrep (1) Search a file for a pattern
-grep grep (1) Search a file for a pattern
-gzgrep gzgrep (1) Search a possibly compressed file for a regular expression
-nisgrep nismatch (1) Utilities for searching NIS+ tables
-pgrep pgrep (1) Find or signal a process by name or other attribute
-zgrep zgrep (1) Search a possibly compressed file for a regular expression
-...
- </pre>
- <p id="ch7interim_assessment_61">
- In this example, the user uses
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- to search for the string "grep", and apropos returns the indicated
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- pages that include the term "grep".
- </p>
- <p id="ch7interim_assessment_62">
- A short index of explanations for commands is available using the
- <span class="emphasis">
- <em>
- whatis
- </em>
- </span>
- command, like in the examples below:
- </p>
- <pre class="programlisting">
- $whatis ls
-ls (1) - list directory contents
- </pre>
- <p id="ch7interim_assessment_63">
- This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
- </p>
- <p id="ch7interim_assessment_64">
- If you don't know where to get started and which man page to read,
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- gives more information. Say that you do not know how to start a browser, then you could enter the following command:
- </p>
- <pre class="programlisting">
- $apropos browser
-gmusicbrowser (1) - Jukebox for large collections of audio files
-infobrowser (1) - read Info documents
-libsmbclient (7) - An extension library for browsers and that can be used...
-opera (1) - a standards-compliant graphical Web browser
-sensible-browser (1) - sensible editing, paging, and web browsing
-smbtree (1) - A text based smb network browser
-tvtk_doc (1) - A GUI based TVTK documentation search browser.
-viewres (1) - graphical class browser for Xt
-w3m (1) - a text based Web browser and pager
-www-browser (1) - a text based Web browser and pager
-...
- </pre>
- </div>
- <div class="section" title="4.2.man">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2652961">
- </a>
- 4.2.man
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_65">
- Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- . Each page is a self-contained document.
- </p>
- <p id="ch7interim_assessment_66">
- To read a manual page for a Unix command, one can use:
- </p>
- <pre class="programlisting">
- $ man <command_name>
- </pre>
- <p id="ch7interim_assessment_67">
- at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- generally uses the less terminal pager.
- </p>
- <p id="ch7interim_assessment_68">
- Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are
- <span class="emphasis">
- <em>
- man(1)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- man(7)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- exit(2)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- exit(3)
- </em>
- </span>
- . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
- <span class="emphasis">
- <em>
- BSD, for example, the syntax for reading *printf(3)
- </em>
- </span>
- is:
- </p>
- <pre class="programlisting">
- $man 3 printf
- </pre>
- <p id="ch7interim_assessment_69">
- Another example:
- </p>
- <pre class="programlisting">
- $man man
- </pre>
- <p id="ch7interim_assessment_6a">
- The previous example will take you to the "Manual" page entry about manual pages!
- </p>
- <div class="section" title="4.2.1.Layout">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2653044">
- </a>
- 4.2.1.Layout
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_6b">
- All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
- </p>
- NAME
- <p id="ch7interim_assessment_6c">
- The name of the command or function, followed by a one-line description of what it does.
- </p>
- SYNOPSIS
- <p id="ch7interim_assessment_6d">
- In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
- </p>
- DESCRIPTION
- <p id="ch7interim_assessment_6e">
- A textual description of the functioning of the command or function.
- </p>
- EXAMPLES
- <p id="ch7interim_assessment_6f">
- Some examples of common usage.
- </p>
- SEE ALSO
- <p id="ch7interim_assessment_70">
- A list of related commands or functions.
- </p>
- <p id="ch7interim_assessment_71">
- Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
- </p>
- <p id="ch7interim_assessment_72">
- These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
- </p>
- <p id="ch7interim_assessment_73">
- However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
- </p>
- <p id="ch7interim_assessment_74">
- Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
- </p>
- <p id="ch7interim_assessment_75">
- Usually the man pages are written in English. Translations into other languages can be also available on the system.
- </p>
- <p id="ch7interim_assessment_76">
- The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
- </p>
- </div>
- </div>
- <div class="section" title="4.3.info">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2653155">
- </a>
- 4.3.info
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_77">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
- </p>
- <p id="ch7interim_assessment_78">
- The syntax is
- </p>
- <pre class="programlisting">
- $ info <command_name>
- </pre>
- <p id="ch7interim_assessment_79">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_7a">
- <span class="emphasis">
- <em>
- n
- </em>
- </span>
- goes to the next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_7b">
- <span class="emphasis">
- <em>
- p
- </em>
- </span>
- goes to the previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_7c">
- <span class="emphasis">
- <em>
- u
- </em>
- </span>
- goes to the upper page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_7d">
- <span class="emphasis">
- <em>
- l
- </em>
- </span>
- goes to the last(visited) node
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_7e">
- To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_7f">
- info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
- </p>
- </div>
- <div class="section" title="4.4.--help">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2653242">
- </a>
- 4.4.--help
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_80">
- Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command:
- </p>
- <pre class="programlisting">
- $ userprompt@host: cat --help
-Usage: cat [OPTION] [FILE]...
-Concatenate FILE(s), or standard input, to standard output.
-
- -A, --show-all equivalent to -vET
- -b, --number-nonblank number nonempty output lines
- -e equivalent to -vE
- -E, --show-ends display $ at end of each line
- -n, --number number all output lines
- -s, --squeeze-blank suppress repeated empty output lines
- -t equivalent to -vT
- -T, --show-tabs display TAB characters as ^I
- -u (ignored)
- -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
- --help display this help and exit
- --version output version information and exit
-
-With no FILE, or when FILE is -, read standard input.
-
-Examples:
- cat f - g Output f's contents, then standard input, then g's contents.
- cat Copy standard input to standard output.
-
-Report bugs to <bug-coreutils@gnu.org>.
- </pre>
- </div>
- </div>
- <div class="section" title="5.Basic file handling">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2653295">
- </a>
- 5.Basic file handling
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="5.1.cp">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2653303">
- </a>
- 5.1.cp
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_81">
- <span class="emphasis">
- <em>
- cp
- </em>
- </span>
- is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
- </p>
- <div class="section" title="5.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2653321">
- </a>
- 5.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_82">
- To copy a file to another file:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
- </pre>
- <p id="ch7interim_assessment_83">
- To copy a file to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
- </pre>
- <p id="ch7interim_assessment_84">
- To copy a directory to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
-SourceDirectory ... TargetDirectory
- </pre>
- </div>
- <div class="section" title="5.1.2.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2653355">
- </a>
- 5.1.2.Flags
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_85">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (force) specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
- </p>
- <p id="ch7interim_assessment_86">
- <span class="emphasis">
- <em>
- -P
- </em>
- </span>
- makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
- </p>
- <p id="ch7interim_assessment_87">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- (interactive) prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
- </p>
- <p id="ch7interim_assessment_88">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- (preserve) duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_89">
- The time of the last data modification and the time of the last access.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_8a">
- The user ID and group ID (only if it has permissions to do this)
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_8b">
- The file permission bits and the SUID and SGID bits.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_8c">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- (recursive) copy directories (recursively copying all the contents)
- </p>
- </div>
- <div class="section" title="5.1.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2653453">
- </a>
- 5.1.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_8d">
- To make a copy of a file in the current directory, enter:
- </p>
- <pre class="programlisting">
- $ cp prog.c prog.bak
- </pre>
- <p id="ch7interim_assessment_8e">
- This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
- </p>
- <p id="ch7interim_assessment_8f">
- To copy a file in your current directory into another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod /home/books/hhgg
- </pre>
- <p id="ch7interim_assessment_90">
- This copies the jones file to /home/books/hhgg/zaphod.
- </p>
- <p id="ch7interim_assessment_91">
- To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
- </p>
- <pre class="programlisting">
- $ cp -p martin_luther_king martin_luther_king.jr
- </pre>
- <p id="ch7interim_assessment_92">
- This copies the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file to the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file. Instead of creating the file with the current date and time stamp, the system gives the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file the same date and time as the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file. The
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file also inherits the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file's access control protection.
- </p>
- <p id="ch7interim_assessment_93">
- To copy all the files in a directory to a new directory, enter:
- </p>
- <pre class="programlisting">
- $ cp /home/galactica/clients/* /home/hhgg/customers
- </pre>
- <p id="ch7interim_assessment_94">
- This copies only the files in the clients directory to the customers directory.
- </p>
- <p id="ch7interim_assessment_95">
- To copy a directory, including all its files and subdirectories, to another directory, enter:
- </p>
- <p id="ch7interim_assessment_96">
- $ cp -R /home/hhgg/clients /home/hhgg/customers
- </p>
- <p id="ch7interim_assessment_97">
- This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
- </p>
- <p id="ch7interim_assessment_98">
- To copy a specific set of files of any extension to another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod arthur ford /home/hhgg/clients
- </pre>
- <p id="ch7interim_assessment_99">
- This copies the
- <span class="emphasis">
- <em>
- zaphod
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- arthur
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- ford
- </em>
- </span>
- files in your current working directory to the /home/hhgg/clients directory.
- </p>
- <p id="ch7interim_assessment_9a">
- To use pattern-matching characters to copy files, enter:
- </p>
- <pre class="programlisting">
- $ cp programs/*.py .
- </pre>
- <p id="ch7interim_assessment_9b">
- This copies the files in the programs directory that end with
- <span class="emphasis">
- <em>
- .py
- </em>
- </span>
- to the current directory, signified by the single "." (dot). You must type a space between the
- <span class="emphasis">
- <em>
- py
- </em>
- </span>
- and the final dot.
- </p>
- </div>
- </div>
- <div class="section" title="5.2.mv">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2653616">
- </a>
- 5.2.mv
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_9c">
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system),
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- will rename the file instead. Write permission is required on all directories being modified.
- </p>
- <div class="section" title="5.2.1.Conflicting existing file">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2653640">
- </a>
- 5.2.1.Conflicting existing file
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_9d">
- In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
- </p>
- </div>
- <div class="section" title="5.2.2.Differences with copy and delete">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2653665">
- </a>
- 5.2.2.Differences with copy and delete
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_9e">
- Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
- </p>
- </div>
- <div class="section" title="5.2.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2653695">
- </a>
- 5.2.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ mv myfile mynewfilename renames a file
-$ mv myfile otherfilename renames a file and deletes the existing file "myfile"
-$ mv myfile /myfile moves 'myfile' from the current directory to the root directory
-$ mv myfile dir/myfile moves 'myfile' to 'dir/myfile' relative to the current directory
-$ mv myfile dir same as the previous command (the filename is implied to be the same)
-$ mv myfile dir/myfile2 moves 'myfile' to dir and renames it to 'myfile2'
-$ mv foo bar baz dir moves multiple files to directory dir
-$ mv --help shows a very concise help about the syntax of the command
-$ man mv prints an extensive user manual for 'mv' in the terminal
- </pre>
- <p id="ch7interim_assessment_9f">
- In all cases, the file or files being moved or renamed can be a directory.
- </p>
- <p id="ch7interim_assessment_a0">
- Note that when the command is called with two arguments (as
- <span class="emphasis">
- <em>
- mv name1 name2
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- mv name1 /dir/name2
- </em>
- </span>
- ), it can have three different effects, depending on whether
- <span class="emphasis">
- <em>
- name2
- </em>
- </span>
- does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
- <span class="emphasis">
- <em>
- /.
- </em>
- </span>
- (or in some Unix versions
- <span class="emphasis">
- <em>
- /
- </em>
- </span>
- is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
- </p>
- </div>
- </div>
- <div class="section" title="5.3.rm">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2653754">
- </a>
- 5.3.rm
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_a1">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
- </p>
- <p id="ch7interim_assessment_a2">
- Here's example to remove a file named "foo" from a directory, here shown with the -i option:
- </p>
- <pre class="programlisting">
- $ rm -i foo
-remove foo? y
- </pre>
- <div class="section" title="5.3.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2653784">
- </a>
- 5.3.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_a3">
- Common options that rm accepts include:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_a4">
- <span class="emphasis">
- <em>
- -r
- </em>
- </span>
- , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_a5">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- , which asks for every deletion to be confirmed ("interactive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_a6">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- , which ignores non-existent files and overrides any confirmation prompts ("force")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_a7">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- , which shows what is being removed as it happens ("verbose")
- </p>
- </li>
- </ul>
- </div>
- <p id="ch7interim_assessment_a8">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
- </p>
- <p id="ch7interim_assessment_a9">
- <span class="emphasis">
- <em>
- rm -rf
- </em>
- </span>
- (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
- </p>
- <p id="ch7interim_assessment_aa">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often used in conjunction with xargs to supply a list of files to delete:
- </p>
- <pre class="programlisting">
- xargs rm < filelist
- </pre>
- <p id="ch7interim_assessment_ab">
- When
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is used on a symbolic link, it deletes the link, but does not affect the target of the link.
- </p>
- </div>
- <div class="section" title="5.3.2.Permissions">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2653882">
- </a>
- 5.3.2.Permissions
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_ac">
- Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
- </p>
- <p id="ch7interim_assessment_ad">
- To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
- </p>
- <p id="ch7interim_assessment_ae">
- If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="6.Command Line Arguments">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2653922">
- </a>
- 6.Command Line Arguments
- </h2>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_af">
- In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
- </p>
- <p id="ch7interim_assessment_b0">
- For example, in Unix and Unix-like environments, an example of a command-line argument is:
- </p>
- <pre class="programlisting">
- rm file.s
- </pre>
- <p id="ch7interim_assessment_b1">
- "file.s" is a command line argument which tells the program rm to remove the file "file.s".
- </p>
- <p id="ch7interim_assessment_b2">
- Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
- </p>
- <p id="ch7interim_assessment_b3">
- A command line option or simply
- <span class="emphasis">
- <em>
- option
- </em>
- </span>
- (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
- </p>
- <p id="ch7interim_assessment_b4">
- Long options are introduced via "--", and are typically whole words. For example,
- <span class="emphasis">
- <em>
- ls --long --classify --all
- </em>
- </span>
- . Arguments to long options are provided with "=", as
- <span class="emphasis">
- <em>
- ls --block-size=1024
- </em>
- </span>
- . Some Unix programs use long options with single dashes, for example MPlayer as in
- <span class="emphasis">
- <em>
- mplayer -nosound
- </em>
- </span>
- .
- </p>
- <p id="ch7interim_assessment_b5">
- Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- by using
- <span class="emphasis">
- <em>
- rm -file1
- </em>
- </span>
- may produce an error, since rm may interpret
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- as a command line switch. Using
- <span class="emphasis">
- <em>
- rm -- -file1
- </em>
- </span>
- removes ambiguity.
- </p>
- </div>
- <div class="section" title="7.Basic Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2654015">
- </a>
- 7.Basic Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="7.1.head">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2654024">
- </a>
- 7.1.head
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_b6">
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:
- </p>
- <pre class="programlisting">
- $ head [options] <file_name>
- </pre>
- <p id="ch7interim_assessment_b7">
- By default,
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ head -n 20 filename
- </pre>
- <p id="ch7interim_assessment_b8">
- This displays the first 5 lines of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ head -n 5 foo*
- </pre>
- <p id="ch7interim_assessment_b9">
- Some versions omit the n and just let you say -5.
- </p>
- <div class="section" title="7.1.1.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2654075">
- </a>
- 7.1.1.Flags
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- -c <x number of bytes> Copy first x number of bytes.
- </pre>
- <p id="ch7interim_assessment_ba">
- Other options:
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- </p>
- <p id="ch7interim_assessment_bb">
- Many early versions of Unix did not have this command, and so documentation and books had
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- do this job:
- </p>
- <pre class="programlisting">
- sed 5q foo
- </pre>
- <p id="ch7interim_assessment_bc">
- This says to print every line (implicit), and quit after the fifth.
- </p>
- </div>
- </div>
- <div class="section" title="7.2.tail">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2654111">
- </a>
- 7.2.tail
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_bd">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
- </p>
- <p id="ch7interim_assessment_be">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ tail [options] <file_name>
- </pre>
- <p id="ch7interim_assessment_bf">
- By default,
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ tail -n 20 filename
- </pre>
- <p id="ch7interim_assessment_c0">
- This example shows the last 15 bytes of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ tail -c 15 foo*
- </pre>
- <p id="ch7interim_assessment_c1">
- This example shows all lines of filename from the second line onwards:
- </p>
- <pre class="programlisting">
- $ tail -n +2 filename
- </pre>
- <p id="ch7interim_assessment_c2">
- Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:
- </p>
- <pre class="programlisting">
- $ tail -20 filename
-$ tail -50c filename
- </pre>
- <p id="ch7interim_assessment_c3">
- However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
- </p>
- <div class="section" title="7.2.1.File monitoring">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2654190">
- </a>
- 7.2.1.File monitoring
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_c4">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- has a special command line option
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:
- </p>
- <pre class="programlisting">
- $ tail -f /var/adm/messages
- </pre>
- <p id="ch7interim_assessment_c5">
- To interrupt tail while it is monitoring, break-in with
- <span class="emphasis">
- <em>
- Ctrl+C
- </em>
- </span>
- . This command can be run "in the background" with &, see job control.
- </p>
- <p id="ch7interim_assessment_c6">
- If you have a command's result to monitor, you can use the
- <span class="emphasis">
- <em>
- watch
- </em>
- </span>
- command.
- </p>
- </div>
- </div>
- <div class="section" title="7.3.cut">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2654239">
- </a>
- 7.3.cut
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_c7">
- In computing,
- <span class="emphasis">
- <em>
- cut
- </em>
- </span>
- is a Unix command line utility which is used to extract sections from each line of input usually from a file.
- </p>
- <p id="ch7interim_assessment_c8">
- Extraction of line segments can typically be done by
- <span class="emphasis">
- <em>
- bytes (-b), characters (-c)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- fields (-f)
- </em>
- </span>
- separated by a
- <span class="emphasis">
- <em>
- delimiter (-d the tab character by default)
- </em>
- </span>
- . A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
- </p>
- <p id="ch7interim_assessment_c9">
- Assuming a file named file containing the lines:
- </p>
- <pre class="programlisting">
- foo:bar:baz:qux:quux
-one:two:three:four:five:six:seven
-alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- <p id="ch7interim_assessment_ca">
- To output the fourth through tenth characters of each line:
- </p>
- <pre class="programlisting">
- $ cut -c 4-10 file
- </pre>
- <p id="ch7interim_assessment_cb">
- This gives the output:
- </p>
- <pre class="programlisting">
- :bar:ba
-:two:th
-ha:beta
- </pre>
- <p id="ch7interim_assessment_cc">
- To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
- </p>
- <pre class="programlisting">
- $ cut -d : -f 5- file
- </pre>
- <p id="ch7interim_assessment_cd">
- This gives the output:
- </p>
- <pre class="programlisting">
- quux
-five:six:seven
-epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- </div>
- <div class="section" title="7.4.paste">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2654326">
- </a>
- 7.4.paste
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_ce">
- <span class="emphasis">
- <em>
- paste
- </em>
- </span>
- is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command which operates on the vertical plane of two or more files.
- </p>
- <p id="ch7interim_assessment_cf">
- To paste several columns of data together into the file
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- from files
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- where
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- when
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ paste who where when > www
- </pre>
- <p id="ch7interim_assessment_d0">
- If the files contain:
- </p>
- <table summary="paste" border="1">
- <colgroup>
- <col width="11">
- </col>
- <col width="12">
- </col>
- <col width="12">
- </col>
- </colgroup>
- </table>
- <p id="ch7interim_assessment_dd">
- This creates the file named
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- containing:
- </p>
- <pre class="programlisting">
- Batman GothamCity January 3
-Trillian Andromeda February 4
-Jeeves London March 19
- </pre>
- </div>
- </div>
- <div class="section" title="8.Shell Meta Characters">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2654460">
- </a>
- 8.Shell Meta Characters
- </h2>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_de">
- Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
- </p>
- <p id="ch7interim_assessment_df">
- The shell meta characters include:
- </p>
- <p id="ch7interim_assessment_e0">
- / < > ! $ % ^ & * | { } [ ] " ' ` ~ ;
- </p>
- <p id="ch7interim_assessment_e1">
- Different shells may differ in the meta characters recognized.
- </p>
- <p id="ch7interim_assessment_e2">
- As an example,
- </p>
- <pre class="programlisting">
- $ ls file.*
- </pre>
- <p id="ch7interim_assessment_e3">
- run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
- </p>
- <pre class="programlisting">
- $ ls file.?
- </pre>
- <p id="ch7interim_assessment_e4">
- run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:
- </p>
- <pre class="programlisting">
- $ more c*
- </pre>
- <p id="ch7interim_assessment_e5">
- because the c* matches that long file name.
- </p>
- <p id="ch7interim_assessment_e6">
- Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named "``*`|more"` can be accomplished with:
- </p>
- <pre class="programlisting">
- $ rm ??more
- </pre>
- <p id="ch7interim_assessment_e7">
- or:
- </p>
- <pre class="programlisting">
- $ rm $\backslash$*$\backslash$|more
- </pre>
- <p id="ch7interim_assessment_e8">
- or:
- </p>
- <pre class="programlisting">
- $ rm ''*|more''
- </pre>
- </div>
- <div class="section" title="9.Looking At Files">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2654565">
- </a>
- 9.Looking At Files
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="9.1.cat">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2654574">
- </a>
- 9.1.cat
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_e9">
- The
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
- <span class="emphasis">
- <em>
- concatenate
- </em>
- </span>
- .
- </p>
- <p id="ch7interim_assessment_ea">
- The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
- </p>
- <p id="ch7interim_assessment_eb">
- If the filename is specified as -, then
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input at that point in the sequence. If no files are specified,
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input entered.
- </p>
- <div class="section" title="9.1.1.Jargon File Definition">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2654617">
- </a>
- 9.1.1.Jargon File Definition
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_ec">
- The Jargon File version 4.4.7 lists this as the definition of
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- 1. To spew an entire file to the screen or some other output sink without
- pause (syn. blast).
-
-2. By extension, to dump large amounts of data at an unprepared target or
- with no intention of browsing it carefully. Usage: considered silly.
- Rare outside Unix sites. See also dd, BLT.
-
- Among Unix fans, *cat(1)* is considered an excellent example of
- user-interface design, because it delivers the file contents without
- such verbosity as spacing or headers between the files, and because
- it does not require the files to consist of lines of text, but works
- with any sort of data.
-
- Among Unix critics, *cat(1)* is considered the canonical example of
- bad user-interface design, because of its woefully unobvious name.
- It is far more often used to blast a single file to standard output
- than to concatenate two or more files. The name cat for the former
- operation is just as unintuitive as, say, LISP's cdr.
-
- Of such oppositions are holy wars made...
- </pre>
- </div>
- <div class="section" title="9.1.2.Useless Use of 'cat'">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2654657">
- </a>
- 9.1.2.Useless Use of 'cat'
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_ed">
- UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
- <span class="emphasis">
- <em>
- comp.unix.shell
- </em>
- </span>
- , The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
- </p>
- <p id="ch7interim_assessment_ee">
- Nevertheless one sees people doing:
- </p>
- <pre class="programlisting">
- $ cat file | some_command and its args ...
- </pre>
- <p id="ch7interim_assessment_ef">
- instead of the equivalent and cheaper:
- </p>
- <pre class="programlisting">
- <file some_command and its args ...
- </pre>
- <p id="ch7interim_assessment_f0">
- or (equivalently and more classically):
- </p>
- <pre class="programlisting">
- some_command and its args ... <file
- </pre>
- <p id="ch7interim_assessment_f1">
- Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
- </p>
- <p id="ch7interim_assessment_f2">
- Amongst many, it is still considered safer to use
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
- </p>
- </div>
- <div class="section" title="9.1.3.zcat">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2654728">
- </a>
- 9.1.3.zcat
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_f3">
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- is a Unix program similar to
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- , that decompresses individual files and concatenates them to standard output. Traditionally
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- operated on files compressed by compress but today it is usually able to operate on
- <span class="emphasis">
- <em>
- gzip
- </em>
- </span>
- or even
- <span class="emphasis">
- <em>
- bzip2
- </em>
- </span>
- archives. On such systems, it is equivalent to
- <span class="emphasis">
- <em>
- gunzip -c
- </em>
- </span>
- </p>
- </div>
- </div>
- <div class="section" title="9.2.more">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2654762">
- </a>
- 9.2.more
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_f4">
- In computing,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
- </p>
- <div class="section" title="9.2.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2654781">
- </a>
- 9.2.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_f5">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ more [options] [file_name]
- </pre>
- <p id="ch7interim_assessment_f6">
- If no file name is provided,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- looks for input from stdin.
- </p>
- <p id="ch7interim_assessment_f7">
- Once
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has paged through. (This percentage includes the text displayed on the current screen.) When
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- , which advances the output by one line, and
- <span class="emphasis">
- <em>
- Space
- </em>
- </span>
- , which advances the output by one screen.
- </p>
- <p id="ch7interim_assessment_f8">
- There are also other commands that can be used while navigating through the document; consult
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- 's
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page for more details.
- </p>
- <p id="ch7interim_assessment_f9">
- <span class="emphasis">
- <em>
- Options
- </em>
- </span>
- are typically entered before the file name, but can also be entered in the environment variable
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- . Options entered in the actual command line will override those entered in the
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- environment variable. Available options may vary between Unix systems.
- </p>
- </div>
- </div>
- <div class="section" title="9.3.less">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2654872">
- </a>
- 9.3.less
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_fa">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- does not need to read the entire file before starting, resulting in faster load times with large files.
- </p>
- <div class="section" title="9.3.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2654901">
- </a>
- 9.3.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_fb">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- vi
- </em>
- </span>
- . It is also possible to search for character patterns in the file.
- </p>
- <p id="ch7interim_assessment_fc">
- By default,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
- </p>
- <p id="ch7interim_assessment_fd">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ less [options] file_name
- </pre>
- </div>
- <div class="section" title="9.3.2.Frequently Used Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2654956">
- </a>
- 9.3.2.Frequently Used Options
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_fe">
- -g: Highlights just the current match of any searched string.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_ff">
- -I: Case-insensitive searches.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_100">
- -M: Shows more detailed prompt, including file position.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_101">
- -N: Shows line numbers (useful for source code viewing).
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_102">
- -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_103">
- -?: Shows help.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.3.Frequently Used Commands">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2655008">
- </a>
- 9.3.3.Frequently Used Commands
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_104">
- [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_105">
- [Space bar]: Next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_106">
- b: Previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_107">
- ng: Jump to line number n. Default is the start of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_108">
- nG: Jump to line number n. Default is the end of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_109">
- /pattern: Search for pattern. Regular expressions can be used.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_10a">
- '^ or g: Go to start of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_10b">
- '$ or G: Go to end of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_10c">
- s: Save current content (got from another program like grep) in a file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_10d">
- =: File information.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_10e">
- h: Help.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_10f">
- q: Quit.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.4.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2655098">
- </a>
- 9.3.4.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ less -M readme.txt #Read "readme.txt."
-$ less +F /var/log/mail.log #Follow mode for log
-$ file * | less #Easier file analysis.
-$ grep -i void *.c | less -I -p void #Case insensitive search for "void" in all .c files
- </pre>
- </div>
- </div>
- </div>
- <div class="section" title="10.Directory Structure">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2655114">
- </a>
- 10.Directory Structure
- </h2>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_110">
- In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
- </p>
- <p id="ch7interim_assessment_111">
- The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
- </p>
- <table summary="Directory Structure" border="1">
- <colgroup>
- <col width="15">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <div class="section" title="10.1.man hier">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2655388">
- </a>
- 10.1.man hier
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_136">
- This is the manual page on the UNIX filesystem. The syntax for this is:
- </p>
- <pre class="programlisting">
- $ man hier
- </pre>
- </div>
- <div class="section" title="10.2.ls -l">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2655404">
- </a>
- 10.2.ls -l
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_137">
- Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
- </p>
- <pre class="programlisting">
- $ ls -l
- </pre>
- <p id="ch7interim_assessment_138">
- This can be done after entering the required directory.
- </p>
- </div>
- </div>
- <div class="section" title="11.Permissions and Ownership">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2655428">
- </a>
- 11.Permissions and Ownership
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="11.1.chmod">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2655436">
- </a>
- 11.1.chmod
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_139">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.
- </p>
- <div class="section" title="11.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2655462">
- </a>
- 11.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_13a">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command options are specified like this:
- </p>
- <pre class="programlisting">
- $ chmod [options] mode[,mode] file1 [file2 ...]
- </pre>
- <p id="ch7interim_assessment_13b">
- To view what the permissions currently are, type:
- </p>
- <pre class="programlisting">
- $ ls -l file
- </pre>
- </div>
- <div class="section" title="11.1.2.Command line options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2655490">
- </a>
- 11.1.2.Command line options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_13c">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command has a number of command line options that affect its behavior. The most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_13d">
- -R: Changes the modes of directories and files recursively
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch7interim_assessment_13e">
- -v: Verbose mode; lists all files as they are being processed
- </p>
- </li>
- </ul>
- </div>
- <div class="section" title="11.1.2.1.Symbolic modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2655526">
- </a>
- 11.1.2.1.Symbolic modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_13f">
- To the
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
- </p>
- <pre class="programlisting">
- $ chmod [references][operator][modes] file1 ...
- </pre>
- <p id="ch7interim_assessment_140">
- The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="8">
- </col>
- <col width="45">
- </col>
- </colgroup>
- </table>
- <p id="ch7interim_assessment_150">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="54">
- </col>
- </colgroup>
- </table>
- <p id="ch7interim_assessment_157">
- The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="5">
- </col>
- <col width="14">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <p id="ch7interim_assessment_16d">
- The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
- </p>
- </div>
- <div class="section" title="11.1.2.2.Symbolic examples">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2656087">
- </a>
- 11.1.2.2.Symbolic examples
- </h5>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_16e">
- Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
- </p>
- <pre class="programlisting">
- $ chmod ug+rw mydir
-$ ls -ld mydir
-drw-rw---- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- <p id="ch7interim_assessment_16f">
- For a file, remove
- <span class="emphasis">
- <em>
- write
- </em>
- </span>
- permissions for all classes:
- </p>
- <pre class="programlisting">
- $ chmod a-w myfile
-$ ls -l myfile
--r-xr-xr-x 2 starwars yoda 96 Dec 8 12:53 myfile
- </pre>
- <p id="ch7interim_assessment_170">
- Set the permissions for the
- <span class="emphasis">
- <em>
- u*ser and the *g*roup to read and execute only (no write permission) on *mydir
- </em>
- </span>
- .
- </p>
- <pre class="programlisting">
- $ chmod ug=rx mydir
-$ ls -ld mydir
-dr-xr-x--- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- </div>
- <div class="section" title="11.1.2.3.Octal numbers">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2656130">
- </a>
- 11.1.2.3.Octal numbers
- </h5>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_171">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
- </p>
- <pre class="programlisting">
- $ chmod 664 myfile
-$ ls -l myfile
--rw-rw-r-- 1 57 Jul 3 10:13 myfile
- </pre>
- <p id="ch7interim_assessment_172">
- Since the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- sticky
- </em>
- </span>
- bits are not set, this is equivalent to:
- </p>
- <pre class="programlisting">
- $ chmod 0664 myfile
- </pre>
- </div>
- <div class="section" title="11.1.2.4.Special modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2656169">
- </a>
- 11.1.2.4.Special modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_173">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
- <span class="strong">
- <strong>
- s
- </strong>
- </span>
- to represent the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- modes, and
- <span class="strong">
- <strong>
- t
- </strong>
- </span>
- to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
- </p>
- <p id="ch7interim_assessment_174">
- Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
- </p>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="12.Redirection and Piping">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2656213">
- </a>
- 12.Redirection and Piping
- </h2>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_175">
- In computing,
- <span class="emphasis">
- <em>
- redirection
- </em>
- </span>
- is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
- </p>
- <p id="ch7interim_assessment_176">
- Programs do redirection with the
- <span class="emphasis">
- <em>
- dup2(2)
- </em>
- </span>
- system call, or its less-flexible but higher-level stdio analogues,
- <span class="emphasis">
- <em>
- freopen(3)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- popen(3)
- </em>
- </span>
- .
- </p>
- <div class="section" title="12.1.Redirecting standard input and standard output">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2656248">
- </a>
- 12.1.Redirecting standard input and standard output
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_177">
- Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
- </p>
- <pre class="programlisting">
- $ command1 > file1
- </pre>
- <p id="ch7interim_assessment_178">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , placing the output in file1. Note that this will truncate any existing data in
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- . To append output to the end of the file, use the >> operator.:
- </p>
- <pre class="programlisting">
- $ command1 < file1
- </pre>
- <p id="ch7interim_assessment_179">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- as the source of input (as opposed to the keyboard).:
- </p>
- <pre class="programlisting">
- $ command1 < infile > outfile
- </pre>
- <p id="ch7interim_assessment_17a">
- combines the two capabilities:
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- reads from
- <span class="emphasis">
- <em>
- infile
- </em>
- </span>
- and writes to
- <span class="emphasis">
- <em>
- outfile
- </em>
- </span>
- </p>
- </div>
- <div class="section" title="12.2.Piping">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2656318">
- </a>
- 12.2.Piping
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_17b">
- Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
-A pipeline of three programs run on a text terminal:
- </p>
- <pre class="programlisting">
- $ command1 | command2
- </pre>
- <p id="ch7interim_assessment_17c">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using its output as the input for
- <span class="emphasis">
- <em>
- command2
- </em>
- </span>
- (commonly called piping, since the "|" character is known as a "pipe").
- </p>
- <p id="ch7interim_assessment_17d">
- This is equivalent to using two redirects and a temporary file:
- </p>
- <pre class="programlisting">
- $ command1 > tempfile
-$ command2 < tempfile
-$ rm tempfile
- </pre>
- <p id="ch7interim_assessment_17e">
- A good example for command piping is combining
- <span class="emphasis">
- <em>
- echo
- </em>
- </span>
- with another command to achieve something interactive in a non-interactive shell, e.g.:
- </p>
- <pre class="programlisting">
- $ echo -e "user\npass" | ftp localhost
- </pre>
- <p id="ch7interim_assessment_17f">
- This runs the ftp client with input user, press return, then pass.
- </p>
- </div>
- <div class="section" title="12.3.Redirecting to and from the standard file handles">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2656380">
- </a>
- 12.3.Redirecting to and from the standard file handles
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_180">
- In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
- </p>
- <table summary="Redirecting to and from the standard file handles" border="1">
- <colgroup>
- <col width="12">
- </col>
- <col width="13">
- </col>
- <col width="24">
- </col>
- </colgroup>
- </table>
- <p id="ch7interim_assessment_18d">
- For example:
- </p>
- <pre class="programlisting">
- $ command1 2> file1
- </pre>
- <p id="ch7interim_assessment_18e">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , directing the standard error stream to
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- .
- </p>
- <p id="ch7interim_assessment_18f">
- In shells derived from
- <span class="emphasis">
- <em>
- csh
- </em>
- </span>
- (the C shell), the syntax instead appends the & character to the redirect characters, thus achieving a similar result.
- </p>
- <p id="ch7interim_assessment_190">
- Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
- </p>
- <pre class="programlisting">
- $ find / -name .profile > results 2>&1
- </pre>
- <p id="ch7interim_assessment_191">
- will try to find all files named
- <span class="emphasis">
- <em>
- .profile
- </em>
- </span>
- . Executed without redirection, it will output hits to
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- and errors (e.g. for lack of privilege to traverse protected directories) to
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- . If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- (handle 2) into
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- (handle 1) using 2>&1 .
- </p>
- <p id="ch7interim_assessment_192">
- It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
- </p>
- <p id="ch7interim_assessment_193">
- If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus:
- </p>
- <pre class="programlisting">
- $ find / -name .profile 2>&1 | less
- </pre>
- <p id="ch7interim_assessment_194">
- A simplified form of the command:
- </p>
- <pre class="programlisting">
- $ command > file 2>&1
- </pre>
- <p id="ch7interim_assessment_195">
- is:
- </p>
- <pre class="programlisting">
- $ command &>file
- </pre>
- <p id="ch7interim_assessment_196">
- or:
- </p>
- <pre class="programlisting">
- $command >&file
- </pre>
- </div>
- <div class="section" title="12.4.Chained pipelines">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2656587">
- </a>
- 12.4.Chained pipelines
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_197">
- The redirection and piping tokens can be chained together to create complex commands. For example:
- </p>
- <pre class="programlisting">
- $ ls | grep '\.sh' | sort > shlist
- </pre>
- <p id="ch7interim_assessment_198">
- lists the contents of the current directory, where this output is filtered to only contain lines which contain
- <span class="emphasis">
- <em>
- .sh
- </em>
- </span>
- , sort this resultant output lexicographically, and place the final output in
- <span class="emphasis">
- <em>
- shlist
- </em>
- </span>
- . This type of construction is used very commonly in shell scripts and batch files.
- </p>
- </div>
- <div class="section" title="12.5.Redirect to multiple outputs">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2656622">
- </a>
- 12.5.Redirect to multiple outputs
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_199">
- The standard command
- <span class="emphasis">
- <em>
- tee
- </em>
- </span>
- can redirect output from a command to several destinations.
- </p>
- <pre class="programlisting">
- $ ls -lrt | tee xyz
- </pre>
- <p id="ch7interim_assessment_19a">
- This directs the file list output to both standard output as well as to the file
- <span class="emphasis">
- <em>
- xyz
- </em>
- </span>
- .
- </p>
- </div>
- </div>
- <div class="section" title="13.More Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2656652">
- </a>
- 13.More Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="13.1.grep">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2656661">
- </a>
- 13.1.grep
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_19b">
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- is a command line text search utility originally written for Unix. The name is taken from the first letters in
- <span class="emphasis">
- <em>
- global / regular expression / print
- </em>
- </span>
- , a series of instructions for the
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- text editor. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
- </p>
- <div class="section" title="13.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2656692">
- </a>
- 13.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_19c">
- This is an example of a common
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- usage:
- </p>
- <pre class="programlisting">
- $ grep apple fruitlist.txt
- </pre>
- <p id="ch7interim_assessment_19d">
- In this case,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- prints all lines containing 'apple' from the file
- <span class="emphasis">
- <em>
- fruitlist.txt
- </em>
- </span>
- , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
- </p>
- <p id="ch7interim_assessment_19e">
- Like most Unix commands,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- accepts command line arguments to change this and many other behaviors. For example:
- </p>
- <pre class="programlisting">
- $ grep -i apple fruitlist.txt
- </pre>
- <p id="ch7interim_assessment_19f">
- This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be case insensitive, or to ignore case.
- </p>
- <p id="ch7interim_assessment_1a0">
- To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
- </p>
- <pre class="programlisting">
- $ grep -w apple fruitlist.txt
- </pre>
- <p id="ch7interim_assessment_1a1">
- Regular expressions can be used to match more complicated queries.
- </p>
- <div class="section" title="13.1.1.1.Variations">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2656772">
- </a>
- 13.1.1.1.Variations
- </h5>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_1a2">
- There are countless implementations and derivatives of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- available for many operating systems. Early variants of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- included
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- . The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- may also behave differently depending on the name by which it is invoked, allowing
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be links to the same program.
- </p>
- <p id="ch7interim_assessment_1a3">
- <span class="emphasis">
- <em>
- pcregrep
- </em>
- </span>
- is an implementation of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- that uses Perl regular expression syntax.
- </p>
- <p id="ch7interim_assessment_1a4">
- Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
- <span class="emphasis">
- <em>
- pgrep
- </em>
- </span>
- utility, for instance, displays the processes whose names match a given regular expression.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="13.2.tr">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2656851">
- </a>
- 13.2.tr
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_1a5">
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- (abbreviated from
- <span class="emphasis">
- <em>
- translate
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- transliterate
- </em>
- </span>
- ) is a command in Unix-like operating systems.
- </p>
- <p id="ch7interim_assessment_1a6">
- When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
- </p>
- <pre class="programlisting">
- $ tr 'abcd' 'jkmn'
- </pre>
- <p id="ch7interim_assessment_1a7">
- maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
- </p>
- <p id="ch7interim_assessment_1a8">
- Sets of characters may be abbreviated by using character ranges. The previous example could be written:
- </p>
- <pre class="programlisting">
- $ tr 'a-d' 'jkmn'
- </pre>
- <p id="ch7interim_assessment_1a9">
- In POSIX compliant versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
- </p>
- <p id="ch7interim_assessment_1aa">
- The
- <span class="emphasis">
- <em>
- -c
- </em>
- </span>
- flag complements the first set of characters.
- </p>
- <pre class="programlisting">
- $ tr -cd '[:alnum:]'
- </pre>
- <p id="ch7interim_assessment_1ab">
- therefore removes all non-alphanumeric characters.
- </p>
- <p id="ch7interim_assessment_1ac">
- The
- <span class="emphasis">
- <em>
- -s
- </em>
- </span>
- flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
- </p>
- <pre class="programlisting">
- $ tr -s '\n' '\n'
- </pre>
- <p id="ch7interim_assessment_1ad">
- replaces sequences of one or more newline characters with a single newline.
- </p>
- <p id="ch7interim_assessment_1ae">
- The
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
- </p>
- <pre class="programlisting">
- $ tr -d '\r'
- </pre>
- <p id="ch7interim_assessment_1af">
- Most versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , including GNU
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- and classic Unix
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
- </p>
- <p id="ch7interim_assessment_1b0">
- Ruby and Perl also have an internal
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- operator, which operates analogously. Tcl's
- <span class="emphasis">
- <em>
- string map
- </em>
- </span>
- command is more general in that it maps strings to strings while
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- maps characters to characters.
- </p>
- </div>
- </div>
- <div class="section" title="14.Elementary Regex">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2657002">
- </a>
- 14.Elementary Regex
- </h2>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_1b1">
- In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
- </p>
- <p id="ch7interim_assessment_1b2">
- Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributionsincluding the editor
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- and the filter
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- were the first to popularize the concept of regular expressions.
- </p>
- <p id="ch7interim_assessment_1b3">
- Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
- <span class="emphasis">
- <em>
- Basic Regular Expressions
- </em>
- </span>
- (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
- </p>
- <p id="ch7interim_assessment_1b4">
- In the BRE syntax, most characters are treated as literals they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
- </p>
- <table summary="Elementary Regex" border="1">
- <colgroup>
- <col width="13">
- </col>
- <col width="60">
- </col>
- </colgroup>
- </table>
- <div class="section" title="14.1.Lazy quantification">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2657216">
- </a>
- 14.1.Lazy quantification
- </h3>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_1c9">
- The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example:
- </p>
- <pre class="programlisting">
- Another whale explosion occurred on <January 26>, <2004>.
- </pre>
- <p id="ch7interim_assessment_1ca">
- ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the * quantifier is greedy it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
- </p>
- <p id="ch7interim_assessment_1cb">
- Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as
- <span class="emphasis">
- <em>
- lazy
- </em>
- </span>
- (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
- </p>
- </div>
- </div>
- <div class="section" title="15.One Liners">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2657292">
- </a>
- 15.One Liners
- </h2>
- </div>
- </div>
- </div>
- <p id="ch7interim_assessment_1cc">
- A
- <span class="emphasis">
- <em>
- one-liner
- </em>
- </span>
- is textual input to the command-line of an operating system shell that performs some function in just one line of input.
- </p>
- <p id="ch7interim_assessment_1cd">
- The one liner can be
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch7interim_assessment_1ce">
- An expression written in the language of the shell.
- </p>
- </li>
- <li class="listitem">
- <p id="ch7interim_assessment_1cf">
- The invocation of an interpreter together with program source for the interpreter to run.
- </p>
- </li>
- <li class="listitem">
- <p id="ch7interim_assessment_1d0">
- The invocation of a compiler together with source to compile and
-instructions for executing the compiled program.
- </p>
- </li>
- </ol>
- </div>
- <p id="ch7interim_assessment_1d1">
- Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
- </p>
- <p id="ch7interim_assessment_1d2">
- The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
- </p>
- <p id="ch7interim_assessment_1d3">
- The word
- <span class="emphasis">
- <em>
- One-liner
- </em>
- </span>
- has two references in the index of the book
- <span class="emphasis">
- <em>
- The AWK Programming Language
- </em>
- </span>
- (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
- </p>
- <pre class="programlisting">
- The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.
- </pre>
- <p id="ch7interim_assessment_1d4">
- Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
- </p>
- <p id="ch7interim_assessment_1d5">
- The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
- </p>
- <p id="ch7interim_assessment_1d6">
- Here are the first few of them:
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch7interim_assessment_1d7">
- Print the total number of input lines:
- </p>
- <p id="ch7interim_assessment_1d8">
- END { print NR }
- </p>
- </li>
- <li class="listitem">
- <p id="ch7interim_assessment_1d9">
- Print the tenth input line:
- </p>
- <p id="ch7interim_assessment_1da">
- NR == 10
- </p>
- </li>
- <li class="listitem">
- <p id="ch7interim_assessment_1db">
- Print the last field of every input line:
- </p>
- <p id="ch7interim_assessment_1dc">
- { print $NF }
- </p>
- </li>
- </ol>
- </div>
- <p id="ch7interim_assessment_1dd">
- One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
- </p>
- <p id="ch7interim_assessment_1de">
- The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:
- </p>
- <pre class="programlisting">
- main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
-*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
- </pre>
- <p id="ch7interim_assessment_1df">
- This one-liner program is a
- <span class="emphasis">
- <em>
- glob pattern matcher
- </em>
- </span>
- . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
- </p>
- <p id="ch7interim_assessment_1e0">
- Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:
- </p>
- <pre class="programlisting">
- $ prog foo 'f??'; echo $?
-
-$ prog 'best short program' '??st*o**p?*'; echo $?
- </pre>
- <p id="ch7interim_assessment_1e1">
- Here is a one line shell script to show directories:
- </p>
- <pre class="programlisting">
- $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
- </pre>
- </div>
</div>
</div>
</body>
--- a/SEESenv/web/html/ch8ult_module_plan.html Mon Feb 22 18:46:07 2010 +0530
+++ b/SEESenv/web/html/ch8ult_module_plan.html Mon Feb 22 22:38:51 2010 +0530
@@ -15,7 +15,7 @@
</script>
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
- <div class="chapter" id="ult_module_plan">
+ <div class="chapter" id="ch8ult_module_plan">
<div class="titlepage">
</div>
<div class="toc">
@@ -27,5228 +27,22 @@
<dl>
<dt>
<span class="article">
- <a href="#id2916253">
+ <a href="#id2944857">
</a>
</span>
</dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2726378">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2916058">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2967315">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2967589">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2967729">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2967738">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2968018">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2968026">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2968189">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2968249">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2968351">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2968434">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2968601">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2968610">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2967107">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969025">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969112">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2969165">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2969173">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969486">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969618">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2969786">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969880">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2969888">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969975">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2970103">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2970190">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2970324">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2970430">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2970438">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2970626">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2970737">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2970978">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2971252">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2971268">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2971291">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2971300">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2972077">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2972112">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2972182">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2972244">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2972451">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2972486">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2972516">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2972525">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2972715">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2972866">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2973079">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2973154">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </dd>
</dl>
</div>
<div class="article">
<div class="titlepage">
<div>
<div>
- <h2 class="title" id="id2916253">
+ <h2 class="title" id="id2944857">
</h2>
</div>
</div>
<hr />
</div>
- <div class="toc">
- <p>
- <b>
- Table of Contents
- </b>
- </p>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2726378">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2916058">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2967315">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2967589">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2967729">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2967738">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2968018">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2968026">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2968189">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2968249">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2968351">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2968434">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2968601">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2968610">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2967107">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969025">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969112">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2969165">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2969173">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969486">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969618">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2969786">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969880">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2969888">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2969975">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2970103">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2970190">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2970324">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2970430">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2970438">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2970626">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2970737">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2970978">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2971252">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2971268">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2971291">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2971300">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2972077">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2972112">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2972182">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2972244">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2972451">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2972486">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2972516">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2972525">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id2972715">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2972866">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2973079">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id2973154">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </div>
- <div class="section" title="1.Introducing Linux">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2726378">
- </a>
- 1.Introducing Linux
- </h2>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_1">
- (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
- </p>
- <p id="ch8ult_module_plan_2">
- Linux (usually pronounced lnks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
- </p>
- <p id="ch8ult_module_plan_3">
- Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
- </p>
- <p id="ch8ult_module_plan_4">
- The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
- </p>
- <div class="section" title="1.1.Historical Background">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2916058">
- </a>
- 1.1.Historical Background
- </h3>
- </div>
- </div>
- </div>
- <div class="section" title="1.1.1.Events leading to the creation">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2914039">
- </a>
- 1.1.1.Events leading to the creation
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_5">
- The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_6">
- In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="1.1.2.The Creation of Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2967270">
- </a>
- 1.1.2.The Creation of Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_7">
- In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
- </p>
- <p id="ch8ult_module_plan_8">
- Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
- </p>
- </div>
- </div>
- <div class="section" title="1.2.Design and Implications">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2967315">
- </a>
- 1.2.Design and Implications
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_9">
- A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
- </p>
- <div class="section" title="1.2.1.User Interface">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2967340">
- </a>
- 1.2.1.User Interface
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_a">
- Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
- </p>
- <p id="ch8ult_module_plan_b">
- A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
- </p>
- </div>
- <div class="section" title="1.2.2.Development">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2967393">
- </a>
- 1.2.2.Development
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_c">
- The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
- </p>
- <p id="ch8ult_module_plan_d">
- Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
- </p>
- <p id="ch8ult_module_plan_e">
- A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
- </p>
- </div>
- <div class="section" title="1.2.3.Community">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2967450">
- </a>
- 1.2.3.Community
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_f">
- A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
- </p>
- <p id="ch8ult_module_plan_10">
- In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
- </p>
- <p id="ch8ult_module_plan_11">
- Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
- </p>
- </div>
- <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2967495">
- </a>
- 1.2.4.Can I make a profit out of running a business involving Linux?
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_12">
- The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
- </p>
- </div>
- <div class="section" title="1.2.5.Programming on Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2967541">
- </a>
- 1.2.5.Programming on Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_13">
- Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
- </p>
- <p id="ch8ult_module_plan_14">
- Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
- </p>
- <p id="ch8ult_module_plan_15">
- The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
- </p>
- </div>
- </div>
- <div class="section" title="1.3.Reasons for Using Linux">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2967589">
- </a>
- 1.3.Reasons for Using Linux
- </h3>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_16">
- Linux is free:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_17">
- As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
-Most of all, Linux is free as in "free speech":
-The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_18">
- Linux is portable to any hardware platform:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_19">
- A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_1a">
- Linux was made to keep on running:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_1b">
- As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_1c">
- Linux is secure and versatile:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_1d">
- The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_1e">
- Linux is scalable:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_1f">
- From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_20">
- The Linux OS and Linux applications have very short debugtimes:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_21">
- Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
- </p>
- </div>
- </div>
- <div class="section" title="2.Getting Started">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2967729">
- </a>
- 2.Getting Started
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="2.1.Logging in, activating the user interface and logging out">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2967738">
- </a>
- 2.1.Logging in, activating the user interface and logging out
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_22">
- In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PCbased Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multiuser features, or in graphical console mode, which looks better but eats more system resources.
- </p>
- <div class="section" title="2.1.1.Graphical Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2967768">
- </a>
- 2.1.1.Graphical Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_23">
- This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
- </p>
- <p id="ch8ult_module_plan_24">
- To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
- <span class="emphasis">
- <em>
- OK
- </em>
- </span>
- or press
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- .
-It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
- </p>
- <p id="ch8ult_module_plan_25">
- After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
- </p>
- <p id="ch8ult_module_plan_26">
- To continue, you will need to open a
- <span class="emphasis">
- <em>
- terminal window
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
- <span class="emphasis">
- <em>
- Applications>Utilities->System Tools
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- Internet menu
- </em>
- </span>
- , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
- </p>
- <p id="ch8ult_module_plan_27">
- While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old pointnclick method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
- </p>
- <p id="ch8ult_module_plan_28">
- A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
- </p>
- <p id="ch8ult_module_plan_29">
- Another common form for a prompt is this one:
-[
- </p>
- <div class="reference">
- <div class="titlepage">
- <hr />
- </div>
- user@host
- </div>
- <p>
- dir]
- </p>
- <p id="ch8ult_module_plan_2a">
- In the above example,
- <span class="emphasis">
- <em>
- user
- </em>
- </span>
- will be your login name,
- <span class="emphasis">
- <em>
- hosts
- </em>
- </span>
- the name of the machine you are working on, and
- <span class="emphasis">
- <em>
- dir
- </em>
- </span>
- an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- icon or find
- <span class="emphasis">
- <em>
- Log Out
- </em>
- </span>
- in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
- </p>
- <p id="ch8ult_module_plan_2b">
- When you see the login screen again, asking to enter user name and password, logout was successful.
- </p>
- </div>
- <div class="section" title="2.1.2.Text Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2967928">
- </a>
- 2.1.2.Text Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_2c">
- One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
- </p>
- <p id="ch8ult_module_plan_2d">
- The login is different from a graphical login, in that you have to hit the
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- . You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
-reasons.
- </p>
- <p id="ch8ult_module_plan_2e">
- When the system has accepted you as a valid user, you may get some more information, called the
- <span class="emphasis">
- <em>
- message of the day
- </em>
- </span>
- , which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
- </p>
- <p id="ch8ult_module_plan_2f">
- Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a nonprivileged user.
- </p>
- <p id="ch8ult_module_plan_30">
- Logging out is done by entering the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't poweroff the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="3.Basic Commands">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2968018">
- </a>
- 3.Basic Commands
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="3.1.ls">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2968026">
- </a>
- 3.1.ls
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_31">
- When invoked without any arguments,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- is derived from
- <span class="emphasis">
- <em>
- list segments
- </em>
- </span>
- which was used in earlier systems.
- </p>
- <p id="ch8ult_module_plan_32">
- Files whose names start with "." are not listed, unless the
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- flag is specified or the files are specified explicitly.
- </p>
- <p id="ch8ult_module_plan_33">
- Without options,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_34">
- <span class="emphasis">
- <em>
- -l
- </em>
- </span>
- long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_35">
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_36">
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_37">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- recursively lists subdirectories. The command ls -R / would therefore list all files.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_38">
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_39">
- <span class="emphasis">
- <em>
- -t
- </em>
- </span>
- sort the list of files by modification time.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_3a">
- <span class="emphasis">
- <em>
- -h
- </em>
- </span>
- print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_3b">
- In some environments, providing the option
- <span class="emphasis">
- <em>
- --color
- </em>
- </span>
- (for GNU ls) or
- <span class="emphasis">
- <em>
- -G
- </em>
- </span>
- (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- would. To determine what color to use for a file, GNU
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks the Unix file type, the file permissions, and the file extension, while FreeBSD
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks only the Unix file type and file permissions.:
- </p>
- <pre class="programlisting">
- $ ls
-jeeves.rst psmith.html blandings.html
-$ ls -l
-drwxr--r-- 1 plum editors 4096 jeeves
--rw-r--r-- 1 plum editors 30405 psmith
--r-xr-xr-x 1 plum plum 8460 blandings
- </pre>
- <p id="ch8ult_module_plan_3c">
- Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
- </p>
- </div>
- <div class="section" title="3.2.date">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2968189">
- </a>
- 3.2.date
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_3d">
- The Unix date command displays the time and date. The super-user can use it to set the system clock.
- </p>
- <p id="ch8ult_module_plan_3e">
- With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:
- </p>
- <pre class="programlisting">
- $date
-Tue Sep 8 12:01:45 IST 2009
- </pre>
- <p id="ch8ult_module_plan_3f">
- On some systems to set the current date and time to September 8, 2004 01:22 you type:
- </p>
- <pre class="programlisting">
- $date --set="20040908 01:22"
- </pre>
- <p id="ch8ult_module_plan_40">
- In order to view the various options for the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command, type:
- </p>
- <pre class="programlisting">
- $man date
- </pre>
- <p id="ch8ult_module_plan_41">
- This will take you to the "Manual" page comprising of all the details on the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command. You can return to the terminal from the "man" page by pressing the
- <span class="emphasis">
- <em>
- Esc
- </em>
- </span>
- key in the keyboard and typing ":q" in that order.
- </p>
- </div>
- <div class="section" title="3.3.cd">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2968249">
- </a>
- 3.3.cd
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_42">
- This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, cd .. can be used.
- </p>
- <p id="ch8ult_module_plan_43">
- One dot '.' represents the current directory while two dots '..' represent the parent directory.
- </p>
- <p id="ch8ult_module_plan_44">
- cd - will return you to the previous directory (a bit like an undo).
- </p>
- <p id="ch8ult_module_plan_45">
- You can also use cd absolute path or cd relative path (see below):
- </p>
- <p id="ch8ult_module_plan_46">
- Absolute paths:
- </p>
- <p id="ch8ult_module_plan_47">
- An absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
- </p>
- <p id="ch8ult_module_plan_48">
- For example to get to /boot/grub you would type:
- </p>
- <pre class="programlisting">
- $cd /boot/grub
- </pre>
- <p id="ch8ult_module_plan_49">
- This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
- </p>
- <p id="ch8ult_module_plan_4a">
- Relative paths:
- </p>
- <p id="ch8ult_module_plan_4b">
- A relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
- </p>
- <p id="ch8ult_module_plan_4c">
- For example if you are in root's home directory and want to get to /root/music, you type:
- </p>
- <pre class="programlisting">
- $ cd music
- </pre>
- <p id="ch8ult_module_plan_4d">
- Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
- </p>
- </div>
- <div class="section" title="3.4.who">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2968351">
- </a>
- 3.4.who
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_4e">
- The standard Unix command
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- displays a list of users who are currently logged into a computer.
- </p>
- <p id="ch8ult_module_plan_4f">
- The
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command is related to the command
- <span class="emphasis">
- <em>
- w
- </em>
- </span>
- , which provides the same information but also displays additional data and statistics.:
- </p>
- <pre class="programlisting">
- $who
-beeblebrox tty7 2009-09-08 10:50 (:0)
-beeblebrox pts/0 2009-09-08 11:25 (:0.0)
-dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in)
-beeblebrox pts/2 2009-09-08 18:53 (:0.0)
- </pre>
- <p id="ch8ult_module_plan_50">
- The command can be invoked with the arguments
- <span class="emphasis">
- <em>
- am i
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- am I
- </em>
- </span>
- (so it is invoked as
- <span class="emphasis">
- <em>
- who am i
- </em>
- </span>
- or * who am I*), showing information about the current terminal only (see the
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- option below, of which this invocation is equivalent).
- </p>
- <p id="ch8ult_module_plan_51">
- In order to find out the various options that can be appended to the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command, check the
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page by typing out the following in the terminal:
- </p>
- <pre class="programlisting">
- $man who
- </pre>
- <p id="ch8ult_module_plan_52">
- This will take you to the "Manual" page containing details about the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command
- </p>
- </div>
- <div class="section" title="3.5.mkdir">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2968434">
- </a>
- 3.5.mkdir
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_53">
- This command is used to make a new directory. Normal usage is as straightforward as follows:
- </p>
- <pre class="programlisting">
- $mkdir name_of_directory
- </pre>
- <p id="ch8ult_module_plan_54">
- Where
- <span class="emphasis">
- <em>
- name_of_directory
- </em>
- </span>
- is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- will try to create all of them.
- </p>
- <div class="section" title="3.5.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2968466">
- </a>
- 3.5.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_55">
- On Unix-like operating systems,
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- takes options. Three of the most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_56">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- : will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_57">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- : display each directory that mkdir creates. Most often used with -p.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_58">
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- : specify the octal permissions of directories created by mkdir.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_59">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
- </p>
- </div>
- <div class="section" title="3.5.2.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2968525">
- </a>
- 3.5.2.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_5a">
- An example of
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- in action is:
- </p>
- <pre class="programlisting">
- $mkdir -p /tmp/a/b/c
- </pre>
- <p id="ch8ult_module_plan_5b">
- If
- <span class="emphasis">
- <em>
- /tmp/a
- </em>
- </span>
- exists but
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- does not, mkdir will create
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- before creating
- <span class="emphasis">
- <em>
- /tmp/a/b/c
- </em>
- </span>
- .
- </p>
- <p id="ch8ult_module_plan_5c">
- And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
- </p>
- <pre class="programlisting">
- $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
- </pre>
- <p id="ch8ult_module_plan_5d">
- This will create:
- </p>
- tmpdir - branches
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_5e">
- tag
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- trunk - sources - includes
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_5f">
- docs
- </p>
- </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="4.Getting Help">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2968601">
- </a>
- 4.Getting Help
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="4.1.apropos and whatis">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2968610">
- </a>
- 4.1.apropos and whatis
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_60">
- This is a command to search the manual pages files in Unix and Unix-like operating systems.
- </p>
- <pre class="programlisting">
- $ apropos grep
-egrep egrep (1) Search a file for a pattern using full regular expressions
-fgrep fgrep (1) Search a file for a fixed-character string
-fmlgrep fmlgrep (1) Search a file for a pattern
-grep grep (1) Search a file for a pattern
-gzgrep gzgrep (1) Search a possibly compressed file for a regular expression
-nisgrep nismatch (1) Utilities for searching NIS+ tables
-pgrep pgrep (1) Find or signal a process by name or other attribute
-zgrep zgrep (1) Search a possibly compressed file for a regular expression
-...
- </pre>
- <p id="ch8ult_module_plan_61">
- In this example, the user uses
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- to search for the string "grep", and apropos returns the indicated
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- pages that include the term "grep".
- </p>
- <p id="ch8ult_module_plan_62">
- A short index of explanations for commands is available using the
- <span class="emphasis">
- <em>
- whatis
- </em>
- </span>
- command, like in the examples below:
- </p>
- <pre class="programlisting">
- $whatis ls
-ls (1) - list directory contents
- </pre>
- <p id="ch8ult_module_plan_63">
- This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
- </p>
- <p id="ch8ult_module_plan_64">
- If you don't know where to get started and which man page to read,
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- gives more information. Say that you do not know how to start a browser, then you could enter the following command:
- </p>
- <pre class="programlisting">
- $apropos browser
-gmusicbrowser (1) - Jukebox for large collections of audio files
-infobrowser (1) - read Info documents
-libsmbclient (7) - An extension library for browsers and that can be used...
-opera (1) - a standards-compliant graphical Web browser
-sensible-browser (1) - sensible editing, paging, and web browsing
-smbtree (1) - A text based smb network browser
-tvtk_doc (1) - A GUI based TVTK documentation search browser.
-viewres (1) - graphical class browser for Xt
-w3m (1) - a text based Web browser and pager
-www-browser (1) - a text based Web browser and pager
-...
- </pre>
- </div>
- <div class="section" title="4.2.man">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2967107">
- </a>
- 4.2.man
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_65">
- Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- . Each page is a self-contained document.
- </p>
- <p id="ch8ult_module_plan_66">
- To read a manual page for a Unix command, one can use:
- </p>
- <pre class="programlisting">
- $ man <command_name>
- </pre>
- <p id="ch8ult_module_plan_67">
- at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- generally uses the less terminal pager.
- </p>
- <p id="ch8ult_module_plan_68">
- Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are
- <span class="emphasis">
- <em>
- man(1)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- man(7)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- exit(2)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- exit(3)
- </em>
- </span>
- . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
- <span class="emphasis">
- <em>
- BSD, for example, the syntax for reading *printf(3)
- </em>
- </span>
- is:
- </p>
- <pre class="programlisting">
- $man 3 printf
- </pre>
- <p id="ch8ult_module_plan_69">
- Another example:
- </p>
- <pre class="programlisting">
- $man man
- </pre>
- <p id="ch8ult_module_plan_6a">
- The previous example will take you to the "Manual" page entry about manual pages!
- </p>
- <div class="section" title="4.2.1.Layout">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2968914">
- </a>
- 4.2.1.Layout
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_6b">
- All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
- </p>
- NAME
- <p id="ch8ult_module_plan_6c">
- The name of the command or function, followed by a one-line description of what it does.
- </p>
- SYNOPSIS
- <p id="ch8ult_module_plan_6d">
- In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
- </p>
- DESCRIPTION
- <p id="ch8ult_module_plan_6e">
- A textual description of the functioning of the command or function.
- </p>
- EXAMPLES
- <p id="ch8ult_module_plan_6f">
- Some examples of common usage.
- </p>
- SEE ALSO
- <p id="ch8ult_module_plan_70">
- A list of related commands or functions.
- </p>
- <p id="ch8ult_module_plan_71">
- Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
- </p>
- <p id="ch8ult_module_plan_72">
- These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
- </p>
- <p id="ch8ult_module_plan_73">
- However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
- </p>
- <p id="ch8ult_module_plan_74">
- Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
- </p>
- <p id="ch8ult_module_plan_75">
- Usually the man pages are written in English. Translations into other languages can be also available on the system.
- </p>
- <p id="ch8ult_module_plan_76">
- The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
- </p>
- </div>
- </div>
- <div class="section" title="4.3.info">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2969025">
- </a>
- 4.3.info
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_77">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
- </p>
- <p id="ch8ult_module_plan_78">
- The syntax is
- </p>
- <pre class="programlisting">
- $ info <command_name>
- </pre>
- <p id="ch8ult_module_plan_79">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_7a">
- <span class="emphasis">
- <em>
- n
- </em>
- </span>
- goes to the next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_7b">
- <span class="emphasis">
- <em>
- p
- </em>
- </span>
- goes to the previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_7c">
- <span class="emphasis">
- <em>
- u
- </em>
- </span>
- goes to the upper page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_7d">
- <span class="emphasis">
- <em>
- l
- </em>
- </span>
- goes to the last(visited) node
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_7e">
- To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_7f">
- info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
- </p>
- </div>
- <div class="section" title="4.4.--help">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2969112">
- </a>
- 4.4.--help
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_80">
- Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command:
- </p>
- <pre class="programlisting">
- $ userprompt@host: cat --help
-Usage: cat [OPTION] [FILE]...
-Concatenate FILE(s), or standard input, to standard output.
-
- -A, --show-all equivalent to -vET
- -b, --number-nonblank number nonempty output lines
- -e equivalent to -vE
- -E, --show-ends display $ at end of each line
- -n, --number number all output lines
- -s, --squeeze-blank suppress repeated empty output lines
- -t equivalent to -vT
- -T, --show-tabs display TAB characters as ^I
- -u (ignored)
- -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
- --help display this help and exit
- --version output version information and exit
-
-With no FILE, or when FILE is -, read standard input.
-
-Examples:
- cat f - g Output f's contents, then standard input, then g's contents.
- cat Copy standard input to standard output.
-
-Report bugs to <bug-coreutils@gnu.org>.
- </pre>
- </div>
- </div>
- <div class="section" title="5.Basic file handling">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2969165">
- </a>
- 5.Basic file handling
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="5.1.cp">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2969173">
- </a>
- 5.1.cp
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_81">
- <span class="emphasis">
- <em>
- cp
- </em>
- </span>
- is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
- </p>
- <div class="section" title="5.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2969191">
- </a>
- 5.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_82">
- To copy a file to another file:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
- </pre>
- <p id="ch8ult_module_plan_83">
- To copy a file to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
- </pre>
- <p id="ch8ult_module_plan_84">
- To copy a directory to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
-SourceDirectory ... TargetDirectory
- </pre>
- </div>
- <div class="section" title="5.1.2.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2969225">
- </a>
- 5.1.2.Flags
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_85">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (force) specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
- </p>
- <p id="ch8ult_module_plan_86">
- <span class="emphasis">
- <em>
- -P
- </em>
- </span>
- makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
- </p>
- <p id="ch8ult_module_plan_87">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- (interactive) prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
- </p>
- <p id="ch8ult_module_plan_88">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- (preserve) duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_89">
- The time of the last data modification and the time of the last access.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_8a">
- The user ID and group ID (only if it has permissions to do this)
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_8b">
- The file permission bits and the SUID and SGID bits.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_8c">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- (recursive) copy directories (recursively copying all the contents)
- </p>
- </div>
- <div class="section" title="5.1.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2969323">
- </a>
- 5.1.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_8d">
- To make a copy of a file in the current directory, enter:
- </p>
- <pre class="programlisting">
- $ cp prog.c prog.bak
- </pre>
- <p id="ch8ult_module_plan_8e">
- This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
- </p>
- <p id="ch8ult_module_plan_8f">
- To copy a file in your current directory into another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod /home/books/hhgg
- </pre>
- <p id="ch8ult_module_plan_90">
- This copies the jones file to /home/books/hhgg/zaphod.
- </p>
- <p id="ch8ult_module_plan_91">
- To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
- </p>
- <pre class="programlisting">
- $ cp -p martin_luther_king martin_luther_king.jr
- </pre>
- <p id="ch8ult_module_plan_92">
- This copies the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file to the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file. Instead of creating the file with the current date and time stamp, the system gives the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file the same date and time as the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file. The
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file also inherits the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file's access control protection.
- </p>
- <p id="ch8ult_module_plan_93">
- To copy all the files in a directory to a new directory, enter:
- </p>
- <pre class="programlisting">
- $ cp /home/galactica/clients/* /home/hhgg/customers
- </pre>
- <p id="ch8ult_module_plan_94">
- This copies only the files in the clients directory to the customers directory.
- </p>
- <p id="ch8ult_module_plan_95">
- To copy a directory, including all its files and subdirectories, to another directory, enter:
- </p>
- <p id="ch8ult_module_plan_96">
- $ cp -R /home/hhgg/clients /home/hhgg/customers
- </p>
- <p id="ch8ult_module_plan_97">
- This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
- </p>
- <p id="ch8ult_module_plan_98">
- To copy a specific set of files of any extension to another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod arthur ford /home/hhgg/clients
- </pre>
- <p id="ch8ult_module_plan_99">
- This copies the
- <span class="emphasis">
- <em>
- zaphod
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- arthur
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- ford
- </em>
- </span>
- files in your current working directory to the /home/hhgg/clients directory.
- </p>
- <p id="ch8ult_module_plan_9a">
- To use pattern-matching characters to copy files, enter:
- </p>
- <pre class="programlisting">
- $ cp programs/*.py .
- </pre>
- <p id="ch8ult_module_plan_9b">
- This copies the files in the programs directory that end with
- <span class="emphasis">
- <em>
- .py
- </em>
- </span>
- to the current directory, signified by the single "." (dot). You must type a space between the
- <span class="emphasis">
- <em>
- py
- </em>
- </span>
- and the final dot.
- </p>
- </div>
- </div>
- <div class="section" title="5.2.mv">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2969486">
- </a>
- 5.2.mv
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_9c">
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system),
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- will rename the file instead. Write permission is required on all directories being modified.
- </p>
- <div class="section" title="5.2.1.Conflicting existing file">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2969510">
- </a>
- 5.2.1.Conflicting existing file
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_9d">
- In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
- </p>
- </div>
- <div class="section" title="5.2.2.Differences with copy and delete">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2969529">
- </a>
- 5.2.2.Differences with copy and delete
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_9e">
- Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
- </p>
- </div>
- <div class="section" title="5.2.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2969560">
- </a>
- 5.2.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ mv myfile mynewfilename renames a file
-$ mv myfile otherfilename renames a file and deletes the existing file "myfile"
-$ mv myfile /myfile moves 'myfile' from the current directory to the root directory
-$ mv myfile dir/myfile moves 'myfile' to 'dir/myfile' relative to the current directory
-$ mv myfile dir same as the previous command (the filename is implied to be the same)
-$ mv myfile dir/myfile2 moves 'myfile' to dir and renames it to 'myfile2'
-$ mv foo bar baz dir moves multiple files to directory dir
-$ mv --help shows a very concise help about the syntax of the command
-$ man mv prints an extensive user manual for 'mv' in the terminal
- </pre>
- <p id="ch8ult_module_plan_9f">
- In all cases, the file or files being moved or renamed can be a directory.
- </p>
- <p id="ch8ult_module_plan_a0">
- Note that when the command is called with two arguments (as
- <span class="emphasis">
- <em>
- mv name1 name2
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- mv name1 /dir/name2
- </em>
- </span>
- ), it can have three different effects, depending on whether
- <span class="emphasis">
- <em>
- name2
- </em>
- </span>
- does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
- <span class="emphasis">
- <em>
- /.
- </em>
- </span>
- (or in some Unix versions
- <span class="emphasis">
- <em>
- /
- </em>
- </span>
- is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
- </p>
- </div>
- </div>
- <div class="section" title="5.3.rm">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2969618">
- </a>
- 5.3.rm
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_a1">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
- </p>
- <p id="ch8ult_module_plan_a2">
- Here's example to remove a file named "foo" from a directory, here shown with the -i option:
- </p>
- <pre class="programlisting">
- $ rm -i foo
-remove foo? y
- </pre>
- <div class="section" title="5.3.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2969648">
- </a>
- 5.3.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_a3">
- Common options that rm accepts include:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_a4">
- <span class="emphasis">
- <em>
- -r
- </em>
- </span>
- , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_a5">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- , which asks for every deletion to be confirmed ("interactive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_a6">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- , which ignores non-existent files and overrides any confirmation prompts ("force")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_a7">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- , which shows what is being removed as it happens ("verbose")
- </p>
- </li>
- </ul>
- </div>
- <p id="ch8ult_module_plan_a8">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
- </p>
- <p id="ch8ult_module_plan_a9">
- <span class="emphasis">
- <em>
- rm -rf
- </em>
- </span>
- (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
- </p>
- <p id="ch8ult_module_plan_aa">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often used in conjunction with xargs to supply a list of files to delete:
- </p>
- <pre class="programlisting">
- xargs rm < filelist
- </pre>
- <p id="ch8ult_module_plan_ab">
- When
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is used on a symbolic link, it deletes the link, but does not affect the target of the link.
- </p>
- </div>
- <div class="section" title="5.3.2.Permissions">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2969747">
- </a>
- 5.3.2.Permissions
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_ac">
- Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
- </p>
- <p id="ch8ult_module_plan_ad">
- To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
- </p>
- <p id="ch8ult_module_plan_ae">
- If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="6.Command Line Arguments">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2969786">
- </a>
- 6.Command Line Arguments
- </h2>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_af">
- In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
- </p>
- <p id="ch8ult_module_plan_b0">
- For example, in Unix and Unix-like environments, an example of a command-line argument is:
- </p>
- <pre class="programlisting">
- rm file.s
- </pre>
- <p id="ch8ult_module_plan_b1">
- "file.s" is a command line argument which tells the program rm to remove the file "file.s".
- </p>
- <p id="ch8ult_module_plan_b2">
- Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
- </p>
- <p id="ch8ult_module_plan_b3">
- A command line option or simply
- <span class="emphasis">
- <em>
- option
- </em>
- </span>
- (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
- </p>
- <p id="ch8ult_module_plan_b4">
- Long options are introduced via "--", and are typically whole words. For example,
- <span class="emphasis">
- <em>
- ls --long --classify --all
- </em>
- </span>
- . Arguments to long options are provided with "=", as
- <span class="emphasis">
- <em>
- ls --block-size=1024
- </em>
- </span>
- . Some Unix programs use long options with single dashes, for example MPlayer as in
- <span class="emphasis">
- <em>
- mplayer -nosound
- </em>
- </span>
- .
- </p>
- <p id="ch8ult_module_plan_b5">
- Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- by using
- <span class="emphasis">
- <em>
- rm -file1
- </em>
- </span>
- may produce an error, since rm may interpret
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- as a command line switch. Using
- <span class="emphasis">
- <em>
- rm -- -file1
- </em>
- </span>
- removes ambiguity.
- </p>
- </div>
- <div class="section" title="7.Basic Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2969880">
- </a>
- 7.Basic Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="7.1.head">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2969888">
- </a>
- 7.1.head
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_b6">
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:
- </p>
- <pre class="programlisting">
- $ head [options] <file_name>
- </pre>
- <p id="ch8ult_module_plan_b7">
- By default,
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ head -n 20 filename
- </pre>
- <p id="ch8ult_module_plan_b8">
- This displays the first 5 lines of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ head -n 5 foo*
- </pre>
- <p id="ch8ult_module_plan_b9">
- Some versions omit the n and just let you say -5.
- </p>
- <div class="section" title="7.1.1.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2969940">
- </a>
- 7.1.1.Flags
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- -c <x number of bytes> Copy first x number of bytes.
- </pre>
- <p id="ch8ult_module_plan_ba">
- Other options:
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- </p>
- <p id="ch8ult_module_plan_bb">
- Many early versions of Unix did not have this command, and so documentation and books had
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- do this job:
- </p>
- <pre class="programlisting">
- sed 5q foo
- </pre>
- <p id="ch8ult_module_plan_bc">
- This says to print every line (implicit), and quit after the fifth.
- </p>
- </div>
- </div>
- <div class="section" title="7.2.tail">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2969975">
- </a>
- 7.2.tail
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_bd">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
- </p>
- <p id="ch8ult_module_plan_be">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ tail [options] <file_name>
- </pre>
- <p id="ch8ult_module_plan_bf">
- By default,
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ tail -n 20 filename
- </pre>
- <p id="ch8ult_module_plan_c0">
- This example shows the last 15 bytes of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ tail -c 15 foo*
- </pre>
- <p id="ch8ult_module_plan_c1">
- This example shows all lines of filename from the second line onwards:
- </p>
- <pre class="programlisting">
- $ tail -n +2 filename
- </pre>
- <p id="ch8ult_module_plan_c2">
- Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:
- </p>
- <pre class="programlisting">
- $ tail -20 filename
-$ tail -50c filename
- </pre>
- <p id="ch8ult_module_plan_c3">
- However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
- </p>
- <div class="section" title="7.2.1.File monitoring">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2970054">
- </a>
- 7.2.1.File monitoring
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_c4">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- has a special command line option
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:
- </p>
- <pre class="programlisting">
- $ tail -f /var/adm/messages
- </pre>
- <p id="ch8ult_module_plan_c5">
- To interrupt tail while it is monitoring, break-in with
- <span class="emphasis">
- <em>
- Ctrl+C
- </em>
- </span>
- . This command can be run "in the background" with &, see job control.
- </p>
- <p id="ch8ult_module_plan_c6">
- If you have a command's result to monitor, you can use the
- <span class="emphasis">
- <em>
- watch
- </em>
- </span>
- command.
- </p>
- </div>
- </div>
- <div class="section" title="7.3.cut">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2970103">
- </a>
- 7.3.cut
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_c7">
- In computing,
- <span class="emphasis">
- <em>
- cut
- </em>
- </span>
- is a Unix command line utility which is used to extract sections from each line of input usually from a file.
- </p>
- <p id="ch8ult_module_plan_c8">
- Extraction of line segments can typically be done by
- <span class="emphasis">
- <em>
- bytes (-b), characters (-c)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- fields (-f)
- </em>
- </span>
- separated by a
- <span class="emphasis">
- <em>
- delimiter (-d the tab character by default)
- </em>
- </span>
- . A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
- </p>
- <p id="ch8ult_module_plan_c9">
- Assuming a file named file containing the lines:
- </p>
- <pre class="programlisting">
- foo:bar:baz:qux:quux
-one:two:three:four:five:six:seven
-alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- <p id="ch8ult_module_plan_ca">
- To output the fourth through tenth characters of each line:
- </p>
- <pre class="programlisting">
- $ cut -c 4-10 file
- </pre>
- <p id="ch8ult_module_plan_cb">
- This gives the output:
- </p>
- <pre class="programlisting">
- :bar:ba
-:two:th
-ha:beta
- </pre>
- <p id="ch8ult_module_plan_cc">
- To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
- </p>
- <pre class="programlisting">
- $ cut -d : -f 5- file
- </pre>
- <p id="ch8ult_module_plan_cd">
- This gives the output:
- </p>
- <pre class="programlisting">
- quux
-five:six:seven
-epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- </div>
- <div class="section" title="7.4.paste">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2970190">
- </a>
- 7.4.paste
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_ce">
- <span class="emphasis">
- <em>
- paste
- </em>
- </span>
- is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command which operates on the vertical plane of two or more files.
- </p>
- <p id="ch8ult_module_plan_cf">
- To paste several columns of data together into the file
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- from files
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- where
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- when
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ paste who where when > www
- </pre>
- <p id="ch8ult_module_plan_d0">
- If the files contain:
- </p>
- <table summary="paste" border="1">
- <colgroup>
- <col width="11">
- </col>
- <col width="12">
- </col>
- <col width="12">
- </col>
- </colgroup>
- </table>
- <p id="ch8ult_module_plan_dd">
- This creates the file named
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- containing:
- </p>
- <pre class="programlisting">
- Batman GothamCity January 3
-Trillian Andromeda February 4
-Jeeves London March 19
- </pre>
- </div>
- </div>
- <div class="section" title="8.Shell Meta Characters">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2970324">
- </a>
- 8.Shell Meta Characters
- </h2>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_de">
- Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
- </p>
- <p id="ch8ult_module_plan_df">
- The shell meta characters include:
- </p>
- <p id="ch8ult_module_plan_e0">
- / < > ! $ % ^ & * | { } [ ] " ' ` ~ ;
- </p>
- <p id="ch8ult_module_plan_e1">
- Different shells may differ in the meta characters recognized.
- </p>
- <p id="ch8ult_module_plan_e2">
- As an example,
- </p>
- <pre class="programlisting">
- $ ls file.*
- </pre>
- <p id="ch8ult_module_plan_e3">
- run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
- </p>
- <pre class="programlisting">
- $ ls file.?
- </pre>
- <p id="ch8ult_module_plan_e4">
- run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:
- </p>
- <pre class="programlisting">
- $ more c*
- </pre>
- <p id="ch8ult_module_plan_e5">
- because the c* matches that long file name.
- </p>
- <p id="ch8ult_module_plan_e6">
- Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named "``*`|more"` can be accomplished with:
- </p>
- <pre class="programlisting">
- $ rm ??more
- </pre>
- <p id="ch8ult_module_plan_e7">
- or:
- </p>
- <pre class="programlisting">
- $ rm $\backslash$*$\backslash$|more
- </pre>
- <p id="ch8ult_module_plan_e8">
- or:
- </p>
- <pre class="programlisting">
- $ rm ''*|more''
- </pre>
- </div>
- <div class="section" title="9.Looking At Files">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2970430">
- </a>
- 9.Looking At Files
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="9.1.cat">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2970438">
- </a>
- 9.1.cat
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_e9">
- The
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
- <span class="emphasis">
- <em>
- concatenate
- </em>
- </span>
- .
- </p>
- <p id="ch8ult_module_plan_ea">
- The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
- </p>
- <p id="ch8ult_module_plan_eb">
- If the filename is specified as -, then
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input at that point in the sequence. If no files are specified,
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input entered.
- </p>
- <div class="section" title="9.1.1.Jargon File Definition">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2970482">
- </a>
- 9.1.1.Jargon File Definition
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_ec">
- The Jargon File version 4.4.7 lists this as the definition of
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- 1. To spew an entire file to the screen or some other output sink without
- pause (syn. blast).
-
-2. By extension, to dump large amounts of data at an unprepared target or
- with no intention of browsing it carefully. Usage: considered silly.
- Rare outside Unix sites. See also dd, BLT.
-
- Among Unix fans, *cat(1)* is considered an excellent example of
- user-interface design, because it delivers the file contents without
- such verbosity as spacing or headers between the files, and because
- it does not require the files to consist of lines of text, but works
- with any sort of data.
-
- Among Unix critics, *cat(1)* is considered the canonical example of
- bad user-interface design, because of its woefully unobvious name.
- It is far more often used to blast a single file to standard output
- than to concatenate two or more files. The name cat for the former
- operation is just as unintuitive as, say, LISP's cdr.
-
- Of such oppositions are holy wars made...
- </pre>
- </div>
- <div class="section" title="9.1.2.Useless Use of 'cat'">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2970521">
- </a>
- 9.1.2.Useless Use of 'cat'
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_ed">
- UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
- <span class="emphasis">
- <em>
- comp.unix.shell
- </em>
- </span>
- , The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
- </p>
- <p id="ch8ult_module_plan_ee">
- Nevertheless one sees people doing:
- </p>
- <pre class="programlisting">
- $ cat file | some_command and its args ...
- </pre>
- <p id="ch8ult_module_plan_ef">
- instead of the equivalent and cheaper:
- </p>
- <pre class="programlisting">
- <file some_command and its args ...
- </pre>
- <p id="ch8ult_module_plan_f0">
- or (equivalently and more classically):
- </p>
- <pre class="programlisting">
- some_command and its args ... <file
- </pre>
- <p id="ch8ult_module_plan_f1">
- Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
- </p>
- <p id="ch8ult_module_plan_f2">
- Amongst many, it is still considered safer to use
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
- </p>
- </div>
- <div class="section" title="9.1.3.zcat">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2970592">
- </a>
- 9.1.3.zcat
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_f3">
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- is a Unix program similar to
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- , that decompresses individual files and concatenates them to standard output. Traditionally
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- operated on files compressed by compress but today it is usually able to operate on
- <span class="emphasis">
- <em>
- gzip
- </em>
- </span>
- or even
- <span class="emphasis">
- <em>
- bzip2
- </em>
- </span>
- archives. On such systems, it is equivalent to
- <span class="emphasis">
- <em>
- gunzip -c
- </em>
- </span>
- </p>
- </div>
- </div>
- <div class="section" title="9.2.more">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2970626">
- </a>
- 9.2.more
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_f4">
- In computing,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
- </p>
- <div class="section" title="9.2.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2970645">
- </a>
- 9.2.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_f5">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ more [options] [file_name]
- </pre>
- <p id="ch8ult_module_plan_f6">
- If no file name is provided,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- looks for input from stdin.
- </p>
- <p id="ch8ult_module_plan_f7">
- Once
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has paged through. (This percentage includes the text displayed on the current screen.) When
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- , which advances the output by one line, and
- <span class="emphasis">
- <em>
- Space
- </em>
- </span>
- , which advances the output by one screen.
- </p>
- <p id="ch8ult_module_plan_f8">
- There are also other commands that can be used while navigating through the document; consult
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- 's
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page for more details.
- </p>
- <p id="ch8ult_module_plan_f9">
- <span class="emphasis">
- <em>
- Options
- </em>
- </span>
- are typically entered before the file name, but can also be entered in the environment variable
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- . Options entered in the actual command line will override those entered in the
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- environment variable. Available options may vary between Unix systems.
- </p>
- </div>
- </div>
- <div class="section" title="9.3.less">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2970737">
- </a>
- 9.3.less
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_fa">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- does not need to read the entire file before starting, resulting in faster load times with large files.
- </p>
- <div class="section" title="9.3.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2970765">
- </a>
- 9.3.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_fb">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- vi
- </em>
- </span>
- . It is also possible to search for character patterns in the file.
- </p>
- <p id="ch8ult_module_plan_fc">
- By default,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
- </p>
- <p id="ch8ult_module_plan_fd">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ less [options] file_name
- </pre>
- </div>
- <div class="section" title="9.3.2.Frequently Used Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2970820">
- </a>
- 9.3.2.Frequently Used Options
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_fe">
- -g: Highlights just the current match of any searched string.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_ff">
- -I: Case-insensitive searches.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_100">
- -M: Shows more detailed prompt, including file position.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_101">
- -N: Shows line numbers (useful for source code viewing).
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_102">
- -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_103">
- -?: Shows help.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.3.Frequently Used Commands">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2970872">
- </a>
- 9.3.3.Frequently Used Commands
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_104">
- [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_105">
- [Space bar]: Next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_106">
- b: Previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_107">
- ng: Jump to line number n. Default is the start of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_108">
- nG: Jump to line number n. Default is the end of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_109">
- /pattern: Search for pattern. Regular expressions can be used.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_10a">
- '^ or g: Go to start of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_10b">
- '$ or G: Go to end of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_10c">
- s: Save current content (got from another program like grep) in a file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_10d">
- =: File information.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_10e">
- h: Help.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_10f">
- q: Quit.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.4.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2970962">
- </a>
- 9.3.4.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ less -M readme.txt #Read "readme.txt."
-$ less +F /var/log/mail.log #Follow mode for log
-$ file * | less #Easier file analysis.
-$ grep -i void *.c | less -I -p void #Case insensitive search for "void" in all .c files
- </pre>
- </div>
- </div>
- </div>
- <div class="section" title="10.Directory Structure">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2970978">
- </a>
- 10.Directory Structure
- </h2>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_110">
- In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
- </p>
- <p id="ch8ult_module_plan_111">
- The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
- </p>
- <table summary="Directory Structure" border="1">
- <colgroup>
- <col width="15">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <div class="section" title="10.1.man hier">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2971252">
- </a>
- 10.1.man hier
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_136">
- This is the manual page on the UNIX filesystem. The syntax for this is:
- </p>
- <pre class="programlisting">
- $ man hier
- </pre>
- </div>
- <div class="section" title="10.2.ls -l">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2971268">
- </a>
- 10.2.ls -l
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_137">
- Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
- </p>
- <pre class="programlisting">
- $ ls -l
- </pre>
- <p id="ch8ult_module_plan_138">
- This can be done after entering the required directory.
- </p>
- </div>
- </div>
- <div class="section" title="11.Permissions and Ownership">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2971291">
- </a>
- 11.Permissions and Ownership
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="11.1.chmod">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2971300">
- </a>
- 11.1.chmod
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_139">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.
- </p>
- <div class="section" title="11.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2971326">
- </a>
- 11.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_13a">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command options are specified like this:
- </p>
- <pre class="programlisting">
- $ chmod [options] mode[,mode] file1 [file2 ...]
- </pre>
- <p id="ch8ult_module_plan_13b">
- To view what the permissions currently are, type:
- </p>
- <pre class="programlisting">
- $ ls -l file
- </pre>
- </div>
- <div class="section" title="11.1.2.Command line options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2971354">
- </a>
- 11.1.2.Command line options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_13c">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command has a number of command line options that affect its behavior. The most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_13d">
- -R: Changes the modes of directories and files recursively
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch8ult_module_plan_13e">
- -v: Verbose mode; lists all files as they are being processed
- </p>
- </li>
- </ul>
- </div>
- <div class="section" title="11.1.2.1.Symbolic modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2971390">
- </a>
- 11.1.2.1.Symbolic modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_13f">
- To the
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
- </p>
- <pre class="programlisting">
- $ chmod [references][operator][modes] file1 ...
- </pre>
- <p id="ch8ult_module_plan_140">
- The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="8">
- </col>
- <col width="45">
- </col>
- </colgroup>
- </table>
- <p id="ch8ult_module_plan_150">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="54">
- </col>
- </colgroup>
- </table>
- <p id="ch8ult_module_plan_157">
- The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="5">
- </col>
- <col width="14">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <p id="ch8ult_module_plan_16d">
- The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
- </p>
- </div>
- <div class="section" title="11.1.2.2.Symbolic examples">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2971951">
- </a>
- 11.1.2.2.Symbolic examples
- </h5>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_16e">
- Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
- </p>
- <pre class="programlisting">
- $ chmod ug+rw mydir
-$ ls -ld mydir
-drw-rw---- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- <p id="ch8ult_module_plan_16f">
- For a file, remove
- <span class="emphasis">
- <em>
- write
- </em>
- </span>
- permissions for all classes:
- </p>
- <pre class="programlisting">
- $ chmod a-w myfile
-$ ls -l myfile
--r-xr-xr-x 2 starwars yoda 96 Dec 8 12:53 myfile
- </pre>
- <p id="ch8ult_module_plan_170">
- Set the permissions for the
- <span class="emphasis">
- <em>
- u*ser and the *g*roup to read and execute only (no write permission) on *mydir
- </em>
- </span>
- .
- </p>
- <pre class="programlisting">
- $ chmod ug=rx mydir
-$ ls -ld mydir
-dr-xr-x--- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- </div>
- <div class="section" title="11.1.2.3.Octal numbers">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2971994">
- </a>
- 11.1.2.3.Octal numbers
- </h5>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_171">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
- </p>
- <pre class="programlisting">
- $ chmod 664 myfile
-$ ls -l myfile
--rw-rw-r-- 1 57 Jul 3 10:13 myfile
- </pre>
- <p id="ch8ult_module_plan_172">
- Since the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- sticky
- </em>
- </span>
- bits are not set, this is equivalent to:
- </p>
- <pre class="programlisting">
- $ chmod 0664 myfile
- </pre>
- </div>
- <div class="section" title="11.1.2.4.Special modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2972033">
- </a>
- 11.1.2.4.Special modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_173">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
- <span class="strong">
- <strong>
- s
- </strong>
- </span>
- to represent the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- modes, and
- <span class="strong">
- <strong>
- t
- </strong>
- </span>
- to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
- </p>
- <p id="ch8ult_module_plan_174">
- Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
- </p>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="12.Redirection and Piping">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2972077">
- </a>
- 12.Redirection and Piping
- </h2>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_175">
- In computing,
- <span class="emphasis">
- <em>
- redirection
- </em>
- </span>
- is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
- </p>
- <p id="ch8ult_module_plan_176">
- Programs do redirection with the
- <span class="emphasis">
- <em>
- dup2(2)
- </em>
- </span>
- system call, or its less-flexible but higher-level stdio analogues,
- <span class="emphasis">
- <em>
- freopen(3)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- popen(3)
- </em>
- </span>
- .
- </p>
- <div class="section" title="12.1.Redirecting standard input and standard output">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2972112">
- </a>
- 12.1.Redirecting standard input and standard output
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_177">
- Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
- </p>
- <pre class="programlisting">
- $ command1 > file1
- </pre>
- <p id="ch8ult_module_plan_178">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , placing the output in file1. Note that this will truncate any existing data in
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- . To append output to the end of the file, use the >> operator.:
- </p>
- <pre class="programlisting">
- $ command1 < file1
- </pre>
- <p id="ch8ult_module_plan_179">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- as the source of input (as opposed to the keyboard).:
- </p>
- <pre class="programlisting">
- $ command1 < infile > outfile
- </pre>
- <p id="ch8ult_module_plan_17a">
- combines the two capabilities:
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- reads from
- <span class="emphasis">
- <em>
- infile
- </em>
- </span>
- and writes to
- <span class="emphasis">
- <em>
- outfile
- </em>
- </span>
- </p>
- </div>
- <div class="section" title="12.2.Piping">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2972182">
- </a>
- 12.2.Piping
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_17b">
- Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
-A pipeline of three programs run on a text terminal:
- </p>
- <pre class="programlisting">
- $ command1 | command2
- </pre>
- <p id="ch8ult_module_plan_17c">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using its output as the input for
- <span class="emphasis">
- <em>
- command2
- </em>
- </span>
- (commonly called piping, since the "|" character is known as a "pipe").
- </p>
- <p id="ch8ult_module_plan_17d">
- This is equivalent to using two redirects and a temporary file:
- </p>
- <pre class="programlisting">
- $ command1 > tempfile
-$ command2 < tempfile
-$ rm tempfile
- </pre>
- <p id="ch8ult_module_plan_17e">
- A good example for command piping is combining
- <span class="emphasis">
- <em>
- echo
- </em>
- </span>
- with another command to achieve something interactive in a non-interactive shell, e.g.:
- </p>
- <pre class="programlisting">
- $ echo -e "user\npass" | ftp localhost
- </pre>
- <p id="ch8ult_module_plan_17f">
- This runs the ftp client with input user, press return, then pass.
- </p>
- </div>
- <div class="section" title="12.3.Redirecting to and from the standard file handles">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2972244">
- </a>
- 12.3.Redirecting to and from the standard file handles
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_180">
- In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
- </p>
- <table summary="Redirecting to and from the standard file handles" border="1">
- <colgroup>
- <col width="12">
- </col>
- <col width="13">
- </col>
- <col width="24">
- </col>
- </colgroup>
- </table>
- <p id="ch8ult_module_plan_18d">
- For example:
- </p>
- <pre class="programlisting">
- $ command1 2> file1
- </pre>
- <p id="ch8ult_module_plan_18e">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , directing the standard error stream to
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- .
- </p>
- <p id="ch8ult_module_plan_18f">
- In shells derived from
- <span class="emphasis">
- <em>
- csh
- </em>
- </span>
- (the C shell), the syntax instead appends the & character to the redirect characters, thus achieving a similar result.
- </p>
- <p id="ch8ult_module_plan_190">
- Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
- </p>
- <pre class="programlisting">
- $ find / -name .profile > results 2>&1
- </pre>
- <p id="ch8ult_module_plan_191">
- will try to find all files named
- <span class="emphasis">
- <em>
- .profile
- </em>
- </span>
- . Executed without redirection, it will output hits to
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- and errors (e.g. for lack of privilege to traverse protected directories) to
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- . If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- (handle 2) into
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- (handle 1) using 2>&1 .
- </p>
- <p id="ch8ult_module_plan_192">
- It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
- </p>
- <p id="ch8ult_module_plan_193">
- If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus:
- </p>
- <pre class="programlisting">
- $ find / -name .profile 2>&1 | less
- </pre>
- <p id="ch8ult_module_plan_194">
- A simplified form of the command:
- </p>
- <pre class="programlisting">
- $ command > file 2>&1
- </pre>
- <p id="ch8ult_module_plan_195">
- is:
- </p>
- <pre class="programlisting">
- $ command &>file
- </pre>
- <p id="ch8ult_module_plan_196">
- or:
- </p>
- <pre class="programlisting">
- $command >&file
- </pre>
- </div>
- <div class="section" title="12.4.Chained pipelines">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2972451">
- </a>
- 12.4.Chained pipelines
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_197">
- The redirection and piping tokens can be chained together to create complex commands. For example:
- </p>
- <pre class="programlisting">
- $ ls | grep '\.sh' | sort > shlist
- </pre>
- <p id="ch8ult_module_plan_198">
- lists the contents of the current directory, where this output is filtered to only contain lines which contain
- <span class="emphasis">
- <em>
- .sh
- </em>
- </span>
- , sort this resultant output lexicographically, and place the final output in
- <span class="emphasis">
- <em>
- shlist
- </em>
- </span>
- . This type of construction is used very commonly in shell scripts and batch files.
- </p>
- </div>
- <div class="section" title="12.5.Redirect to multiple outputs">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2972486">
- </a>
- 12.5.Redirect to multiple outputs
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_199">
- The standard command
- <span class="emphasis">
- <em>
- tee
- </em>
- </span>
- can redirect output from a command to several destinations.
- </p>
- <pre class="programlisting">
- $ ls -lrt | tee xyz
- </pre>
- <p id="ch8ult_module_plan_19a">
- This directs the file list output to both standard output as well as to the file
- <span class="emphasis">
- <em>
- xyz
- </em>
- </span>
- .
- </p>
- </div>
- </div>
- <div class="section" title="13.More Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2972516">
- </a>
- 13.More Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="13.1.grep">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2972525">
- </a>
- 13.1.grep
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_19b">
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- is a command line text search utility originally written for Unix. The name is taken from the first letters in
- <span class="emphasis">
- <em>
- global / regular expression / print
- </em>
- </span>
- , a series of instructions for the
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- text editor. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
- </p>
- <div class="section" title="13.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2972556">
- </a>
- 13.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_19c">
- This is an example of a common
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- usage:
- </p>
- <pre class="programlisting">
- $ grep apple fruitlist.txt
- </pre>
- <p id="ch8ult_module_plan_19d">
- In this case,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- prints all lines containing 'apple' from the file
- <span class="emphasis">
- <em>
- fruitlist.txt
- </em>
- </span>
- , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
- </p>
- <p id="ch8ult_module_plan_19e">
- Like most Unix commands,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- accepts command line arguments to change this and many other behaviors. For example:
- </p>
- <pre class="programlisting">
- $ grep -i apple fruitlist.txt
- </pre>
- <p id="ch8ult_module_plan_19f">
- This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be case insensitive, or to ignore case.
- </p>
- <p id="ch8ult_module_plan_1a0">
- To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
- </p>
- <pre class="programlisting">
- $ grep -w apple fruitlist.txt
- </pre>
- <p id="ch8ult_module_plan_1a1">
- Regular expressions can be used to match more complicated queries.
- </p>
- <div class="section" title="13.1.1.1.Variations">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id2972636">
- </a>
- 13.1.1.1.Variations
- </h5>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_1a2">
- There are countless implementations and derivatives of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- available for many operating systems. Early variants of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- included
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- . The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- may also behave differently depending on the name by which it is invoked, allowing
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be links to the same program.
- </p>
- <p id="ch8ult_module_plan_1a3">
- <span class="emphasis">
- <em>
- pcregrep
- </em>
- </span>
- is an implementation of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- that uses Perl regular expression syntax.
- </p>
- <p id="ch8ult_module_plan_1a4">
- Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
- <span class="emphasis">
- <em>
- pgrep
- </em>
- </span>
- utility, for instance, displays the processes whose names match a given regular expression.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="13.2.tr">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2972715">
- </a>
- 13.2.tr
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_1a5">
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- (abbreviated from
- <span class="emphasis">
- <em>
- translate
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- transliterate
- </em>
- </span>
- ) is a command in Unix-like operating systems.
- </p>
- <p id="ch8ult_module_plan_1a6">
- When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
- </p>
- <pre class="programlisting">
- $ tr 'abcd' 'jkmn'
- </pre>
- <p id="ch8ult_module_plan_1a7">
- maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
- </p>
- <p id="ch8ult_module_plan_1a8">
- Sets of characters may be abbreviated by using character ranges. The previous example could be written:
- </p>
- <pre class="programlisting">
- $ tr 'a-d' 'jkmn'
- </pre>
- <p id="ch8ult_module_plan_1a9">
- In POSIX compliant versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
- </p>
- <p id="ch8ult_module_plan_1aa">
- The
- <span class="emphasis">
- <em>
- -c
- </em>
- </span>
- flag complements the first set of characters.
- </p>
- <pre class="programlisting">
- $ tr -cd '[:alnum:]'
- </pre>
- <p id="ch8ult_module_plan_1ab">
- therefore removes all non-alphanumeric characters.
- </p>
- <p id="ch8ult_module_plan_1ac">
- The
- <span class="emphasis">
- <em>
- -s
- </em>
- </span>
- flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
- </p>
- <pre class="programlisting">
- $ tr -s '\n' '\n'
- </pre>
- <p id="ch8ult_module_plan_1ad">
- replaces sequences of one or more newline characters with a single newline.
- </p>
- <p id="ch8ult_module_plan_1ae">
- The
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
- </p>
- <pre class="programlisting">
- $ tr -d '\r'
- </pre>
- <p id="ch8ult_module_plan_1af">
- Most versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , including GNU
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- and classic Unix
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
- </p>
- <p id="ch8ult_module_plan_1b0">
- Ruby and Perl also have an internal
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- operator, which operates analogously. Tcl's
- <span class="emphasis">
- <em>
- string map
- </em>
- </span>
- command is more general in that it maps strings to strings while
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- maps characters to characters.
- </p>
- </div>
- </div>
- <div class="section" title="14.Elementary Regex">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2972866">
- </a>
- 14.Elementary Regex
- </h2>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_1b1">
- In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
- </p>
- <p id="ch8ult_module_plan_1b2">
- Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributionsincluding the editor
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- and the filter
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- were the first to popularize the concept of regular expressions.
- </p>
- <p id="ch8ult_module_plan_1b3">
- Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
- <span class="emphasis">
- <em>
- Basic Regular Expressions
- </em>
- </span>
- (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
- </p>
- <p id="ch8ult_module_plan_1b4">
- In the BRE syntax, most characters are treated as literals they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
- </p>
- <table summary="Elementary Regex" border="1">
- <colgroup>
- <col width="13">
- </col>
- <col width="60">
- </col>
- </colgroup>
- </table>
- <div class="section" title="14.1.Lazy quantification">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2973079">
- </a>
- 14.1.Lazy quantification
- </h3>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_1c9">
- The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example:
- </p>
- <pre class="programlisting">
- Another whale explosion occurred on <January 26>, <2004>.
- </pre>
- <p id="ch8ult_module_plan_1ca">
- ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the * quantifier is greedy it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
- </p>
- <p id="ch8ult_module_plan_1cb">
- Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as
- <span class="emphasis">
- <em>
- lazy
- </em>
- </span>
- (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
- </p>
- </div>
- </div>
- <div class="section" title="15.One Liners">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2973154">
- </a>
- 15.One Liners
- </h2>
- </div>
- </div>
- </div>
- <p id="ch8ult_module_plan_1cc">
- A
- <span class="emphasis">
- <em>
- one-liner
- </em>
- </span>
- is textual input to the command-line of an operating system shell that performs some function in just one line of input.
- </p>
- <p id="ch8ult_module_plan_1cd">
- The one liner can be
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch8ult_module_plan_1ce">
- An expression written in the language of the shell.
- </p>
- </li>
- <li class="listitem">
- <p id="ch8ult_module_plan_1cf">
- The invocation of an interpreter together with program source for the interpreter to run.
- </p>
- </li>
- <li class="listitem">
- <p id="ch8ult_module_plan_1d0">
- The invocation of a compiler together with source to compile and
-instructions for executing the compiled program.
- </p>
- </li>
- </ol>
- </div>
- <p id="ch8ult_module_plan_1d1">
- Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
- </p>
- <p id="ch8ult_module_plan_1d2">
- The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
- </p>
- <p id="ch8ult_module_plan_1d3">
- The word
- <span class="emphasis">
- <em>
- One-liner
- </em>
- </span>
- has two references in the index of the book
- <span class="emphasis">
- <em>
- The AWK Programming Language
- </em>
- </span>
- (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
- </p>
- <pre class="programlisting">
- The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.
- </pre>
- <p id="ch8ult_module_plan_1d4">
- Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
- </p>
- <p id="ch8ult_module_plan_1d5">
- The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
- </p>
- <p id="ch8ult_module_plan_1d6">
- Here are the first few of them:
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch8ult_module_plan_1d7">
- Print the total number of input lines:
- </p>
- <p id="ch8ult_module_plan_1d8">
- END { print NR }
- </p>
- </li>
- <li class="listitem">
- <p id="ch8ult_module_plan_1d9">
- Print the tenth input line:
- </p>
- <p id="ch8ult_module_plan_1da">
- NR == 10
- </p>
- </li>
- <li class="listitem">
- <p id="ch8ult_module_plan_1db">
- Print the last field of every input line:
- </p>
- <p id="ch8ult_module_plan_1dc">
- { print $NF }
- </p>
- </li>
- </ol>
- </div>
- <p id="ch8ult_module_plan_1dd">
- One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
- </p>
- <p id="ch8ult_module_plan_1de">
- The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:
- </p>
- <pre class="programlisting">
- main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
-*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
- </pre>
- <p id="ch8ult_module_plan_1df">
- This one-liner program is a
- <span class="emphasis">
- <em>
- glob pattern matcher
- </em>
- </span>
- . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
- </p>
- <p id="ch8ult_module_plan_1e0">
- Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:
- </p>
- <pre class="programlisting">
- $ prog foo 'f??'; echo $?
-
-$ prog 'best short program' '??st*o**p?*'; echo $?
- </pre>
- <p id="ch8ult_module_plan_1e1">
- Here is a one line shell script to show directories:
- </p>
- <pre class="programlisting">
- $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
- </pre>
- </div>
</div>
</div>
</body>
--- a/SEESenv/web/html/ch9Using_Linux_Tools.html Mon Feb 22 18:46:07 2010 +0530
+++ b/SEESenv/web/html/ch9Using_Linux_Tools.html Mon Feb 22 22:38:51 2010 +0530
@@ -27,5228 +27,22 @@
<dl>
<dt>
<span class="article">
- <a href="#id2949704">
+ <a href="#id2617109">
</a>
</span>
</dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2759829">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2949508">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3000755">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3001166">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3001306">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3001315">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3001595">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3001603">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3001766">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3001826">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3001928">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3002011">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3002178">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3002187">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3002282">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3002475">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3002562">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3002615">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3002624">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3002936">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003069">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3003237">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003330">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3003339">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003426">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003554">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003640">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3003775">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003880">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3003888">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3004076">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3004187">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3004428">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3004703">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3004719">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3004742">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3004751">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3005528">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3005563">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3005633">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3005695">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3005902">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3005936">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3005967">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3005976">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3006166">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3006317">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3006530">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3006606">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </dd>
</dl>
</div>
<div class="article">
<div class="titlepage">
<div>
<div>
- <h2 class="title" id="id2949704">
+ <h2 class="title" id="id2617109">
</h2>
</div>
</div>
<hr />
</div>
- <div class="toc">
- <p>
- <b>
- Table of Contents
- </b>
- </p>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2759829">
- 1. Introducing Linux
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id2949508">
- 1.1. Historical Background
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3000755">
- 1.2. Design and Implications
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3001166">
- 1.3. Reasons for Using Linux
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3001306">
- 2. Getting Started
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3001315">
- 2.1. Logging in, activating the user interface and logging out
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3001595">
- 3. Basic Commands
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3001603">
- 3.1. ls
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3001766">
- 3.2. date
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3001826">
- 3.3. cd
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3001928">
- 3.4. who
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3002011">
- 3.5. mkdir
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3002178">
- 4. Getting Help
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3002187">
- 4.1. apropos and whatis
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3002282">
- 4.2. man
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3002475">
- 4.3. info
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3002562">
- 4.4. --help
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3002615">
- 5. Basic file handling
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3002624">
- 5.1. cp
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3002936">
- 5.2. mv
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003069">
- 5.3. rm
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3003237">
- 6. Command Line Arguments
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003330">
- 7. Basic Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3003339">
- 7.1. head
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003426">
- 7.2. tail
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003554">
- 7.3. cut
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003640">
- 7.4. paste
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3003775">
- 8. Shell Meta Characters
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3003880">
- 9. Looking At Files
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3003888">
- 9.1. cat
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3004076">
- 9.2. more
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3004187">
- 9.3. less
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3004428">
- 10. Directory Structure
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3004703">
- 10.1. man hier
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3004719">
- 10.2. ls -l
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3004742">
- 11. Permissions and Ownership
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3004751">
- 11.1. chmod
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3005528">
- 12. Redirection and Piping
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3005563">
- 12.1. Redirecting standard input and standard output
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3005633">
- 12.2. Piping
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3005695">
- 12.3. Redirecting to and from the standard file handles
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3005902">
- 12.4. Chained pipelines
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3005936">
- 12.5. Redirect to multiple outputs
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3005967">
- 13. More Text Processing
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3005976">
- 13.1. grep
- </a>
- </span>
- </dt>
- <dt>
- <span class="section">
- <a href="#id3006166">
- 13.2. tr
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3006317">
- 14. Elementary Regex
- </a>
- </span>
- </dt>
- <dd>
- <dl>
- <dt>
- <span class="section">
- <a href="#id3006530">
- 14.1. Lazy quantification
- </a>
- </span>
- </dt>
- </dl>
- </dd>
- <dt>
- <span class="section">
- <a href="#id3006606">
- 15. One Liners
- </a>
- </span>
- </dt>
- </dl>
- </div>
- <div class="section" title="1.Introducing Linux">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id2759829">
- </a>
- 1.Introducing Linux
- </h2>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_1">
- (Attribution : A significant chunk of the content under this section is based on data from Wikipedia and the Linux Documentation Project)
- </p>
- <p id="ch9Using_Linux_Tools_2">
- Linux (usually pronounced lnks') is a generic term referring to Unix-like computer operating systems based on the Linux kernel, where a kernel is the intermediate layer between the hardware and the applications. The kernel is, on an abstract level, the core of (most) operating systems, that manages the various system resources. The development of the Linux OS is considered the basis for Free and Open Source Software (FOSS) collaboration since typically the underlying source code can be used, modified freely, and redistributed by anyone under the terms of the GNU (a recursive acronym for "GNU's Not Unix!") Global Public License (GPL) and other free software licences. This freedom to access and reuse various components of a system, is one of the primary reasons for the popularity of Linux.
- </p>
- <p id="ch9Using_Linux_Tools_3">
- Linux is installed on a variety of computer hardware, that include mobile phones, embedded devices and supercomputers, but is infamous for its use in servers.
- </p>
- <p id="ch9Using_Linux_Tools_4">
- The name "Linux" comes from the Linux kernel, originally written in 1991 by Linus Torvalds. The rest of the system usually comprises components such as the Apache HTTP Server, the X Window System, the GNOME and KDE desktop environments, and utilities and libraries from the GNU Project (announced in 1983 by Richard Stallman). Commonly-used applications with desktop Linux systems include the Mozilla Firefox web-browser and the OpenOffice.org office application suite. The GNU contribution is the basis for the Free Software Foundation's preferred name GNU/Linux. The kernel's mascot is a penguin named "Tux". Mozilla Firefox and OpenOffice.org are open-source projects which can be run on most Operating Systems, including proprietary ones.
- </p>
- <div class="section" title="1.1.Historical Background">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id2949508">
- </a>
- 1.1.Historical Background
- </h3>
- </div>
- </div>
- </div>
- <div class="section" title="1.1.1.Events leading to the creation">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id2947490">
- </a>
- 1.1.1.Events leading to the creation
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_5">
- The Unix operating system was developed in the 1960s and released for public use in 1970. Its accessibility and portability caused it to be widely adopted, copied and modified by academic institutions and businesses. Its design became influential to authors of other systems. Other free operating systems include the Berkeley Software Distribution (BSD), developed at the University of California at Berkeley, and MINIX which was released by Andrew S. Tanenbaum. The development and adoption of BSD and MINIX were limited due to various reasons, and this lack of a widely-adopted and free kernel triggered Linus Torvalds into starting his project.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_6">
- In 1983, Richard Stallman started the GNU project with the goal of creating a free UNIX-like operating system. As part of this work, he wrote the GNU General Public License (GPL). By the early 1990s there was almost enough available software to create a full operating system. However, the GNU kernel, called Hurd, failed to attract enough attention from developers leaving GNU incomplete.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="1.1.2.The Creation of Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3000720">
- </a>
- 1.1.2.The Creation of Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_7">
- In 1991, Linus Torvalds began a project at the University of Helsinki that later became the Linux kernel. It was initially a terminal (command-line) emulator, which Torvalds used to access the large UNIX servers of the university. He wrote the program targeting just the hardware he was using and independent of an operating system because he wanted to use the functions of his computer with an 80386 processor. Development was done on Minix using the GNU C compiler. This application is still the main choice for compiling Linux today (although the code can be built with other compilers, such as the Intel C Compiler).
- </p>
- <p id="ch9Using_Linux_Tools_8">
- Torvalds continues to direct the development of the kernel. Stallman heads the Free Software Foundation, which in turn supports the GNU components. Finally, individuals and corporations develop third-party non-GNU components, which constitute a vast body of work and including kernel modules, and user applications and libraries. Linux vendors and communities combine and distribute the kernel, GNU components, and non-GNU components, with additional package management software in the form of Linux distributions.
- </p>
- </div>
- </div>
- <div class="section" title="1.2.Design and Implications">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3000755">
- </a>
- 1.2.Design and Implications
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_9">
- A Linux-based system is a modular Unix-like operating system, deriving much of its basic design from principles established in Unix earlier. Such a system uses a monolithic kernel, called the Linux kernel, which handles process control, networking, and peripheral and file system access. Device drivers are integrated directly with the kernel. Separate projects that interface with the kernel provide much of the system's higher-level functionality. The GNU userland is an important part of most Linux-based systems, providing the most common implementation of the C library, a popular shell, and many of the common Unix tools which carry out many basic operating system tasks. The graphical user interface (or GUI) used by most Linux systems is based on the "X Window System".
- </p>
- <div class="section" title="1.2.1.User Interface">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3000780">
- </a>
- 1.2.1.User Interface
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_a">
- Users can control a Linux-based system through a command line interface (or CLI), a graphical user interface (or GUI), or through controls attached to the associated hardware (this is common for embedded systems). For desktop systems, the default mode is usually the GUI. On desktop machines, "KDE", "GNOME" and "Xfce" are the most popular user interfaces,though a variety of additional user interfaces exist. Most popular user interfaces run on top of the "X Window System" (or X), which enables a graphical application running on one machine to be displayed and controlled from another in a network.
- </p>
- <p id="ch9Using_Linux_Tools_b">
- A Linux system also provides a CLI of some sort through a shell, which is the traditional way of interacting with a Unix system. A Linux distribution specialized for servers may use the CLI as its only interface. A headless system (system run without even a monitor) can be controlled by the command line via a remote-control protocol such as SSH or telnet. The CLI is particularly suited for automation of repetitive or delayed tasks, and provides very simple inter-process communication. A graphical terminal emulator program is often used to access the CLI from a Linux desktop.
- </p>
- </div>
- <div class="section" title="1.2.2.Development">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3000834">
- </a>
- 1.2.2.Development
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_c">
- The primary difference between Linux and many other popular contemporary operating systems is that the Linux kernel and other components are free and open source software. Linux is not the only such operating system, although it is by far the most widely used. Some free and open source software licenses are based on the principle of "copyleft", a kind of reciprocity: any work derived from a copyleft piece of software must also be copyleft itself. The most common free software license, the GNU GPL, is a form of copyleft, and is used for the Linux kernel and many of the components from the GNU project.
- </p>
- <p id="ch9Using_Linux_Tools_d">
- Linux based distributions are intended by developers for interoperability with other operating systems and established computing standards. Linux systems adhere to POSIX, SUS, ISO and ANSI standards where possible, although to date only one Linux distribution has been POSIX.1 certified, Linux-FT.Free software projects, although developed in a collaborative fashion, are often produced independently of each other. The fact that the software licenses explicitly permit redistribution, however, provides a basis for larger scale projects that collect the software produced by stand-alone projects and make it available all at once in the form of a Linux distribution.
- </p>
- <p id="ch9Using_Linux_Tools_e">
- A Linux distribution, commonly called a "distro", is a project that manages a remote collection of system software and application software packages available for download and installation through a network connection. This allows the user to adapt the operating system to his/her specific needs. Distributions are maintained by individuals, loose-knit teams, volunteer organizations, and commercial entities. A distribution can be installed using a CD that contains distribution-specific software for initial system installation and configuration. A package manager such as Synaptic or YAST allows later package upgrades and installations. A distribution is responsible for the default configuration of the installed Linux kernel, general system security, and more generally integration of the different software packages into a coherent whole.
- </p>
- </div>
- <div class="section" title="1.2.3.Community">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3000535">
- </a>
- 1.2.3.Community
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_f">
- A distribution is largely driven by its developer and user communities. Some vendors develop and fund their distributions on a volunteer basis. Examples include Debian and the Debian-based, Ubuntu. Others maintain a community version of their commercial distributions, as Red Hat does with Fedora.
- </p>
- <p id="ch9Using_Linux_Tools_10">
- In many cities and regions, local associations known as Linux Users Groups (LUGs) seek to promote their preferred distribution and by extension free software. They hold meetings and provide free demonstrations, training, technical support, and operating system installation to new users. Many Internet communities also provide support to Linux users and developers. Most distributions and free software / open source projects have IRC (Internet Relay Chat) chatrooms or newsgroups. Online forums are another means for support. Linux distributions host mailing lists; commonly there will be a specific topic such as usage or development for a given list. All these can be found simply by running an appropriate search on Google.
- </p>
- <p id="ch9Using_Linux_Tools_11">
- Although Linux distributions are generally available without charge, several large corporations sell, support, and contribute to the development of the components of the system and of free software. These include Dell, IBM, HP, Oracle, Sun Microsystems, Novell, Nokia. A number of corporations, notably Red Hat, have built their entire business around Linux distributions.
- </p>
- </div>
- <div class="section" title="1.2.4.Can I make a profit out of running a business involving Linux?">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3000580">
- </a>
- 1.2.4.Can I make a profit out of running a business involving Linux?
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_12">
- The answer is, "Yes!". The free software licenses, on which the various software packages of a distribution built on the Linux kernel are based, explicitly accommodate and encourage commercialization; the relationship between a Linux distribution as a whole and individual vendors may be seen as symbiotic. One common business model of commercial suppliers is charging for support, especially for business users. A number of companies also offer a specialized business version of their distribution, which adds proprietary support packages and tools to administer higher numbers of installations or to simplify administrative tasks. Another business model is to give away the software in order to sell hardware. Examples of corporations that are extensively (and sometimes exclusively) open-source and Linux-powered , with successful revenue generation models involving these, are Google, SUN, Mozilla, etc.
- </p>
- </div>
- <div class="section" title="1.2.5.Programming on Linux">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3000626">
- </a>
- 1.2.5.Programming on Linux
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_13">
- Most Linux distributions support dozens of programming languages. The most common collection of utilities for building both Linux applications and operating system programs is found within the GNU toolchain, which includes the GNU Compiler Collection (GCC) and the GNU build system. Amongst others, GCC provides compilers for Ada, C, C++, Java, and Fortran. The Linux kernel itself is written to be compiled with GCC. Proprietary compilers for Linux include the Intel C++ Compiler, Sun Studio, and IBM XL C/C++ Compiler.
- </p>
- <p id="ch9Using_Linux_Tools_14">
- Most distributions also include support for PHP, Perl, Ruby, Python and other dynamic languages. Examples of languages that are less common, but still supported, are C# via the Mono project, sponsored by Novell, and Scheme. A number of Java Virtual Machines and development kits run on Linux, including the original Sun Microsystems JVM (HotSpot), and IBM's J2SE RE, as well as many open-source projects like Kaffe.
- </p>
- <p id="ch9Using_Linux_Tools_15">
- The two main frameworks for developing graphical applications are those of GNOME and KDE. These projects are based on the GTK+ and Qt widget toolkits, respectively, which can also be used independently of the larger framework. Both support a wide variety of languages. There are a number of Integrated Development Environments (IDEs) available including Anjuta, Code::Blocks, Eclipse, KDevelop, Lazarus, MonoDevelop, NetBeans, and Omnis Studio while the long-established editors Vim and Emacs remain popular.
- </p>
- </div>
- </div>
- <div class="section" title="1.3.Reasons for Using Linux">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3001166">
- </a>
- 1.3.Reasons for Using Linux
- </h3>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_16">
- Linux is free:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_17">
- As in "free beer". Linux can be downloaded in its entirety from the Internet completely for free. No registration fees, no costs per user, free updates, and freely available source code in case you want to change the behavior of your system.
-Most of all, Linux is free as in "free speech":
-The license commonly used is the GNU Public License (GPL). The license says that anybody who may want to do so, has the right to change Linux and eventually to redistribute a changed version, on the one condition that the code is still available after redistribution. In practice, you are free to grab a kernel image and sell the new code, as long as your customers can still have a copy of that code.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_18">
- Linux is portable to any hardware platform:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_19">
- A vendor, who wants to sell a new type of computer and who does not know what kind of OS his/her new machine will run, can take a Linux kernel and make it work on his/her hardware, because documentation related to this activity is freely available.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_1a">
- Linux was made to keep on running:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_1b">
- As with UNIX, a Linux system expects to run without rebooting all the time. That is why a lot of tasks are being executed at night or scheduled automatically for other times, resulting in higher availability during busier periods and a more balanced use of the hardware. This property allows for Linux to be applicable to environments where people do not have the time or the possibility to control their systems constantly.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_1c">
- Linux is secure and versatile:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_1d">
- The security model used in Linux is based on the UNIX idea of security, which is known to be robust and of proven quality. But Linux is not only safe from attacks from the Internet: it will adapt equally to other situations, utilizing the same high standards for security.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_1e">
- Linux is scalable:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_1f">
- From a Palmtop with 2 MB of memory to a petabyte storage cluster with hundreds of nodes: add or remove the appropriate packages and Linux fits all. One does not need a supercomputer anymore,because you can use Linux to do big things using the building blocks provided with the system. If one wants to do little things, such as making an operating system for an embedded processor or just recycling your old 486, Linux will do that as well.
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_20">
- The Linux OS and Linux applications have very short debugtimes:
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_21">
- Because Linux has been developed and tested by thousands of people, both errors and people to fix them are found very quickly. It often happens that there are only a couple of hours between discovery and fixing of a bug.
- </p>
- </div>
- </div>
- <div class="section" title="2.Getting Started">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3001306">
- </a>
- 2.Getting Started
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="2.1.Logging in, activating the user interface and logging out">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3001315">
- </a>
- 2.1.Logging in, activating the user interface and logging out
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_22">
- In order to work on a Linux system directly, one needs to provide a user name and password. You always need to authenticate to the system. Most PCbased Linux systems have two basic modes for a system to run in: either quick and clean in text console mode,which includes with mouse, multitasking and multiuser features, or in graphical console mode, which looks better but eats more system resources.
- </p>
- <div class="section" title="2.1.1.Graphical Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3001345">
- </a>
- 2.1.1.Graphical Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_23">
- This is the default nowadays on most desktop computers. You know you will be connecting to the system using graphical mode when you are first asked for your user name, and then to type your password.
- </p>
- <p id="ch9Using_Linux_Tools_24">
- To log in, make sure the mouse pointer is in the login window, provide your user name and password to the system and click
- <span class="emphasis">
- <em>
- OK
- </em>
- </span>
- or press
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- .
-It is generally considered a bad idea to connect (graphically) using the root user name, the system adminstrator's account, since the use of graphics includes running a lot of extra programs, in root's case with a lot of extra permissions. To keep all risks as low as possible, use a normal user account to connect graphically. But there are enough risks to keep this in mind as a general advice, for all use of the root account: only log in as root when extra privileges are required.
- </p>
- <p id="ch9Using_Linux_Tools_25">
- After entering your user name/password combination, it can take a little while before the graphical environment is started, depending on the CPU speed of your computer, on the software you use and on your personal settings.
- </p>
- <p id="ch9Using_Linux_Tools_26">
- To continue, you will need to open a
- <span class="emphasis">
- <em>
- terminal window
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- for short (X being the name for the underlying software supporting the graphical environment). This program can be found in the
- <span class="emphasis">
- <em>
- Applications>Utilities->System Tools
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- Internet menu
- </em>
- </span>
- , depending on what window manager you are using. There might be icons that you can use as a shortcut to get an
- <span class="emphasis">
- <em>
- xterm
- </em>
- </span>
- window as well, and clicking the right mouse button on the desktop background will usually present you with a menu containing a terminal window application.
- </p>
- <p id="ch9Using_Linux_Tools_27">
- While browsing the menus, you will notice that a lot of things can be done without entering commands via the keyboard. For most users, the good old pointnclick method of dealing with the computer will do. But for those who want to enter the "heart" of the system, a tool stronger than a mouse will be required to handle the various tasks. This tool is the shell, and when in graphical mode, we activate our shell by opening a terminal window.
- </p>
- <p id="ch9Using_Linux_Tools_28">
- A terminal window should always show a command prompt when you open one. This terminal shows a standard prompt, which displays the user's login name, and the current working directory, represented by the twiddle (~)
- </p>
- <p id="ch9Using_Linux_Tools_29">
- Another common form for a prompt is this one:
-[
- </p>
- <div class="reference">
- <div class="titlepage">
- <hr />
- </div>
- user@host
- </div>
- <p>
- dir]
- </p>
- <p id="ch9Using_Linux_Tools_2a">
- In the above example,
- <span class="emphasis">
- <em>
- user
- </em>
- </span>
- will be your login name,
- <span class="emphasis">
- <em>
- hosts
- </em>
- </span>
- the name of the machine you are working on, and
- <span class="emphasis">
- <em>
- dir
- </em>
- </span>
- an indication of your current location in the file system. Prompts can display all kinds of information, but they are not part of the commands you are giving to your system. To disconnect from the system in graphical mode, you need to close all terminal windows and other applications. After that, hit the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- icon or find
- <span class="emphasis">
- <em>
- Log Out
- </em>
- </span>
- in the menu. Closing everything is not really necessary, and the system can do this for you, but session management might put all currently open applications back on your screen when you connect again, which takes longer and is not always the desired effect. However, this behavior is configurable.
- </p>
- <p id="ch9Using_Linux_Tools_2b">
- When you see the login screen again, asking to enter user name and password, logout was successful.
- </p>
- </div>
- <div class="section" title="2.1.2.Text Mode">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3001505">
- </a>
- 2.1.2.Text Mode
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_2c">
- One is in text mode when the whole screen is black, showing (in most cases white) characters. A text mode login screen typically shows some information about the machine you are working on, the name of the machine and a prompt waiting for you to log in.
- </p>
- <p id="ch9Using_Linux_Tools_2d">
- The login is different from a graphical login, in that you have to hit the
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- key after providing your user name, because there are no buttons on the screen that you can click with the mouse. Then you should type your password, followed by another
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- . You will not see any indication that you are entering something, not even an asterisk, and you won't see the cursor move. But this is normal on Linux and is done for security
-reasons.
- </p>
- <p id="ch9Using_Linux_Tools_2e">
- When the system has accepted you as a valid user, you may get some more information, called the
- <span class="emphasis">
- <em>
- message of the day
- </em>
- </span>
- , which can be anything. Additionally, it is popular on UNIX systems to display a fortune cookie, which contains some general wise or unwise (this is up to you) thoughts. After that, you will be given a shell, indicated with the same prompt that you would get in graphical mode.
- </p>
- <p id="ch9Using_Linux_Tools_2f">
- Also in text mode: log in as root only to do setup and configuration that absolutely requires administrator privileges, such as adding users, installing software packages, and performing network and other system configuration. Once you are finished, immediately leave the special account and resume your work as a nonprivileged user.
- </p>
- <p id="ch9Using_Linux_Tools_30">
- Logging out is done by entering the
- <span class="emphasis">
- <em>
- logout
- </em>
- </span>
- command, followed by Enter. You are successfully disconnected from the system when you see the login screen again.Don't poweroff the computer after logging out. It is not meant to be shut off without application of the proper procedures for halting the system. Powering it off without going through the halting process might cause severe damage!
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="3.Basic Commands">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3001595">
- </a>
- 3.Basic Commands
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="3.1.ls">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3001603">
- </a>
- 3.1.ls
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_31">
- When invoked without any arguments,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- lists the files in the current working directory. A directory that is not the current working directory can be specified and ls will list the files there. The user also may specify any list of files and directories. In this case, all files and all contents of specified directories will be listed. The name
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- is derived from
- <span class="emphasis">
- <em>
- list segments
- </em>
- </span>
- which was used in earlier systems.
- </p>
- <p id="ch9Using_Linux_Tools_32">
- Files whose names start with "." are not listed, unless the
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- flag is specified or the files are specified explicitly.
- </p>
- <p id="ch9Using_Linux_Tools_33">
- Without options,
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- displays files in a bare format. This bare format however makes it difficult to establish the type, permissions, and size of the files. The most common options to reveal this information or change the list of files are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_34">
- <span class="emphasis">
- <em>
- -l
- </em>
- </span>
- long format, displaying Unix file types, permissions, number of hard links, owner, group, size, date, and filename
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_35">
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- appends a character revealing the nature of a file, for example, * for an executable, or / for a directory. Regular files have no suffix.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_36">
- <span class="emphasis">
- <em>
- -a
- </em>
- </span>
- lists all files in the given directory, including those whose names start with "." (which are hidden files in Unix). By default, these files are excluded from the list.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_37">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- recursively lists subdirectories. The command ls -R / would therefore list all files.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_38">
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- shows information about a symbolic link or directory, rather than about the link's target or listing the contents of a directory.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_39">
- <span class="emphasis">
- <em>
- -t
- </em>
- </span>
- sort the list of files by modification time.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_3a">
- <span class="emphasis">
- <em>
- -h
- </em>
- </span>
- print sizes in human readable format. (e.g., 1K, 234M, 2G, etc.)
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_3b">
- In some environments, providing the option
- <span class="emphasis">
- <em>
- --color
- </em>
- </span>
- (for GNU ls) or
- <span class="emphasis">
- <em>
- -G
- </em>
- </span>
- (FreeBSD ls) causes ls to highlight different types of files with different colors, instead of with characters as
- <span class="emphasis">
- <em>
- -F
- </em>
- </span>
- would. To determine what color to use for a file, GNU
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks the Unix file type, the file permissions, and the file extension, while FreeBSD
- <span class="emphasis">
- <em>
- ls
- </em>
- </span>
- checks only the Unix file type and file permissions.:
- </p>
- <pre class="programlisting">
- $ ls
-jeeves.rst psmith.html blandings.html
-$ ls -l
-drwxr--r-- 1 plum editors 4096 jeeves
--rw-r--r-- 1 plum editors 30405 psmith
--r-xr-xr-x 1 plum plum 8460 blandings
- </pre>
- <p id="ch9Using_Linux_Tools_3c">
- Here "$" actually is the beginning of the prompt. This is typical in most Unix-based systems.
- </p>
- </div>
- <div class="section" title="3.2.date">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3001766">
- </a>
- 3.2.date
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_3d">
- The Unix date command displays the time and date. The super-user can use it to set the system clock.
- </p>
- <p id="ch9Using_Linux_Tools_3e">
- With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:
- </p>
- <pre class="programlisting">
- $date
-Tue Sep 8 12:01:45 IST 2009
- </pre>
- <p id="ch9Using_Linux_Tools_3f">
- On some systems to set the current date and time to September 8, 2004 01:22 you type:
- </p>
- <pre class="programlisting">
- $date --set="20040908 01:22"
- </pre>
- <p id="ch9Using_Linux_Tools_40">
- In order to view the various options for the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command, type:
- </p>
- <pre class="programlisting">
- $man date
- </pre>
- <p id="ch9Using_Linux_Tools_41">
- This will take you to the "Manual" page comprising of all the details on the
- <span class="emphasis">
- <em>
- date
- </em>
- </span>
- command. You can return to the terminal from the "man" page by pressing the
- <span class="emphasis">
- <em>
- Esc
- </em>
- </span>
- key in the keyboard and typing ":q" in that order.
- </p>
- </div>
- <div class="section" title="3.3.cd">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3001826">
- </a>
- 3.3.cd
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_42">
- This stands for "change directory". When one wants to go up to the parent directory, bypassing the tree of directories one has entered, cd .. can be used.
- </p>
- <p id="ch9Using_Linux_Tools_43">
- One dot '.' represents the current directory while two dots '..' represent the parent directory.
- </p>
- <p id="ch9Using_Linux_Tools_44">
- cd - will return you to the previous directory (a bit like an undo).
- </p>
- <p id="ch9Using_Linux_Tools_45">
- You can also use cd absolute path or cd relative path (see below):
- </p>
- <p id="ch9Using_Linux_Tools_46">
- Absolute paths:
- </p>
- <p id="ch9Using_Linux_Tools_47">
- An absolute path is easily recognised from the leading forward slash, /. The / means that you start at the top level directory and continue down.
- </p>
- <p id="ch9Using_Linux_Tools_48">
- For example to get to /boot/grub you would type:
- </p>
- <pre class="programlisting">
- $cd /boot/grub
- </pre>
- <p id="ch9Using_Linux_Tools_49">
- This is an absolute path because you start at the top of the hierarchy and go downwards from there (it doesn't matter where in the filesystem you were when you typed the command).
- </p>
- <p id="ch9Using_Linux_Tools_4a">
- Relative paths:
- </p>
- <p id="ch9Using_Linux_Tools_4b">
- A relative path doesn't have a preceding slash. Use a relative path when you start from a directory below the top level directory structure. This is dependent on where you are in the filesystem.
- </p>
- <p id="ch9Using_Linux_Tools_4c">
- For example if you are in root's home directory and want to get to /root/music, you type:
- </p>
- <pre class="programlisting">
- $ cd music
- </pre>
- <p id="ch9Using_Linux_Tools_4d">
- Please note that there is no / using the above cd command. Using a / would cause this to be an absolute path, working from the top of the hierarchy downward.
- </p>
- </div>
- <div class="section" title="3.4.who">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3001928">
- </a>
- 3.4.who
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_4e">
- The standard Unix command
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- displays a list of users who are currently logged into a computer.
- </p>
- <p id="ch9Using_Linux_Tools_4f">
- The
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command is related to the command
- <span class="emphasis">
- <em>
- w
- </em>
- </span>
- , which provides the same information but also displays additional data and statistics.:
- </p>
- <pre class="programlisting">
- $who
-beeblebrox tty7 2009-09-08 10:50 (:0)
-beeblebrox pts/0 2009-09-08 11:25 (:0.0)
-dumbledore pts/1 2009-09-08 18:11 (potter.xyz.in)
-beeblebrox pts/2 2009-09-08 18:53 (:0.0)
- </pre>
- <p id="ch9Using_Linux_Tools_50">
- The command can be invoked with the arguments
- <span class="emphasis">
- <em>
- am i
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- am I
- </em>
- </span>
- (so it is invoked as
- <span class="emphasis">
- <em>
- who am i
- </em>
- </span>
- or * who am I*), showing information about the current terminal only (see the
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- option below, of which this invocation is equivalent).
- </p>
- <p id="ch9Using_Linux_Tools_51">
- In order to find out the various options that can be appended to the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command, check the
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page by typing out the following in the terminal:
- </p>
- <pre class="programlisting">
- $man who
- </pre>
- <p id="ch9Using_Linux_Tools_52">
- This will take you to the "Manual" page containing details about the
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- command
- </p>
- </div>
- <div class="section" title="3.5.mkdir">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3002011">
- </a>
- 3.5.mkdir
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_53">
- This command is used to make a new directory. Normal usage is as straightforward as follows:
- </p>
- <pre class="programlisting">
- $mkdir name_of_directory
- </pre>
- <p id="ch9Using_Linux_Tools_54">
- Where
- <span class="emphasis">
- <em>
- name_of_directory
- </em>
- </span>
- is the name of the directory one wants to create. When typed as above (ie. normal usage), the new directory would be created within the current directory. On Unix, multiple directories can be specified, and
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- will try to create all of them.
- </p>
- <div class="section" title="3.5.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3002043">
- </a>
- 3.5.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_55">
- On Unix-like operating systems,
- <span class="emphasis">
- <em>
- mkdir
- </em>
- </span>
- takes options. Three of the most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_56">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- : will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_57">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- : display each directory that mkdir creates. Most often used with -p.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_58">
- <span class="emphasis">
- <em>
- -m
- </em>
- </span>
- : specify the octal permissions of directories created by mkdir.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_59">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
- </p>
- </div>
- <div class="section" title="3.5.2.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3002102">
- </a>
- 3.5.2.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_5a">
- An example of
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- in action is:
- </p>
- <pre class="programlisting">
- $mkdir -p /tmp/a/b/c
- </pre>
- <p id="ch9Using_Linux_Tools_5b">
- If
- <span class="emphasis">
- <em>
- /tmp/a
- </em>
- </span>
- exists but
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- does not, mkdir will create
- <span class="emphasis">
- <em>
- /tmp/a/b
- </em>
- </span>
- before creating
- <span class="emphasis">
- <em>
- /tmp/a/b/c
- </em>
- </span>
- .
- </p>
- <p id="ch9Using_Linux_Tools_5c">
- And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
- </p>
- <pre class="programlisting">
- $mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
- </pre>
- <p id="ch9Using_Linux_Tools_5d">
- This will create:
- </p>
- tmpdir - branches
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_5e">
- tag
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- trunk - sources - includes
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_5f">
- docs
- </p>
- </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="4.Getting Help">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3002178">
- </a>
- 4.Getting Help
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="4.1.apropos and whatis">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3002187">
- </a>
- 4.1.apropos and whatis
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_60">
- This is a command to search the manual pages files in Unix and Unix-like operating systems.
- </p>
- <pre class="programlisting">
- $ apropos grep
-egrep egrep (1) Search a file for a pattern using full regular expressions
-fgrep fgrep (1) Search a file for a fixed-character string
-fmlgrep fmlgrep (1) Search a file for a pattern
-grep grep (1) Search a file for a pattern
-gzgrep gzgrep (1) Search a possibly compressed file for a regular expression
-nisgrep nismatch (1) Utilities for searching NIS+ tables
-pgrep pgrep (1) Find or signal a process by name or other attribute
-zgrep zgrep (1) Search a possibly compressed file for a regular expression
-...
- </pre>
- <p id="ch9Using_Linux_Tools_61">
- In this example, the user uses
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- to search for the string "grep", and apropos returns the indicated
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- pages that include the term "grep".
- </p>
- <p id="ch9Using_Linux_Tools_62">
- A short index of explanations for commands is available using the
- <span class="emphasis">
- <em>
- whatis
- </em>
- </span>
- command, like in the examples below:
- </p>
- <pre class="programlisting">
- $whatis ls
-ls (1) - list directory contents
- </pre>
- <p id="ch9Using_Linux_Tools_63">
- This displays short information about a command, and the first section in the collection of man pages that contains an appropriate page.
- </p>
- <p id="ch9Using_Linux_Tools_64">
- If you don't know where to get started and which man page to read,
- <span class="emphasis">
- <em>
- apropos
- </em>
- </span>
- gives more information. Say that you do not know how to start a browser, then you could enter the following command:
- </p>
- <pre class="programlisting">
- $apropos browser
-gmusicbrowser (1) - Jukebox for large collections of audio files
-infobrowser (1) - read Info documents
-libsmbclient (7) - An extension library for browsers and that can be used...
-opera (1) - a standards-compliant graphical Web browser
-sensible-browser (1) - sensible editing, paging, and web browsing
-smbtree (1) - A text based smb network browser
-tvtk_doc (1) - A GUI based TVTK documentation search browser.
-viewres (1) - graphical class browser for Xt
-w3m (1) - a text based Web browser and pager
-www-browser (1) - a text based Web browser and pager
-...
- </pre>
- </div>
- <div class="section" title="4.2.man">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3002282">
- </a>
- 4.2.man
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_65">
- Man pages (short for "manual pages") are the extensive documentation that comes preinstalled with almost all substantial Unix and Unix-like operating systems. The Unix command used to display them is
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- . Each page is a self-contained document.
- </p>
- <p id="ch9Using_Linux_Tools_66">
- To read a manual page for a Unix command, one can use:
- </p>
- <pre class="programlisting">
- $ man <command_name>
- </pre>
- <p id="ch9Using_Linux_Tools_67">
- at a shell prompt; for example, "man ftp". In order to simplify navigation through the output,
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- generally uses the less terminal pager.
- </p>
- <p id="ch9Using_Linux_Tools_68">
- Pages are traditionally referred to using the notation "name(section)"; for example, ftp(1). The same page name may appear in more than one section of the manual, this can occur when the names of system calls, user commands, or macro packages coincide. Two examples are
- <span class="emphasis">
- <em>
- man(1)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- man(7)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- exit(2)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- exit(3)
- </em>
- </span>
- . The syntax for accessing the non-default manual section varies between different man implementations. On Linux and
- <span class="emphasis">
- <em>
- BSD, for example, the syntax for reading *printf(3)
- </em>
- </span>
- is:
- </p>
- <pre class="programlisting">
- $man 3 printf
- </pre>
- <p id="ch9Using_Linux_Tools_69">
- Another example:
- </p>
- <pre class="programlisting">
- $man man
- </pre>
- <p id="ch9Using_Linux_Tools_6a">
- The previous example will take you to the "Manual" page entry about manual pages!
- </p>
- <div class="section" title="4.2.1.Layout">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3002364">
- </a>
- 4.2.1.Layout
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_6b">
- All man pages follow a common layout that is optimized for presentation on a simple ASCII text display, possibly without any form of highlighting or font control. Sections present may include:
- </p>
- NAME
- <p id="ch9Using_Linux_Tools_6c">
- The name of the command or function, followed by a one-line description of what it does.
- </p>
- SYNOPSIS
- <p id="ch9Using_Linux_Tools_6d">
- In the case of a command, you get a formal description of how to run it and what command line options it takes. For program functions, a list of the parameters the function takes and which header file contains its definition. For experienced users, this may be all the documentation they need.
- </p>
- DESCRIPTION
- <p id="ch9Using_Linux_Tools_6e">
- A textual description of the functioning of the command or function.
- </p>
- EXAMPLES
- <p id="ch9Using_Linux_Tools_6f">
- Some examples of common usage.
- </p>
- SEE ALSO
- <p id="ch9Using_Linux_Tools_70">
- A list of related commands or functions.
- </p>
- <p id="ch9Using_Linux_Tools_71">
- Other sections may be present, but these are not well standardized across man pages. Common examples include: OPTIONS, EXIT STATUS, ENVIRONMENT, KNOWN BUGS, FILES, AUTHOR, REPORTING BUGS, HISTORY and COPYRIGHT.
- </p>
- <p id="ch9Using_Linux_Tools_72">
- These days virtually every Unix command line application comes with its man page, and many Unix users perceive a lack of man pages as a sign of low quality; indeed, some projects, such as Debian, go out of their way to write man pages for programs lacking one. Few alternatives to
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- have enjoyed much popularity, with the possible exception of the GNU project's "info" system, an early and simple hypertext system.
- </p>
- <p id="ch9Using_Linux_Tools_73">
- However, the format of a single page for each application, the lack of classification within the sections and the relatively unsophisticated formatting facilities have motivated the development of alternative documentation systems, such as the previously mentioned "info" system.
- </p>
- <p id="ch9Using_Linux_Tools_74">
- Most Unix GUI applications (particularly those built using the GNOME and KDE development environments) now provide end-user documentation in HTML and include embedded HTML viewers such as yelp for reading the help within the application.
- </p>
- <p id="ch9Using_Linux_Tools_75">
- Usually the man pages are written in English. Translations into other languages can be also available on the system.
- </p>
- <p id="ch9Using_Linux_Tools_76">
- The default format of the man pages is troff, with either the macro package man (appearance oriented) or on some systems mdoc (semantic oriented). This makes it possible to typeset a man page to PostScript, PDF and various other formats for viewing or printing.
- </p>
- </div>
- </div>
- <div class="section" title="4.3.info">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3002475">
- </a>
- 4.3.info
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_77">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- is a software utility which forms a hypertextual, multipage documentation and help viewer working on a command line interface, useful when there is no GUI available.
- </p>
- <p id="ch9Using_Linux_Tools_78">
- The syntax is
- </p>
- <pre class="programlisting">
- $ info <command_name>
- </pre>
- <p id="ch9Using_Linux_Tools_79">
- <span class="emphasis">
- <em>
- info
- </em>
- </span>
- processes info files, which are Texinfo formatted files, and presents the documentation as a tree, with simple commands to traverse the tree and to follow cross references. For instance
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_7a">
- <span class="emphasis">
- <em>
- n
- </em>
- </span>
- goes to the next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_7b">
- <span class="emphasis">
- <em>
- p
- </em>
- </span>
- goes to the previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_7c">
- <span class="emphasis">
- <em>
- u
- </em>
- </span>
- goes to the upper page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_7d">
- <span class="emphasis">
- <em>
- l
- </em>
- </span>
- goes to the last(visited) node
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_7e">
- To follow a cross reference, the cursor can be moved over a link (a word preceded by a *) and enter pressed.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_7f">
- info was initially written for use with GNU/Linux and then ported to other Unix-like operating systems.
- </p>
- </div>
- <div class="section" title="4.4.--help">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3002562">
- </a>
- 4.4.--help
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_80">
- Most GNU commands support the --help, which gives a short explanation about how to use the command and a list of available options. Below is the output of this option with the
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command:
- </p>
- <pre class="programlisting">
- $ userprompt@host: cat --help
-Usage: cat [OPTION] [FILE]...
-Concatenate FILE(s), or standard input, to standard output.
-
- -A, --show-all equivalent to -vET
- -b, --number-nonblank number nonempty output lines
- -e equivalent to -vE
- -E, --show-ends display $ at end of each line
- -n, --number number all output lines
- -s, --squeeze-blank suppress repeated empty output lines
- -t equivalent to -vT
- -T, --show-tabs display TAB characters as ^I
- -u (ignored)
- -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB
- --help display this help and exit
- --version output version information and exit
-
-With no FILE, or when FILE is -, read standard input.
-
-Examples:
- cat f - g Output f's contents, then standard input, then g's contents.
- cat Copy standard input to standard output.
-
-Report bugs to <bug-coreutils@gnu.org>.
- </pre>
- </div>
- </div>
- <div class="section" title="5.Basic file handling">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3002615">
- </a>
- 5.Basic file handling
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="5.1.cp">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3002624">
- </a>
- 5.1.cp
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_81">
- <span class="emphasis">
- <em>
- cp
- </em>
- </span>
- is the command entered in a Unix shell to copy a file from one place to another, possibly on a different filesystem. The original file remains unchanged, and the new file may have the same or a different name.
- </p>
- <div class="section" title="5.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3002641">
- </a>
- 5.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_82">
- To copy a file to another file:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ][ -- ] SourceFile TargetFile
- </pre>
- <p id="ch9Using_Linux_Tools_83">
- To copy a file to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -r | -R ] [ -- ] SourceFile ... TargetDirectory
- </pre>
- <p id="ch9Using_Linux_Tools_84">
- To copy a directory to a directory:
- </p>
- <pre class="programlisting">
- $ cp [ -f ] [ -H ] [ -i ] [ -p ] [ -- ] { -r | -R }
-SourceDirectory ... TargetDirectory
- </pre>
- </div>
- <div class="section" title="5.1.2.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3002676">
- </a>
- 5.1.2.Flags
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_85">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (force) specifies removal of the target file if it cannot be opened for write operations. The removal precedes any copying performed by the cp command.
- </p>
- <p id="ch9Using_Linux_Tools_86">
- <span class="emphasis">
- <em>
- -P
- </em>
- </span>
- makes the cp command copy symbolic links. The default is to follow symbolic links, that is, to copy files to which symbolic links point.
- </p>
- <p id="ch9Using_Linux_Tools_87">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- (interactive) prompts you with the name of a file to be overwritten. This occurs if the TargetDirectory or TargetFile parameter contains a file with the same name as a file specified in the SourceFile or SourceDirectory parameter. If you enter y or the locale's equivalent of y, the cp command continues. Any other answer prevents the cp command from overwriting the file.
- </p>
- <p id="ch9Using_Linux_Tools_88">
- <span class="emphasis">
- <em>
- -p
- </em>
- </span>
- (preserve) duplicates the following characteristics of each SourceFile/SourceDirectory in the corresponding TargetFile and/or TargetDirectory:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_89">
- The time of the last data modification and the time of the last access.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_8a">
- The user ID and group ID (only if it has permissions to do this)
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_8b">
- The file permission bits and the SUID and SGID bits.
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_8c">
- <span class="emphasis">
- <em>
- -R
- </em>
- </span>
- (recursive) copy directories (recursively copying all the contents)
- </p>
- </div>
- <div class="section" title="5.1.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3002773">
- </a>
- 5.1.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_8d">
- To make a copy of a file in the current directory, enter:
- </p>
- <pre class="programlisting">
- $ cp prog.c prog.bak
- </pre>
- <p id="ch9Using_Linux_Tools_8e">
- This copies prog.c to prog.bak. If the prog.bak file does not already exist, the cp command creates it. If it does exist, the cp command replaces it with a copy of the prog.c file.
- </p>
- <p id="ch9Using_Linux_Tools_8f">
- To copy a file in your current directory into another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod /home/books/hhgg
- </pre>
- <p id="ch9Using_Linux_Tools_90">
- This copies the jones file to /home/books/hhgg/zaphod.
- </p>
- <p id="ch9Using_Linux_Tools_91">
- To copy a file to a new file and preserve the modification date, time, and access control list associated with the source file, enter:
- </p>
- <pre class="programlisting">
- $ cp -p martin_luther_king martin_luther_king.jr
- </pre>
- <p id="ch9Using_Linux_Tools_92">
- This copies the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file to the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file. Instead of creating the file with the current date and time stamp, the system gives the
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file the same date and time as the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file. The
- <span class="emphasis">
- <em>
- martin_luther_king.jr
- </em>
- </span>
- file also inherits the
- <span class="emphasis">
- <em>
- martin_luther_king
- </em>
- </span>
- file's access control protection.
- </p>
- <p id="ch9Using_Linux_Tools_93">
- To copy all the files in a directory to a new directory, enter:
- </p>
- <pre class="programlisting">
- $ cp /home/galactica/clients/* /home/hhgg/customers
- </pre>
- <p id="ch9Using_Linux_Tools_94">
- This copies only the files in the clients directory to the customers directory.
- </p>
- <p id="ch9Using_Linux_Tools_95">
- To copy a directory, including all its files and subdirectories, to another directory, enter:
- </p>
- <p id="ch9Using_Linux_Tools_96">
- $ cp -R /home/hhgg/clients /home/hhgg/customers
- </p>
- <p id="ch9Using_Linux_Tools_97">
- This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, to the customers/clients directory.
- </p>
- <p id="ch9Using_Linux_Tools_98">
- To copy a specific set of files of any extension to another directory, enter:
- </p>
- <pre class="programlisting">
- $ cp zaphod arthur ford /home/hhgg/clients
- </pre>
- <p id="ch9Using_Linux_Tools_99">
- This copies the
- <span class="emphasis">
- <em>
- zaphod
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- arthur
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- ford
- </em>
- </span>
- files in your current working directory to the /home/hhgg/clients directory.
- </p>
- <p id="ch9Using_Linux_Tools_9a">
- To use pattern-matching characters to copy files, enter:
- </p>
- <pre class="programlisting">
- $ cp programs/*.py .
- </pre>
- <p id="ch9Using_Linux_Tools_9b">
- This copies the files in the programs directory that end with
- <span class="emphasis">
- <em>
- .py
- </em>
- </span>
- to the current directory, signified by the single "." (dot). You must type a space between the
- <span class="emphasis">
- <em>
- py
- </em>
- </span>
- and the final dot.
- </p>
- </div>
- </div>
- <div class="section" title="5.2.mv">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3002936">
- </a>
- 5.2.mv
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_9c">
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- (short for move) is a Unix command that moves one or more files or directories from one place to another. The original file is deleted, and the new file may have the same or a different name. If possible (i.e. when the original and new files are on the same file system),
- <span class="emphasis">
- <em>
- mv
- </em>
- </span>
- will rename the file instead. Write permission is required on all directories being modified.
- </p>
- <div class="section" title="5.2.1.Conflicting existing file">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3002960">
- </a>
- 5.2.1.Conflicting existing file
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_9d">
- In all cases, when a file is moved to have the name of an existing file (in the same directory), the existing file is deleted. If the existing file is not writable but is in a directory that is writable, then the mv command asks for confirmation if possible (i.e. if run from a terminal) before proceeding, unless the -f (force) option is used.
- </p>
- </div>
- <div class="section" title="5.2.2.Differences with copy and delete">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3002980">
- </a>
- 5.2.2.Differences with copy and delete
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_9e">
- Note that, usually, when moving files within the same volume, moving (and/or renaming) is not the same as simply copying and then deleting the original. When moving a file, the link is simply removed from the old parent directory and added to the new parent directory. However, the file itself is untouched (i.e. it has the same inodes and resides at the same place on the disk). For example, you cannot copy a file you cannot read, but you can move (and/or rename) it (provided you have write permission to its old and new parent directories). Also, suppose there is a non-empty directory you do not have write permission to. You cannot delete this directory (since you cannot delete its contents); but you can move (and/or rename) it. Also, since moving between filenames on a single volume does not involve copying, it is faster and does not place strain of lots of reads and writes on the disk. Moving files across different volumes, however, does necessitate copying and deleting.
- </p>
- </div>
- <div class="section" title="5.2.3.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3003010">
- </a>
- 5.2.3.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ mv myfile mynewfilename renames a file
-$ mv myfile otherfilename renames a file and deletes the existing file "myfile"
-$ mv myfile /myfile moves 'myfile' from the current directory to the root directory
-$ mv myfile dir/myfile moves 'myfile' to 'dir/myfile' relative to the current directory
-$ mv myfile dir same as the previous command (the filename is implied to be the same)
-$ mv myfile dir/myfile2 moves 'myfile' to dir and renames it to 'myfile2'
-$ mv foo bar baz dir moves multiple files to directory dir
-$ mv --help shows a very concise help about the syntax of the command
-$ man mv prints an extensive user manual for 'mv' in the terminal
- </pre>
- <p id="ch9Using_Linux_Tools_9f">
- In all cases, the file or files being moved or renamed can be a directory.
- </p>
- <p id="ch9Using_Linux_Tools_a0">
- Note that when the command is called with two arguments (as
- <span class="emphasis">
- <em>
- mv name1 name2
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- mv name1 /dir/name2
- </em>
- </span>
- ), it can have three different effects, depending on whether
- <span class="emphasis">
- <em>
- name2
- </em>
- </span>
- does not exist, is an existing file, or is an existing directory. If the user intends to refer to an existing directory,
- <span class="emphasis">
- <em>
- /.
- </em>
- </span>
- (or in some Unix versions
- <span class="emphasis">
- <em>
- /
- </em>
- </span>
- is sufficient) may be appended to the name to force the system to check this. To move a file to a new directory, the directory must be created first.
- </p>
- </div>
- </div>
- <div class="section" title="5.3.rm">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3003069">
- </a>
- 5.3.rm
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_a1">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- (short for "remove") is one of several basic Unix command lines that operates on files. It is used to delete files from a filesystem. The data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused.
- </p>
- <p id="ch9Using_Linux_Tools_a2">
- Here's example to remove a file named "foo" from a directory, here shown with the -i option:
- </p>
- <pre class="programlisting">
- $ rm -i foo
-remove foo? y
- </pre>
- <div class="section" title="5.3.1.Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3003099">
- </a>
- 5.3.1.Options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_a3">
- Common options that rm accepts include:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_a4">
- <span class="emphasis">
- <em>
- -r
- </em>
- </span>
- , which removes directories, removing the contents recursively beforehand (so as not to leave files without a directory to reside in) ("recursive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_a5">
- <span class="emphasis">
- <em>
- -i
- </em>
- </span>
- , which asks for every deletion to be confirmed ("interactive")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_a6">
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- , which ignores non-existent files and overrides any confirmation prompts ("force")
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_a7">
- <span class="emphasis">
- <em>
- -v
- </em>
- </span>
- , which shows what is being removed as it happens ("verbose")
- </p>
- </li>
- </ul>
- </div>
- <p id="ch9Using_Linux_Tools_a8">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often aliased to "rm -i" so as to avoid accidental deletion of files. If a user still wishes to delete a large number of files without confirmation, they can manually cancel out the -i argument by adding the -f option (as the option specified later on the expanded command line "rm -i -f" takes precedence).
- </p>
- <p id="ch9Using_Linux_Tools_a9">
- <span class="emphasis">
- <em>
- rm -rf
- </em>
- </span>
- (variously, rm -rf /, rm -rf *, and others) is frequently used in jokes and anecdotes about Unix disasters. The rm -rf variant of the command, if run by a superuser on the root directory, would cause the contents of every writable mounted filesystem on the computer to be deleted.
- </p>
- <p id="ch9Using_Linux_Tools_aa">
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is often used in conjunction with xargs to supply a list of files to delete:
- </p>
- <pre class="programlisting">
- xargs rm < filelist
- </pre>
- <p id="ch9Using_Linux_Tools_ab">
- When
- <span class="emphasis">
- <em>
- rm
- </em>
- </span>
- is used on a symbolic link, it deletes the link, but does not affect the target of the link.
- </p>
- </div>
- <div class="section" title="5.3.2.Permissions">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3003197">
- </a>
- 5.3.2.Permissions
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_ac">
- Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)
- </p>
- <p id="ch9Using_Linux_Tools_ad">
- To delete a directory (with rm -r), one must delete all of its contents recursively. This requires that one must have read and write and execute permission to that directory (if it's not empty) and all non-empty subdirectories recursively (if there are any). The read permissions are needed to list the contents of the directory in order to delete them. This sometimes leads to an odd situation where a non-empty directory cannot be deleted because one doesn't have write permission to it and so cannot delete its contents; but if the same directory were empty, one would be able to delete it.
- </p>
- <p id="ch9Using_Linux_Tools_ae">
- If a file resides in a directory with the sticky bit set, then deleting the file requires one to be the owner of the file.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="6.Command Line Arguments">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3003237">
- </a>
- 6.Command Line Arguments
- </h2>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_af">
- In computer command line interfaces, a command line argument is an argument sent to a program being called. In general, a program can take any number of command line arguments, which may be necessary for the program to run, or may even be ignored, depending on the function of that program.
- </p>
- <p id="ch9Using_Linux_Tools_b0">
- For example, in Unix and Unix-like environments, an example of a command-line argument is:
- </p>
- <pre class="programlisting">
- rm file.s
- </pre>
- <p id="ch9Using_Linux_Tools_b1">
- "file.s" is a command line argument which tells the program rm to remove the file "file.s".
- </p>
- <p id="ch9Using_Linux_Tools_b2">
- Programming languages such as C, C++ and Java allow a program to interpret the command line arguments by handling them as string parameters in the main function.
- </p>
- <p id="ch9Using_Linux_Tools_b3">
- A command line option or simply
- <span class="emphasis">
- <em>
- option
- </em>
- </span>
- (also known as a command line parameter, flag, or a switch) is an indication by a user that a computer program should change its default output.
- </p>
- <p id="ch9Using_Linux_Tools_b4">
- Long options are introduced via "--", and are typically whole words. For example,
- <span class="emphasis">
- <em>
- ls --long --classify --all
- </em>
- </span>
- . Arguments to long options are provided with "=", as
- <span class="emphasis">
- <em>
- ls --block-size=1024
- </em>
- </span>
- . Some Unix programs use long options with single dashes, for example MPlayer as in
- <span class="emphasis">
- <em>
- mplayer -nosound
- </em>
- </span>
- .
- </p>
- <p id="ch9Using_Linux_Tools_b5">
- Linux also uses "--" to terminate option lists. For example, an attempt to delete a file called
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- by using
- <span class="emphasis">
- <em>
- rm -file1
- </em>
- </span>
- may produce an error, since rm may interpret
- <span class="emphasis">
- <em>
- -file1
- </em>
- </span>
- as a command line switch. Using
- <span class="emphasis">
- <em>
- rm -- -file1
- </em>
- </span>
- removes ambiguity.
- </p>
- </div>
- <div class="section" title="7.Basic Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3003330">
- </a>
- 7.Basic Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="7.1.head">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3003339">
- </a>
- 7.1.head
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_b6">
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the first few lines of a text file or piped data. The command syntax is:
- </p>
- <pre class="programlisting">
- $ head [options] <file_name>
- </pre>
- <p id="ch9Using_Linux_Tools_b7">
- By default,
- <span class="emphasis">
- <em>
- head
- </em>
- </span>
- will print the first 10 lines of its input to the standard output. The number of lines printed may be changed with a command line option. The following example shows the first 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ head -n 20 filename
- </pre>
- <p id="ch9Using_Linux_Tools_b8">
- This displays the first 5 lines of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ head -n 5 foo*
- </pre>
- <p id="ch9Using_Linux_Tools_b9">
- Some versions omit the n and just let you say -5.
- </p>
- <div class="section" title="7.1.1.Flags">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3003390">
- </a>
- 7.1.1.Flags
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- -c <x number of bytes> Copy first x number of bytes.
- </pre>
- <p id="ch9Using_Linux_Tools_ba">
- Other options:
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- </p>
- <p id="ch9Using_Linux_Tools_bb">
- Many early versions of Unix did not have this command, and so documentation and books had
- <span class="emphasis">
- <em>
- sed
- </em>
- </span>
- do this job:
- </p>
- <pre class="programlisting">
- sed 5q foo
- </pre>
- <p id="ch9Using_Linux_Tools_bc">
- This says to print every line (implicit), and quit after the fifth.
- </p>
- </div>
- </div>
- <div class="section" title="7.2.tail">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3003426">
- </a>
- 7.2.tail
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_bd">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- is a program on Unix and Unix-like systems used to display the last few lines of a text file or piped data.
- </p>
- <p id="ch9Using_Linux_Tools_be">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ tail [options] <file_name>
- </pre>
- <p id="ch9Using_Linux_Tools_bf">
- By default,
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- will print the last 10 lines of its input to the standard output. With command line options the number of lines printed and the printing units (lines, blocks or bytes) may be changed. The following example shows the last 20 lines of filename:
- </p>
- <pre class="programlisting">
- $ tail -n 20 filename
- </pre>
- <p id="ch9Using_Linux_Tools_c0">
- This example shows the last 15 bytes of all files starting with
- <span class="emphasis">
- <em>
- foo
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ tail -c 15 foo*
- </pre>
- <p id="ch9Using_Linux_Tools_c1">
- This example shows all lines of filename from the second line onwards:
- </p>
- <pre class="programlisting">
- $ tail -n +2 filename
- </pre>
- <p id="ch9Using_Linux_Tools_c2">
- Using an older syntax (still used in Sun Solaris as the -n option is not supported), the last 20 lines and the last 50 bytes of filename can be shown with the following command:
- </p>
- <pre class="programlisting">
- $ tail -20 filename
-$ tail -50c filename
- </pre>
- <p id="ch9Using_Linux_Tools_c3">
- However this syntax is now obsolete and does not conform with the POSIX 1003.1-2001 standard. Even if still supported in current versions, when used with other options (like -f, see below), these switches could not work at all.
- </p>
- <div class="section" title="7.2.1.File monitoring">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3003504">
- </a>
- 7.2.1.File monitoring
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_c4">
- <span class="emphasis">
- <em>
- tail
- </em>
- </span>
- has a special command line option
- <span class="emphasis">
- <em>
- -f
- </em>
- </span>
- (follow) that allows a file to be monitored. Instead of displaying the last few lines and exiting, tail displays the lines and then monitors the file. As new lines are added to the file by another process, tail updates the display. This is particularly useful for monitoring log files. The following command will display the last 10 lines of messages and append new lines to the display as new lines are added to messages:
- </p>
- <pre class="programlisting">
- $ tail -f /var/adm/messages
- </pre>
- <p id="ch9Using_Linux_Tools_c5">
- To interrupt tail while it is monitoring, break-in with
- <span class="emphasis">
- <em>
- Ctrl+C
- </em>
- </span>
- . This command can be run "in the background" with &, see job control.
- </p>
- <p id="ch9Using_Linux_Tools_c6">
- If you have a command's result to monitor, you can use the
- <span class="emphasis">
- <em>
- watch
- </em>
- </span>
- command.
- </p>
- </div>
- </div>
- <div class="section" title="7.3.cut">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3003554">
- </a>
- 7.3.cut
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_c7">
- In computing,
- <span class="emphasis">
- <em>
- cut
- </em>
- </span>
- is a Unix command line utility which is used to extract sections from each line of input usually from a file.
- </p>
- <p id="ch9Using_Linux_Tools_c8">
- Extraction of line segments can typically be done by
- <span class="emphasis">
- <em>
- bytes (-b), characters (-c)
- </em>
- </span>
- , or
- <span class="emphasis">
- <em>
- fields (-f)
- </em>
- </span>
- separated by a
- <span class="emphasis">
- <em>
- delimiter (-d the tab character by default)
- </em>
- </span>
- . A range must be provided in each case which consists of one of N, N-M, N- (N to the end of the line), or -M (beginning of the line to M), where N and M are counted from 1 (there is no zeroth value). Since version 6, an error is thrown if you include a zeroth value. Prior to this the value was ignored and assumed to be 1.
- </p>
- <p id="ch9Using_Linux_Tools_c9">
- Assuming a file named file containing the lines:
- </p>
- <pre class="programlisting">
- foo:bar:baz:qux:quux
-one:two:three:four:five:six:seven
-alpha:beta:gamma:delta:epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- <p id="ch9Using_Linux_Tools_ca">
- To output the fourth through tenth characters of each line:
- </p>
- <pre class="programlisting">
- $ cut -c 4-10 file
- </pre>
- <p id="ch9Using_Linux_Tools_cb">
- This gives the output:
- </p>
- <pre class="programlisting">
- :bar:ba
-:two:th
-ha:beta
- </pre>
- <p id="ch9Using_Linux_Tools_cc">
- To output the fifth field through the end of the line of each line using the colon character as the field delimiter:
- </p>
- <pre class="programlisting">
- $ cut -d : -f 5- file
- </pre>
- <p id="ch9Using_Linux_Tools_cd">
- This gives the output:
- </p>
- <pre class="programlisting">
- quux
-five:six:seven
-epsilon:zeta:eta:teta:iota:kappa:lambda:mu
- </pre>
- </div>
- <div class="section" title="7.4.paste">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3003640">
- </a>
- 7.4.paste
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_ce">
- <span class="emphasis">
- <em>
- paste
- </em>
- </span>
- is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. It is effectively the horizontal equivalent to the utility
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command which operates on the vertical plane of two or more files.
- </p>
- <p id="ch9Using_Linux_Tools_cf">
- To paste several columns of data together into the file
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- from files
- <span class="emphasis">
- <em>
- who
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- where
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- when
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- $ paste who where when > www
- </pre>
- <p id="ch9Using_Linux_Tools_d0">
- If the files contain:
- </p>
- <table summary="paste" border="1">
- <colgroup>
- <col width="11">
- </col>
- <col width="12">
- </col>
- <col width="12">
- </col>
- </colgroup>
- </table>
- <p id="ch9Using_Linux_Tools_dd">
- This creates the file named
- <span class="emphasis">
- <em>
- www
- </em>
- </span>
- containing:
- </p>
- <pre class="programlisting">
- Batman GothamCity January 3
-Trillian Andromeda February 4
-Jeeves London March 19
- </pre>
- </div>
- </div>
- <div class="section" title="8.Shell Meta Characters">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3003775">
- </a>
- 8.Shell Meta Characters
- </h2>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_de">
- Unix recognizes certain special characters, called "meta characters," as command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command.
- </p>
- <p id="ch9Using_Linux_Tools_df">
- The shell meta characters include:
- </p>
- <p id="ch9Using_Linux_Tools_e0">
- / < > ! $ % ^ & * | { } [ ] " ' ` ~ ;
- </p>
- <p id="ch9Using_Linux_Tools_e1">
- Different shells may differ in the meta characters recognized.
- </p>
- <p id="ch9Using_Linux_Tools_e2">
- As an example,
- </p>
- <pre class="programlisting">
- $ ls file.*
- </pre>
- <p id="ch9Using_Linux_Tools_e3">
- run on a directory containing the files file, file.c, file.lst, and myfile would list the files file.c and file.lst. However,:
- </p>
- <pre class="programlisting">
- $ ls file.?
- </pre>
- <p id="ch9Using_Linux_Tools_e4">
- run on the same directory would only list file.c because the ? only matches one character, no more, no less. This can save you a great deal of typing time. For example, if there is a file called california_cornish_hens_with_wild_rice and no other files whose names begin with 'c', you could view the file without typing the whole name by typing this:
- </p>
- <pre class="programlisting">
- $ more c*
- </pre>
- <p id="ch9Using_Linux_Tools_e5">
- because the c* matches that long file name.
- </p>
- <p id="ch9Using_Linux_Tools_e6">
- Filenames containing metacharacters can pose many problems and should never be intentionally created. If you do find that you've created a file with metacharacters, and you would like to remove it, you have three options. You may use wildcards to match metacharacter, use the to directly enter the filename, or put the command in double quotes (except in the case of double quotes within the file name, these must be captured with one of the first two methods). For example, deleting a file named "``*`|more"` can be accomplished with:
- </p>
- <pre class="programlisting">
- $ rm ??more
- </pre>
- <p id="ch9Using_Linux_Tools_e7">
- or:
- </p>
- <pre class="programlisting">
- $ rm $\backslash$*$\backslash$|more
- </pre>
- <p id="ch9Using_Linux_Tools_e8">
- or:
- </p>
- <pre class="programlisting">
- $ rm ''*|more''
- </pre>
- </div>
- <div class="section" title="9.Looking At Files">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3003880">
- </a>
- 9.Looking At Files
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="9.1.cat">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3003888">
- </a>
- 9.1.cat
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_e9">
- The
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- command is a standard Unix program used to concatenate and display files. The name is from "catenate", a synonym of
- <span class="emphasis">
- <em>
- concatenate
- </em>
- </span>
- .
- </p>
- <p id="ch9Using_Linux_Tools_ea">
- The Single Unix Specification specifies the behavior that the contents of each of the files given in sequence as arguments will be written to the standard output in the same sequence, and mandates one option, -u, where each byte is printed as it is read.
- </p>
- <p id="ch9Using_Linux_Tools_eb">
- If the filename is specified as -, then
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input at that point in the sequence. If no files are specified,
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- will read from standard input entered.
- </p>
- <div class="section" title="9.1.1.Jargon File Definition">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3003932">
- </a>
- 9.1.1.Jargon File Definition
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_ec">
- The Jargon File version 4.4.7 lists this as the definition of
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- :
- </p>
- <pre class="programlisting">
- 1. To spew an entire file to the screen or some other output sink without
- pause (syn. blast).
-
-2. By extension, to dump large amounts of data at an unprepared target or
- with no intention of browsing it carefully. Usage: considered silly.
- Rare outside Unix sites. See also dd, BLT.
-
- Among Unix fans, *cat(1)* is considered an excellent example of
- user-interface design, because it delivers the file contents without
- such verbosity as spacing or headers between the files, and because
- it does not require the files to consist of lines of text, but works
- with any sort of data.
-
- Among Unix critics, *cat(1)* is considered the canonical example of
- bad user-interface design, because of its woefully unobvious name.
- It is far more often used to blast a single file to standard output
- than to concatenate two or more files. The name cat for the former
- operation is just as unintuitive as, say, LISP's cdr.
-
- Of such oppositions are holy wars made...
- </pre>
- </div>
- <div class="section" title="9.1.2.Useless Use of 'cat'">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3003971">
- </a>
- 9.1.2.Useless Use of 'cat'
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_ed">
- UUOC (from comp.unix.shell on Usenet) stands for Useless Use of cat. As it is observed on
- <span class="emphasis">
- <em>
- comp.unix.shell
- </em>
- </span>
- , The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
- </p>
- <p id="ch9Using_Linux_Tools_ee">
- Nevertheless one sees people doing:
- </p>
- <pre class="programlisting">
- $ cat file | some_command and its args ...
- </pre>
- <p id="ch9Using_Linux_Tools_ef">
- instead of the equivalent and cheaper:
- </p>
- <pre class="programlisting">
- <file some_command and its args ...
- </pre>
- <p id="ch9Using_Linux_Tools_f0">
- or (equivalently and more classically):
- </p>
- <pre class="programlisting">
- some_command and its args ... <file
- </pre>
- <p id="ch9Using_Linux_Tools_f1">
- Since 1995, occasional awards for UUOC have been given out. The activity of fixing instances of UUOC is sometimes called 'demoggification'.
- </p>
- <p id="ch9Using_Linux_Tools_f2">
- Amongst many, it is still considered safer to use
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- for such cases given that the < and > keys are next to each other in many popular keyboard mappings. While the risk might be low, the impact of using > instead of < can be high and prohibitive.
- </p>
- </div>
- <div class="section" title="9.1.3.zcat">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3004043">
- </a>
- 9.1.3.zcat
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_f3">
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- is a Unix program similar to
- <span class="emphasis">
- <em>
- cat
- </em>
- </span>
- , that decompresses individual files and concatenates them to standard output. Traditionally
- <span class="emphasis">
- <em>
- zcat
- </em>
- </span>
- operated on files compressed by compress but today it is usually able to operate on
- <span class="emphasis">
- <em>
- gzip
- </em>
- </span>
- or even
- <span class="emphasis">
- <em>
- bzip2
- </em>
- </span>
- archives. On such systems, it is equivalent to
- <span class="emphasis">
- <em>
- gunzip -c
- </em>
- </span>
- </p>
- </div>
- </div>
- <div class="section" title="9.2.more">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3004076">
- </a>
- 9.2.more
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_f4">
- In computing,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). It is available on Unix and Unix-like systems, DOS, OS/2 and Microsoft Windows. Programs of this sort are called pagers.
- </p>
- <div class="section" title="9.2.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3004096">
- </a>
- 9.2.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_f5">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ more [options] [file_name]
- </pre>
- <p id="ch9Using_Linux_Tools_f6">
- If no file name is provided,
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- looks for input from stdin.
- </p>
- <p id="ch9Using_Linux_Tools_f7">
- Once
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has obtained input, it displays as much as can fit on the current screen and waits for user input to advance, with the exception that a form feed (^L) will also cause
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- to wait at that line, regardless of the amount of text on the screen. In the lower-left corner of the screen is displayed the text "--More--" and a percentage, representing the percent of the file that
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- has paged through. (This percentage includes the text displayed on the current screen.) When
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- reaches the end of a file (100%) it exits. The most common methods of navigating through a file are
- <span class="emphasis">
- <em>
- Enter
- </em>
- </span>
- , which advances the output by one line, and
- <span class="emphasis">
- <em>
- Space
- </em>
- </span>
- , which advances the output by one screen.
- </p>
- <p id="ch9Using_Linux_Tools_f8">
- There are also other commands that can be used while navigating through the document; consult
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- 's
- <span class="emphasis">
- <em>
- man
- </em>
- </span>
- page for more details.
- </p>
- <p id="ch9Using_Linux_Tools_f9">
- <span class="emphasis">
- <em>
- Options
- </em>
- </span>
- are typically entered before the file name, but can also be entered in the environment variable
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- . Options entered in the actual command line will override those entered in the
- <span class="emphasis">
- <em>
- $MORE
- </em>
- </span>
- environment variable. Available options may vary between Unix systems.
- </p>
- </div>
- </div>
- <div class="section" title="9.3.less">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3004187">
- </a>
- 9.3.less
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_fa">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is a terminal pager program on Unix, Windows and Unix-like systems used to view (but not change) the contents of a text file one screen at a time. It is similar to
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- , but has the extended capability of allowing both forward and backward navigation through the file. Unlike most Unix text editors/viewers,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- does not need to read the entire file before starting, resulting in faster load times with large files.
- </p>
- <div class="section" title="9.3.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3004216">
- </a>
- 9.3.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_fb">
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- can be invoked with options to change its behaviour, for example, the number of lines to display on the screen. A few options vary depending on the operating system. While
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- is displaying the file, various commands can be used to navigate through the file. These commands are based on those used by both
- <span class="emphasis">
- <em>
- more
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- vi
- </em>
- </span>
- . It is also possible to search for character patterns in the file.
- </p>
- <p id="ch9Using_Linux_Tools_fc">
- By default,
- <span class="emphasis">
- <em>
- less
- </em>
- </span>
- displays the contents of the file to the standard output (one screen at a time). If the file name argument is omitted, it displays the contents from standard input (usually the output of another command through a pipe). If the output is redirected to anything other than a terminal, for example a pipe to another command, less behaves like cat.
- </p>
- <p id="ch9Using_Linux_Tools_fd">
- The command-syntax is:
- </p>
- <pre class="programlisting">
- $ less [options] file_name
- </pre>
- </div>
- <div class="section" title="9.3.2.Frequently Used Options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3004271">
- </a>
- 9.3.2.Frequently Used Options
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_fe">
- -g: Highlights just the current match of any searched string.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_ff">
- -I: Case-insensitive searches.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_100">
- -M: Shows more detailed prompt, including file position.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_101">
- -N: Shows line numbers (useful for source code viewing).
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_102">
- -S: Disables line wrap ("chop long lines"). Long lines can be seen by side scrolling.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_103">
- -?: Shows help.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.3.Frequently Used Commands">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3004323">
- </a>
- 9.3.3.Frequently Used Commands
- </h4>
- </div>
- </div>
- </div>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_104">
- [Arrows]/[Page Up]/[Page Down]/[Home]/[End]: Navigation.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_105">
- [Space bar]: Next page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_106">
- b: Previous page.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_107">
- ng: Jump to line number n. Default is the start of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_108">
- nG: Jump to line number n. Default is the end of the file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_109">
- /pattern: Search for pattern. Regular expressions can be used.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_10a">
- '^ or g: Go to start of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_10b">
- '$ or G: Go to end of file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_10c">
- s: Save current content (got from another program like grep) in a file.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_10d">
- =: File information.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_10e">
- h: Help.
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_10f">
- q: Quit.
- </p>
- </li>
- </ul>
- </div>
- </div>
- <div class="section" title="9.3.4.Examples">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3004413">
- </a>
- 9.3.4.Examples
- </h4>
- </div>
- </div>
- </div>
- <pre class="programlisting">
- $ less -M readme.txt #Read "readme.txt."
-$ less +F /var/log/mail.log #Follow mode for log
-$ file * | less #Easier file analysis.
-$ grep -i void *.c | less -I -p void #Case insensitive search for "void" in all .c files
- </pre>
- </div>
- </div>
- </div>
- <div class="section" title="10.Directory Structure">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3004428">
- </a>
- 10.Directory Structure
- </h2>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_110">
- In the File Hierarchy Standard (FHS) all files and directories appear under the root directory "/", even if they are stored on different physical devices. Note however that some of these directories may or may not be present on a Unix system depending on whether certain subsystems, such as the X Window System, are installed.
- </p>
- <p id="ch9Using_Linux_Tools_111">
- The majority of these directories exist in all UNIX operating systems and are generally used in much the same way; however, the descriptions here are those used specifically for the FHS, and are not considered authoritative for platforms other than Linux.
- </p>
- <table summary="Directory Structure" border="1">
- <colgroup>
- <col width="15">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <div class="section" title="10.1.man hier">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3004703">
- </a>
- 10.1.man hier
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_136">
- This is the manual page on the UNIX filesystem. The syntax for this is:
- </p>
- <pre class="programlisting">
- $ man hier
- </pre>
- </div>
- <div class="section" title="10.2.ls -l">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3004719">
- </a>
- 10.2.ls -l
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_137">
- Shows you huge amounts of information (permissions, owners, size, and when last modified) for folders and files. The syntax is
- </p>
- <pre class="programlisting">
- $ ls -l
- </pre>
- <p id="ch9Using_Linux_Tools_138">
- This can be done after entering the required directory.
- </p>
- </div>
- </div>
- <div class="section" title="11.Permissions and Ownership">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3004742">
- </a>
- 11.Permissions and Ownership
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="11.1.chmod">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3004751">
- </a>
- 11.1.chmod
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_139">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command (abbreviated from 'change mode') is a shell command and C language function in Unix and Unix-like environments. When executed, it can change file system modes of files and directories. The modes include permissions and special modes.A chmod command first appeared in AT&T Unix version 1, and is still used today on Unix-like machines.
- </p>
- <div class="section" title="11.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3004777">
- </a>
- 11.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_13a">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command options are specified like this:
- </p>
- <pre class="programlisting">
- $ chmod [options] mode[,mode] file1 [file2 ...]
- </pre>
- <p id="ch9Using_Linux_Tools_13b">
- To view what the permissions currently are, type:
- </p>
- <pre class="programlisting">
- $ ls -l file
- </pre>
- </div>
- <div class="section" title="11.1.2.Command line options">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3004805">
- </a>
- 11.1.2.Command line options
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_13c">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command has a number of command line options that affect its behavior. The most common options are:
- </p>
- <div class="itemizedlist">
- <ul class="itemizedlist" type="*">
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_13d">
- -R: Changes the modes of directories and files recursively
- </p>
- </li>
- <li class="listitem" style="list-style-type: *">
- <p id="ch9Using_Linux_Tools_13e">
- -v: Verbose mode; lists all files as they are being processed
- </p>
- </li>
- </ul>
- </div>
- <div class="section" title="11.1.2.1.Symbolic modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id3004841">
- </a>
- 11.1.2.1.Symbolic modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_13f">
- To the
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
- </p>
- <pre class="programlisting">
- $ chmod [references][operator][modes] file1 ...
- </pre>
- <p id="ch9Using_Linux_Tools_140">
- The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to all but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="8">
- </col>
- <col width="45">
- </col>
- </colgroup>
- </table>
- <p id="ch9Using_Linux_Tools_150">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="14">
- </col>
- <col width="54">
- </col>
- </colgroup>
- </table>
- <p id="ch9Using_Linux_Tools_157">
- The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
- </p>
- <table summary="Symbolic modes" border="1">
- <colgroup>
- <col width="5">
- </col>
- <col width="14">
- </col>
- <col width="48">
- </col>
- </colgroup>
- </table>
- <p id="ch9Using_Linux_Tools_16d">
- The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
- </p>
- </div>
- <div class="section" title="11.1.2.2.Symbolic examples">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id3005402">
- </a>
- 11.1.2.2.Symbolic examples
- </h5>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_16e">
- Add the 'read' and 'write' permissions to the 'user' and 'group' classes of a directory:
- </p>
- <pre class="programlisting">
- $ chmod ug+rw mydir
-$ ls -ld mydir
-drw-rw---- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- <p id="ch9Using_Linux_Tools_16f">
- For a file, remove
- <span class="emphasis">
- <em>
- write
- </em>
- </span>
- permissions for all classes:
- </p>
- <pre class="programlisting">
- $ chmod a-w myfile
-$ ls -l myfile
--r-xr-xr-x 2 starwars yoda 96 Dec 8 12:53 myfile
- </pre>
- <p id="ch9Using_Linux_Tools_170">
- Set the permissions for the
- <span class="emphasis">
- <em>
- u*ser and the *g*roup to read and execute only (no write permission) on *mydir
- </em>
- </span>
- .
- </p>
- <pre class="programlisting">
- $ chmod ug=rx mydir
-$ ls -ld mydir
-dr-xr-x--- 2 starwars yoda 96 Dec 8 12:53 mydir
- </pre>
- </div>
- <div class="section" title="11.1.2.3.Octal numbers">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id3005445">
- </a>
- 11.1.2.3.Octal numbers
- </h5>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_171">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command also accepts three and four-digit octal numbers representing modes. Using a three-digit octal number to set the modes of a file named myfile :
- </p>
- <pre class="programlisting">
- $ chmod 664 myfile
-$ ls -l myfile
--rw-rw-r-- 1 57 Jul 3 10:13 myfile
- </pre>
- <p id="ch9Using_Linux_Tools_172">
- Since the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- sticky
- </em>
- </span>
- bits are not set, this is equivalent to:
- </p>
- <pre class="programlisting">
- $ chmod 0664 myfile
- </pre>
- </div>
- <div class="section" title="11.1.2.4.Special modes">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id3005484">
- </a>
- 11.1.2.4.Special modes
- </h5>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_173">
- The
- <span class="emphasis">
- <em>
- chmod
- </em>
- </span>
- command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use
- <span class="strong">
- <strong>
- s
- </strong>
- </span>
- to represent the
- <span class="emphasis">
- <em>
- setuid
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- setgid
- </em>
- </span>
- modes, and
- <span class="strong">
- <strong>
- t
- </strong>
- </span>
- to represent the sticky mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.
- </p>
- <p id="ch9Using_Linux_Tools_174">
- Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used.
- </p>
- </div>
- </div>
- </div>
- </div>
- <div class="section" title="12.Redirection and Piping">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3005528">
- </a>
- 12.Redirection and Piping
- </h2>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_175">
- In computing,
- <span class="emphasis">
- <em>
- redirection
- </em>
- </span>
- is a function common to most command-line interpreters, including the various Unix shells that can redirect standard streams to user-specified locations.
- </p>
- <p id="ch9Using_Linux_Tools_176">
- Programs do redirection with the
- <span class="emphasis">
- <em>
- dup2(2)
- </em>
- </span>
- system call, or its less-flexible but higher-level stdio analogues,
- <span class="emphasis">
- <em>
- freopen(3)
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- popen(3)
- </em>
- </span>
- .
- </p>
- <div class="section" title="12.1.Redirecting standard input and standard output">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3005563">
- </a>
- 12.1.Redirecting standard input and standard output
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_177">
- Redirection is usually implemented by placing certain characters between commands. Typically, the syntax of these characters is as follows:
- </p>
- <pre class="programlisting">
- $ command1 > file1
- </pre>
- <p id="ch9Using_Linux_Tools_178">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , placing the output in file1. Note that this will truncate any existing data in
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- . To append output to the end of the file, use the >> operator.:
- </p>
- <pre class="programlisting">
- $ command1 < file1
- </pre>
- <p id="ch9Using_Linux_Tools_179">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- as the source of input (as opposed to the keyboard).:
- </p>
- <pre class="programlisting">
- $ command1 < infile > outfile
- </pre>
- <p id="ch9Using_Linux_Tools_17a">
- combines the two capabilities:
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- reads from
- <span class="emphasis">
- <em>
- infile
- </em>
- </span>
- and writes to
- <span class="emphasis">
- <em>
- outfile
- </em>
- </span>
- </p>
- </div>
- <div class="section" title="12.2.Piping">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3005633">
- </a>
- 12.2.Piping
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_17b">
- Programs can be run together such that one program reads the output from another with no need for an explicit intermediate file:
-A pipeline of three programs run on a text terminal:
- </p>
- <pre class="programlisting">
- $ command1 | command2
- </pre>
- <p id="ch9Using_Linux_Tools_17c">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , using its output as the input for
- <span class="emphasis">
- <em>
- command2
- </em>
- </span>
- (commonly called piping, since the "|" character is known as a "pipe").
- </p>
- <p id="ch9Using_Linux_Tools_17d">
- This is equivalent to using two redirects and a temporary file:
- </p>
- <pre class="programlisting">
- $ command1 > tempfile
-$ command2 < tempfile
-$ rm tempfile
- </pre>
- <p id="ch9Using_Linux_Tools_17e">
- A good example for command piping is combining
- <span class="emphasis">
- <em>
- echo
- </em>
- </span>
- with another command to achieve something interactive in a non-interactive shell, e.g.:
- </p>
- <pre class="programlisting">
- $ echo -e "user\npass" | ftp localhost
- </pre>
- <p id="ch9Using_Linux_Tools_17f">
- This runs the ftp client with input user, press return, then pass.
- </p>
- </div>
- <div class="section" title="12.3.Redirecting to and from the standard file handles">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3005695">
- </a>
- 12.3.Redirecting to and from the standard file handles
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_180">
- In Unix shells derived from the original Bourne shell, the first two actions can be further modified by placing a number (the file descriptor) immediately before the character; this will affect which stream is used for the redirection. The Unix standard I/O streams are:
- </p>
- <table summary="Redirecting to and from the standard file handles" border="1">
- <colgroup>
- <col width="12">
- </col>
- <col width="13">
- </col>
- <col width="24">
- </col>
- </colgroup>
- </table>
- <p id="ch9Using_Linux_Tools_18d">
- For example:
- </p>
- <pre class="programlisting">
- $ command1 2> file1
- </pre>
- <p id="ch9Using_Linux_Tools_18e">
- executes
- <span class="emphasis">
- <em>
- command1
- </em>
- </span>
- , directing the standard error stream to
- <span class="emphasis">
- <em>
- file1
- </em>
- </span>
- .
- </p>
- <p id="ch9Using_Linux_Tools_18f">
- In shells derived from
- <span class="emphasis">
- <em>
- csh
- </em>
- </span>
- (the C shell), the syntax instead appends the & character to the redirect characters, thus achieving a similar result.
- </p>
- <p id="ch9Using_Linux_Tools_190">
- Another useful capability is to redirect one standard file handle to another. The most popular variation is to merge standard error into standard output so error messages can be processed together with (or alternately to) the usual output. Example:
- </p>
- <pre class="programlisting">
- $ find / -name .profile > results 2>&1
- </pre>
- <p id="ch9Using_Linux_Tools_191">
- will try to find all files named
- <span class="emphasis">
- <em>
- .profile
- </em>
- </span>
- . Executed without redirection, it will output hits to
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- and errors (e.g. for lack of privilege to traverse protected directories) to
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- . If standard output is directed to file results, error messages appear on the console. To see both hits and error messages in file results, merge
- <span class="emphasis">
- <em>
- stderr
- </em>
- </span>
- (handle 2) into
- <span class="emphasis">
- <em>
- stdout
- </em>
- </span>
- (handle 1) using 2>&1 .
- </p>
- <p id="ch9Using_Linux_Tools_192">
- It's possible use 2>&1 before ">" but it doesn't work. In fact, when the interpreter reads 2>&1, it doesn't know yet where standard output is redirected and then standard error isn't merged.
- </p>
- <p id="ch9Using_Linux_Tools_193">
- If the merged output is to be piped into another program, the file merge sequence 2>&1 must precede the pipe symbol, thus:
- </p>
- <pre class="programlisting">
- $ find / -name .profile 2>&1 | less
- </pre>
- <p id="ch9Using_Linux_Tools_194">
- A simplified form of the command:
- </p>
- <pre class="programlisting">
- $ command > file 2>&1
- </pre>
- <p id="ch9Using_Linux_Tools_195">
- is:
- </p>
- <pre class="programlisting">
- $ command &>file
- </pre>
- <p id="ch9Using_Linux_Tools_196">
- or:
- </p>
- <pre class="programlisting">
- $command >&file
- </pre>
- </div>
- <div class="section" title="12.4.Chained pipelines">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3005902">
- </a>
- 12.4.Chained pipelines
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_197">
- The redirection and piping tokens can be chained together to create complex commands. For example:
- </p>
- <pre class="programlisting">
- $ ls | grep '\.sh' | sort > shlist
- </pre>
- <p id="ch9Using_Linux_Tools_198">
- lists the contents of the current directory, where this output is filtered to only contain lines which contain
- <span class="emphasis">
- <em>
- .sh
- </em>
- </span>
- , sort this resultant output lexicographically, and place the final output in
- <span class="emphasis">
- <em>
- shlist
- </em>
- </span>
- . This type of construction is used very commonly in shell scripts and batch files.
- </p>
- </div>
- <div class="section" title="12.5.Redirect to multiple outputs">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3005936">
- </a>
- 12.5.Redirect to multiple outputs
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_199">
- The standard command
- <span class="emphasis">
- <em>
- tee
- </em>
- </span>
- can redirect output from a command to several destinations.
- </p>
- <pre class="programlisting">
- $ ls -lrt | tee xyz
- </pre>
- <p id="ch9Using_Linux_Tools_19a">
- This directs the file list output to both standard output as well as to the file
- <span class="emphasis">
- <em>
- xyz
- </em>
- </span>
- .
- </p>
- </div>
- </div>
- <div class="section" title="13.More Text Processing">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3005967">
- </a>
- 13.More Text Processing
- </h2>
- </div>
- </div>
- </div>
- <div class="section" title="13.1.grep">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3005976">
- </a>
- 13.1.grep
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_19b">
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- is a command line text search utility originally written for Unix. The name is taken from the first letters in
- <span class="emphasis">
- <em>
- global / regular expression / print
- </em>
- </span>
- , a series of instructions for the
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- text editor. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.
- </p>
- <div class="section" title="13.1.1.Usage">
- <div class="titlepage">
- <div>
- <div>
- <h4 class="title">
- <a name="id3006007">
- </a>
- 13.1.1.Usage
- </h4>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_19c">
- This is an example of a common
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- usage:
- </p>
- <pre class="programlisting">
- $ grep apple fruitlist.txt
- </pre>
- <p id="ch9Using_Linux_Tools_19d">
- In this case,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- prints all lines containing 'apple' from the file
- <span class="emphasis">
- <em>
- fruitlist.txt
- </em>
- </span>
- , regardless of word boundaries; therefore lines containing 'pineapple' or 'apples' are also printed. The
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- command is case sensitive by default, so this example's output does not include lines containing 'Apple' (with a capital A) unless they also contain 'apple'.
- </p>
- <p id="ch9Using_Linux_Tools_19e">
- Like most Unix commands,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- accepts command line arguments to change this and many other behaviors. For example:
- </p>
- <pre class="programlisting">
- $ grep -i apple fruitlist.txt
- </pre>
- <p id="ch9Using_Linux_Tools_19f">
- This prints all lines containing 'apple' regardless of capitalization. The '-i' argument tells
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be case insensitive, or to ignore case.
- </p>
- <p id="ch9Using_Linux_Tools_1a0">
- To print all lines containing 'apple' as a word ('pineapple' and 'apples' will not match):
- </p>
- <pre class="programlisting">
- $ grep -w apple fruitlist.txt
- </pre>
- <p id="ch9Using_Linux_Tools_1a1">
- Regular expressions can be used to match more complicated queries.
- </p>
- <div class="section" title="13.1.1.1.Variations">
- <div class="titlepage">
- <div>
- <div>
- <h5 class="title">
- <a name="id3006086">
- </a>
- 13.1.1.1.Variations
- </h5>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_1a2">
- There are countless implementations and derivatives of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- available for many operating systems. Early variants of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- included
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- and
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- . The former applies an extended regular expression syntax that was added to Unix after Ken Thompson's original regular expression implementation. The latter searches for any of a list of 'fixed' strings using the Aho-Corasick algorithm. These variants are embodied in most modern
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- implementations as command-line switches (and standardized as -E and -F in POSIX). In such combined implementations,
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- may also behave differently depending on the name by which it is invoked, allowing
- <span class="emphasis">
- <em>
- fgrep
- </em>
- </span>
- ,
- <span class="emphasis">
- <em>
- egrep
- </em>
- </span>
- , and
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- to be links to the same program.
- </p>
- <p id="ch9Using_Linux_Tools_1a3">
- <span class="emphasis">
- <em>
- pcregrep
- </em>
- </span>
- is an implementation of
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- that uses Perl regular expression syntax.
- </p>
- <p id="ch9Using_Linux_Tools_1a4">
- Other commands contain the word 'grep' to indicate that they search (usually for regular expression matches). The
- <span class="emphasis">
- <em>
- pgrep
- </em>
- </span>
- utility, for instance, displays the processes whose names match a given regular expression.
- </p>
- </div>
- </div>
- </div>
- <div class="section" title="13.2.tr">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3006166">
- </a>
- 13.2.tr
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_1a5">
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- (abbreviated from
- <span class="emphasis">
- <em>
- translate
- </em>
- </span>
- or
- <span class="emphasis">
- <em>
- transliterate
- </em>
- </span>
- ) is a command in Unix-like operating systems.
- </p>
- <p id="ch9Using_Linux_Tools_1a6">
- When executed, the program reads from the standard input and writes to the standard output. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set. For example,
- </p>
- <pre class="programlisting">
- $ tr 'abcd' 'jkmn'
- </pre>
- <p id="ch9Using_Linux_Tools_1a7">
- maps 'a' to 'j', 'b' to 'k', 'c' to 'm', and 'd' to 'n'.
- </p>
- <p id="ch9Using_Linux_Tools_1a8">
- Sets of characters may be abbreviated by using character ranges. The previous example could be written:
- </p>
- <pre class="programlisting">
- $ tr 'a-d' 'jkmn'
- </pre>
- <p id="ch9Using_Linux_Tools_1a9">
- In POSIX compliant versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- the set represented by a character range depends on the locale's collating order, so it is safer to avoid character ranges in scripts that might be executed in a locale different from that in which they were written. Ranges can often be replaced with POSIX character sets such as [:alpha:].
- </p>
- <p id="ch9Using_Linux_Tools_1aa">
- The
- <span class="emphasis">
- <em>
- -c
- </em>
- </span>
- flag complements the first set of characters.
- </p>
- <pre class="programlisting">
- $ tr -cd '[:alnum:]'
- </pre>
- <p id="ch9Using_Linux_Tools_1ab">
- therefore removes all non-alphanumeric characters.
- </p>
- <p id="ch9Using_Linux_Tools_1ac">
- The
- <span class="emphasis">
- <em>
- -s
- </em>
- </span>
- flag causes tr to compress sequences of identical adjacent characters in its output to a single token. For example,
- </p>
- <pre class="programlisting">
- $ tr -s '\n' '\n'
- </pre>
- <p id="ch9Using_Linux_Tools_1ad">
- replaces sequences of one or more newline characters with a single newline.
- </p>
- <p id="ch9Using_Linux_Tools_1ae">
- The
- <span class="emphasis">
- <em>
- -d
- </em>
- </span>
- flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters, thereby converting a file in DOS/Windows format to one in Unix format.
- </p>
- <pre class="programlisting">
- $ tr -d '\r'
- </pre>
- <p id="ch9Using_Linux_Tools_1af">
- Most versions of
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , including GNU
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- and classic Unix
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- , operate on single byte characters and are not Unicode compliant. An exception is the Heirloom Toolchest implementation, which provides basic Unicode support.
- </p>
- <p id="ch9Using_Linux_Tools_1b0">
- Ruby and Perl also have an internal
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- operator, which operates analogously. Tcl's
- <span class="emphasis">
- <em>
- string map
- </em>
- </span>
- command is more general in that it maps strings to strings while
- <span class="emphasis">
- <em>
- tr
- </em>
- </span>
- maps characters to characters.
- </p>
- </div>
- </div>
- <div class="section" title="14.Elementary Regex">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3006317">
- </a>
- 14.Elementary Regex
- </h2>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_1b1">
- In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters. A regular expression (often shortened to regex or regexp) is written in a formal language that can be interpreted by a regular expression processor, a program that either serves as a parser generator or examines text and identifies parts that match the provided specification.
- </p>
- <p id="ch9Using_Linux_Tools_1b2">
- Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl, Ruby and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributionsincluding the editor
- <span class="emphasis">
- <em>
- ed
- </em>
- </span>
- and the filter
- <span class="emphasis">
- <em>
- grep
- </em>
- </span>
- were the first to popularize the concept of regular expressions.
- </p>
- <p id="ch9Using_Linux_Tools_1b3">
- Traditional Unix regular expression syntax followed common conventions but often differed from tool to tool. The IEEE POSIX
- <span class="emphasis">
- <em>
- Basic Regular Expressions
- </em>
- </span>
- (BRE) standard (released alongside an alternative flavor called Extended Regular Expressions or ERE) was designed mostly for backward compatibility with the traditional (Simple Regular Expression) syntax but provided a common standard which has since been adopted as the default syntax of many Unix regular expression tools, though there is often some variation or additional features. Many such tools also provide support for ERE syntax with command line arguments.
- </p>
- <p id="ch9Using_Linux_Tools_1b4">
- In the BRE syntax, most characters are treated as literals they match only themselves (i.e., a matches "a"). The exceptions, listed below, are called metacharacters or metasequences.
- </p>
- <table summary="Elementary Regex" border="1">
- <colgroup>
- <col width="13">
- </col>
- <col width="60">
- </col>
- </colgroup>
- </table>
- <div class="section" title="14.1.Lazy quantification">
- <div class="titlepage">
- <div>
- <div>
- <h3 class="title">
- <a name="id3006530">
- </a>
- 14.1.Lazy quantification
- </h3>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_1c9">
- The standard quantifiers in regular expressions are greedy, meaning they match as much as they can, only giving back as necessary to match the remainder of the regex. For example, someone new to regexes wishing to find the first instance of an item between < and > symbols in this example:
- </p>
- <pre class="programlisting">
- Another whale explosion occurred on <January 26>, <2004>.
- </pre>
- <p id="ch9Using_Linux_Tools_1ca">
- ...would likely come up with the pattern <.*>, or similar. However, this pattern will actually return "<January 26>, <2004>" instead of the "<January 26>" which might be expected, because the * quantifier is greedy it will consume as many characters as possible from the input, and "January 26>, <2004" has more characters than "January 26".
- </p>
- <p id="ch9Using_Linux_Tools_1cb">
- Though this problem can be avoided in a number of ways (e.g., by specifying the text that is not to be matched: <[^>]*>), modern regular expression tools allow a quantifier to be specified as
- <span class="emphasis">
- <em>
- lazy
- </em>
- </span>
- (also known as non-greedy, reluctant, minimal, or ungreedy) by putting a question mark after the quantifier (e.g., <.*?>), or by using a modifier which reverses the greediness of quantifiers (though changing the meaning of the standard quantifiers can be confusing). By using a lazy quantifier, the expression tries the minimal match first. Though in the previous example lazy matching is used to select one of many matching results, in some cases it can also be used to improve performance when greedy matching would require more backtracking.
- </p>
- </div>
- </div>
- <div class="section" title="15.One Liners">
- <div class="titlepage">
- <div>
- <div>
- <h2 class="title" style="clear: both">
- <a name="id3006606">
- </a>
- 15.One Liners
- </h2>
- </div>
- </div>
- </div>
- <p id="ch9Using_Linux_Tools_1cc">
- A
- <span class="emphasis">
- <em>
- one-liner
- </em>
- </span>
- is textual input to the command-line of an operating system shell that performs some function in just one line of input.
- </p>
- <p id="ch9Using_Linux_Tools_1cd">
- The one liner can be
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch9Using_Linux_Tools_1ce">
- An expression written in the language of the shell.
- </p>
- </li>
- <li class="listitem">
- <p id="ch9Using_Linux_Tools_1cf">
- The invocation of an interpreter together with program source for the interpreter to run.
- </p>
- </li>
- <li class="listitem">
- <p id="ch9Using_Linux_Tools_1d0">
- The invocation of a compiler together with source to compile and
-instructions for executing the compiled program.
- </p>
- </li>
- </ol>
- </div>
- <p id="ch9Using_Linux_Tools_1d1">
- Certain dynamic scripting languages such as AWK, sed, and perl have traditionally been adept at expressing one-liners. Specialist shell interpreters such as these Unix shells or the Windows PowerShell, allow for the construction of powerful one-liners.
- </p>
- <p id="ch9Using_Linux_Tools_1d2">
- The use of the phrase one-liner has been widened to also include program-source for any language that does something useful in one line.
- </p>
- <p id="ch9Using_Linux_Tools_1d3">
- The word
- <span class="emphasis">
- <em>
- One-liner
- </em>
- </span>
- has two references in the index of the book
- <span class="emphasis">
- <em>
- The AWK Programming Language
- </em>
- </span>
- (the book is often referred to by the abbreviation TAPL). It explains the programming language AWK, which is part of the Unix operating system. The authors explain the birth of the One-liner paradigm with their daily work on early Unix machines:
- </p>
- <pre class="programlisting">
- The 1977 version had only a few built-in variables and predefined functions. It was designed for writing short programs [...] Our model was that an invocation would be one or two lines long, typed in and used immediately. Defaults were chosen to match this style [...] We, being the authors, knew how the language was supposed to be used, and so we only wrote one-liners.
- </pre>
- <p id="ch9Using_Linux_Tools_1d4">
- Notice that this original definition of a One-liner implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a One-liner. But this strict understanding of a One-liner was broadened in 1985 when the IOCCC introduced the category of Best One Liner for C, which is a compiled language.
- </p>
- <p id="ch9Using_Linux_Tools_1d5">
- The TAPL book contains 20 examples of One-liners (A Handful of Useful awk One-Liners) at the end of the book's first chapter.
- </p>
- <p id="ch9Using_Linux_Tools_1d6">
- Here are the first few of them:
- </p>
- <div class="orderedlist">
- <ol class="orderedlist" type="1">
- <li class="listitem">
- <p id="ch9Using_Linux_Tools_1d7">
- Print the total number of input lines:
- </p>
- <p id="ch9Using_Linux_Tools_1d8">
- END { print NR }
- </p>
- </li>
- <li class="listitem">
- <p id="ch9Using_Linux_Tools_1d9">
- Print the tenth input line:
- </p>
- <p id="ch9Using_Linux_Tools_1da">
- NR == 10
- </p>
- </li>
- <li class="listitem">
- <p id="ch9Using_Linux_Tools_1db">
- Print the last field of every input line:
- </p>
- <p id="ch9Using_Linux_Tools_1dc">
- { print $NF }
- </p>
- </li>
- </ol>
- </div>
- <p id="ch9Using_Linux_Tools_1dd">
- One-liners are also used to show off the differential expressive power of programming languages. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.
- </p>
- <p id="ch9Using_Linux_Tools_1de">
- The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC, here split to two lines for presentation).:
- </p>
- <pre class="programlisting">
- main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return
-*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
- </pre>
- <p id="ch9Using_Linux_Tools_1df">
- This one-liner program is a
- <span class="emphasis">
- <em>
- glob pattern matcher
- </em>
- </span>
- . It understands the glob characters '*' meaning 'zero or more characters' and '?' meaning exactly one character, just like most Unix shells.
- </p>
- <p id="ch9Using_Linux_Tools_1e0">
- Run it with two args, the string and the glob pattern. The exit status is 0 (shell true) when the pattern matches, 1 otherwise. The glob pattern must match the whole string, so you may want to use * at the beginning and end of the pattern if you are looking for something in the middle. Examples:
- </p>
- <pre class="programlisting">
- $ prog foo 'f??'; echo $?
-
-$ prog 'best short program' '??st*o**p?*'; echo $?
- </pre>
- <p id="ch9Using_Linux_Tools_1e1">
- Here is a one line shell script to show directories:
- </p>
- <pre class="programlisting">
- $ ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
- </pre>
- </div>
</div>
</div>
</body>