鲜为人知的Linux命令(3)

本文介绍了一系列实用的Linux命令,包括刷新文件内容、计划任务、计算目录大小等技巧,旨在提高用户的操作效率。
1. > file.txt 命令


这个命令会刷新文件的内容而不需删除然后创建相同的文件。当我们需要反复输出,或者在相同的文件上记录日志时,这个命令就非常有用。


我有一个有很多文字的‘test.txt’文件在我的‘Desktop‘上。


avi@localhost:~/Desktop$ cat test.txt 

 

Linux 

GNU 

Debian 

Fedora 

kali 

ubuntu 

git 

Linus 

Torvalds

 

 

avi@localhost:~/Desktop$ > test.txt 

avi@localhost:~/Desktop$ cat test.txt


注意:再说一次,这个命令可能很危险!永远不要尝试刷新系统文件或者某篇日志文件的内容。如果你这么做了,你可能会遭遇严重的问题!


2. at 命令


‘at‘命令与cron 命令相似也可用于安排一个任务或者在某个特定时刻执行命令。


avi@localhost:~/Desktop$ echo "ls -l > /dev/pts/0" | at 14:012



avi@localhost:~/Desktop$ echo "ls -l > /dev/pts/0" | at 2:12 PM


示例输出


-rw-r--r-- 1 avi  avi      220492 Nov  1 13:49 Screenshot-1.png

-rw-r--r-- 1 root root        358 Oct 17 10:11 sources.list

-rw-r--r-- 1 avi  avi  4695982080 Oct 10 20:29 squeeze.iso

..

..

-rw-r--r-- 1 avi  avi       90624 Nov  5 12:59 Untitled 1.doc

-rw-r--r-- 1 avi  avi       96206 Nov  5 12:56 Untitled 1.odt

-rw-r--r-- 1 avi  avi        9405 Nov 12 23:22 Untitled.png


注意:echo “ls -l”的意思是,将这串命令(这里是 ls -l)输出在标准终端上。你可以用你需要或者选择的命令替代‘ls -l‘。


> :重定向输出


/dev/pts/0: 这是输出设备和/或文件,输出到指定的地方,这里输出在终端(/dev/pts/0)。


就我而言,此时我的tty在/dev/pts/0。你可以用tty命令检查你的tty。


avi@localhost:~/Desktop$ tty

 

/dev/pts/0


注意: ‘at‘会在系统时间匹配到特定时间时会尽快执行。


3. du -h –max-depth=1 命令


下面的命令以人类可读的形式输出当前目录的子目录的大小。


avi@localhost:/home/avi/Desktop# du -h --max-depth=1 

 

38M     ./test

1.1G    ./shivji

42M     ./drupal

6.9G    ./101MSDCF

16G .


注意:上面的命令在检查系统使用率是非常有用。


3. expr 命令


‘expr‘不是那么鲜为人知的命令。这个命令在终端中计算简单的算数时非常有用。


avi@localhost:/home/avi/Desktop# expr 2 + 3 

5

 

avi@localhost:/home/avi/Desktop# expr 6 – 3 

3

 

avi@localhost:/home/avi/Desktop# expr 12 / 3 

4

 

avi@localhost:/home/avi/Desktop# expr 2 \* 9 

18

4. look 命令


在终端上从英文字典上查单词以防混淆。比如说,我记不清了是该拼成carrier还是carieer。


avi@localhost:/home/avi/Documents# look car


Cara 

Cara's 

... 

carps 

carpus 

carpus's

carrel 

carrel's 

carrels 

carriage 

carriage's

carriages 

carriageway 

carriageway's 

carried 

carrier 

carrier's

carriers 

carries

...

caryatids


上面的命令会显示字典上所有以’car’开头的单词。我得到了我想找的。


5. yes 命令


另外一个命令在通常基础上并不会经常使用,但是在脚本语言和系统管理时非常有用。


这个命令会持续地输出给定的字符串,直到由你的中断命令打断。


