diff --git a/sources/tech/20150316 5 Interesting Command Line Tips and Tricks in Linux--Part 1.md b/sources/tech/20150316 5 Interesting Command Line Tips and Tricks in Linux--Part 1.md deleted file mode 100644 index 073e5f9370..0000000000 --- a/sources/tech/20150316 5 Interesting Command Line Tips and Tricks in Linux--Part 1.md +++ /dev/null @@ -1,117 +0,0 @@ -Translating by goreliu ... - -5 Interesting Command Line Tips and Tricks in Linux – Part 1 -================================================================================ -Are you making most out of the Linux? There are lots of helpful features which appears to be Tips and Tricks for many of Linux Users. Sometimes Tips and Tricks become the need. It helps you get productive with the same set of commands yet with enhanced functionality. - -![5 Command Line Tips and Tricks](http://www.tecmint.com/wp-content/uploads/2015/03/5-Command-Line-Tips.jpg) -5 Command Line Tips and Tricks - -Here we are starting a new series, where we will be writing some tips and tricks and will try to yield as more as we can in small time. - -### 1. To audit the commands we’d run in past, we use [history command][1]. Here is a sample output of history command. ### - - # history - -![history command example](http://www.tecmint.com/wp-content/uploads/2015/03/history-command.gif) -history command example - -Obvious from output, the history command do not output the time stamp with the log of last executed commands. Any solution for this? Yeah! Run the below command. - - # HISTTIMEFORMAT="%d/%m/%y %T " - # history - -If you want to permanently append this change, add the below line to `~/.bashrc`. - - export HISTTIMEFORMAT="%d/%m/%y %T " - -and then, from terminal run, - - # source ~/.bashrc - -Explanation of commands and switches. - -- history – GNU History Library -- HISTIMEFORMAT – Environmental Variable -- %d – Day -- %m – Month -- %y – Year -- %T – Time Stamp -- source – in short send the contents of file to shell -- .bashrc – is a shell script that BASH runs whenever it is started interactively. - -![history Command Logs](http://www.tecmint.com/wp-content/uploads/2015/03/History-Command-Logs.gif) -history Command Logs - -### 2. The next gem in the list is – how to check disk write speed? Well one liner dd command script serves the purpose. ### - - # dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync; rm -rf /tmp/output.img - -![dd Command Example](http://www.tecmint.com/wp-content/uploads/2015/03/dd-Command-Example.gif) -dd Command Example - -Explanation of commands and switches. - -- dd – Convert and Copy a file -- if=/dev/zero – Read the file and not stdin -- of=/tmp/output.img – Write to file and not stdout -- bs – Read and Write maximum upto M bytes, at one time -- count – Copy N input block -- conv – Convert the file as per comma separated symbol list. -- rm – Removes files and folder -- -rf – (-r) removes directories and contents recursively and (-f) Force the removal without prompt. - -### 3. How will you check the top six files that are eating out your space? A simple one liner script made from [du command][2], which is primarily used as file space usages. ### - - # du -hsx * | sort -rh | head -6 - -![Check Disk Space Usage](http://www.tecmint.com/wp-content/uploads/2015/03/check-disk-space-usage.gif) -Check Disk Space Usage - -Explanation of commands and switches. - -- du – Estimate file space usages -- -hsx – (-h) Human Readable Format, (-s) Summaries Output, (-x) One File Format, skip directories on other file format. -- sort – Sort text file lines -- -rf – (-r) Reverse the result of comparison, (-f) Ignore case -- head – output first n lines of file. - -### 4. The next step involves statistics in terminal of a file of every kind. We can output the statistics related to a file with the help of stat (output file/fileSystem status) command. ### - - # stat filename_ext (viz., stat abc.pdf) - -![Check File Statistics](http://www.tecmint.com/wp-content/uploads/2015/03/Check-File-Statistics.gif) -Check File Statistics - -### 5. The next and last but not the least, this one line script is for those, who are newbies. If you are an experienced user you probably don’t need it, unless you want some fun out of it. Well newbies are Linux-command-line phobic and the below one liner will generate random man pages. The benefit is as a newbie you always get something to learn and never get bored. ### - - # man $(ls /bin | shuf | head -1) - -![Generate Random Man Pages](http://www.tecmint.com/wp-content/uploads/2015/03/Generate-Random-Man-Pages.gif) -Generate Random Man Pages - -Explanation of commands and switches. - -- man – Linux Man pages -- ls – Linux Listing Commands -- /bin – System Binary file Location -- shuf – Generate Random Permutation -- head – Output first n line of file. - -That’s all for now. If you know any such tips and tricks you may share with us and we will post the same in your words on our reputed Tecmint.com website. - -If you want to share any tips and tricks that you cannot make into article you may share it at tecmint[dot]com[at]gmail[dot]com and we will include it in our article. Don’t forget to provide us with your valuable feedback in the comments below. Keep connected. Like and share us and help us get spread. - --------------------------------------------------------------------------------- - -via: http://www.tecmint.com/5-linux-command-line-tricks/ - -作者:[Avishek Kumar][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出 - -[a]:http://www.tecmint.com/author/avishek/ -[1]:http://www.tecmint.com/history-command-examples/ -[2]:http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/ diff --git a/translated/tech/20150316 5 Interesting Command Line Tips and Tricks in Linux--Part 1.md b/translated/tech/20150316 5 Interesting Command Line Tips and Tricks in Linux--Part 1.md new file mode 100644 index 0000000000..6bf88dba2c --- /dev/null +++ b/translated/tech/20150316 5 Interesting Command Line Tips and Tricks in Linux--Part 1.md @@ -0,0 +1,115 @@ +5个有趣的Linux命令行技巧(第一部分) +================================================================================ +你有将Linux物尽其用吗?对很多Linux用户来说,有很多看起来是技巧的有用特性。有些时候你会需要这些技巧。本文会帮助你更好得使用一些命令,发挥其更强大的功能。 + +![5个命令行技巧](http://www.tecmint.com/wp-content/uploads/2015/03/5-Command-Line-Tips.jpg) +图1:5个命令行技巧 + +我们开始一个新的系列,在这里我们还会写一些技巧,并且用尽量小的篇幅写清楚。 + +### 1. 我们可以使用[`history`命令][1]来查看曾经运行过的命令。这里是一个`history`命令的示例输出。 ### + + # history + +![history命令例子](http://www.tecmint.com/wp-content/uploads/2015/03/history-command.gif) +图2:history命令例子 + +从`history`命令输出看,很明显,命令的执行时间没有被打出来。有解决方法吗?有的!运行如下命令: + + # HISTTIMEFORMAT="%d/%m/%y %T " + # history + +如果你想让这个修改永久生效,添加如下的一行内容到`~/.bashrc`文件中: + + export HISTTIMEFORMAT="%d/%m/%y %T " + +然后,在终端中运行: + + # source ~/.bashrc + +命令和选项的解释: + +- history – 查看运行过的命令 +- HISTIMEFORMAT – 设置时间格式的环境变量 +- %d – 天 +- %m – 月 +- %y – 年 +- %T – 时间戳 +- source – 简而言之就是将文件内容发送给shell来执行 +- .bashrc – BASH以交互方式启动时运行的脚本文件 + +![history命令输出的日志](http://www.tecmint.com/wp-content/uploads/2015/03/History-Command-Logs.gif) +图3:`history`命令输出的日志 + +### 2. 如何测试磁盘写入速度?一行`dd`命令脚本就可以实现。### + + # dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync; rm -rf /tmp/output.img + +![dd命令例子](http://www.tecmint.com/wp-content/uploads/2015/03/dd-Command-Example.gif) +图4:`dd`命令例子 + +命令和选项的解释: + +- dd – 转换和复制文件 +- if=/dev/zero – 指定输入文件,默认为stdin(标准输入) +- of=/tmp/output.img – 指定输出文件,默认为stdout(标准输出) +- bs – 一次读和写的大小,最大可以以MB为单位 +- count – 复制次数 +- conv – 使用逗号分隔的策略来转换文件(LCTT 译注:比如将大写字母转换成小写,echo AA | dd conv=lcase) +- rm – 删除文件和目录 +- -rf – (-r) 递归地删除目录和其中的内容,(-f)强行删除而不输出确认信息 + +### 3. 你如何获取吃掉你磁盘空间的最大的6个文件?一个使用[`du`命令][2]的简单单行脚本即可实现,`du`命令主要用于获取文件的空间使用情况。### + + # du -hsx * | sort -rh | head -6 + +![获取磁盘空间使用情况的方法](http://www.tecmint.com/wp-content/uploads/2015/03/check-disk-space-usage.gif) +图5:获取磁盘空间使用情况的方法 + +命令和选项的解释: + +- du – 估计文件的空间使用情况 +- -hsx – (-h)更易读的格式,(-s)汇总输出,(-x)跳过其他文件系统的文件 +- sort – 对文本文件按行排序 +- -rf – (-r)将比较的结果逆序输出,(-f)忽略大小写 +- head – 输出文件的头几行 + +### 4. 获取一个文件的详细状态信息,可以使用`stat`命令。 ### + + # stat filename_ext (例如:stat abc.pdf) + +![获取文件的详细信息](http://www.tecmint.com/wp-content/uploads/2015/03/Check-File-Statistics.gif) +图6:获取文件的详细信息 + +### 5. 最后一个技巧是为那些入门者准备的,如果你是有经验的用户,可能不需要它,除非你想从中寻找乐趣。入门者可能有Linux命令行恐惧症,下面的命令会随机显示一个man手册页。对入门者来说,好处是总会学到新的东西,而且不会厌倦。 ### + + # man $(ls /bin | shuf | head -1) + +![查看随机的man手册页](http://www.tecmint.com/wp-content/uploads/2015/03/Generate-Random-Man-Pages.gif) +图7:查看随机的man手册页 + +命令和选项的解释: + +- man – Linux man手册 +- ls – 列出文件 +- /bin – 系统可执行文件的路径 +- shuf – 把输入内容按行随机打乱并输出 +- head – 输出文件的头几行 + +这就是所有的内容了。如果你知道任何类似的技巧,可以分享给我们,我们会用你的语言在Tecmint.com网站上发表出来。 + +如果你想分享任何技巧,但不想写成文章,可以发到tecmint[dot]com[at]gmail[dot]com,我们会将其包含在我们的文章中。不要忘记在下边评论框中留下有价值的反馈。保持联系。可以点赞或者将本文分享来帮助我们更好地传播内容。 + +-------------------------------------------------------------------------------- + +via: http://www.tecmint.com/5-linux-command-line-tricks/ + +作者:[Avishek Kumar][a] +译者:[goreliu](https://github.com/goreliu) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出 + +[a]:http://www.tecmint.com/author/avishek/ +[1]:http://www.tecmint.com/history-command-examples/ +[2]:http://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/ \ No newline at end of file