strategies和tactics区别(stattrak和普通的区别)
单词联想stratum strata substrate strategy
strategy
英/ˈstrætədʒi/美/ˈstrætədʒi/
n. (尤指为获得某物制定长期的)策略,行动计划;战略,战略学
词源
strategy战略,策略
词源同 stratum,strew.-eg,做,引导,词源同 agent,pedagogy,-y,行为,学说。 后词义通用化为战略,策略
The strategy worked brilliantly.
这项策略非常成功。
stratum
英/ˈstrɑːtəm/美/ˈstreɪtəm/
n. (组织的)层;[地质] 地层;社会阶层
Tramps are from the lowest stratum of society.
流浪汉来自社会最下层。
strata
英/ˈstrɑːtə/美/ˈstreɪtə/
n. 层;[地质]地层;阶层
strata-title 分层所有权分层一切权分层占有权慲
overlying strata 表层覆层上覆岩层
strata control 岩层控制地压挖制顶板控制地层控制
rock strata 岩层
series of strata 层系,岩系
substrate
英/ˈsʌbstreɪt/美/ˈsʌbstreɪt/
n. 培养基,基质,基层;底物,酶作用物;(供放置或刻的)底面
substrate底层,基底
sub-,在下,-strat,地层,岩层,词源同 strategy,structure.1.
glass substrate 玻璃衬底
substrate material 基材
silicon substrate 硅衬底
Greenboard is an acceptable substrate.
绿板是一种可以接受的基板。
Each cell has five layers of solid material that has been deposited onto a paper substrate.
每个电池有五层放在纸质板上的固体材料。
为何中国曾经连日本都挡不住却能在朝鲜战争中和美国打成平手?
朝鲜战争是我们的立国之战,洗刷了近百年的屈辱史,在美版知乎Quora上,美国网友提问道:为什么中国在20世纪40年代那么弱,之至于无法抵抗日本的入侵,却在20世纪50年代突然能够将美国领导的联合国部队赶回三八线?在这么短的时间内发生了什么变化?这引起了各国网友的围观和热议,我们看看他们的观点。
问题
美国华裔网友马里奥•李的回答
In fact, the answer is already in your question.
事实上,答案已经在你的问题中了。
Your question: Why was China so weak in the 1940s that it could not resist the Japanese invasion, but in the 1950s it was able to repel the United Nations forces led by the United States back to the 38th Front? What has changed in such a short time? It is mainly because they have changed from a loose sand to a people's army twisted into a rope.
你的问题:为什么中国在20世纪40年代那么弱,都无法抵抗日本的入侵,却在20世纪50年代突然能够将美国领导的联合国部队赶回三八线?在这么短的时间内发生了什么变化?我认为主要是他们从一盘散沙变成了拧成一股绳的人民军队。
After 1840, China was defeated in the war with all the aggressors: Britain, France, Russia, even Belgium and other countries - China signed unequal treaties with all these countries.
1840年后,中国在与所有侵略者的战争中节节败退:英国、法国、俄罗斯,甚至小到比利时等国家——中国与所有这些国家签订了不平等条约。
This is a picture of how China was divided by foreign powers at that time: France (frog) extended its tentacles to the southwest of China, Japan (sun) tightly grasped its tentacles to Taiwan and Fujian, and Russia occupied the north like a bear. Bottom line: China is like Syria now, a fragmented country, with little hope of recovery. Therefore, he was insulted by the great powers as the sick man of East Asia. Therefore, in the first few months of the Japanese invasion, people doubted whether China would still exist, which was "reasonable". Under the oppression of the three great mountains (imperialism, feudalism and bureaucratism), how can China turn over?
这是一张关于中国当时如何被列强瓜分的图片:法国(青蛙)将触角伸向中国西南部,日本(太阳)将触角紧紧抓住台湾和福建,俄罗斯则像一头熊盘踞在北方。一句话:中国就像现在的叙利亚——一个支离破碎的国家,几乎没有恢复的希望。因此,被列强侮辱为:東亞病夫 。因此,在日本入侵的最初几个月,人们怀疑中国是否还会存在,这是“合理的”。整个中国在三座大山(帝国主义、封建主义、官僚主义)的压迫下,如何会有翻身之日?
However, the CPC led by Mao Zedong united the people and overthrew these three mountains one after another through a series of struggles (the Long March, the War of Resistance against Japan and the War of Liberation). On September 2, 1945, Japan finally surrendered to the Allies. Shortly afterwards, in 1949, Chinese Mainland and Hainan were liberated and unified under the leadership of the People's Republic of China, the People's Republic of China.
但是,领导的中国通过一系列的斗争(长征、抗日战争和解放战争),团结了人民,相继推翻了这三座大山。1945年9月2日,日本终于向盟军投降。不久后,1949年,中国大陆和海南解放并在新中国——中华人民共和国的领导下统一。
In modern times, tens of millions of people have died (more specifically, 35 million people), but the Chinese have learned one thing: faith - they have the ability to defeat any kind of enemy. Unless they sit back and ignore them, no one can defeat them. Of course, in this period of history, you cannot ignore the achievements of the CPC in organizing, encouraging and inspiring the whole country. However, to put it simply: Napoleon Bonaparte described the "sleeping lion" as just waking up.
近代以来,数千万人牺牲(更具体地说是3500万人),但中国人学到了一件事:信仰——他们有能力战胜任何类型的敌人,除非他们坐视不理,否则任何人都无法战胜他们。当然,在这段历史中,你不能忽视中国组织、建设和激励了整个国家的功绩。但是,简单地说:拿破仑·波拿巴描述的“沉睡的雄狮”刚刚苏醒。
As a united nation, China has been tempered in the struggle against the Japanese aggressors. Now, as a country, China faces the U.S. military (I don't mention the countries involved in the United Nations military, because they are really weak and have little combat effectiveness, and have made little contribution to their allies, including the Korean military), protects their own homeland, and creates a peaceful and stable development environment for their relatives and future generations, Instead of becoming a fragmented land again under the threat of powerful enemies.
中国作为一个团结一致的民族,在与日本侵略者的斗争中得到了锻炼,现在作为一个国家面对美队(我不提联合中涉及的国家,因为他们真的又少战斗力又弱,对他们的盟友,包括韩队,贡献很少),保护他们自己的家园,为他们的亲人和后代创建一个和平稳定的发展环境,而不是在强敌的威胁下再次化为一盘散沙。
This progress is not only reflected in the will to fight, but also in the organization, logistics and soldiers' understanding of their own values (they now know who they are fighting for, even if they die).
这一进步不仅体现在战斗意志上,还体现在组织、后勤和士兵对自身价值的理解上(他们现在知道自己在为谁而战,即使他们死了也心甘情愿)。
After the Korean War, Peng Dehuai said, "The era when Western aggressors could seize a country by erecting several cannons on the eastern coast for hundreds of years is gone forever." In the 1960s, former colonial countries around the world had just ushered in a wave of liberation. It is precisely for the same reason that Cuba, Egypt, Iraq, Iran and many other former colonial countries have gained independence and liberation under the inspiration of China.
朝鲜战争结束后,彭德怀说,“西方侵略者几百年来只要在东方一个海岸上架起几尊大炮就可霸占一个国家的时代是一去不复返了。”20世纪60年代,世界各地的前殖家刚刚迎来了解放浪潮。正是出于同样的原因,在中国的感召下,古巴、埃及、伊拉克、伊朗和其他许多前殖家相继获得了独立和解放。
As far as military construction is concerned, the difference between the People's Volunteers and the Kuomintang troops in the 1940s is as big as that between modern and medieval armies.
就军队建设来说,人民志愿军和四十年代军队之间的差别就像现代军队和中世纪军队之间的区别一样大。
In fact, the Kuomintang army is just a combination of several warlord forces. Chiang Kai shek was never able to mobilize them to fight the Japanese throughout the country. On the contrary, they always choose to face weak enemies and leave the tough ones to others. Usually, when some people are in fierce battle with the Japanese army, others will wait and see what happens so as to retain their troops when they are weakened or destroyed.
事实上,军队只是几个军阀势力的组合。始终无法动员他们在全国范围内与日本人作战。相反,他们总是选择面对弱小的敌人,把硬骨头留给其他人。通常的情况是,当一部分人与日军激战时,另一部分人会静观其变,以便在他们被削弱或消灭时保留自己的部队。
The military structure under the leadership of the Kuomintang is as follows: there is a warlord above it. As the leader, he is the most trusted central army. Below this core army is a fighting force composed of the overwhelming majority of soldiers recruited by force: most of them are peasants, who have no choice but to survive as such soldiers in troubled times, and a few of them are beggars, hooligans, and so on. Most of these soldiers were badly fed, never paid their wages on time, and were treated as thieves: officers could punish them at will without any special reason. It is very common for these people to escape at any time without the supervision of the central army.
统领的军队结构是这样的:有一个军阀在上面,作为老大,他手下是他最信任的中央部队,在这个核心部队下面是绝大多数以武力为标准招募的士兵组成的战斗部队:他们中的大多数是农民,他们别无选择,乱世之中只能成为这样的士兵来生存,其他少部分是乞丐、流氓等等。这些士兵中的大多数都吃得很差,从未按时支付工资,而且被当作小偷对待:军官们可以随心所欲地惩罚他们,没有任何特殊原因。如果没有中央部队的监督,这些人随时都会逃跑,这是非常常见的。
On the other hand, the People's Volunteers is a modern army. Unlike the Kuomintang army, the Central Committee has centralized decision- power. Although it may make tactical sacrifices, it can still ensure the realization of strategic objectives.
另一方面,人民志愿军是一支现代化的军队。与军队不同,中央拥有集中决策权,尽管可能在战术上有所牺牲,但仍能确保战略目标的实现。
Their other secret is to maintain democracy in the army. Yes, yes, democracy. The social background of the volunteer army is similar to that of the soldiers in the Kuomintang army, but their rights have been consolidated in the army: soldiers who are members of the Communist Party of China (this is because Chairman Mao Zedong ensured that educated soldiers and illiterate soldiers were treated equally, as long as they made contributions to the revolution) were included in the decision- process, and their opinions were paid equal attention to those of educated people, regardless of their level. In addition, when a soldier is ill treated, he has the right to appeal to the Military Commission, which can protect him because many of its members are soldiers themselves, and they will feel the same way.
他们另一个秘密是保持军队的。是的,没错,。志愿军的社会背景与军队的军人差不多,但他们的权利在军队中得到了巩固:作为党员的士兵(这是因为主席确保平等对待受过教育的士兵和文盲士兵,只要他们为革命做出了贡献)被纳入决策过程,并确保他们的意见得到与受过教育的人同等的重视,无论他们的级别如何。此外,当一名士兵受到虐待时,他有权向军事委员会申诉,而委员会能够保护他,因为其许多成员本身就是士兵,他们会感同身受。
The difference is obvious: in the Kuomintang army, you are a slave, while in the Communist army, you are treated as a comrade, just like anyone else. So, you see, if you fought in the Kuomintang army before and then rose up and joined the Communist army, you will clearly see the difference between the two and know that you are fighting for the country and the people, not for the personal interests of some bureaucrats.
区别很明显:在军队里,你是一个奴隶,而在军队中,你被当作一位同志,就像其他任何人一样。所以,你看,如果你以前在军队战斗,然后起义加入了军队,你会很清楚地看到二者的区别,知道自己在为国家和人民在战斗,而不是为了某些官僚的私利。
德国网友詹姆斯•克里斯赫尔曼的回答
Unity, leadership and tactics.
团结、领导力和战术。
Before and after the Second World War, China was in dire straits of civil war. The rest of the country is controlled by major warlord factions. This country is not industrialized, the illiteracy rate is very high, and the social structure is still feudal. The country is poor and fragmented, and is still scarred by colonialism, opium, the collapse of dynasties and natural disasters. Even when the Japanese attacked, Chiang Kai shek still shouted, "You have to settle down before you fight outside"!
在第二次世界大战前后,中国处于内战的水深火热之中。该国其他地区由各大军阀派系控制。这个国家没有工业化,文盲率很高,社会结构仍然是封建的。这个国家贫穷,四分五裂,仍在殖义、、王朝崩溃和自然灾害中伤痕累累。即使在日本人进攻的时候,集团还在高呼“攘外必先安内”!
Seeing these weaknesses prompted the Japanese to seize the opportunity to invade. According to their calculations, they believe that they can invade and occupy the whole of China within three months. Unfortunately, Nanjing was a turning point that inspired the Chinese to fight back. However, the lack of weapons and resources seriously hindered their struggle, which lasted for eight years.
看到这些弱点,促使日本人抓住机会入侵。根据他们的计算,他们认为可以在3个月内侵占全中国。不幸的是,南京是一个转折点,激发了中国人的反击。但缺乏武器和资源严重阻碍了他们的抗争,让抗日战争持续了八年之久。
After World War II, the CPC defeated the better equipped Kuomintang because it had more popular support and better strategies and tactics.
第二次世界大战后,中国战胜了装备更好的,因为它有更多的民众支持和更好的战略战术。
During the Korean War, the morale of the volunteer army was much higher. They accumulated rich experience after decades of war. Their strategic goal is only to confront a new imperial force, to destroy their attacks and protect the newly established country. Their commander is Marshall, and they are familiar with the tactics used by the United Nations, which is to use stealth/night to conduct intensive attacks on small forces, while close range is to defend against air power and artillery. Walking is also suitable for mountainous terrain, not armored or mobile columns.
在朝鲜战争期间,志愿军的士气要高得多,他们在经历了几十年的战争后积累了丰富的经验。他们的战略目标只是为了对抗一个新的帝国力量,以摧毁他们的进攻,保护新建立的国家。他们的指挥官是马歇尔,他们对联合国使用的熟悉战术是利用隐身/夜间对小型部队进行密集攻击,而近距则是对空中力量和火炮的防御。步行也适合山区地形,而不是装甲或机动纵队。
Because of the inherent tactical advantage of attacking an unsuspecting United Nations force, it only took two years to push them back to the 38th Front. I suspect that the US military may also have some complacency, because after winning the defeat of Japan in the Second World War and the collapse of the Korean army, Marshall did not think that the Asian army was optimistic.
由于对一支毫无戒心的联合国部队的攻击具有先天的战术优势,所以仅用两年就把他们推回了三八线。我怀疑美军可能也有一些自满情绪,因为在赢得对第二次世界大战中日本的惨败和即将崩溃的朝鲜军队之后,在麦克阿瑟眼里,亚洲军队并不被看好。
However, the willpower and combat effectiveness of the volunteer army are shocking. Although all they had was rifles, grenades and courage, it was enough to beat the US troops with advanced equipment into a panic attack.
但志愿军的意志力和战斗力令人震惊。虽然,他们倾其所有也只是步枪、手榴弹和勇气,但这足以将拥有先进装备的美军打得抱头鼠窜。
海外网友丹尼斯的回答
There may be two factors: differences in will and experience.
可能有两个因素:意志和经验的差异。
To be fair, China was able to resist the Japanese offensive in the 1940s. In an endless tug of war, the Chinese army held back most of the strength of the Japanese army. Although China failed to drive them away, Japan also failed to conquer more than one third of China's territory.
公平地说,中国在20世纪40年代能够抵抗住日本的攻势。在一场永无止境的拉锯战中,中队拖住了了日本军队的绝大部分力量。虽然中国没能赶走他们,但日本也没能征服中国三分之一以上的领土。
In the late 1940s, China experienced dramatic changes. First, victory over Japan. This is of great significance to China, because it is the first war China has won since the defeat of the Opium War against Britain in 1840. The bloody resistance against Japan for more than ten years has united the fragmented China and ended the regional disputes among warlords in China's provinces, which may split China into a country similar to Europe and produce a unified multi-ethnic country. (China's warlord fighting and division was an important factor for Japan to make progress in the early days of the war.) In addition, most of the Chinese troops that survived the war have become experienced experts in guerrilla warfare, which will prove very valuable in later Korea.
20世纪40年代中后期,中国经历了戏剧性的变化。首先是对日本的胜利。这对中国来说意义重大,因为这是自1840年对英国战争失败以来,中国赢得的第一场战争。十多年来对日本的血腥抵抗使支离破碎的中国团结起来,结束了中国各省之间军阀的地区纷争,这可能会把中国成类似欧洲的国家,并产生了一个统一的多民族国家。(中国的军阀混战和是日本在战争早期取得进展的一个重要因素)此外,大多数在战争中幸存下来的中队都成为了游击战的经验丰富的专家,这将在后来的朝鲜证明是非常宝贵的。
In 1949, the Communist Party won the civil war in China. At that time, its value was that everyone was equal, rather than letting selfish and greedy capitalists exploit workers indefinitely, as was the case in China. The Kuomintang government that the CPC opposes is a cruel military dictatorship. A few rich people live in luxury, while most people live in extreme poverty. Scholars and politicians with different views are often assassinated.
1949年,在中国内战中取得胜利。当时它的价值观是人人平等,而不是放手自私贪婪的资本家无限剥削工人,中国就是这样。中国所反抗的政府是一个残酷的军事,少数富人生活奢侈,而大多数人则生活在赤贫之中,持不同观点的学者和政治家经常遭到。
When the Communist Party came to power, it was the first time in Chinese history that the majority ruled the minority. Hungry Chinese people have been concerned only with survival for decades and suddenly have access to free land, food, education and health care. Overnight, the bad habits of the old society were abolished, and women were given equal rights, sometimes even more than men. In the past, most of them were not even allowed to learn to read.
当掌权时,这是中国历史上第一次由多数人统治少数人。饥饿的中国人几十年来只关心生存,突然获得了免费的土地、食物、教育和医疗保健。一夜之间,旧社会的陋习被废除,女性被赋予了平等的权利,有时甚至比男性更多,而以前她们中的大多数人甚至不被允许学习阅读。
In the eyes of Chinese people around the world, this is the beginning of a paradise on earth. Many patriotic overseas Chinese, some of whom are academic talents, seek to return to China and rebuild their country. (For example, Qian Xuesen is a rising scientific star who returned home with cutting-edge nuclear knowledge from the United States and led China's nuclear program after the Soviet Union withdrew its experts.)
在世界各地的中国人看来,这是一个类似人间天堂的开始。许多爱国华侨,其中一些是学术人才,寻求回国重建国家。(例如:钱学森是一位冉冉升起的科学明星,他带着美国的尖端核知识回国,并在苏联撤回专家后领导了中国的核计划)
However, the outbreak of the Korean War broke the pace of development and construction of New China.
但朝鲜战争的爆发打破了新中国发展建设的步伐。
Suddenly, China was faced with another possible invasion from the direction of Korea (the Japanese Empire first conquered Korea and began to invade China from there). American aircraft occasionally violated the airspace, randomly bombed Korean troops fleeing, and General MacArthur threatened to bomb Chinese coastal cities, falsely claiming to help the Kuomintang authorities recapture Chinese Mainland, confirming the Chinese people's concerns.
突然间,中国面临着来自朝鲜方向的又一次可能的入侵(日本帝国首先征服了朝鲜,并从那里开始了对中国的入侵)。美国飞机偶尔侵犯领空、随机轰炸逃离的朝鲜军队,以及麦克阿瑟将军威胁轰炸中国沿海城市,妄称帮助当局夺回中国大陆,证实了中国人的担忧。
Hiroshima was only five years away. The good image of Americans among the Chinese (American mercenary pilots flying for China, also known as Flying Tigers, are rock stars) was immediately replaced by new memories of atrocities committed by foreign powers after their occupation. The Chinese people are determined to protect their hard won . Even Chairman Mao sent his eldest son to fight in Korea (later died in the US bombing).
当时的广岛距离此时只有5年的时间。美国人在中国人中的良好形象(为中国飞行的美国雇佣兵飞行员,又名飞虎队,是摇滚明星)立即被列强占领后大施的新记忆所取代。中国人民决心保护他们来之不易的自由。就连毛主席也派他的大儿子去朝鲜作战(后来在美国轰炸中牺牲)。
Yes, the Communists used rifles and grenades against American tanks and aircraft. But in the 1940s, they used homemade explosives and farm tools to fight against the Japanese imperial army.
是的,人用步枪和手榴弹对付美国的坦克和飞机,但在20世纪40年代,他们用自制炸药和农具与日本帝队作战。
The Chinese defended a fortification in North Korea with stones.
中国人用石头保卫着朝鲜的一个防御工事。
Therefore, you have a United Nations police force led by the United States. They are composed of soldiers who have never set foot on the Asian continent. They want to know why they do not go home to enjoy peace and complain to their superiors about why they do not go home before Christmas, since the Second World War has finally ended? How can they win with such mentality?
因此,你有一支由美国领导的联合国警察部队,他们由从未踏上亚洲大陆的士兵组成,他们想知道,既然第二次世界大战终于结束,他们为什么不回家享受和平,并向上级抱怨为什么圣诞节前不回家?他们这样的心态怎么可能打得赢?
Linux文件操作的常用系统函数说明
1. open打开文件 (man 2 open 查看)
int open(const char *pathname, int flags);//pathname文件名(路径);flags打开模式,有O_RDONLY, O_WRONLY, O_RDWR
int open(const char *pathname, int flags, mode_t mode);//该函数一般用于创建新文件,flags添加O_CREAT,比如:O_RDWR|O_CREAT
int creat(const char *pathname, mode_t mode);//创建新文件,mode权限说明,比如0644(八进制,取反后和umask做与运算得到真正结果)
返回值:成功返回文件描述符fd,失败返回-1 。
举例说明:
int fd = open(\"test.txt\", O_WRONLY);//只写的方式打开test.txt,返回文件描述符
附:文件描述符说明(32位机器上文件描述符从0到1023): 0表示标准输入,1表示表示输出,2表示表示错误;我们程序打开的从3开始,每次总是使用最小的。
2. read文件读取 (man 2 write 查看)
ssize_t read(int fd, void *buf, size_t count);//ssize_t有符号整数;fd文件描述符;buf传出参数,读取的内容就在buf里;count表示buf的长度
返回值:大于0表示读取的字节数,等于0表示读取完,-1表示读取失败
3. write文件写入 (man 2 write 查看)
ssize_t write(int fd, const void *buf, size_t count);//buf需要写入的内容,count需要写入的内容的长度;ssize_t有符号整数;size_t无符号整数
返回值:大于表示写入的字节数,0表示没有写入任何数据,-1表示写入失败
4. lseek移动文件指针 (man 2 lseek 查看)
off_t lseek(int fd, off_t offset, int whence); //fd文件描述符,offset移动偏移量,whence移动参考点
whence的三个取值:SEEK_SET文件开始位置,SEEK_CUR表示指针当前位置,SEEK_END文件结束位置
返回值:大于等于0表示离文件开始处的偏移量,-1表示失败
附:该函数可用于扩容,比如 lseek(fd,100,SEEK_END);表示扩容100个字节,但是要执行一次写操作扩容才生效。
5. stat获取一个文件的信息 (man 2 stat 查看)
int stat(const char *path, struct stat *buf);//path文件路径;buf传出参数,获取的文件信息就在buf里面
int fstat(int fd, struct stat *buf);//fd文件描述符
int lstat(const char *path, struct stat *buf);//lstat和stat的区别只在于符号链接文件,lstat读取符号链接文件,stat读取符号链接对应的源文件
返回值:成功返回0;失败返回-1 。
附:下面说明一下 struct stat结构体的组成
struct stat {
dev_t st_dev; /* ID of device containing file 设备ID*/
ino_t st_ino; /* inode number Inode节点*/
mode_t st_mode; /* protection 文件的类型和存取的权限等等(这个字段很重要,该字段的具体说明请看man文档)*/
nlink_t st_nlink; /* number of hard links 硬链接数*/
uid_t st_uid; /* user ID of owner 用户ID*/
gid_t st_gid; /* group ID of owner 组ID*/
dev_t st_rdev; /* device ID (if special file) 若此文件为设备文件,则为其设备编号*/
off_t st_size; /* total size, in bytes 文件字节数,即文件大小*/
blksize_t st_blksize; /* blocksize for file system I/O 块的大小,即文件系统的I/O缓冲区大小*/
blkcnt_t st_blocks; /* number of 512B blocks allocated 块的数量*/
time_t st_atime; /* time of last access 最后一次访问时间*/
time_t st_mtime; /* time of last modification 最后一次修改时间*/
time_t st_ctime; /* time of last status change 最后一次更改时间*/
};
结构体struct stat的st_mode的说明:
...check the file type using the st_mode field://使用st_mode检查文件类型的宏定义如下
S_ISREG//普通文件(m) is it a regular file?
S_ISDIR//目录(m) directory?
S_ISCHR//字符设备(m) character device?
S_ISBLK//块设备(m) block device?
S_ISFIFO//管道(m) FIFO (named pipe)?
S_ISLNK//符号链接(m) symbolic link? (Not in POSIX.1-1996.)
S_ISSOCK//套接字(m) socket? (Not in POSIX.1-1996.)
举例说明:
switch (sb.st_mode & S_IFMT){ //S_IFMT是文件类型掩码,其值是八进制170000
case S_IFBLK: printf(\"block device\n\"); break;
case S_IFCHR: printf(\"character device\n\"); break;
case S_IFDIR: printf(\"directory\n\"); break;
case S_IFIFO: printf(\"FIFO/pipe\n\"); break;
case S_IFLNK: printf(\"symlink\n\"); b reak;
case S_IFREG: printf(\"regular file\n\"); break;
case S_IFSOCK: printf(\"socket\n\"); break;
default: printf(\"unknown?\n\"); break;
}
附:S_IRWXU文件所有者权限掩码,其值为00700;S_IRWXG组权限掩码,其值为00070;S_IRWXO其他限掩码,其值为00007;具体看man手册。用法都是一样,以S_IRWXU为例,如下所示:
switch(sb.st_mode & S_IRWXU){
case:S_IRUSR printf(\"owner has read permission\n\"); break;
case:S_IWUSR printf(\"owner has wirte permission\n\"); break;
case:S_IXUSR printf(\"owner has execute permission\n\"); break;
}
6. access检查文件权限 (man 2 access 查看)
int access(const char *pathname, int mode);//pathname文件名称,mode权限
返回值:所有权限被允许返回0;只要有一个权限不允许的就返回-1,错误也是返回-1;
mode的值说明:
要不是F_OK :表示文件是否存在
要不是R_OK | W_OK | X_OK ,可以是一个或者多个,多个之间按位与;R_OK是否可读,W_OK是否可写,X_OK是否可执行
7. chmod改变文件权限
int chmod(const char *path, mode_t mode);//path文件路径;mode_t整数,mode权限,必须是一个八进制数,或者使用预定义宏,具体查看man手册
int fchmod(int fd, mode_t mode);//fd文件描述符
返回值:成功返回0;失败返回-1 。
8. chown改变文件所有者 (一般需要root权限才能操作成功)
int chown(const char *path, uid_t owner, gid_t group);//穿透符号链接;文件路径
int fchown(int fd, uid_t owner, gid_t group);//直接文件操作;fd文件描述符
int lchown(const char *path, uid_t owner, gid_t group);//不穿透符号链接;文件路径
返回值:成功返回0;失败返回-1 。
9. truncate更改文件到指定的长度
int truncate(const char *path, off_t length);//path文件路径,必须有写权限;length文件长度,单位字节数
int ftruncate(int fd, off_t length);//fd文件描述符,文件必须是打开状态
返回值:成功返回0;失败返回-1 。
附:该函数可用于文件扩容,不需要写一次才能生效;lseek函数扩容需要写一次才能生效。
10. link创建一个硬链接
int link(const char *oldpath, const char *newpath);//oldpath源文件,newpath要创建的硬链接的路径
返回值:成功返回0;失败返回-1 。
11. symlink创建一个软连接
int symlink(const char *oldpath, const char *newpath);//oldpath源文件路径,newpath软连接路径
返回值:成功返回0;失败返回-1 。
12. readlink读取软连接对应的文件名(不是读取源文件的内容)
ssize_t readlink(const char *path, char *buf, size_t buf-siz);//path软连接路径;buf传出参数,buf-siz是buf的长度;读取的内容就在buf里面
返回值:成功返回读取的内容的长度,失败返回-1 。
13. unlink删除一个链接
如果是符号链接,删除符号链接;
如果是硬链接,硬链接数减1;当减为0时,释放数据块和Inode;
附:如果硬链接数为0,但有进程占用着该文件,则必须等进程关闭该文件,才会真正地删除该文件,可利用这个特性创建临时文件,
先open或者creat创建一个文件,然后接着unlink。这样进程关闭该文件或者进程退出时,该文件会自动删除。
int unlink(const char *pathname);//pathname文件路径
返回值:成功返回0;失败返回-1 。
14. rename文件重命名
int rename(const char *oldpath, const char *newpath);//oldpath原文件,newpath新的文件
返回值:成功返回0;失败返回-1 。
15. fcntl操作文件描述符(记忆:file control)
int fcntl(int fd, int cmd, ... /* arg */ );//fd文件描述符;cmd命令;第三个是可变参数,可选的
返回值:成功返回大于等于0,根据cmd的取值返回不同的含义值;失败返回-1 。
举例说明:
int fcntl(int fd, int cmd);
int fcntl(int fd, int cmd, long arg);
int fcntl(int fd, int cmd, struct flock *lock);
根据功能分类确定cmd的值:
1.复制一个现有的文件描述符,cmd为F_DUPFD
2.获取或设置文件描述符标记,cmd为F_GETFD、F_SETFD
3.获取或设置文件状态标记,cmd为F_GETFL、F_SETFL
4.获取或设置锁,cmd为F_SETLK、F_SETLKW、F_GETLK
5.获取或设置异步IO所有权,cmd为F_GETOWN、F_SETOWN、F_GETSIG、F_SETSIG
6.lease、File and directory change notification等等,具体查看man手册。
16. dup, dup2, dup3复制文件描述符
int dup(int oldfd);//旧的文件描述符
int dup2(int oldfd, int newfd);//oldfd旧的文件描述符,newfd新的文件描述符
返回值:成功返回新的文件描述符,失败返回-1 。
声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送至邮件举报,一经查实,本站将立刻删除。转载务必注明出处:http://www.hixs.net/article/20240217/169625664895430.html