avi@localhost:~/Desktop$ yes "Tecmint is one of the best site dedicated to Linux, how to"

 

Tecmint is one of the best site dedicated to Linux, how to

Tecmint is one of the best site dedicated to Linux, how to

Tecmint is one of the best site dedicated to Linux, how to

Tecmint is one of the best site dedicated to Linux, how to

...

Tecmint is one of the best site dedicated to Linux, how to

Tecmint is one of the best site dedicated to Linux, how to

Tecmint is one of the best site dedicated to Linux, how to


6. factor 命令


factor实际是一个源于数学的命令。这个命令会输出所有给定数字的因数。


avi@localhost:~/Desktop$ factor 22

222 11

 

avi@localhost:~/Desktop$ factor 21

213 7

 

avi@localhost:~/Desktop$ factor 11

1111


7. ping -i 60 -a IP_address


我们都用ping命令检测服务器是否连通。我通常ping google,来检测我是否连接到了因特网。


当你等待或者持续盯着你的终端等待命令的回应或者等待服务器的连接时,有时是很气人的。


一旦服务器连通就有一个声音如何(译注:下面命令是等60秒PING一次)?


avi@localhost:~/Desktop$ ping -i 60 -a www.google.com 

 

PING www.google.com (74.125.200.103) 56(84) bytes of data.

64 bytes from www.google.com (74.125.200.103)icmp_req=1 ttl=44 time=105 ms

64 bytes from 74.125.200.103icmp_req=2 ttl=44 time=281 ms


注意,当你发现命令不会返回声音时。请确保你的系统不是静音的,声音已经在‘sound preferences(声音选项)‘ 中启用并确保勾选了‘Enable window and window sound‘。


8. tac 命令


这个命令很有趣,他会以倒序输出文本文件的内容。也就是从最后一行到第一行。


在home目录下,我的Documents目录下有一个35.txt文件。用cat 命令检查内容。


avi@localhost:~/Documents$ cat 35.txt


示例输出


  1. Linux is built with certain powerful tools, which are unavailable in windows.

  2. One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it’s Linux Counterpart.

  3. Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages.


现在用tac命令反转文件内容(译注:当然,我们知道cat反转过来就是tac)。


avi@localhost:~/Documents$ tac 35.txt


示例输出


  1. Shell scripting/programming makes it possible to execute command(s), piped to get desired output in order to automate day-to-day usages.

  2. One of such important tool is Shell Scripting. Windows however comes with such a tool but as usual it is much weak as compared to it’s Linux Counterpart.

  3. Linux is built with certain powerful tools, which are unavailable in windows.

基于STM32 F4的永磁同步电机无位置传感器控制策略研究内容概要:本文围绕基于STM32 F4的永磁同步电机(PMSM)无位置传感器控制策略展开研究,重点探讨在不依赖物理位置传感器的情况下,如何通过算法实现对电机转子位置和速度的精确估计与控制。文中结合嵌入式开发平台STM32 F4,采用如滑模观测器、扩展卡尔曼滤波或高频注入法等先进观测技术,实现对电机反电动势或磁链的估算,进而完成无传感器矢量控制(FOC)。同时,研究涵盖系统建模、控制算法设计、仿真验证(可能使用Simulink)以及在STM32硬件平台上的代码实现与调试,旨在提高电机控制系统的可靠性、降低成本并增强环境适应性。; 适合人群:具备一定电力电子、自动控制理论基础和嵌入式开发经验的电气工程、自动化及相关专业的研究生、科研人员及从事电机驱动开发的工程师。; 使用场景及目标:①掌握永磁同步电机无位置传感器控制的核心原理与实现方法;②学习如何在STM32平台上进行电机控制算法的移植与优化;③为开发高性能、低成本的电机驱动系统提供技术参考与实践指导。; 阅读建议:建议读者结合文中提到的控制理论、仿真模型与实际代码实现进行系统学习,有条件者应在实验平台上进行验证,重点关注观测器设计、参数整定及系统稳定性分析等关键环节。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值