The ling 令, literally "commander", was an ancient title for the local administrator on the district (xian 縣) level. It was created in several states of the Warring States period 戰國 (5th cent. - 221 BCE) but was only systematically implemented during the Qin 秦 (221-206 BCE) and Han 漢 (206 BCE-220 CE) periods. During the Yuan period 元 (1279-1368) the office was renamed xianyin 縣尹 "district governor", and was from the Ming period 明 (1368-1644) on known as zhixian 知縣 "district magistrate". The term ling was during the Qing period 清 (1644-1911) still anachronistically used for the district magistrates.
In the central government the title of ling was during the Han period given to the directors of ministerial offices directly subordinated to the Department of State Affairs (shangshusheng 尚書省), the Palace Secretariat (zhongshusheng 中書省), the Nine Chamberlains (jiuqing 九卿) or the local administration in princedoms, like Director of the Department of State Affairs (shangshu ling 尚書令) or Secretariat Director (zhongshu ling 中書令).
During the Sui 隋 (581-618) and Tang 唐 (618-907) periods the title was exteneded to the heads of virtually all second-level central government agencies like the various courts (si 寺) and directorates (jian 監), the bureaus of the Palace Domestic Service (neishisheng 內侍省), the Astrological Service (taishiju 太史局) of the Palace Library (mishusheng 秘書省), the bureaus of the Household Administration of the Heir Apparent (taizi jialing si 太子家令寺), or of the Court of the Watches (leigengsi 率更寺, special reading!), and also the heads of the administration of the princedoms (xinwangguo 親王國), the estates of princesses (gongzhu yi 公主邑), district magistrates, and the heads of of small military posts at the "Five Mountains and the Four Rivers" 五嶽四瀆, passes (guan 關) and fords (jin 津).