├── README.org ├── common ├── 4 Ways to Watch or Monitor Log Files in Real Time.org ├── Boot Linux ISO From Android Phone.org ├── Find Devices Connected To Your Wifi In Linux.org ├── Fix Host 'IP' is blocked because of many connection errors on MySQL.org ├── How To Easily Recall Linux Commands.org ├── How to Quickly Type Special Characters in Linux.org ├── How to View Colored Man Pages in Linux.org ├── ccat - Show 'cat Command' Output with Syntax Hightlight.org └── how to burn iso image to dvd and usb using dd.org ├── examples ├── 10 wget command examples.org ├── 11 Useful split command examples for Linux systems.org └── Learn sed command with 20 examples.org ├── game └── play hearthstone-on-ubuntu-linux.org ├── index-generator.sh ├── raw ├── 10 Best Linux Business Apps.org ├── 12 MySQL-MariaDB Security Best Practices for Linux.org ├── 4 Ways to Speed Up SSH Connections in Linux.org ├── How to Check Integrity of Fil and Directory Using "AIDE" in Linux.org ├── How to Check MySQL Database Size in Linux.org ├── How to Configure Custom Access and Error Log Formats in Nginx.org ├── How to Easily Remember Linux Commands.org ├── How to Run Multiple Commands on Multiple Linux Servers.org ├── How to Search DuckDuckGo from the Linux Terminal.org ├── InsecRes - A Tool to Find Insecure Resources on HTTPS Sites.org ├── Testssl.sh - Testing TLS-SSL Encryption Anywere on Any Port.org ├── Top 10 Linux tools.org └── Top Ways to Learn Linux Online.org ├── shell └── How to modify scripts behavior on signals using bash traps.org ├── system ├── 4 Tools to Manage EXT2,EXT3 and EXT4 Health in Linux.org ├── 5 tricks for using the sudo command.org ├── How To Check Installed Linux Kernels.org ├── How To Set or Change Hostname in CentOS 7.org ├── How to Permanently Disable Swap in Linux.org ├── How to Set Up Easy Remote Desktop Access in linux.org ├── How to replicate SELinux policies among Linux machines.org ├── How to use cron in Linux.org ├── The Pinky Finger habits Of Experienced Sysadmins.org └── how to reset sudo password.org └── tools ├── 3 open source alternatives to MATLAB.org ├── Cryptr - A Simple CLI Utility To Encrypt And Decrypt File.org ├── File better bugs with coredumpctl.org ├── Googler:A Command Line Tool To Search Google.org ├── How To Control Media Players From Commandline In Linux.org ├── How to Install and Use TeamViewer on Linux.org ├── Packup - A Script To Quickly Share Updates Via USB Drive In Arch Linux.org └── sosreport in RHEL.org /README.org: -------------------------------------------------------------------------------- 1 | * Contributors 2 | 感谢GitHub以及: 3 | + splasky 4 | 5 | 感谢大家的热情参与,也欢迎更多的志愿者参与翻译 6 | * common 7 | 未分类的内容 8 | 9 | + [[https://github.com/lujun9972/linux-document/blob/master/common/How to View Colored Man Pages in Linux.org][ 给你一个五彩缤纷的Man Page]] <2017-12-22> 10 | + [[https://github.com/lujun9972/linux-document/blob/master/common/ccat - Show 'cat Command' Output with Syntax Hightlight.org][ ccat - 对'cat 命令'的输出进行语法高亮]] <2017-12-22> 11 | + [[https://github.com/lujun9972/linux-document/blob/master/common/How To Easily Recall Linux Commands.org][ 如何回忆起遗忘的Linux命令]] <2017-11-21> 12 | + [[https://github.com/lujun9972/linux-document/blob/master/common/Boot Linux ISO From Android Phone.org][ Boot Linux ISO From Android Phone]] <2017-11-21> 13 | + [[https://github.com/lujun9972/linux-document/blob/master/common/Fix Host 'IP' is blocked because of many connection errors on MySQL.org][ 修复MySQL由于太多连接引发的"Host 'IP' is blocked"的问题]] <2017-11-20> 14 | + [[https://github.com/lujun9972/linux-document/blob/master/common/4 Ways to Watch or Monitor Log Files in Real Time.org][ 实时监控日志文件的4中方法]] <2017-11-04> 15 | + [[https://github.com/lujun9972/linux-document/blob/master/common/how to burn iso image to dvd and usb using dd.org][ 如何使用dd将ISO镜像烧录入DVD和USB中]] <2017-10-30> 16 | + [[https://github.com/lujun9972/linux-document/blob/master/common/How to Quickly Type Special Characters in Linux.org][ Linux下如何快速输入特殊字符]] <2017-10-28> 17 | + [[https://github.com/lujun9972/linux-document/blob/master/common/Find Devices Connected To Your Wifi In Linux.org][ Linux中找出连上你Wifi的那些设备]] <2017-10-27> 18 | * examples 19 | 读什么手册啊,跟着我来做就好了. 20 | 21 | + [[https://github.com/lujun9972/linux-document/blob/master/examples/11 Useful split command examples for Linux systems.org][ 11个应用案例教你使用split]] <2017-11-16> 22 | + [[https://github.com/lujun9972/linux-document/blob/master/examples/Learn sed command with 20 examples.org][ 20个例子带你入门sed命令]] <2017-11-14> 23 | + [[https://github.com/lujun9972/linux-document/blob/master/examples/10 wget command examples.org][ 10个例子教你学会wget命令]] <2017-11-02> 24 | * game 25 | Linux好游戏 26 | 27 | + [[https://github.com/lujun9972/linux-document/blob/master/game/play hearthstone-on-ubuntu-linux.org][ 如何在Ubuntu linux上玩炉石传说]] <2017-11-02> 28 | * processing 29 | 正在翻译的内容,别人的东西可不要抢哦~ 30 | 31 | * raw 32 | 未翻译的内容,欢迎大家领取 33 | 34 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/InsecRes - A Tool to Find Insecure Resources on HTTPS Sites.org][ InsecRes - A Tool to Find Insecure Resources on HTTPS Sites]] <2017-12-22> 35 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/How to Easily Remember Linux Commands.org][ How to Easily Remember Linux Commands]] <2017-12-22> 36 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/How to Check Integrity of Fil and Directory Using "AIDE" in Linux.org][ How to Check Integrity of Fil and Directory Using "AIDE" in Linux]] <2017-12-22> 37 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/Testssl.sh - Testing TLS-SSL Encryption Anywere on Any Port.org][ Testssl.sh - Testing TLS-SSL Encryption Anywere on Any Port]] <2017-12-21> 38 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/How to Search DuckDuckGo from the Linux Terminal.org][ How to Search DuckDuckGo from the Linux Terminal]] <2017-12-21> 39 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/How to Run Multiple Commands on Multiple Linux Servers.org][ How to Run Multiple Commands on Multiple Linux Servers]] <2017-12-21> 40 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/How to Configure Custom Access and Error Log Formats in Nginx.org][ How to Configure Custom Access and Error Log Formats in Nginx]] <2017-12-21> 41 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/How to Check MySQL Database Size in Linux.org][ How to Check MySQL Database Size in Linux]] <2017-12-21> 42 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/4 Ways to Speed Up SSH Connections in Linux.org][ 4 Ways to Speed Up SSH Connections in Linux]] <2017-12-21> 43 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/12 MySQL-MariaDB Security Best Practices for Linux.org][ 12 MySQL-MariaDB Security Best Practices for Linux]] <2017-12-21> 44 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/10 Best Linux Business Apps.org][ 10 Best Linux Business Apps]] <2017-12-16> 45 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/Top 10 Linux tools.org][ Top 10 Linux tools]] <2017-11-16> 46 | + [[https://github.com/lujun9972/linux-document/blob/master/raw/Top Ways to Learn Linux Online.org][ Top Ways to Learn Linux Online]] <2017-11-06> 47 | * shell 48 | 别不把shell当语言 49 | 50 | + [[https://github.com/lujun9972/linux-document/blob/master/shell/How to modify scripts behavior on signals using bash traps.org][ 使用bash trap修改脚本应对信号的行为]] <2017-10-29> 51 | * system 52 | 系统管理相关内容 53 | 54 | + [[https://github.com/lujun9972/linux-document/blob/master/system/How to Permanently Disable Swap in Linux.org][ 如何永久禁用Linux交换空间]] <2017-12-22> 55 | + [[https://github.com/lujun9972/linux-document/blob/master/system/How To Set or Change Hostname in CentOS 7.org][ 如何设置/更改CentOS7的主机名]] <2017-12-21> 56 | + [[https://github.com/lujun9972/linux-document/blob/master/system/5 tricks for using the sudo command.org][ sudo命令的5个小技巧]] <2017-11-16> 57 | + [[https://github.com/lujun9972/linux-document/blob/master/system/How to Set Up Easy Remote Desktop Access in linux.org][ 如何设置Linux版的远程桌面连接]] <2017-11-13> 58 | + [[https://github.com/lujun9972/linux-document/blob/master/system/How to use cron in Linux.org][ 如何使用Linux中的cron]] <2017-11-11> 59 | + [[https://github.com/lujun9972/linux-document/blob/master/system/4 Tools to Manage EXT2,EXT3 and EXT4 Health in Linux.org][ 4个管理 EXT2,EXT3 以及 EXT4 健康状况的工具]] <2017-11-08> 60 | + [[https://github.com/lujun9972/linux-document/blob/master/system/The Pinky Finger habits Of Experienced Sysadmins.org][ 系统管理老手教你小指的妙用]] <2017-11-07> 61 | + [[https://github.com/lujun9972/linux-document/blob/master/system/How to replicate SELinux policies among Linux machines.org][ 如何在Linux机器之间复制SELinux策略]] <2017-11-06> 62 | + [[https://github.com/lujun9972/linux-document/blob/master/system/How To Check Installed Linux Kernels.org][ 如何查看已安装的Linux Kernels]] <2017-11-02> 63 | + [[https://github.com/lujun9972/linux-document/blob/master/system/how to reset sudo password.org][ 如何重置sudo密码]] <2017-10-30> 64 | * tools 65 | 又有什么新玩意? 66 | 67 | + [[https://github.com/lujun9972/linux-document/blob/master/tools/How to Install and Use TeamViewer on Linux.org][ TeamViewer使用指南]] <2017-11-21> 68 | + [[https://github.com/lujun9972/linux-document/blob/master/tools/File better bugs with coredumpctl.org][ 使用coredumpctl帮你定位bug]] <2017-11-16> 69 | + [[https://github.com/lujun9972/linux-document/blob/master/tools/sosreport in RHEL.org][ RHEL sosreport简介]] <2017-11-14> 70 | + [[https://github.com/lujun9972/linux-document/blob/master/tools/Cryptr - A Simple CLI Utility To Encrypt And Decrypt File.org][ Cryptr - 一款简单的加解密CLI工具]] <2017-11-14> 71 | + [[https://github.com/lujun9972/linux-document/blob/master/tools/How To Control Media Players From Commandline In Linux.org][ 如何在Linux命令行控制媒体播放器]] <2017-11-09> 72 | + [[https://github.com/lujun9972/linux-document/blob/master/tools/Packup - A Script To Quickly Share Updates Via USB Drive In Arch Linux.org][ Packup - 一款通过U盘快速共享Arch Linux升级包的脚本]] <2017-11-06> 73 | + [[https://github.com/lujun9972/linux-document/blob/master/tools/3 open source alternatives to MATLAB.org][ 3个MATLAB的开源替代]] <2017-11-05> 74 | + [[https://github.com/lujun9972/linux-document/blob/master/tools/Googler:A Command Line Tool To Search Google.org][ Googler:搜索Google的命令行工具]] <2017-11-02> 75 | -------------------------------------------------------------------------------- /common/4 Ways to Watch or Monitor Log Files in Real Time.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 实时监控日志文件的4中方法 2 | #+URL: https://www.tecmint.com/watch-or-monitor-linux-log-files-in-real-time/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: log common 5 | #+DATE: [2017-11-02 四 22:00] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 在Linux下如何才能实时查看日志内容呢? 有很多工具可以帮助我们在文件持续修改的同时输出文件内容. 11 | 最常用的莫过于 [[https://www.tecmint.com/view-contents-of-file-in-linux/][tail命令]] 了. 12 | 13 | Read Also: [[https://www.tecmint.com/best-linux-log-monitoring-and-management-tools/][4 Good Open Source Log Monitoring and Management Tools for Linux]] 14 | 15 | * 1. tail Command – Monitor Logs in Real Time 16 | 17 | 如前所述, =tail= 命令是实施显示日志的最常用的方法. 不过该命令有两个版本,如下所示. 18 | 19 | 第一个例子是为 =tail= 命令加上 =f= 参数. 20 | 21 | #+BEGIN_SRC shell 22 | $ sudo tail -f /var/log/apache2/access.log 23 | #+END_SRC 24 | 25 | [[https://www.tecmint.com/wp-content/uploads/2017/10/Monitor-Apache-Logs-in-Real-Time.png]] 26 | 27 | 28 | 第二个版本就是 =tailf= 命令. 它本身内建了 =-f= 参数,因此你无需再为它指定 =-f= 参数. 29 | 30 | #+BEGIN_SRC shell 31 | $ sudo tailf /var/log/apache2/access.log 32 | #+END_SRC 33 | 34 | [[https://www.tecmint.com/wp-content/uploads/2017/10/Apache-Logs-Monitoring.png]] 35 | 36 | 通常Linxu服务器上的日志都是轮转日志. 这种情况下,你需要用 =-F= 参数. 37 | 38 | Read Also: [[https://www.tecmint.com/manage-linux-system-logs-using-rsyslogd-and-logrotate/][How to Manage System Logs (Configure, Rotate and Import Into Database) in Linux]] 39 | 40 | =tail -F= 会监控是否创建了新日志(译者注:所谓新日志指的是同一个名字,但是fd不一样的日志文件),并且会转而显示新日志的内容,而不是老文件的内容. 41 | 42 | #+BEGIN_SRC shell 43 | $ sudo tail -F /var/log/apache2/access.log 44 | #+END_SRC 45 | 46 | 然而, 默认情况下, =tail= 命令只会显示文件最后10行的内容. 如果你只想在实时模式下查看最后两行的内容,那么可以连用 =-n= 和 =-f= 参数,如下这样. 47 | 48 | #+BEGIN_SRC shell 49 | $ sudo tail -n2 -f /var/log/apache2/access.log 50 | #+END_SRC 51 | 52 | [[https://www.tecmint.com/wp-content/uploads/2017/10/Watch-Last-Two-Lines-of-Log.png]] 53 | 54 | 55 | * 2. Multitail Command – Monitor Multiple Log Files in Real Time 56 | 57 | 另一个好玩的命令是 [[https://www.tecmint.com/view-multiple-files-in-linux/][multitail command]]. 从名字中就能看出它可以实时监控多个日志. 58 | Multitail还能让你前后翻阅被监控的文件. 59 | 60 | 使用下面命令可以在基于Debian或RedHat的系统中安装 mulitail. 61 | 62 | #+BEGIN_SRC shell 63 | $ sudo apt install multitail [On Debian & Ubuntu] 64 | $ sudo yum install multitail [On RedHat & CentOS] 65 | $ sudo dnf install multitail [On Fedora 22+ version] 66 | #+END_SRC 67 | 68 | 下面例子演示了如何同时显示两个日志文件. 69 | 70 | #+BEGIN_SRC shell 71 | $ sudo multitail /var/log/apache2/access.log /var/log/apache2/error.log 72 | #+END_SRC 73 | 74 | [[https://www.tecmint.com/wp-content/uploads/2017/10/Multitail-Monitor-Logs.png]] 75 | 76 | * 3. lnav Command – Monitor Multiple Log Files in Real Time 77 | 78 | 另一个类似 =multitail= 的命令是 [[https://www.tecmint.com/lnav-watch-and-analyze-apache-logs-in-linux/][lnav]]. =Lnav= 也能实时监控多个文件. 79 | 80 | 使用如下命令安装 =lnav=. 81 | 82 | #+BEGIN_SRC shell 83 | $ sudo apt install lnav [On Debian & Ubuntu] 84 | $ sudo yum install lnav [On RedHat & CentOS] 85 | $ sudo dnf install lnav [On Fedora 22+ version] 86 | #+END_SRC 87 | 88 | 同时查看两个日志的方法如下. 89 | 90 | #+BEGIN_SRC shell 91 | $ sudo lnav /var/log/apache2/access.log /var/log/apache2/error.log 92 | #+END_SRC 93 | 94 | [[https://www.tecmint.com/wp-content/uploads/2017/10/Lnav-Real-Time-Logs-Monitoring.png]] 95 | 96 | * 4. less Command – Display Real Time Output of Log Files 97 | 98 | 最后你可以用 [[https://www.tecmint.com/linux-more-command-and-less-command-examples/][less命令]] 查看日志文件,然后按下 =Shift+F= 也能实时查看日志内容. 99 | 100 | 跟 =tail= 一样, 在 =less= 中按下 =Shift+F= 会追踪文件末尾的内容. 你也可以在调用 =less= 命令时就加上 =+F= 参数. 101 | 102 | #+BEGIN_SRC shell 103 | $ sudo less +F /var/log/apache2/access.log 104 | #+END_SRC 105 | 106 | [[https://www.tecmint.com/wp-content/uploads/2017/10/Watch-Logs-Using-Less-Command.png]] 107 | 108 | 这是这样! 下面是其他一些关于日志监控与管理的文章,值得一读. 109 | 110 | 1. [[https://www.tecmint.com/view-contents-of-file-in-linux/][Manage Files Effectively using head, tail and cat Commands in Linux]] 111 | 2. [[https://www.tecmint.com/install-logrotate-to-manage-log-rotation-in-linux/][How to Setup and Manage Log Rotation Using Logrotate in Linux]] 112 | 3. [[https://www.tecmint.com/petiti-log-analysis-tool-for-linux-sysadmins/][Petiti – An Open Source Log Analysis Tool for Linux SysAdmins]] 113 | 4. [[https://www.tecmint.com/query-audit-logs-using-ausearch-tool-on-centos-rhel/][How to Query Audit Logs Using ‘ausearch’ Tool on CentOS/RHEL]] 114 | 5. [[https://www.tecmint.com/manage-systemd-logs-using-journalctl/][Manage Log Messages Under Systemd Using Journalctl {Comprehensive Guide}]] 115 | -------------------------------------------------------------------------------- /common/Boot Linux ISO From Android Phone.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Boot Linux ISO From Android Phone 2 | #+URL: http://www.linuxandubuntu.com/home/boot-linux-iso-from-android-phone 3 | #+AUTHOR: lujun9972 4 | #+TAGS: ISO android 5 | #+DATE: [2017-11-20 一 20:50] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | ​我们Linux用户总是不肯只局限于使用某一个特定的发行版. 我们总是探索新东西,探索那些令人兴奋的东西. 新的[[http://www.linuxandubuntu.com/home/5-best-linux-desktop-environments-with-pros-cons][桌面环境]], 新的内核或者新的Linux体验. 10 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/flirt-with-linux-distributions-meme_orig.jpg]] 11 | 这也是为什么我们总是在第一时间试用那些新出现的发行版以及流行发行版的更新版本. 12 | 13 | 但是有个问题,我们需要为每个发行版都制作一个可启动的U盘. 那么有什么方法能够解决这个问题吗? 答案是 YES! 14 | 15 | 解决的方法是 ‘不要去制作可启动的U盘’. 没错, 你没有看错. 16 | 17 | 有一个名叫 =DriveDroid= ([[http://www.theitstuff.com/root-android-phone][需要root权限]])的 Android 应用,它可以将iso镜像挂载为USB驱动盘从而让你启动进入所选择的发行版. 18 | 然后你就可以测试并且安装这个Linux发行版了. 19 | 20 | 你需要: 21 | 22 | 1 一台root过的 Android 设备 ([[http://www.theitstuff.com/root-android-phone][How to root Android?]]) 23 | 2 一个Linux发行版的iso镜像 24 | 3 一根USB线 25 | 4 安装好DriveDroid ([[https://play.google.com/store/apps/details?id=com.softwarebakery.drivedroid&hl=en][click here]] to Install) 26 | 27 | ​安装好​ DriveDroid 后, 运行该应用,会弹出一个窗口,之间点击skip就行了. 28 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/install-drivedroid-in-android-from-play-store_orig.jpg]] 29 | 然后, 它会要求超级用户(root)权限. 点击授权. 30 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/drivedroid-needs-superuser-permissions_orig.jpg]] 31 | 然后你会看到下面的窗口 32 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/make-android-iso-bootable-drivedroid_orig.jpg]] 33 | 现在打开你的文件管理器,将Linux iso文件拷贝到内部存储的 =Downloads/images= 中. 若该目录不存在则创建它. 34 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/browse-to-linux-distro-iso-in-drivedroid_orig.jpg]] 35 | 现在回到​ =DriveDroid=, 你会看到已经能够列出你的iso文件了. 点击它. 36 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/boot-ubuntu-17-10-from-android_orig.jpg]] 37 | ​这会弹出一个类似下面的窗口. 你最多一次可以挂载两个不同的ISO文件. 现在点击 =Mass Storage 1= 的那个 =Writable USB= 图标. 38 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/drivedroid-permissions_orig.jpg]] 39 | DriveDroid随后会尝试挂载ISO文件,你可以在通知栏上看到进度. 40 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/host-iso-to-android-device_orig.jpg]] 41 | 挂载完成后(最多10秒),通知栏会出现类似下面的成功信息. 42 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/make-device-bootable-from-android_orig.jpg]] 43 | 现在启动介质已经准备好了. 重启计算机然后按下启动磁盘选择键. 你会发现有新磁盘出现在启动磁盘列表中. 44 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/boot-linux-from-android-device_orig.jpg]] 45 | 这里的 =UEFI: Linux File-Stor Gadget 0318= 就是刚创建的启动盘. 46 | 47 | 选中它就会启动你的iso镜像. 48 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ubuntu-17-10-boot-menu_orig.jpg]] 49 | BAM! 我们成功了. 50 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/boot-linux-from-android-phone_orig.jpg]] 51 | 我们成功的从android手机上启动了一个Linux发行版. 我已经用了 DriveDroid 超过10个月了,它棒极了. 52 | 53 | * 结论 54 | 55 | 你可以用Android设备挂载Linux ISO文件来创建一个启动介质​. 你需要一个有root权限的android设备, USB 线, Drivedroid 应用 以及 一个 Linux iso文件. 56 | 通过android创建的虚拟USB用起来跟实际的USB一样. 这比创建一个实际的安装介质要快速和方便的多. 57 | -------------------------------------------------------------------------------- /common/Find Devices Connected To Your Wifi In Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Linux中找出连上你Wifi的那些设备 2 | #+URL: http://www.linuxandubuntu.com/home/find-devices-connected-to-your-wifi-in-linux 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-10-27 五 14:12] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 通常来说,我们的互联网连接应该是私有的,能够隔绝坏家伙的. 10 | 然而当今要获取连接网络的密钥太容易了,任何人只要有少许网络知识就能在几分钟之内入侵我们的网络,消耗我们的带宽,让我们的网络变得缓慢无比. 11 | 当我们发现可疑行为时,最好检查一下连接到我们网络中的所有设备,验证他们的身份,并在发现未授权设备时采取相应的措施. 12 | 本文我们将会演示如何获取连接上我们网络的所有设备列表,从而找出是否有入侵者. 13 | 14 | 最简单的方法莫过于登陆路由器的控制面板,查看"连接设备". 15 | 16 | 然而,很多时候我们并没有权限登陆路由器,因此我们得采取其他方法代替. 17 | 18 | * 在终端探测连接上本地网络的计算机 19 | 20 | 第一步是获知我们网络IP的格式. 打开终端并输入: 21 | #+BEGIN_SRC shell 22 | $ ifconfig 23 | #+END_SRC 24 | 会显示类似下面的内容: 25 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/ipconfig_orig.jpg]] 26 | 27 | 这里我们可以看到网络的格式形如 192.168.1.X 并且广播 IP (用于通知网络中的所有计算机) 为 192.168.1.255 (在 Bcast 后面). 28 | 29 | 有了这些数据,我们可以这样做: 30 | #+BEGIN_SRC shell 31 | $ ping -b 192.168.1.255 32 | #+END_SRC 33 | 这种方法不一定有用,因为有些计算机可能根本不会回应ping. 在我的本地网络中就没有收到任何回复. 34 | 35 | * 使用nmap探测网络上的计算机 36 | 37 | 如果你想识别网络中的所有机器(当你的网络是无线wifi时,这特别的有用). 38 | 39 | 在终端中输入: 40 | #+BEGIN_SRC shell 41 | # nmap -sP 42 | #+END_SRC 43 | Nmap会显示类似下面的结果: 44 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/nmap-command_orig.jpg]] 45 | #+BEGIN_SRC shell 46 | # nmap -sP 192.168.0.0/24 47 | Starting Nmap 4.20 (http://insecure.org) at 2017-08-18 11:45 EST 48 | Host Router (192.168.0.254) appears to be up. 49 | Host pc (192.168.0.1) appears to be up. 50 | Host mac (192.168.0.2) appears to be up. 51 | #+END_SRC 52 | 我们可以看到,对于连接上网络的每个设备都有如下信息: 53 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/nmap-scan-report_orig.jpg]] 54 | 55 | 其中显示了设备IP,MAC以及其他一些附加信息(在括号中显示的那些内容). 56 | 57 | 注意: 如果不是用sudo调用的,则不会显示 MAC 地址. 58 | 59 | * 结语 60 | 61 | 然而, 入侵者可以使用别的设备或者更改网卡的MAC地址后再次入侵我们的网络. 62 | 为了防止这种情况再出现,我们可以改变MAC的过滤策略,让它只允许指定MAC的设备连接进来,这样网络会变得更加安全. 63 | -------------------------------------------------------------------------------- /common/Fix Host 'IP' is blocked because of many connection errors on MySQL.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 修复MySQL由于太多连接引发的"Host 'IP' is blocked"的问题 2 | #+URL: https://www.cyberciti.biz/faq/error-1129-hy000-host-is-blocked-because-of-many-connection-errors/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: database MySQL MqriaDB 5 | #+DATE: [2017-11-16 四 19:16] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 11 | 使用下面命令登陆 mysql/mysqld 服务器: 12 | #+BEGIN_SRC shell 13 | $ mysql -u foo -h 172.16.5.100 -p dbnmame 14 | #+END_SRC 15 | 但却显示如下错误: 16 | #+BEGIN_EXAMPLE 17 | ERROR 1129 (HY000): Host ‘172.16.5.100’ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’ 18 | #+END_EXAMPLE 19 | 在Linux以及类UNIX系统中该如何解决这个问题呢? 20 | 21 | 允许连接的数量由 MySQL/MariaDB 的系统值 max_connections 决定. 当MySQL用于Web server时,为了改善性能,这个默认值设为151. 22 | 当网站特别繁忙时,或者 [[https://www.cyberciti.biz/faq/how-to-set-up-mariadb-master-slave-replication-with-ssl-on-ubuntu-linux/][MariaDB server in clustered mode]] 或者 [[https://www.cyberciti.biz/faq/howto-install-configure-mariadb-galera-master-cluster-ubuntulinux/][using a Galera master to master DB cluster]] 时,这常常会引起一些问题. 23 | 如果你需要支持更多的连接, 就应该修改该变量值. 24 | 25 | * 如何获取 max_connections 的当前值 26 | 27 | 输入以下命令: 28 | #+BEGIN_SRC shell 29 | $ mysql -u root -p 30 | #+END_SRC 31 | 然后输入下面sql语句: 32 | #+BEGIN_SRC sql 33 | mysql> show variables like "max_connections"; 34 | #+END_SRC 35 | 输出为: 36 | 37 | #+BEGIN_EXAMPLE 38 | +-----------------+--------+ 39 | | Variable_name | Value | 40 | +-----------------+--------+ 41 | | max_connections | 151 | 42 | +-----------------+--------+ 43 | 1 row in set (0.00 sec) 44 | #+END_EXAMPLE 45 | 46 | * 如何增加 increase max_connections 的值? 47 | 48 | 编辑 =/etc/= 目录中的 =my.cnf= 或 =mariadb.conf.d/50-server.cnf=: 49 | #+BEGIN_SRC shell 50 | $ sudo vim /etc/mariadb.conf.d/50-server.cnf 51 | #+END_SRC 52 | 将下列行加到 =[mysqld]= 章节中(这里我们设置值为 1000. 最大可达 100000): 53 | #+BEGIN_SRC conf 54 | max_connections = 1000 55 | #+END_SRC 56 | 保存并关闭文件. 然后, [[https://www.cyberciti.biz/faq/ssh-restart-stop-mysql-server-unix-linux-command/][重启 mysqld 服务]]: 57 | #+BEGIN_SRC shell 58 | $ sudo systemctl restart mysql 59 | #+END_SRC 60 | 若是 CentOS/RHEL/Fedora/Oracle/Scientific Linux, 则运行: 61 | #+BEGIN_SRC shell 62 | $ sudo systemctl restart mysqld 63 | #+END_SRC 64 | 若为 [[https://www.cyberciti.biz/faq/freebsd-start-stop-restart-mysql-server/][FreeBSD unix, 则运行下面命令来重启系统]]: 65 | #+BEGIN_SRC shell 66 | $ sudo /usr/local/etc/rc.d/mysql-server restart 67 | #+END_SRC 68 | 使用下面命令来验证新的限制数: 69 | #+BEGIN_SRC shell 70 | $ mysql -u root -p -e 'show variables like "max_connections";' 71 | #+END_SRC 72 | [[https://www.cyberciti.biz/media/new/faq/2017/11/mysql-mariadb-max_connections.jpg]] 73 | Fig.01: How to view mac_connection limits when using MySQL/MariaDB 74 | 75 | * 关于 mysqladmin 命令的说明 76 | 77 | 运行下面bash命令来刷新所有缓存了的主机并删除限制 78 | #+BEGIN_SRC shell 79 | $ mysqladmin flush-hosts 80 | #+END_SRC 81 | 也可以带上用户名然后输入密码: 82 | #+BEGIN_SRC shell 83 | $ mysqladmin -u root -p flush-hosts 84 | #+END_SRC 85 | 86 | * 关于 “Too many open files” 错误的说明 87 | 88 | 这个错误说明你需要更改 mysqld 允许使用的文件描述符数量. 运行下面命令可以查看当前的文件描述服限制数: 89 | #+BEGIN_SRC shell 90 | $ mysql -u root -p -e 'show variables like "open_files_limit";' 91 | #+END_SRC 92 | 输出为: 93 | 94 | #+BEGIN_EXAMPLE 95 | Enter password: 96 | +------------------+--------+ 97 | | Variable_name | Value | 98 | +------------------+--------+ 99 | | open_files_limit | 500005 | 100 | +------------------+--------+ 101 | #+END_EXAMPLE 102 | 103 | 再次编辑 =my.cnf= 文件: 104 | #+BEGIN_SRC shell 105 | $ sudo vi my.cnf 106 | #+END_SRC 107 | 或者 108 | #+BEGIN_SRC shell 109 | $ sudo vim /etc/mariadb.conf.d/50-server.cnf 110 | #+END_SRC 111 | 设置 [mysqld] 章节中的值 112 | #+BEGIN_SRC conf 113 | open_files_limit = 1024000 114 | #+END_SRC 115 | 保存并关闭文件. 然后像上面那样重启 =mysqld=. 若你使用给予 GNU/Linux systemd 的发行版(比如RHEL/CentOS 7),则创建一个文件: 116 | #+BEGIN_SRC shell 117 | $ sudo vi /etc/systemd/system/mysqld.service 118 | #+END_SRC 119 | 在文件后添加这么一段内容: 120 | #+BEGIN_SRC conf 121 | [Service] 122 | User=mysql 123 | Group=mysql 124 | LimitNOFILE=1024000 125 | #+END_SRC 126 | 然后再重启服务: 127 | #+BEGIN_SRC shell 128 | $ sudo systemctl daemon-reload 129 | $ sudo systemctl restart mysqld 130 | #+END_SRC 131 | -------------------------------------------------------------------------------- /common/How To Easily Recall Linux Commands.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何回忆起遗忘的Linux命令 2 | #+URL: https://www.ostechnix.com/easily-recall-forgotten-linux-commands/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: apropos history bash 5 | #+DATE: [2017-11-17 五 09:40] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | Linux有几千个命令, 要想全部记住这些命令是不可能的,也是没有必要的. 有时候,我脑袋会发蒙记不起特定的命令. 而我只能呆呆的看着终端,尝试想起要输入的命令,却最终还是记不起来. 11 | 如果你也跟我一样, 那么你有福了. 借助 =Apropos= 命令和 BASH history 的功能能够帮助我们回想起忘记的Linux命令. 12 | Apropos 是一个用指定关键字搜索定位手册页中名字和描述部分的Linux命令. 大多数Linux发行版都预先安装了该命令,而且它的用法也很简单. 13 | 14 | * Apropos 命令 – 快速回忆起遗忘的Linux命令 15 | 16 | 假设你忘了那个命令可以输出目录中的内容了. 让我们看看 apropos 是否能够帮到你. 17 | 18 | #+BEGIN_SRC shell 19 | apropos "list directory" 20 | #+END_SRC 21 | 22 | 输出为:[[http://www.ostechnix.com/wp-content/uploads/2017/11/apropos.png]] 23 | 24 | 看到没? apropos 命令列出了一些与搜索字符串匹配的命令. 从中你可以看出, 使用 “dir” 命令可以列出目录内容. 25 | 26 | 我知道记住 “dir” 命令是一件很简单的事情, 我只是用它来演示一下 Apropos 命令而已. 你可以搜索任意的字符串. 但搜索的字符串应该足够精确. 27 | 比如下面的命令会列出所有包含单词 “list” 的命令. 28 | 29 | #+BEGIN_SRC shell 30 | apropos "list" 31 | #+END_SRC 32 | 33 | 这种情况下, apropos 对你的搜索根本没有什么帮助. 34 | 35 | 让我们再看看其他例子. 想查询内核但是忘了用哪个命令? 你可以这样做. 36 | 37 | #+BEGIN_SRC shell 38 | apropos "kernel" 39 | #+END_SRC 40 | 41 | 也可以不带引号. 42 | 43 | #+BEGIN_SRC shell 44 | apropos kernel 45 | #+END_SRC 46 | 47 | [[http://www.ostechnix.com/wp-content/uploads/2017/11/DeepinScreenshot_mate-terminal_20171115190817.png]] 48 | 49 | 从中可以看出, 可以使用 “uname” 命令来显示Linux内核的详细信息. 50 | 51 | 请注意,当搜索字符串中包含不止一个单词时应该用引号引起来. 52 | 53 | 忘了哪个命令可以连接到远程系统了? 不要紧! 用下面命令查一下就好!! 54 | 55 | #+BEGIN_SRC shell 56 | apropos "remote" 57 | #+END_SRC 58 | 59 | 请注意, Apropos 命令会显示出所有描述中包含搜索字符串的命令. 因此你很可能需要滚动搜索列表才能找出需要的命令. 60 | 61 | 更多细节, 参见 man pages. 62 | 63 | #+BEGIN_SRC shell 64 | man apropos 65 | #+END_SRC 66 | 67 | * 忘了几天前输过的一长串命令该怎么办呢? 68 | 69 | 没问题. 我还有方法. 70 | 71 | 按下 “CTRL+R” 然后输入命令的前面几个自负,就可以快速向后搜索输入过的命令. 你会看到一系列在bash history出现的命令. 72 | 使用 UP/DOWN 方向键可以切换命令. 当找到想要的那个命令后, 按下 TAB 或者 右方向键可以选中该命令,再按下 ENTER 执行该命令. 73 | 74 | 此外, 你也可以将重要的和常用的命令保存起来或者加上书签, 这样你无需搜索网站或man page就能找回这些命令. 75 | 详细说明请阅读下面链接. 76 | 77 | + [[https://www.ostechnix.com/save-commands-terminal-use-demand/][Save commands in Terminal and use them on demand]] 78 | + [[https://www.ostechnix.com/bookmark-linux-commands-easier-repeated-invocation/][Bookmark the frequently used commands]] 79 | 80 | 这就是所有内容了. 希望本文对你有所帮助. 如果你有其他好方法请给我们留言. More good stuffs to come. Stay tuned! 81 | -------------------------------------------------------------------------------- /common/How to Quickly Type Special Characters in Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Linux下如何快速输入特殊字符 2 | #+URL: https://www.maketecheasier.com/quickly-type-special-characters-linux/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-10-28 六 16:56] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 有时你可能需要输入一些特殊字符,比如外国文字中的带音标字符或者数学中的公式符号. 11 | 而这些符号在键盘上并没有按键对应,那该怎么办呢? 12 | 13 | 你可以使用系统内建的字符映射程序或者类似 =GNOME Characters= 这样的第三方程序来查询出想要的字符,然后拷贝该字符并将之粘帖出来. 14 | 但是这种方法很繁琐,尤其当你经常要输入特殊字符时,就特别的浪费时间了. 15 | 16 | 本文演示两种在Linux中快速输入特定Unicode字符的方式,而且这两种方式都无需用到外部程序. 17 | 18 | * 1. 使用Unicode码点来输入 19 | 20 | 每个 Unicode 字符都有一个码点与之对应. 比如, 美元符($)的表示法为 U+0024. 码点就是 =U+= 后面的那个 “0024.” 21 | 22 | 如果你想插入一个键盘上没有的字符, 可以按下 =Ctrl + Shift + U= 然后输入4个子的码点, 再按下回车就行了. 23 | 24 | [[https://www.maketecheasier.com/assets/uploads/2017/10/special-characters-linux-unicode.gif]] 25 | 26 | 该方法需要你记忆常用字符的Unicode码点. 你可以在这篇 [[https://en.wikipedia.org/wiki/List_of_Unicode_characters][Wikipedia article]] 中找到英文阅读者最常用的那些码点. 27 | 28 | 相关资料: [[https://www.maketecheasier.com/use-emojis-in-linux/][How to Use Emojis in Linux]] 29 | 30 | * 2. 使用组合键输入 31 | 32 | 另一个简单而快速地输入特殊字符的方法是使用 compose key 序列. 33 | 键盘上并没有一个叫做 compose key 的键; 你需要将一个键定义成这个 compose key. 34 | 35 | 在GNOME中,你需要安装 =Gnome Tweak Tool= 来定义 compose key. 在Ubuntu中可以通过下面命令来安装: 36 | 37 | #+BEGIN_SRC shell 38 | sudo apt install gnome-tweak-tool 39 | #+END_SRC 40 | 41 | 安装好后, 运行它,然后在边栏上选择 “Keyboard & Mouse”, 在点击 =Compose Key= 设置后的 "Disabled" 按钮开启该功能并选择一个按键作为 Compose Key. 42 | 43 | [[https://www.maketecheasier.com/assets/uploads/2017/10/special-characters-linux-compose-1.jpg]] 44 | 45 | 需要注意的是,设置为compose key的按键只能作为compose key来使用,而失去了原始的功能. 46 | 47 | 设置好 compose key 后, 任何字符都能通过按下compose key并接着其他键序列的方式输入. 48 | 49 | 你可以在 [[https://web.archive.org/web/20140412090608/http://www.hermit.org/Linux/ComposeKeys.html][这里]] 查看常用Unicode字符的 compose key sequences. 50 | 比如, 商标字符 © 的序列是 =oc=. 那么按下 Compose Key再输入 =oc= 就会插入这个字符了. 51 | 52 | 类似的,按下 Compose Key 再输入 =oo= 就是输入温度符号 °. 53 | 54 | 注意到 compose key sequence 跟实际要插入的字符多少有点类似,而且最多只有两个字符,因此它很容易记忆. 55 | 56 | * 结尾 57 | 58 | 我们演示了两个在Linux中输入特殊字符的方法. 如果你喜欢那种方法呢?或者你有什么其他方法么?请一定告诉我们. 59 | -------------------------------------------------------------------------------- /common/How to View Colored Man Pages in Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 给你一个五彩缤纷的Man Page 2 | #+URL: https://www.tecmint.com/view-colored-man-pages-in-linux/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: man common 5 | #+DATE: [2017-12-21 四 17:10] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 在类Unix操作系统中, man page (全称manual page) 指的是为终端程序/工具提供的文档(一般统称命令). 其中包含有命令的名词,使用的语法,命令描述,参数变量说明,作者,版权,相关命令等内容. 10 | 11 | Read Also: [[https://www.tecmint.com/cat-command-output-with-syntax-highlighting-or-color/][ccat – Show ‘cat Command’ Output with Syntax Highlighting or Colorizing]] 12 | 13 | 你可以使用下面命令来查看manual page; 下面这条命令就会显示 [[https://www.tecmint.com/how-to-check-disk-space-in-linux/][df命令]] 的man页: 14 | 15 | #+BEGIN_SRC shell 16 | $ man df 17 | #+END_SRC 18 | [[https://www.tecmint.com/wp-content/uploads/2017/12/df-Command-Man-Page.png]] 19 | 20 | 默认情况下, man 程序会使用诸如 [[https://www.tecmint.com/linux-more-command-and-less-command-examples/][more 或 less]] 这样的终端分页程序来格式化其输出, 而对于各种文本(粗体,下划线等也是一样)一般都是用白色来显示的. 21 | 22 | 你可以在 =~/.bashrc= 文件中通过设置各种 =LESS_TERMCAP= 变量来设置染色方案从而使得man page更好看. 23 | 24 | #+BEGIN_SRC shell 25 | $ vi ~/.bashrc 26 | #+END_SRC 27 | 28 | 将下面这些变量加进去. 29 | 30 | #+BEGIN_SRC shell 31 | export LESS_TERMCAP_mb=$'\e[1;32m' 32 | export LESS_TERMCAP_md=$'\e[1;32m' 33 | export LESS_TERMCAP_me=$'\e[0m' 34 | export LESS_TERMCAP_se=$'\e[0m' 35 | export LESS_TERMCAP_so=$'\e[01;33m' 36 | export LESS_TERMCAP_ue=$'\e[0m' 37 | export LESS_TERMCAP_us=$'\e[1;4;31m' 38 | #+END_SRC 39 | 40 | 上面配置中颜色代码的意义如下: 41 | 42 | + 31 – red 43 | + 32 – green 44 | + 33 – yellow 45 | 46 | 上面配置中转义代码的意义如下: 47 | 48 | + 0 – reset/normal 49 | + 1 – bold 50 | + 4 – underlined 51 | 52 | 随后你可以通过输入 =reset= 来重置你的终端,或者直接开启一个新shell. 现在查看 [[https://www.tecmint.com/how-to-check-disk-space-in-linux/][df命令]] 的man page, 显示如下, 要比默认的显示好看的多. 53 | 54 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Colored-Man-Page.png]] 55 | 56 | 除此之外, 你也可以使用 [[http://www.jedsoft.org/most/][MOST]] 这个分页程序, 它运行在类Unix操作系统上而且支持多窗口显示,还能从左到右滚动窗口内容. 57 | 58 | #+BEGIN_SRC shell 59 | $ sudo apt install most #Debian/Ubuntu 60 | # yum install most #RHEL/CentOS 61 | # dnf install most #Fedora 22+ 62 | #+END_SRC 63 | 64 | 下一步, 将下面行加入 =~/.bashrc= 文件中, 然后像前面所说那样加载该文件并重置终端. 65 | 66 | #+BEGIN_SRC shell 67 | export PAGER="most" 68 | #+END_SRC 69 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Most-Paging-Program.png]] 70 | 71 | Read Also: [[https://www.tecmint.com/customize-bash-colors-terminal-prompt-linux/][How to Customize Bash Colors and Content in Linux Terminal Prompt]] 72 | -------------------------------------------------------------------------------- /common/ccat - Show 'cat Command' Output with Syntax Hightlight.org: -------------------------------------------------------------------------------- 1 | #+TITLE: ccat - 对'cat 命令'的输出进行语法高亮 2 | #+URL: https://www.tecmint.com/cat-command-output-with-syntax-highlighting-or-color/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: cat common 5 | #+DATE: [2017-12-21 四 17:12] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | ccat 跟 [[https://www.tecmint.com/13-basic-cat-command-examples-in-linux/][cat命令]] 很类似,但是它在显示文件内容时还会针对下面这些编程语言进行语法高亮: Javascript, Java, Go, Ruby, C, Python and Json. 10 | 11 | 要安装ccat, 首先要确保已经安装了[[https://www.tecmint.com/10-wget-command-examples-in-linux/][wget工具]]. 如果[[https://www.tecmint.com/10-wget-command-examples-in-linux/][wget命令]]尚未安装,那么使用下面命令来安装它: 12 | 13 | #+BEGIN_SRC shell 14 | # yum install wget [On CentOS/RHEL/Fedora] 15 | # apt-get install wget [On Debian and Ubuntu] 16 | #+END_SRC 17 | 18 | 要安装最新版的ccat命令,首先通过下面命令来下载压缩包. 二进制与源代码的发布包可以在官方[[https://github.com/jingweno/ccat/releases][ccat github页面]]上找到. 19 | 20 | #+BEGIN_SRC shell 21 | -------------- On 64-Bit -------------- 22 | # wget https://github.com/jingweno/ccat/releases/download/v1.1.0/linux-amd64-1.1.0.tar.gz 23 | -------------- On 32-Bit -------------- 24 | # wget https://github.com/jingweno/ccat/releases/download/v1.1.0/linux-386-1.1.0.tar.gz 25 | #+END_SRC 26 | 27 | 下载完了之后, 先列一下当前工作目录有哪些文件, 然后解压这个 ccat tar包(类似 linux-amd64-1.x.x 这样的名字) 并使用下面命令来将 ccat 可执行文件从解压的tar包中拷出来放到存放Linux可执行文件的系统目录中,比如 =/usr/local/bin/= 目录. 28 | 29 | #+BEGIN_SRC shell 30 | # ls 31 | # tar xfz linux-amd64-1.1.0.tar.gz 32 | # ls linux-amd64-1.1.0 33 | # cp linux-amd64-1.1.0/ccat /usr/local/bin/ 34 | # ls -al /usr/local/bin/ 35 | #+END_SRC 36 | [[https://www.tecmint.com/wp-content/uploads/2017/12/ccat-Command-Executable-Files.png]] 37 | 38 | 若由于某些原因导致可执行文件系统目录中的 ccat 文件没有设置可执行位, 那么使用下面命令为所有用户设置可执行权限. 39 | 40 | #+BEGIN_SRC shell 41 | # chmod +x /usr/local/bin/ccat 42 | #+END_SRC 43 | 44 | 使用下面命令来试着用ccat工具来现实一下系统配置文件. 文件中的内容应该会根据编程语言语法进行高亮. 45 | 46 | #+BEGIN_SRC shell 47 | # ccat /etc/sysconfig/network-scripts/ifcfg-ens33 48 | # ccat /etc/fstab 49 | #+END_SRC 50 | [[https://www.tecmint.com/wp-content/uploads/2017/12/ccat-Command-Usage.png]] 51 | 52 | 要在全系统范围内使用ccat命令替代[[https://www.tecmint.com/13-basic-cat-command-examples-in-linux/][cat command]], 在系统的 =bashrc= 文件中为ccat添加一个别名, 然后登出后再次登陆以使配置生效. 53 | 54 | #+BEGIN_SRC shell 55 | -------------- On CentOS, RHEL & Fedora -------------- 56 | # echo "alias cat='/usr/local/bin/ccat'" >> /etc/bashrc 57 | # exit 58 | -------------- On Debiab & Ubuntu -------------- 59 | # echo "alias cat='/usr/local/bin/ccat'" >> /etc/profile 60 | # exit 61 | #+END_SRC 62 | 63 | 最后, 运行cat命令来查看配置文件以确认ccat别名是否已经替代了cat命令. 现在输出文件的内容应该语法高亮了. 64 | 65 | #+BEGIN_SRC shell 66 | # cat .bashrc 67 | #+END_SRC 68 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Replace-cat-Command-with-ccat.png]] 69 | 70 | ccat 还能用来整合多个文件并以HTML格式显示内容, 比如下面这个例子. 71 | 72 | #+BEGIN_SRC shell 73 | # ccat --html /etc/fstab /etc/sysconfig/network-scripts/ifcfg-ens33> /var/www/html/ccat.html 74 | #+END_SRC 75 | 76 | 不过, 你需要在系统上安装一个类似 Apache HTTP server 或 Nginx 这样的web服务器才能查看HTML文件的内容. 77 | 78 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Display-File-Content-in-HTML.png]] 79 | 80 | 详细的配置和命令选项可以查看 [[https://github.com/jingweno/ccat][ccat官方github页面]]. 81 | -------------------------------------------------------------------------------- /common/how to burn iso image to dvd and usb using dd.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何使用dd将ISO镜像烧录入DVD和USB中 2 | #+URL: http://www.linuxandubuntu.com/home/how-to-burn-iso-image-to-dvd-and-usb-using-dd 3 | #+AUTHOR: lujun9972 4 | #+TAGS: dd common 5 | #+DATE: [2017-10-29 日 18:04] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 作为一名Linux狂热爱好者,我总是在尝试各式各样的 [[http://www.linuxandubuntu.com/home/category/distros][linux发行版]]. Linux上有一些方便的工具可以将ISO镜像写入到磁盘和USB中,比如[[http://www.linuxandubuntu.com/home/how-to-install-linux-mint-from-usb][Unetbootin]] 和 [[http://www.linuxandubuntu.com/home/etcher-burn-images-to-sd-card-make-bootable-usb][Etcher]]. 11 | 大多数的工具都有一个图形界面来引导用户方便地将下载下来的ISO镜像写入到磁盘和USB存储设备中. =dd= 则是一款在终端上完成相同任务的命令行工作. 12 | 那么,如何用 =dd= 来讲下载的ISO镜像写入DVD和USB呢? 让我们拭目以待. 13 | 14 | * 过程 15 | 16 | 步骤很简单. 但请注意,使用 =dd= 将ISO写入磁盘会破坏原磁盘的数据. 虽然后面的步骤都很简单,但我依然建议你,如果不习惯操作终端的话,还是去Windows上使用Etcher 或者 Rufus吧. 17 | 现在我们就开始了. 18 | 19 | ** 1 - 找出PC已经有的存储设备 20 | 21 | 第一步是确定PC上已经有的存储设备有哪些(不包括你要被写入ISO镜像的目标磁盘). 22 | 这一步是为了保证你不会选错目标磁盘,如果你选错了磁盘,那么你磁盘上的所有数据都会被抹掉. 23 | 运行命令 =ls /dev/sd*= 24 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/burn-usb_orig.png]] 25 | 26 | 上图的结果列出了那些我不希望SO文件写入的磁盘. 27 | 28 | ** 2 - 插入目标U盘并确定它的地址 29 | 30 | 现在插入目标存储设备,然后运行命令 =ls /dev/sd*= 31 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/burn-usb_1_orig.png]] 32 | 33 | 从上图中, 我们发现多了两项 =/dev/sdb= 和 =/dev/sdb1= 分别表示新的设备和设备上唯一的分区. 34 | 这里, =/dev/sdb= 表示我们想将ISO写入的目标磁盘. 35 | 36 | ** 3 - 进入ISO文件所在地址 37 | 38 | 知道目标磁盘地址后, 我们进入源ISO文件所在的目录. 本例中为 =Downloads= 目录. 39 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/burn-usb_2_orig.png]] 40 | 41 | ** 4 - 运行 dd 命令将文件从ISO拷贝到磁盘中 42 | 43 | 最后是使用 dd 命令将ISO镜像写入目标磁盘. 请注意,dd会删掉目标磁盘中的所有文件. 运行下面命令: 44 | =sudo dd if=archlinux-2017.iso of=/dev/sdb= 45 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/burn-usb_3_orig.png]] 46 | 47 | 根据ISO文件的大小不同, 完成的时间也不同. 请不要因为dd没有回馈任何进度信息而慌张,耐心点等待便是了. 48 | 49 | * 结论 50 | 51 | 这是一个关于如何使用 =dd= 将ISO镜像写入DVD和USB磁盘的简单教程. 52 | 再一次提醒你,若你不习惯操作 [[http://www.linuxandubuntu.com/home/10-best-linux-terminals-for-ubuntu-and-fedora][Linux终端]], 你可以使用 [[http://www.linuxandubuntu.com/home/how-to-make-a-multiboot-usb-in-linux-and-windows][ImageWriter]], [[http://www.linuxandubuntu.com/home/etcher-burn-images-to-sd-card-make-bootable-usb][Etcher]] 之类的工具. 53 | 希望本文对你有用. 谢谢阅读,欢迎留言. 54 | -------------------------------------------------------------------------------- /examples/10 wget command examples.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 10个例子教你学会wget命令 2 | #+URL: https://www.rosehosting.com/blog/wget-command-examples/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: examples 5 | #+DATE: [2017-10-26 四 16:22] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 我会向你展示10个 Wget 命令的实际案例. Wget 是一个用于下载文件的免费工具,它支持大多数常用的Internet协议,包括 HTTP, HTTPS, 以及 FTP. 11 | 12 | Wget这个名字来源于 World Wide Web + get. Wget 有很多功能,可以很方便地做到下载大型文件,递归下载,一次下载多个文件以及镜像web网站和FTP站点. 13 | 14 | Wget是非交互式的,但是使用起来相当的灵活. 你可以在脚本,cron任务,终端等地方调用它. 15 | 它可以在用户未登陆的情况下运行在后台. 也就是说你可以开始下载文件,然后退出系统,wget会在后台运行直到完成任务. 16 | 17 | 在本文中,我将演示一些wget的使用例子, 这些例子都很常见,比如下载文件,比如镜像整个网站. 18 | 19 | 在演示前,我们先在 [[https://www.rosehosting.com/ubuntu-vps.html][Ubuntu 16.04]] [[https://www.rosehosting.com/ubuntu-vps.html][VPS]] 上安装wget. 20 | 21 | 请注意,虽然该演示是在 Ubuntu 16.04 上进行的, 但是这些命令在其他 [[https://www.rosehosting.com/linux-vps-hosting.html][Linux]] 发行版中同样适用. 22 | 23 | * 登陆服务器并安装wget 24 | 25 | 第一步是 [[https://www.rosehosting.com/blog/connect-to-your-linux-vps-via-ssh/][通过SSH登陆服务器]]. 26 | 27 | 使用下面命令更新你的服务器: 28 | 29 | #+BEGIN_SRC shell 30 | apt-get update 31 | apt-get upgrade 32 | #+END_SRC 33 | 34 | 然后安装wget软件包: 35 | 36 | #+BEGIN_SRC shell 37 | apt-get install wget 38 | #+END_SRC 39 | 40 | 安装完成后,就可以开始使用wget命令了. 41 | 42 | * 1. 下载单个文件 43 | 44 | wget最常用也是最简单的用法就是用来下载单个文件. 45 | 46 | 你可以用下面命令想下载最新版的WordPress 47 | 48 | #+BEGIN_SRC shell 49 | wget https://wordpress.org/latest.zip 50 | #+END_SRC 51 | 52 | 你会看到如下输出: 53 | 54 | #+BEGIN_EXAMPLE 55 | --2017-10-14 03:46:06-- https://wordpress.org/latest.zip 56 | Resolving wordpress.org (wordpress.org)... 66.155.40.250, 66.155.40.249 57 | Connecting to wordpress.org (wordpress.org)|66.155.40.250|:443... connected. 58 | HTTP request sent, awaiting response... 200 OK 59 | Length: 8912693 (8.5M) [application/zip] 60 | Saving to: 'latest.zip' 61 | 62 | latest.zip 100%[=====================================================================================================>] 8.50M 5.03MB/s in 1.7s 63 | 64 | 2017-10-14 03:46:07 (5.03 MB/s) - 'latest.zip' saved [8912693/8912693] 65 | #+END_EXAMPLE 66 | 67 | 从中可以看出,wget还会显示出下载的进度, 当前下载速度, 文件大小, 当前日期时间 以及待下载文件的名称. 68 | 69 | 在我们的例子中, wget会下载文件并以"latest.zip"为名存放到当前目录中.zip” name. 70 | 71 | * 2. 下载文件并重命名 72 | 73 | 若你想以其他名称保存下载的文件,可以使用 =-O= 选项: 74 | 75 | #+BEGIN_SRC shell 76 | wget -O wordpress.zip https://wordpress.org/latest.zip 77 | #+END_SRC 78 | 79 | wget会下载文件并以"wordpress.zip"为名存放到当前目录中.zip” name. 80 | 81 | * 3. 指定下载目录 82 | 83 | 使用 =-P= 选项指定下载目录: 84 | 85 | #+BEGIN_SRC shell 86 | wget -P /opt/wordpress https://wordpress.org/latest.zip 87 | #+END_SRC 88 | 89 | 就会把文件下载到 /opt/wordpress 目录中. 90 | 91 | * 4. 限制下载速度 92 | 93 | 当你下载大型文件时,可能耗时很长,这事你可以限制wget的下载速度以防止它把整个带宽都占满了. 94 | 95 | 下面命令就将下载速度限制在了每秒300k: 96 | 97 | #+BEGIN_SRC shell 98 | wget --limit-rate=300k https://wordpress.org/latest.zip 99 | #+END_SRC 100 | 101 | * 5. 断点续传 102 | 103 | 在下载大型文件时,可能会由于网络连接抖动造成下载中断. 104 | 105 | 为了避免重新下载,可以使用 =-c= 选项进行断点续传: 106 | 107 | #+BEGIN_SRC shell 108 | wget -c https://wordpress.org/latest.zip 109 | #+END_SRC 110 | 111 | 若下载中断后你没有用 =-c= 进行断点续传,而是重新下载, wget 会在文件名后加上 “.1” 防止与前面下载的文件重名. 112 | 113 | * 6. 后台下载 114 | 115 | 当下载大型文件时, 可以使用 =-b= 选项让wget在后台下载文件. 116 | 117 | #+BEGIN_SRC shell 118 | wget -b http://example.com/big-file.zip 119 | #+END_SRC 120 | 121 | 输出内容会写入同目录下的 “wget-log” 文件, 这样你就可以用下面命令来检查下载状态了: 122 | 123 | #+BEGIN_SRC shell 124 | tail -f wget-log 125 | #+END_SRC 126 | 127 | * 7. 设置重试次数 128 | 129 | 若网络有问题导致下载时常中断,就可以使用 =-tries= 选项增加重试次数: 130 | 131 | #+BEGIN_SRC shell 132 | wget -tries=100 https://example.com/file.zip 133 | #+END_SRC 134 | 135 | * 8. 下载多文件 136 | 137 | 若你想同时下载多个文件,你可以将要在的文件URL存放在一个文本文件中(假设该文件名为download.txt). 138 | 139 | 下面命令创建一个文本文件: 140 | #+BEGIN_SRC shell 141 | touch download.txt 142 | #+END_SRC 143 | 144 | 然后可以用 nano 编辑该文件,输入所有想下载的文件URL: 145 | 146 | #+BEGIN_SRC shell 147 | nano download.txt 148 | 149 | http://example.com/file1.zip 150 | 151 | http://example.com/file2.zip 152 | 153 | http://example.com/file3.zip 154 | #+END_SRC 155 | 156 | 保存该文件, 然后使用 =-i= 选项下载文本文件中保存的所有文件: 157 | 158 | #+BEGIN_SRC shell 159 | wget -i download.txt 160 | #+END_SRC 161 | 162 | * 9. 下载FTP文件 163 | 164 | wget还支持下载FTP文件,可以为它设置用户名和密码,如下所示: 165 | 166 | #+BEGIN_SRC shell 167 | wget --ftp-user=username --ftp-password=password ftp://url-to-ftp-file 168 | #+END_SRC 169 | 170 | * 10. 下载整个网站 171 | 172 | 你甚至可以用wget下载完整的站点, 然后进行离线浏览. 方法是使用如下命令: 173 | 174 | #+BEGIN_SRC shell 175 | wget --mirror --convert-links --page-requisites ----no-parent -P /path/to/download https://example-domain.com 176 | #+END_SRC 177 | 178 | —mirror 会开启镜像所需要的所有选项. 179 | 180 | –convert-links 会将所有链接转换成本地链接以便离线浏览. 181 | 182 | –page-requisites 表示下载包括CSS样式文件,图片等所有所需的文件,以便离线时能正确地现实页面. 183 | 184 | –no-parent 用于限制只下载网站的某一部分内容. 185 | 186 | 此外, 你可以使用 =P= 设置下载路径. 187 | 188 | 以上例子覆盖了wget最常用的几个场景.[[https://www.gnu.org/software/wget/manual/wget.html][想更多地了解wget]], 你可以使用 =man wget= 查看它的帮助文档. 189 | 190 | 若你跟我们一样有一台 [[https://www.rosehosting.com/linux-vps-hosting.html][Linux VPS]] , 那么你只需要让Linux管理员帮忙在你的服务器上安装一下wget命令或者为他们提供一些使用wget的建议. 191 | 他们是 24/7 在线的,会帮你解决这个问题. 192 | -------------------------------------------------------------------------------- /examples/11 Useful split command examples for Linux systems.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 11个应用案例教你使用split 2 | #+URL: https://www.linuxtechi.com/split-command-examples-for-linux-unix/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-11-16 四 10:44] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | ‘split‘ 命令是一个Linux和UNIX系统中用于将文件拆分成片的命令. 拆分的结果文件默认为1000行,且以 ‘x’ 打头. 11 | 12 | 本文我们会展示11个使用split命令的案例. 此外我们还会展示如何将分拆的文件合并回原始文件. 13 | split 命令的语法为: 14 | 15 | #+BEGIN_SRC shell 16 | # split {options} {file_name} {prefix} 17 | #+END_SRC 18 | 19 | split 命令的常用参数如下: 20 | 21 | [[https://www.linuxtechi.com/wp-content/uploads/2017/11/Split-Command-Options-Linux.jpg]] 22 | 23 | 24 | * 例1) 拆分文件 25 | 26 | 假设有一个文件 tuxlap.txt, 使用下面命令可以将它拆分成片 27 | 28 | #+BEGIN_SRC shell 29 | [root@linuxtechi ~]# split tuxlap.txt 30 | [root@linuxtechi ~]# ll 31 | total 32 32 | -rw-------. 1 root root  980 Aug 12 00:11 anaconda-ks.cfg 33 | -rw-r--r--. 1 root root 9607 Nov 11 03:22 tuxlap.txt 34 | -rw-r--r--. 1 root root 8744 Nov 11 03:23 xaa 35 | -rw-r--r--. 1 root root  863 Nov 11 03:23 xab 36 | [root@linuxtechi ~]# 37 | #+END_SRC 38 | 39 | 如上所示, ‘tuxlab.txt‘ 被拆分成两个文件,名称分别为 ‘xaa’ 以及 ‘xab’. 40 | 41 | * 例2) Split 命令的 verbose 选项 42 | 43 | 参数 =–verbose= 可以让split运行时输出详细信息, 如下所示: 44 | 45 | #+BEGIN_SRC shell 46 | [root@linuxtechi ~]# split tuxlap.txt --verbose 47 | creating file ‘xaa’ 48 | creating file ‘xab’ 49 | [root@linuxtechi ~]# 50 | #+END_SRC 51 | 52 | * 例3) 指定拆分文件的行数 (-l) 53 | 54 | 假设我想以指定的行数来拆分文件, 比如200行每个文件,那么可以使用 =-l= 参数. 55 | 56 | #+BEGIN_SRC shell 57 | [root@linuxtechi ~]# split -l200 tuxlap.txt --verbose 58 | creating file ‘xaa’ 59 | creating file ‘xab’ 60 | creating file ‘xac’ 61 | creating file ‘xad’ 62 | creating file ‘xae’ 63 | creating file ‘xaf’ 64 | [root@linuxtechi ~]# 65 | #+END_SRC 66 | 67 | 检查一下每个文件多少行 68 | 69 | #+BEGIN_SRC shell 70 | [root@linuxtechi ~]# wc -l xa* 71 | 200 xaa 72 | 200 xab 73 | 200 xac 74 | 200 xad 75 | 200 xae 76 | 91 xaf 77 | 1091 total 78 | [root@linuxtechi ~]# 79 | #+END_SRC 80 | 81 | * 例4) 使用-b参数指定拆分文件的大小 82 | 83 | 我们可以指定文件大小来拆分文件. 只需要准照以下语法拆分文件就行,大小的单位可以是 bytes, KB , MB 以及 GB 84 | 85 | #+BEGIN_SRC shell 86 | # split -b{bytes} {file_name} 87 | 88 | # split -b nK {file_name} // n is the numeric value 89 | 90 | # split -b nM {file_name} // n is the numeric value 91 | 92 | # split -b nG {file_name} // n is the numeric value 93 | #+END_SRC 94 | 95 | 以byte为单位: 96 | 97 | #+BEGIN_SRC shell 98 | [root@linuxtechi ~]# split -b2000000 tuxlap.txt 99 | #+END_SRC 100 | 101 | 以KB为单位: 102 | 103 | #+BEGIN_SRC shell 104 | [root@linuxtechi ~]# split -b 50K tuxlap.txt 105 | #+END_SRC 106 | 107 | 以MB为单位: 108 | 109 | #+BEGIN_SRC shell 110 | [root@linuxtechi ~]# split -b 50M tuxlap.txt 111 | #+END_SRC 112 | 113 | 以GB为单位: 114 | 115 | #+BEGIN_SRC shell 116 | [root@linuxtechi ~]# split -b 1G tuxlap.txt 117 | #+END_SRC 118 | 119 | * 例5) 拆分出来的文件以数字结尾而不是字母结尾 (-d) 120 | 121 | 从上面的例子中可以看到split命令的结果文件是以字母结尾的,像这样: xaa, xab….. xan , 使用 ‘-d’ 选项就会创建出以数字结尾的拆分结果文件了 122 | 123 | #+BEGIN_SRC shell 124 | [root@linuxtechi ~]# split -d tuxlap.txt 125 | 126 | [root@linuxtechi ~]# ll 127 | total 1024256 128 | -rw-------. 1 root root 980 Aug 12 00:11 anaconda-ks.cfg 129 | -rwx------. 1 root root 1048576000 Nov 11 03:54 linux-lite.iso 130 | -rw-r--r--. 1 root root 120010 Nov 11 04:39 tuxlap.txt 131 | -rw-r--r--. 1 root root 11998 Nov 11 04:41 x00 132 | -rw-r--r--. 1 root root 12000 Nov 11 04:41 x01 133 | -rw-r--r--. 1 root root 12000 Nov 11 04:41 x02 134 | -rw-r--r--. 1 root root 12000 Nov 11 04:41 x03 135 | -rw-r--r--. 1 root root 12000 Nov 11 04:41 x04 136 | -rw-r--r--. 1 root root 12000 Nov 11 04:41 x05 137 | -rw-r--r--. 1 root root 12000 Nov 11 04:41 x06 138 | -rw-r--r--. 1 root root 12000 Nov 11 04:41 x07 139 | -rw-r--r--. 1 root root 12000 Nov 11 04:41 x08 140 | -rw-r--r--. 1 root root 12000 Nov 11 04:41 x09 141 | -rw-r--r--. 1 root root 12 Nov 11 04:41 x10 142 | [root@linuxtechi ~]# 143 | #+END_SRC 144 | 145 | * 例6) 指定拆分结果文件的前缀 146 | 147 | 我们可以指定拆分结果文件的前缀. 举个例子 148 | 149 | 语法为: 150 | 151 | #+BEGIN_SRC shell 152 | # split {file_name} {prefix_name} 153 | #+END_SRC 154 | 155 | #+BEGIN_SRC shell 156 | [root@linuxtechi ~]# split tuxlap.txt split_file_ 157 | 158 | [root@linuxtechi ~]# ll 159 | total 1024248 160 | -rw-------. 1 root root 980 Aug 12 00:11 anaconda-ks.cfg 161 | -rwx------. 1 root root 1048576000 Nov 11 03:54 linux-lite.iso 162 | -rw-r--r--. 1 root root 11998 Nov 11 04:56 split_file_aa 163 | -rw-r--r--. 1 root root 12000 Nov 11 04:56 split_file_ab 164 | -rw-r--r--. 1 root root 12000 Nov 11 04:56 split_file_ac 165 | -rw-r--r--. 1 root root 12000 Nov 11 04:56 split_file_ad 166 | -rw-r--r--. 1 root root 12000 Nov 11 04:56 split_file_ae 167 | -rw-r--r--. 1 root root 12000 Nov 11 04:56 split_file_af 168 | -rw-r--r--. 1 root root 12000 Nov 11 04:56 split_file_ag 169 | -rw-r--r--. 1 root root 12000 Nov 11 04:56 split_file_ah 170 | -rw-r--r--. 1 root root 12000 Nov 11 04:56 split_file_ai 171 | -rw-r--r--. 1 root root 12000 Nov 11 04:56 split_file_aj 172 | -rw-r--r--. 1 root root 12 Nov 11 04:56 split_file_ak 173 | -rw-r--r--. 1 root root 120010 Nov 11 04:39 tuxlap.txt 174 | [root@linuxtechi ~]# 175 | #+END_SRC 176 | 177 | * 例7) 指定拆分结果文件的个数 (-n) 178 | 179 | 假设我们想将一个iso文件拆分成5块结果文件. 使用 ‘-n’ 选项设置结果文件的个数. 180 | 181 | #+BEGIN_SRC shell 182 | [root@linuxtechi ~]# split -n5 linux-lite.iso 183 | #+END_SRC 184 | 185 | 使用 =ll= 验证一下拆分结果文件. 186 | 187 | #+BEGIN_SRC shell 188 | [root@linuxtechi ~]# ll 189 | total 2048124 190 | -rw-------. 1 root root        980 Aug 12 00:11 anaconda-ks.cfg 191 | -rwx------. 1 root root 1048576000 Nov 11 03:54 linux-lite.iso 192 | -rw-r--r--. 1 root root     120010 Nov 11 04:39 tuxlap.txt 193 | -rw-r--r--. 1 root root  209715200 Nov 11 05:22 xaa 194 | -rw-r--r--. 1 root root  209715200 Nov 11 05:22 xab 195 | -rw-r--r--. 1 root root  209715200 Nov 11 05:22 xac 196 | -rw-r--r--. 1 root root  209715200 Nov 11 05:23 xad 197 | -rw-r--r--. 1 root root  209715200 Nov 11 05:23 xae 198 | [root@linuxtechi ~]# 199 | #+END_SRC 200 | 201 | * 例8) 禁止产生0字节的结果文件 (-e) 202 | 203 | 当将一个小文件拆分成很多的结果文件时,可能会产生0字节的文件, 使用 =-e= 选项可以防止产生0字节的文件 204 | 205 | #+BEGIN_SRC shell 206 | [root@linuxtechi ~]# split -n60 -e tuxlap.txt 207 | [root@linuxtechi ~]# ls -l x* 208 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xaa 209 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xab 210 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xac 211 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xad 212 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xae 213 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xaf 214 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xag 215 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xah 216 | ............. 217 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xce 218 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xcf 219 | -rw-r--r--. 1 root root 2000 Nov 11 05:34 xcg 220 | -rw-r--r--. 1 root root 2010 Nov 11 05:34 xch 221 | [root@linuxtechi ~]# 222 | #+END_SRC 223 | 224 | * 例9) 指定拆分结果文件的后缀长度 (-a option) 225 | 226 | 使用下面命令会将一个iso文件按500M为限进行拆分,而且拆分的结果文件后缀长度为3: 227 | 228 | #+BEGIN_SRC shell 229 | [root@linuxtechi ~]# split -b 500M linux-lite.iso -a 3 230 | 231 | [root@linuxtechi ~]# ll 232 | total 2048124 233 | -rw-------. 1 root root        980 Aug 12 00:11 anaconda-ks.cfg 234 | -rwx------. 1 root root 1048576000 Nov 11 03:54 linux-lite.iso 235 | -rw-r--r--. 1 root root     120010 Nov 11 04:39 tuxlap.txt 236 | -rw-r--r--. 1 root root  524288000 Nov 11 05:43 xaaa 237 | -rw-r--r--. 1 root root  524288000 Nov 11 05:43 xaab 238 | [root@linuxtechi ~]# 239 | #+END_SRC 240 | 241 | * 例10) 拆分ISO文件后又合并成单个文件 242 | 243 | 假设一个 Windows Server ISO 文件有 4.2 GB大小,由于体积太大无法通过scp上传到远程服务器上. 244 | 245 | 为了解决这个问题,我们将ISO拆分成 n 份,传到远程服务器上后再用 =cat= 命令组合起来 246 | 247 | #+BEGIN_SRC shell 248 | [root@linuxtechi ~]# split -b 800M Windows2012r2.iso Split_IS0_ 249 | #+END_SRC 250 | 251 | 使用 =ll= 命令查看拆分结果文件, 252 | 253 | #+BEGIN_SRC shell 254 | [root@linuxtechi ~]# ll 255 | total 8871788 256 | -rw-------. 1 root root        980 Aug 12 00:11 anaconda-ks.cfg 257 | -rw-r--r--. 1 root root  838860800 Nov 11 06:29 Split_IS0_aa 258 | -rw-r--r--. 1 root root  838860800 Nov 11 06:29 Split_IS0_ab 259 | -rw-r--r--. 1 root root  838860800 Nov 11 06:29 Split_IS0_ac 260 | -rw-r--r--. 1 root root  838860800 Nov 11 06:29 Split_IS0_ad 261 | -rw-r--r--. 1 root root  838860800 Nov 11 06:29 Split_IS0_ae 262 | -rw-r--r--. 1 root root  347987968 Nov 11 06:29 Split_IS0_af 263 | -rw-r--r--. 1 root root     120010 Nov 11 04:39 tuxlap.txt 264 | -rwx------. 1 root root 4542291968 Nov 11 06:03 Windows2012r2.iso 265 | [root@linuxtechi ~]# 266 | #+END_SRC 267 | 268 | 现在使用scp上传这些文件到远程服务器上,然后使用 =cat= 命令合并这些文件 269 | 270 | #+BEGIN_SRC shell 271 | [root@linuxtechi ~]# cat Split_IS0_a* > Windows_Server.iso 272 | [root@linuxtechi ~]# 273 | #+END_SRC 274 | 275 | * 例11) 使用 md5sum 验证合并文件的完整性 276 | 277 | 在例子10中,我们将拆分结果文件合并起来了, 之后我们可以使用 =md5sum= 来验证完整性. 像这样: 278 | 279 | #+BEGIN_SRC shell 280 | [root@linuxtechi ~]# md5sum Windows2012r2.iso 281 | 5b5e08c490ad16b59b1d9fab0def883a  Windows2012r2.iso 282 | [root@linuxtechi ~]# 283 | 284 | [root@linuxtechi ~]# md5sum Windows_Server.iso 285 | 5b5e08c490ad16b59b1d9fab0def883a  Windows_Server.iso 286 | [root@linuxtechi ~]# 287 | #+END_SRC 288 | 289 | 上面的结果确认了文件是完整的,拆分的文件成功的恢复了. 290 | -------------------------------------------------------------------------------- /examples/Learn sed command with 20 examples.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 20个例子带你入门sed命令 2 | #+URL: https://www.linuxtechi.com/20-sed-command-examples-linux-users/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: sed examples 5 | #+DATE: [2017-11-14 二 07:32] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | Sed 命令或者说流编辑器是Linux/Unix系统提供的强力工具. 她主要用于文本替代, 查找并替换.但它也能做其他的文本维护工作,比如插入,删除,搜索等. 11 | 使用SED, 我们做到不用打开文件就完成编辑操作. Sed 还支持正则表达式, 这使得 sed 还成为一款强大的测试工具. 12 | 13 | 本文中, 我们将会通过一些例子学习使用 SED 命令. 使用sed命令的基本语法为, 14 | 15 | #+BEGIN_SRC shell 16 | sed OPTIONS… [SCRIPT] [INPUTFILE…] 17 | #+END_SRC 18 | 19 | [[https://www.linuxtechi.com/wp-content/uploads/2017/11/Sed-Command-Options.jpg]] 20 | 21 | 现在让我们看看一些例子. 22 | 23 | + 例1) 显示文件部分内容 24 | 25 | sed可以让你只查看文件的一部分内容. 使用下面命令来查看指定行的内容, 26 | 27 | #+BEGIN_SRC shell 28 | [linuxtechi@localhost ~]$ sed -n 22,29p testfile.txt 29 | #+END_SRC 30 | 31 | 这里, 选项 ‘n’ 抑制输出所有文件的内容,而命令 ‘p’ 会只输出22行到20行的内容. 32 | 33 | + 例2) 除了某些行外,显示所有内容 34 | 35 | 使用下面命令可以输出除了指定行外的所有内容, 36 | 37 | #+BEGIN_SRC shell 38 | [linuxtechi@localhost ~]$ sed 22,29d testfile.txt 39 | #+END_SRC 40 | 41 | 命令 ‘d’ 会将指定行从输出中删除. 42 | 43 | + 例3) 从第N行开始,每3行显示一行内容 44 | 45 | 要从第2行开始,显示每3行的内容,使用下面命令 46 | 47 | #+BEGIN_SRC shell 48 | [linuxtechi@localhost ~]$ sed -n '2-3p' file.txt 49 | #+END_SRC 50 | 51 | + 例4) 删除一行 52 | 53 | 使用下面命令删除一行, use the following command, 54 | 55 | #+BEGIN_SRC shell 56 | [linuxtechi@localhost ~]$ sed Nd testfile.txt 57 | #+END_SRC 58 | 59 | 这里 ‘N’ 为行好而 ‘d’ 命令删除指定行. 要删除最后一样,则可以这样 60 | 61 | #+BEGIN_SRC shell 62 | [linuxtechi@localhost ~]$ sed $d testfile.txt 63 | #+END_SRC 64 | 65 | + 例5) 删除连续的几行 66 | 67 | 要删除连续几行的内容,运行 68 | 69 | #+BEGIN_SRC shell 70 | [linuxtechi@localhost ~]$ sed '29-34d' testfile.txt 71 | #+END_SRC 72 | 73 | 这会删除 testfile.txt 中的第29到34行的内容.txt file. 74 | 75 | + 例6) 只保留指定范围的内容 76 | 77 | 要删除除了指定行之外的所有内容,使用 ‘!’ 78 | 79 | #+BEGIN_SRC shell 80 | [linuxtechi@localhost ~]$ sed '29-34!d' testfile.txt 81 | #+END_SRC 82 | 83 | 这里 ‘!’ 命令的意思是 =非=, 它会反转条件,即不要删除指定的行. 所有行,除了 29-34 行会从文件 testfile.txt 中删掉. 84 | 85 | + 例7) 增加空行/空格 86 | 87 | 要在每个非空行后添加一个空行, 使用选项 ‘G’, 88 | 89 | #+BEGIN_SRC shell 90 | [linuxtechi@localhost ~]$ sed G testfile.txt 91 | #+END_SRC 92 | 93 | + 例8) 搜索并替换字符串 94 | 95 | 可以这样搜索并替换字符串, 96 | 97 | #+BEGIN_SRC shell 98 | [linuxtechi@localhost ~]$ sed 's/danger/safety/' testfile.txt 99 | #+END_SRC 100 | 101 | 这里命令 ‘s’ 会搜索每行中第一个单词 ‘danger’ 然后将之替换为 ‘safety’. 102 | 103 | + 例9) 全文搜索并替换字符串 104 | 105 | 要全部替换文件中的单词,我们可以将命令 ‘g’ 与 ‘s’ 连用 106 | 107 | #+BEGIN_SRC shell 108 | [linuxtechi@localhost ~]$ sed 's/danger/safety/g' testfile.txt 109 | #+END_SRC 110 | 111 | + 例10) 替换第n次出现的字符串模式 112 | 113 | 我们可以只替换第n次出现的字符串. 比如将第二次淑贤的 ‘safety’ 替换为 ‘danger’, 114 | 115 | #+BEGIN_SRC shell 116 | [linuxtechi@localhost ~]$ sed ‘s/danger/safety/2’ testfile.txt 117 | #+END_SRC 118 | 119 | 将每行中的第二次出现的‘danger’替换掉, 120 | 121 | #+BEGIN_SRC shell 122 | [linuxtechi@localhost ~]$ sed 's/danger/safety/2g' testfile.txt 123 | #+END_SRC 124 | 125 | + 例11) 只替换指定行上的字符串 126 | 127 | 只替换指定行上的字符串, 这样做 128 | 129 | #+BEGIN_SRC shell 130 | [linuxtechi@localhost ~]$ sed '4 s/danger/safety/' testfile.txt 131 | #+END_SRC 132 | 133 | 这只会在第四行上做替换. 你也可以指定一系列的行, 134 | 135 | #+BEGIN_SRC shell 136 | [linuxtechi@localhost ~]$  sed '4-9 s/danger/safety/' testfile.txt 137 | #+END_SRC 138 | 139 | + 例12) 在匹配搜索的后面/前面添加一行 140 | 141 | 在匹配位置的后面添加一行内容, 使用命令 ‘a’ , 142 | 143 | #+BEGIN_SRC shell 144 | [linuxtechi@localhost ~]$ sed '/danger/a "This is new line with text after match"' testfile.txt 145 | #+END_SRC 146 | 147 | 在匹配位置的前面添加一行内容, 使用命令 ‘i’, 148 | 149 | #+BEGIN_SRC shell 150 | [linuxtechi@localhost ~]$ sed '/danger/i "This is new line with text before match" ' testfile.txt 151 | #+END_SRC 152 | 153 | + Example :13) 修改匹配行的整个内容 154 | 155 | 修改匹配行的整个内容使用命令 ‘c’, 156 | 157 | #+BEGIN_SRC shell 158 | [linuxtechi@localhost ~]$ sed '/danger/c "This will be the new line" ' testfile.txt 159 | #+END_SRC 160 | 161 | 这样若某行中包含 ‘danger’, 则整行内容都会改变. 162 | 163 | * sed高级命令 164 | 165 | 到目前为止,我们还只是用到了sed的简单表达式,现在我们来看看sed的更高级用法,这些用法往往会用到正则表达式. 166 | 167 | + 例14) 运行多条sed命令 168 | 169 | 若要运行多条sed表达式, 使用命令 ‘e’ 来将多个sed命令串起来, 170 | 171 | #+BEGIN_SRC shell 172 | [linuxtechi@localhost ~]$  sed -e 's/danger/safety/g' -e 's/hate/love/' testfile.txt 173 | #+END_SRC 174 | 175 | + 例15) 修改文件前做个备份 176 | 177 | 使用选项‘-i.bak’来在修改文件前创建备份, 178 | 179 | #+BEGIN_SRC shell 180 | [linuxtechi@localhost ~]$ sed -i.bak -e 's/danger/safety/g'  testfile.txt 181 | #+END_SRC 182 | 183 | 这回创建一个以 =.bak= 为后缀的备份文件. 当然你也可以选择其他喜欢的扩展名. 184 | 185 | + 例16) 删除以指定模式开头并且以指定模式结尾的行 186 | 187 | 删除以指定模式开头并且以指定模式结尾的行,使用以下命令 188 | 189 | #+BEGIN_SRC shell 190 | [linuxtechi@localhost ~]$ sed -e 's/danger.*stops//g' testfile.txt 191 | #+END_SRC 192 | 193 | 这回删除以‘danger’开头且以‘stops’结尾的行,‘.*’ 表示中间可以有任意多个单词. 194 | 195 | + 例17) 在行中添加内容 196 | 197 | 使用sed和正则表达式在每行前面添加内容 198 | 199 | #+BEGIN_SRC shell 200 | [linuxtechi@localhost ~]$ sed -e 's/.*/testing sed &/' testfile.txt 201 | #+END_SRC 202 | 203 | 现在每一行前面都加上 ‘testing sed’ 了. 204 | 205 | + 例18) 删除所有注释行以及空行 206 | 207 | 删除所有注释的行(以#开头的行)以及空行, 208 | 209 | #+BEGIN_SRC shell 210 | [linuxtechi@localhost ~]$ sed -e 's/#.*//;/^$/d' testfile.txt 211 | #+END_SRC 212 | 213 | 之想删除注释行的话 214 | 215 | #+BEGIN_SRC shell 216 | [linuxtechi@localhost ~]$ sed -e 's/#.*//' testfile.txt 217 | #+END_SRC 218 | 219 | + 例19) 从 =/etc/passwd= 中抽取出所有的用户名列表 220 | 221 | 用下面命令可以从 =/etc/passwd= 中抽取出所有的用户名列表 222 | 223 | #+BEGIN_SRC shell 224 | [linuxtechi@localhost ~]$  sed 's/\([^:]*\).*/\1/' /etc/passwd 225 | #+END_SRC 226 | 227 | 所有用户的列表都会显示在屏幕上. 228 | 229 | + 例20) 防止使用sed时覆写了系统链接 230 | 231 | ‘sed -i’ 命令会删除系链接接并且创建一个常规的文件替代这个链接. 为了防止 ‘sed -i‘ 破坏这个链接, 执行sed时你还需要使用 ‘–follow-symklinks‘ 参数. 232 | 233 | 假设我想金庸 CentOS 或 RHEL 服务器上的 SELinux,可以这样 234 | 235 | #+BEGIN_SRC shell 236 | [linuxtechi@localhost ~]# sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux 237 | #+END_SRC 238 | -------------------------------------------------------------------------------- /game/play hearthstone-on-ubuntu-linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何在Ubuntu linux上玩炉石传说 2 | #+URl: https://www.maketecheasier.com/play-hearthstone-on-ubuntu-linux/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: game hearthstone ubuntu 5 | #+DATE: [2017-11-02 四 14:40] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 炉石传说可能是最流行的电子卡牌游戏了. Blizzard出品的这款以魔兽为主题的游戏十分的火爆,甚至成为了主要的电子竞技游戏之一. 11 | 12 | 虽然炉石在很多平台上都有发布, 甚至包括手机上的Android平台, 但它却从未出过官方的Linux版本. 13 | 好在炉石是一款轻量级的游戏,我们可以通过Wine在Linux上玩到它. 14 | 15 | * 安装 Wine Staging 16 | 17 | 必须给Wine打上staging补丁. 炉石更新十分频繁, 有些更新可能会造成Wine的不兼容. 使用最新的补丁有助于减少这种情况. 18 | 19 | 在Ubuntu上启用 Wine Staging PPA. 你首先需要倒入证书. 20 | 21 | #+BEGIN_SRC shell 22 | cd ~/Downloads 23 | wget -nc https://repos.wine-staging.com/wine/Release.key 24 | sudo apt-key add Release.key 25 | #+END_SRC 26 | 27 | 添加仓库,更新然后安装 Wine Staging. 28 | 29 | #+BEGIN_SRC shell 30 | sudo apt-add-repository 'https://dl.winehq.org/wine-builds/ubuntu/' 31 | sudo apt update 32 | sudo apt install --install-recommends winehq-staging 33 | #+END_SRC 34 | 35 | * 配置 Wine 36 | 37 | 现在你安装好了最新版的 Wine Staging 了, 还需要做一些配置. 打开终端然后运行 =winecfg=. 38 | 39 | [[https://www.maketecheasier.com/assets/uploads/2017/10/hs-wine-staging.jpg]] 40 | 41 | 在打开的窗口中, 点击 “Staging” 选项卡. 点击复选框选中 =CSMT=, =VAAPI=, 和 =EAX=. 42 | 43 | [[https://www.maketecheasier.com/assets/uploads/2017/10/hs-libraries.jpg]] 44 | 45 | 回到 “Libraries” 选项卡,在搜索框中输入 =d3d11=. 添加它. 然后点击那一栏来禁用它. 对 =locationapi= 也重复这一动作. 46 | 完成后,关闭 =winecfg=. 47 | 48 | * Winetricks 49 | 50 | 我们还会用到 =winetricks= 脚本. 使用wget下载最新版本的脚本. 51 | 52 | #+BEGIN_SRC shell 53 | wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks 54 | chmod +x winetricks 55 | #+END_SRC 56 | 57 | 运行该脚本. Winetricks 会打开一个图形程序来让你下载Windows组件和工具来让你的Wine程序运行的更顺畅. 58 | 59 | #+BEGIN_SRC shell 60 | ./winetricks 61 | #+END_SRC 62 | 63 | 请保证第一屏中的 “Use default Wine prefix” 是选中的. 然后点击 “OK” 按钮. 在下一屏选中 “Install DLL” 选项. 找到 =ie8= 并安装它. 64 | 65 | [[https://www.maketecheasier.com/assets/uploads/2017/10/hs-corefonts.jpg]] 66 | 67 | 安装完成后,它会回到刚才的位置. 点击 “Cancel” 回到上一层. 选择“Fonts”. 选中 =corefonts= 并安装. 68 | 安装完成后,不断点击 “Cancel”,退出 Winetricks. 69 | 70 | * 安装 Battle.net 71 | 72 | 现在可以开始安装 Battle.net 客户端了. 去 [[http://us.battle.net/en/app/][Blizzard的下载页面]] 下载最新版的客户端. 73 | 74 | 点击 =resulting.exe= 文件会自动通过wine来运行. 然后跟Windows上一样,按照指示往下走就好了. 75 | 76 | [[https://www.maketecheasier.com/assets/uploads/2017/10/hs-bnet.jpg]] 77 | 78 | 安装完成后, 应该会自动运行 Battle.net 客户端. 如果没有自动运行, 那么可以点击其所创建的图表(如果创建了的话), 或者直接去行“~/.wine/drive_c/Program Files (x86)/Battle.net/Battle.net Launcher.exe.” 79 | 80 | * 安装并运行炉石 81 | 82 | 最艰难的时刻来到了. 在 Battle.net 应用中点击炉石的图表, 然后点击屏幕底部的 “Install” 按钮. 83 | 客户端会自动下载并安装炉石. 84 | 85 | 安装完成后, “Install” 按钮应该会变成 “Play” 按钮. 点击它就能运行游戏了. 86 | 87 | 游戏运行后, 点击右下方的齿轮图标进入设置菜单. 推荐你在 “Windowed” 模式下运行游戏,能优化你的性能. 88 | 你也可以任意修改其他配置. 89 | 90 | 该教程可能会在Blizzard某次升级游戏后失效. 万一出现这种情况, 可以查一下[[https://appdb.winehq.org/objectManager.php?sClass=version&iId=30038][Wine Appdb page]]. 91 | -------------------------------------------------------------------------------- /index-generator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | declare -A catalog_comment_dict 4 | catalog_comment_dict=([examples]="读什么手册啊,跟着我来做就好了." [tools]="又有什么新玩意?" [shell]="别不把shell当语言" [system]="系统管理相关内容" [game]="Linux好游戏" [common]="未分类的内容" [raw]="未翻译的内容,欢迎大家领取" [processing]="正在翻译的内容,别人的东西可不要抢哦~") 5 | 6 | catalogs=$(for catalog in ${!catalog_comment_dict[*]};do 7 | echo $catalog 8 | done |sort) 9 | 10 | function get_contributors() 11 | { 12 | echo "* Contributors" 13 | echo "感谢GitHub以及:" 14 | # git log --pretty='%an<%ae>'|grep -viEw 'darksun|lujun9972' |sort|uniq|sed -e 's/^/+ /' 15 | git shortlog --summary --email HEAD |grep -viEw 'darksun|lujun9972'|cut -f2|sed -e 's/^/+ /' 16 | echo "" 17 | echo "感谢大家的热情参与,也欢迎更多的志愿者参与翻译" 18 | } 19 | 20 | function generate_headline() 21 | { 22 | local catalog="$*" 23 | echo "* $catalog" 24 | echo ${catalog_comment_dict[$catalog]} 25 | echo 26 | generate_links $catalog |sort -t "<" -k2 -r 27 | } 28 | 29 | function generate_links() 30 | { 31 | local catalog=$1 32 | if [[ ! -d $catalog ]];then 33 | mkdir -p $catalog 34 | fi 35 | posts=$(find $catalog -maxdepth 1 -type f) 36 | old_ifs=$IFS 37 | IFS=" 38 | " 39 | for post in $posts 40 | do 41 | modify_date=$(git log --date=short --pretty=format:"%cd" -n 1 $post) # 去除日期前的空格 42 | if [[ -n "$modify_date" ]];then # 没有修改日期的文件没有纳入仓库中,不予统计 43 | postname=$(grep '#+TITLE' $post|head -1|cut -c 9-) 44 | echo "+ [[https://github.com/lujun9972/linux-document/blob/master/$post][$postname]] <$modify_date>" 45 | fi 46 | done|sort -k 2 47 | IFS=$old_ifs 48 | } 49 | 50 | get_contributors 51 | 52 | for catalog in $catalogs 53 | do 54 | generate_headline $catalog 55 | done 56 | -------------------------------------------------------------------------------- /raw/10 Best Linux Business Apps.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 10 Best Linux Business Apps 2 | #+URL: https://www.datamation.com/open-source/slideshows/10-best-linux-business-apps.html 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-16 六 13:17] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | These Linux apps will enable you to accomplish a variety of professionals tasks quickly and effectively. 11 | 12 | * Evolution 13 | 14 | [[https://wiki.gnome.org/Apps/Evolution][Evolution]] - Even though it’s not the most attractive software in the world, there’s no question that Evolution remains the best personal information manager (PIM) for Linux. Evolution supports various groupware solutions including Microsoft Exchange, plus it offers decent Google account support for those who require it. 15 | 16 | * LibreOffice 17 | 18 | [[https://www.libreoffice.org/][LibreOffice]] - I’ll be first to admit that Libre Office isn’t for everyone. Some users in the business space have grown dependent on Excel’s ability with huge spreadsheets or the special add-ons only available for Outlooks users. However for many businesses, LibreOffice is actually perfectly acceptable. LibreOffice offers its users access to a powerful word processor, spreadsheet and presentation program. 19 | 20 | Between you and me, you can indeed add extended functionality to LibreOffice through extensions. And while they may not be as robust as their proprietary alternatives, there are extensions ranging from clipart to grammar/proofreading available. One of the more impressive extensions I've seen, is useful for anyone looking to create ebooks. The extension in question is called [[https://extensions.libreoffice.org/extensions/writer2epub][Writer2ePub]]. 21 | 22 | 23 | * Scribus 24 | 25 | [[https://www.scribus.net/][Scribus]] - If you’re looking to get into print publishing of any kind, Scribus is your first stop. Scribus provides its users with the ability to create professional printed documents, newsletters and even Magazines. 26 | 27 | Another important feature set with Scribus is the ability to import a color profile that is calibrated for your PC’s monitor. This feature, bundled with Scribus’ solid CMYK support makes this the default desktop publishing application for Linux users in the business place. 28 | 29 | 30 | * GIMP 31 | 32 | [[https://www.gimp.org/][GIMP]] - If you can get yourself past the fact that GIMP isn't Photoshop and despite sharing features with the Adobe software, GIMP has strengths of its own. GIMP is a powerful image manipulation program that when fully understood, is very business friendly. 33 | 34 | Like other FoSS software, GIMP can also be made to provide extra functionality through the use of extensions. These extensions add everything from limited CMYK support to GIF animation creation. 35 | 36 | 37 | * VirtualBox 38 | 39 | [[https://www.virtualbox.org/wiki/Downloads][VirtualBox]] - No matter how you look at it, VirtualBox is by far the easiest Virtual Machine management tool available. Besides being dead simple to use, VirtualBox also offers you USB support, various graphical passthroughs and of course, the extensions ISO for extra functionality. 40 | 41 | Seamless mode, seamless mouse control between host/guest OS and shared directories between host/guest OS make VirtualBox a great solution if you need to run Windows or another Linux distro, but prefer to avoid running said OS on bare metal. 42 | 43 | 44 | * TeamViewer 45 | 46 | [[https://www.teamviewer.com/en/download/linux/][TeamViewer]] - While there are few usable remote desktop control applications available, I've come to the conclusion that TeamViewer has proven to be the most reliable of the lot. Yes, it's bundled with a WINE wrapper. However once you're past this issue, the fact remains the software is dead simple to use. 47 | 48 | Obviously due to in-house security policies, many businesses would prefer you access your workstation remotely using an approved VPN setup. However for those of us who just work from home yet also run a business, TeamViewer is actually a very handy way to access remote files, run programs on your local PC from a remote location and even provide remote tech support. 49 | 50 | * Slack 51 | 52 | [[https://slack.com/downloads/linux][Slack]] - Known as the most commonly used communication tool for businesses in 2017, Slack also offers a Linux client. The client provides you with multiple workspaces, desktop notifications and comes with the Slack interface its users have come to know and appreciate. 53 | 54 | There's really no question that Slack is far superior to Email or other chat based alternatives. Best of all, you can archive and search past conversations and projects. 55 | * FreeMind 56 | 57 | [[http://freemind.sourceforge.net/wiki/index.php/Main_Page][FreeMind]] - Even though I'm not an advocate for running Java programs on the desktop, I have to give FreeMind a pass on this one issue. Fact is, FreeMind is a solid mind mapping program for Linux users. 58 | 59 | As fellow mind mappers realize, creating a concise mind map that anyone can follow requires a program that allows its user to visually illustrate complicated thoughts and patterns. FreeMind does very well in this arena and it's definitely suitable for an active business environment. 60 | 61 | * osTicket 62 | 63 | [[http://osticket.com/][osTicket]] - If you run a business that supports software help requests, odds are you have a ticketing system. This is especially true in the web server industry. Running osTicket is fairly straight forward with a LAMP stack and a distro you feel comfortable with. 64 | 65 | Some of the advanced features found with osTicket include Agent Collision Avoidance, Assign and transfer, and of course a reliable auto-responder. 66 | * NextCloud 67 | 68 | [[https://nextcloud.com/][NextCloud]] - If you ever wished you could run your own cloud server, locally and with extras that go beyond what you might find with Dropbox - then NextCloud might be right for your business. 69 | 70 | NextCloud provides you with storage, document sharing, changes tracking and solid account management. Additionally, you'll also find the calendar and contacts feature make using NextCloud as your primary "data bank" a logical fit. 71 | 72 | There’s no question that the [[https://www.datamation.com/open-source/the-best-linux-desktop-environment-1.html][Linux desktop]] can be a highly effective workhorse. Note, as proof of this, the greater coverage in the media of the best business apps for Linux. Keep reading for the best Linux business apps – and please add your own favorite in the Comments section below. 73 | -------------------------------------------------------------------------------- /raw/12 MySQL-MariaDB Security Best Practices for Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 12 MySQL-MariaDB Security Best Practices for Linux 2 | #+URL: https://www.tecmint.com/mysql-mariadb-security-best-practices-for-linux/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-21 四 18:20] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | MySQL is the world’s most popular open source database system and MariaDB (a fork of MySQL) is the world’s fastest growing open source database system. 10 | After installing MySQL server, it is insecure in it’s default configuration, and securing it is one of the essential tasks in general database management. 11 | 12 | Read Also: [[https://www.tecmint.com/learn-mysql-mariadb-for-beginners/][Learn MySQL/MariaDB for Beginners – Part 1]] 13 | 14 | This will contribute to hardening and boosting of overall Linux server security, as attackers always scan vulnerabilities in any part of a system, and databases have 15 | in the past been key target areas. A common example is the brute-forcing of the root password for the MySQL database. 16 | 17 | In this guide, we will explain useful MySQL/MariaDB security best practice for Linux. 18 | 19 | 1. Secure MySQL Installation 20 | 21 | This is the first recommended step after installing MySQL server, towards securing the database server. This script facilitates in improving the security of your 22 | MySQL server by asking you to: 23 | 24 | ,* set a password for the root account, if you didn’t set it during installation. 25 | ,* disable remote root user login by removing root accounts that are accessible from outside the local host. 26 | ,* remove anonymous-user accounts and test database which by default can be accessed by all users, even anonymous users. 27 | 28 | # mysql_secure_installation 29 | 30 | After running it, set the root password and answer the series of questions by entering [Yes/Y] and press [Enter]. 31 | 32 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Secure-MySQL-Installation.png][Secure MySQL Installation 33 | Secure MySQL Installation]] 34 | 35 | Secure MySQL Installation 36 | 37 | 2. Bind Database Server To Loopback Address 38 | 39 | This configuration will restrict access from remote machines, it tells the MySQL server to only accept connections from within the localhost. You can set it in main 40 | configuration file. 41 | 42 | # vi /etc/my.cnf [RHEL/CentOS] 43 | # vi /etc/mysql/my.conf [Debian/Ubuntu] 44 | OR 45 | # vi /etc/mysql/mysql.conf.d/mysqld.cnf [Debian/Ubuntu] 46 | 47 | Add the following line below under [mysqld] section. 48 | 49 | bind-address = 127.0.0.1 50 | 51 | 3. Disable LOCAL INFILE in MySQL 52 | 53 | As part of security hardening, you need to disable local_infile to prevent access to the underlying filesystem from within MySQL using the following directive 54 | under [mysqld] section. 55 | 56 | local-infile=0 57 | 58 | 4. Change MYSQL Default Port 59 | 60 | The Port variable sets the MySQL port number that will be used to listen on TCP/ IP connections. The default port number is 3306 but you can change it under the 61 | [mysqld] section as shown. 62 | 63 | Port=5000 64 | 65 | 5. Enable MySQL Logging 66 | 67 | Logs are one of the best ways to understand what happens on a server, in case of any attacks, you can easily see any intrusion-related activities from log files. You 68 | can enable MySQL logging by adding the following variable under the [mysqld] section. 69 | 70 | log=/var/log/mysql.log 71 | 72 | 6. Set Appropriate Permission on MySQL Files 73 | 74 | Ensure that you have appropriate permissions set for all mysql server files and data directories. The /etc/my.conf file should only be writeable to root. This blocks 75 | other users from changing database server configurations. 76 | 77 | # chmod 644 /etc/my.cnf 78 | 79 | 7. Delete MySQL Shell History 80 | 81 | All commands you execute on MySQL shell are stored by the mysql client in a history file: ~/.mysql_history. This can be dangerous, because for any user 82 | accounts that you will create, all usernames and passwords typed on the shell will recorded in the history file. 83 | 84 | # cat /dev/null > ~/.mysql_history 85 | 86 | 8. Don’t Run MySQL Commands from Commandline 87 | 88 | As you already know, all commands you type on the terminal are stored in a history file, depending on the shell you are using (for example ~/.bash_history for 89 | bash). An attacker who manages to gain access to this history file can easily see any passwords recorded there. 90 | 91 | It is strongly not recommended to type passwords on the command line, something like this: 92 | 93 | # mysql -u root -ppassword_ 94 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Connect-MySQL-with-Password.png][Connect MySQL with Password 95 | Connect MySQL with Password]] 96 | 97 | Connect MySQL with Password 98 | 99 | When you check the last section of the command history file, you will see the password typed above. 100 | 101 | # history 102 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Check-Command-History.png][Check Command History 103 | Check Command History]] 104 | 105 | Check Command History 106 | 107 | The appropriate way to connect MySQL is. 108 | 109 | # mysql -u root -p 110 | Enter password: 111 | 112 | 9. Define Application-Specific Database Users 113 | 114 | For each application running on the server, only give access to a user who is in charge of a database for a given application. For example, if you have a wordpress 115 | site, create a specific user for the wordpress site database as follows. 116 | 117 | # mysql -u root -p 118 | MariaDB [(none)]> CREATE DATABASE osclass_db; 119 | MariaDB [(none)]> CREATE USER 'osclassdmin'@'localhost' IDENTIFIED BY '[[https://www.tecmint.com/cdn-cgi/l/email-protection][{email protected}]]%!2'; 120 | MariaDB [(none)]> GRANT ALL PRIVILEGES ON osclass_db.* TO 'osclassdmin'@'localhost'; 121 | MariaDB [(none)]> FLUSH PRIVILEGES; 122 | MariaDB [(none)]> exit 123 | 124 | and remember to always remove user accounts that are no longer managing any application database on the server. 125 | 126 | 10. Use Additional Security Plugins and Libraries 127 | 128 | MySQL includes a number of security plugins for: authenticating attempts by clients to connect to mysql server, password-validation and securing storage for 129 | sensitive information, which are all available in the free version. 130 | 131 | You can find more here: [[https://dev.mysql.com/doc/refman/5.7/en/security-plugins.html][https://dev.mysql.com/doc/refman/5.7/en/security-plugins.html]] 132 | 133 | 11. Change MySQL Passwords Regularly 134 | 135 | This is a common piece of information/application/system security advice. How often you do this will entirely depend on your internal security policy. However, it 136 | can prevent “snoopers” who might have been tracking your activity over an long period of time, from gaining access to your mysql server. 137 | 138 | MariaDB [(none)]> USE mysql; 139 | MariaDB [(none)]> UPDATE user SET password=PASSWORD('YourPasswordHere') WHERE User='root' AND Host = 'localhost'; 140 | MariaDB [(none)]> FLUSH PRIVILEGES; 141 | 142 | 12. Update MySQL Server Package Regularly 143 | 144 | It is highly recommended to upgrade mysql/mariadb packages regularly to keep up with security updates and bug fixes, from the vendor’s repository. Normally 145 | packages in default operating system repositories are outdated. 146 | 147 | # yum update 148 | # apt update 149 | 150 | After making any changes to the mysql/mariadb server, always restart the service. 151 | 152 | # systemctl restart mariadb #RHEL/CentOS 153 | # systemctl restart mysql #Debian/Ubuntu 154 | 155 | Read Also: [[https://www.tecmint.com/mysql-mariadb-performance-tuning-and-optimization/][15 Useful MySQL/MariaDB Performance Tuning and Optimization Tips]] 156 | 157 | That’s all! We love to hear from you via the comment form below. Do share with us any MySQL/MariaDB security tips missing in the above list. 158 | 159 | -------------------------------------------------------------------------------- /raw/4 Ways to Speed Up SSH Connections in Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 4 Ways to Speed Up SSH Connections in Linux 2 | #+URL: https://www.tecmint.com/speed-up-ssh-connections-in-linux/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-21 四 18:23] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | SSH is the most popular and secure method for managing Linux servers remotely. One of the challenges with remote server management is connection speeds, 10 | especially when it comes to session creation between the remote and local machines. 11 | 12 | There are several bottlenecks to this process, one scenario is when you are connecting to a remote server for the first time; it normally takes a few seconds to 13 | establish a session. However, when you try to start multiple connections in succession, this causes an overhead (combination of excess or indirect computation 14 | time, memory, bandwidth, or other related resources to carry out the operation). 15 | 16 | In this article, we will share four useful tips on how to speed up remote SSH connections in Linux. 17 | 18 | 1. Force SSH Connection Over IPV4 19 | 20 | OpenSSH supports both IPv4/IP6, but at times IPv6 connections tend to be slower. So you can consider forcing ssh connections over IPv4 only, using the syntax 21 | below: 22 | 23 | # ssh -4 [[https://www.tecmint.com/cdn-cgi/l/email-protection][{email protected}]] 24 | 25 | Alternatively, use the AddressFamily (specifies the address family to use when connecting) directive in your ssh configuration file /etc/ssh/ssh_config (global 26 | configuration) or ~/.ssh/config (user specific file). 27 | 28 | The accepted values are “any”, “inet” for IPv4 only, or “inet6”. 29 | 30 | $ vi ~.ssh/config 31 | [[https://www.tecmint.com/wp-content/uploads/2017/11/Disable-SSH-Connections-on-ipv6.png][Disable SSH Connections on ipv6 32 | Disable SSH Connections on ipv6]] 33 | 34 | Disable SSH Connections on ipv6 35 | 36 | Here is a useful starter guide on configuring user specific ssh configuration file: 37 | 38 | 1 [[https://www.tecmint.com/configure-custom-ssh-connection-in-linux/][How to Configure Custom SSH Connections to Simplify Remote Access]] 39 | 40 | Additionally, on the remote machine, you can also instruct the sshd daemon to consider connections over IPv4 by using the above directive in the 41 | /etc/ssh/sshd_config file. 42 | 43 | 2. Disable DNS Lookup On Remote Machine 44 | 45 | By default, sshd daemon looks up the remote host name, and also checks that the resolved host name for the remote IP address maps back to the very same IP 46 | address. This can result into delays in connection establishment or session creation. 47 | 48 | The UseDNS directive controls the above functionality; to disable it, search and uncomment it in the /etc/ssh/sshd_config file. If it’s not set, add it with the value 49 | no. 50 | 51 | UseDNS no 52 | [[https://www.tecmint.com/wp-content/uploads/2017/11/Disable-SSH-DNS-Lookup.png][Disable SSH DNS Lookup 53 | Disable SSH DNS Lookup]] 54 | 55 | Disable SSH DNS Lookup 56 | 57 | 3. Reuse SSH Connection 58 | 59 | An ssh client program is used to establish connections to an sshd daemon accepting remote connections. You can reuse an already-established connection when 60 | creating a new ssh session and this can significantly speed up subsequent sessions. 61 | 62 | You can enable this in your ~/.ssh/config file. 63 | 64 | Host * 65 | ControlMaster auto 66 | ControlPath ~/.ssh/sockets/%[[https://www.tecmint.com/cdn-cgi/l/email-protection][{email protected}]]%h-%p 67 | ControlPersist 600 68 | 69 | The above configuration (Host *) will enable connection re-use for all remote servers you connect to using these directives: 70 | 71 | ,* ControlMaster – enables the sharing of multiple sessions over a single network connection. 72 | ,* ControlPath – defines a path to the control socket used for connection sharing. 73 | ,* ControlPersist – if used together with ControlMaster, tells ssh to keep the master connection open in the background (waiting for future client connections) 74 | once the initial client connection has been closed. 75 | 76 | [[https://www.tecmint.com/wp-content/uploads/2017/11/Reuse-SSH-Connections.png][Reuse SSH Connections 77 | Reuse SSH Connections]] 78 | 79 | Reuse SSH Connections 80 | 81 | You can enable this for connections to a specific remote server, for instance: 82 | 83 | Host server1 84 | HostName www.example.com 85 | IdentityFile ~/.ssh/webserver.pem 86 | User username_here 87 | ControlMaster auto 88 | ControlPath ~/.ssh/sockets/%[[https://www.tecmint.com/cdn-cgi/l/email-protection][{email protected}]]%h-%p 89 | ControlPersist 600 90 | 91 | This way you only suffer the connection overhead for the first connection, and all subsequent connections will be much faster. 92 | 93 | 4. Use Specific SSH Authentication Method 94 | 95 | Another way of speeding up ssh connections is to use a given authentication method for all ssh connections, and here we recommend configuring [[https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/][ssh]] 96 | [[https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/][passwordless login]] using ssh keygen in 5 easy steps. 97 | 98 | Once that is done, use the PreferredAuthentications directive, within ssh_config files (global or user specific) above. This directive defines the order in which 99 | the client should try authentication methods (you can specify a command separated list to use more than one method). 100 | 101 | PreferredAuthentications=publickey 102 | [[https://www.tecmint.com/wp-content/uploads/2017/11/SSH-Authentication-Method.png][SSH Authentication Method 103 | SSH Authentication Method]] 104 | 105 | SSH Authentication Method 106 | 107 | Optionally, use this syntax below from the command line. 108 | 109 | # ssh -o "PreferredAuthentications=publickey" [[https://www.tecmint.com/cdn-cgi/l/email-protection][{email protected}]] 110 | 111 | If you prefer password authentication which is deemed unsecure, use this. 112 | 113 | # ssh -o "PreferredAuthentications=password" [[https://www.tecmint.com/cdn-cgi/l/email-protection][{email protected}]] 114 | 115 | Finally, you need to restart your sshd daemon after making all the above changes. 116 | 117 | # systemctl restart sshd #Systemd 118 | # service sshd restart #SysVInit 119 | 120 | For more information about the directives used here, see the ssh_config and sshd_config man pages. 121 | 122 | # man ssh_config 123 | # man sshd_config 124 | 125 | Also check out these useful guides for securing ssh on Linux systems: 126 | 127 | 1 [[https://www.tecmint.com/5-best-practices-to-secure-and-protect-ssh-server/][5 Best Practices to Secure and Protect SSH Server]] 128 | 2 [[https://www.tecmint.com/auto-disconnect-inactive-or-idle-ssh-connections-in-linux/][How to Disconnect Inactive or Idle SSH Connections in Linux]] 129 | 130 | That’s all for now! Do you have any tips/tricks for speeding up SSH connections. We would love to hear of other ways of doing this. Use the comment form below to 131 | share with us. 132 | 133 | -------------------------------------------------------------------------------- /raw/How to Check Integrity of Fil and Directory Using "AIDE" in Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: How to Check Integrity of Fil and Directory Using "AIDE" in Linux 2 | #+URL: https://www.tecmint.com/check-integrity-of-file-and-directory-using-aide-in-linux/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-21 四 18:22] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | In our mega guide to [[https://www.tecmint.com/security-and-hardening-centos-7-guide/][hardening and securing CentOS 7]], under the section “protect system internally”, one of the useful security tools we listed for internal 10 | system protection against viruses, rootkits, malware, and detection of unauthorized activities is AIDE. 11 | 12 | AIDE (Advanced Intrusion Detection Environment) is a small yet powerful, free open source intrusion detection tool, that uses predefined rules to check file 13 | and directory integrity in Unix-like operating systems such as Linux. It is an independent static binary for simplified client/server monitoring configurations. 14 | 15 | It is feature-rich: uses plain text configuration files and database making it easy to use; supports several message digest algorithms such as but not limited to 16 | md5, sha1, rmd160, tiger; supports common file attributes; also supports powerful regular expressions to selectively include or exclude files and directories to be 17 | scanned. 18 | 19 | Also it can be compiled with exceptional support for Gzip compression, Posix ACL, SELinux, XAttrs and Extended file system attributes. 20 | 21 | Aide works by creating a database (which is simply a snapshot of selected parts of the file system), from the regular expression rules defined in the configuration 22 | file(s). Once this database is initialized, you can verify the integrity of the system files against it. This guide will show how to install and use aide in Linux. 23 | 24 | How to Install AIDE in Linux 25 | 26 | Aide is packaged in official repositories of mainstream Linux distributions, to install it run the command for your distribution using a package manager. 27 | 28 | # apt install aide [On Debian/Ubuntu] 29 | # yum install aide [On RHEL/CentOS] 30 | # dnf install aide [On Fedora 22+] 31 | # zypper install aide [On openSUSE] 32 | # emerge aide [On Gentoo] 33 | 34 | After installing it, the main configuration file is /etc/aide.conf. To view the installed version as well as compile time parameters, run the command below on your 35 | terminal: 36 | 37 | # aide -v 38 | 39 | Sample Output 40 | 41 | Aide 0.14 42 | Compiled with the following options: 43 | WITH_MMAP 44 | WITH_POSIX_ACL 45 | WITH_SELINUX 46 | WITH_PRELINK 47 | WITH_XATTR 48 | WITH_LSTAT64 49 | WITH_READDIR64 50 | WITH_ZLIB 51 | WITH_GCRYPT 52 | WITH_AUDIT 53 | CONFIG_FILE = "/etc/aide.conf" 54 | 55 | You can open the configuration using your favorite editor. 56 | 57 | # vi /etc/aide.conf 58 | 59 | It has directives that define the database location, report location, default rules, the directories/files to be included in the database. 60 | 61 | Understanding Default Aide Rules 62 | 63 | [[https://www.tecmint.com/wp-content/uploads/2017/11/AIDE-Default-Rules.png][AIDE Default Rules 64 | AIDE Default Rules]] 65 | 66 | AIDE Default Rules 67 | 68 | Using the above default rules, you can define new custom rules in the aide.conf file for example. 69 | 70 | PERMS = p+u+g+acl+selinux+xattrs 71 | 72 | The PERMS rule is used for access control only, it will detect any changes to file or directories based on file/directory permissions, user, group, access control 73 | permissions, SELinux context and file attributes. 74 | 75 | This will only check file content and file type. 76 | 77 | CONTENT = sha256+ftype 78 | 79 | This is an extended version of the previous rule, it checks extended content, file type and access. 80 | 81 | CONTENT_EX = sha256+ftype+p+u+g+n+acl+selinux+xattrs 82 | 83 | The DATAONLY rule below will help detect any changes in data inside all files/directory. 84 | 85 | DATAONLY = p+n+u+g+s+acl+selinux+xattrs+sha256 86 | [[https://www.tecmint.com/wp-content/uploads/2017/11/Configure-Aide-Rules.png][Configure Aide Rules 87 | Configure Aide Rules]] 88 | 89 | Configure Aide Rules 90 | 91 | Defining Rules to Watch Files and Directories 92 | 93 | Once you have defined rules, you can specify the file and directories to watch. Considering the PERMS rule above, this definition will check permissions for all files in 94 | root directory. 95 | 96 | /root/\..* PERMS 97 | 98 | This will check all files in the /root directory for any changes. 99 | 100 | /root/ CONTENT_EX 101 | 102 | To help you detect any changes in data inside all files/directory under /etc/, use this. 103 | 104 | /etc/ DATAONLY 105 | [[https://www.tecmint.com/wp-content/uploads/2017/11/Configure-Aide-Rules-for-Filesystem.png][Configure Aide Rules for Filesystem 106 | Configure Aide Rules for Filesystem]] 107 | 108 | Configure Aide Rules for Filesystem 109 | 110 | Using AIDE to Check File and Directory Integrity in Linux 111 | 112 | Start by constructing a database against the checks that will be performed using --init flag. This is expected to be done before your system is connected to a 113 | network. 114 | 115 | The command below will create a database that contains all of the files that you selected in your configuration file. 116 | 117 | # aide --init 118 | [[https://www.tecmint.com/wp-content/uploads/2017/11/Initialize-Aide-Database.png][Initialize Aide Database 119 | Initialize Aide Database]] 120 | 121 | Initialize Aide Database 122 | 123 | Then rename the database to /var/lib/aide/aide.db.gz before proceeding, using this command. 124 | 125 | # mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz 126 | 127 | It is recommended to move the database to a secure location possibly in a read-only media or on another machines, but ensure that you update the configuration 128 | file to read it from there. 129 | 130 | After the database is created, you can now check the integrity of the files and directories using the --check flag. 131 | 132 | # aide --check 133 | 134 | It will read the snapshot in the database and compares it to the files/directories found you system disk. If it finds changes in places that you might not expect, it 135 | generates a report which you can then review. 136 | 137 | [[https://www.tecmint.com/wp-content/uploads/2017/11/Run-File-Integrity-Check.png][Run File Integrity Check 138 | Run File Integrity Check]] 139 | 140 | Run File Integrity Check 141 | 142 | Since no changes have been made to the file system, you will only get an output similar to the one above. Now try to create some files in the file system, in areas 143 | defined in the configuration file. 144 | 145 | # vi /etc/script.sh 146 | # touch all.txt 147 | 148 | Then run a check once more, which should report the files added above. The output of this command depends on the parts of the file system you configured for 149 | checking, it can be lengthy overtime. 150 | 151 | # aide --check 152 | [[https://www.tecmint.com/wp-content/uploads/2017/11/Check-File-System-Changes.png][Check File System Changes 153 | Check File System Changes]] 154 | 155 | Check File System Changes 156 | 157 | You need to run aide checks regularly, and in case of any changes to already selected files or addition of new file definitions in the configuration file, always update 158 | the database using the --update option: 159 | 160 | # aide --update 161 | 162 | After running a database update, to use the new database for future scans, always rename it to /var/lib/aide/aide.db.gz: 163 | 164 | # mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz 165 | 166 | That’s all for now! But take note of these important points: 167 | 168 | ,* One characteristic of most intrusion detection systems AIDE inclusive, is that they will not provide solutions to most security loop holes on a system. They 169 | however, assist in easing the the intrusion response process by helping system administrators examine any changes to system files/directories. So you should 170 | always be vigilant and keep updating your current security measures. 171 | ,* It it highly recommended to keep the newly created database, the configuration file and the AIDE binary in a secure location such as read-only media (possible if 172 | you install from source). 173 | ,* For additional security, consider signing the configuration and/or database. 174 | 175 | For additional information and configurations, see its man page or check out the AIDE Homepage: [[http://aide.sourceforge.net/][http://aide.sourceforge.net/]] 176 | 177 | -------------------------------------------------------------------------------- /raw/How to Check MySQL Database Size in Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: How to Check MySQL Database Size in Linux 2 | #+URL: https://www.tecmint.com/check-mysql-database-size-in-linux/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-21 四 17:08] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | In this article, I will show you how to check the size of MySQL/MariaDB databases and tables via the MySQL shell. You will learn how to determine the real size of a 11 | database file on the disk as well as size of data that it present in a database. 12 | 13 | Read Also: [[https://www.tecmint.com/mysqladmin-commands-for-database-administration-in-linux/][20 MySQL (Mysqladmin) Commands for Database Administration in Linux]] 14 | 15 | By default MySQL/MariaDB stores all the data in the file system, and the size of data that exists on the databases may differ from the actual size of Mysql data on 16 | the disk that we will see later on. 17 | 18 | In addition, MySQL uses the information_schema virtual database to store information about your databases and other settings. You can query it to gather 19 | information about size of databases and their tables as shown. 20 | 21 | # mysql -u root -p 22 | MariaDB [(none)]> SELECT table_schema AS "Database Name", 23 | ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size in (MB)" 24 | FROM information_schema.TABLES 25 | GROUP BY table_schema; 26 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Check-MySQL-Database-Size.png][Check MySQL Database Size 27 | Check MySQL Database Size]] 28 | 29 | Check MySQL Database Size 30 | 31 | To find out the size of a single MySQL database called rcubemail (which displays the size of all tables in it) use the following mysql query. 32 | 33 | MariaDB [(none)]> SELECT table_name AS "Table Name", 34 | ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size in (MB)" 35 | FROM information_schema.TABLES 36 | WHERE table_schema = "rcubemail" 37 | ORDER BY (data_length + index_length) DESC; 38 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Check-Size-of-MySQL-Database.png][Check Size of MySQL Database 39 | Check Size of MySQL Database]] 40 | 41 | Check Size of MySQL Database 42 | 43 | Finally, to find out the actual size of all MySQL database files on the disk (filesystem), run the [[https://www.tecmint.com/check-linux-disk-usage-of-files-and-directories/][du command]] below. 44 | 45 | # du -h /var/lib/mysql 46 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Check-MySQL-Size-on-Disk.png][Check MySQL Size on Disk 47 | Check MySQL Size on Disk]] 48 | 49 | Check MySQL Size on Disk 50 | 51 | You might also like to read these following MySQL related articles. 52 | 53 | 1 [[https://www.tecmint.com/mysql-performance-monitoring/][4 Useful Commandline Tools to Monitor MySQL Performance in Linux]] 54 | 2 [[https://www.tecmint.com/mysql-mariadb-security-best-practices-for-linux/][12 MySQL/MariaDB Security Best Practices for Linux]] 55 | 56 | For any queries or additional ideas you want to share regarding this topic, use the feedback form below. 57 | -------------------------------------------------------------------------------- /raw/How to Configure Custom Access and Error Log Formats in Nginx.org: -------------------------------------------------------------------------------- 1 | #+TITLE: How to Configure Custom Access and Error Log Formats in Nginx 2 | #+URL: https://www.tecmint.com/configure-custom-access-and-error-log-formats-in-nginx/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-21 四 18:26] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | Nginx HTTP server has a phenomenal logging facility which is highly customizable. In this article, we will explain how to configure you own formats for access and 10 | error logs for Nginx in Linux. 11 | 12 | The aim of this guide is to help you understand how logs are generated, so as to configure custom log formats for purposes of debugging, troubleshooting or 13 | analysis of what unfolds within your web server as well as web applications (such as tracing requests). 14 | 15 | Read Also: [[https://www.tecmint.com/best-linux-log-monitoring-and-management-tools/][4 Good Open Source Log Monitoring and Management Tools for Linux]] 16 | 17 | This article is made of three sections which will enlighten you about configuring access/error logs and how to enable conditional logging in Nginx. 18 | 19 | Configuring Access Logs in Nginx 20 | 21 | Under Nginx, all client requests to the server are recored in the access log in a specified format using the ngx_http_log_module module. 22 | 23 | The default log file is log/access.log (usually /var/log/nginx/access_log on Linux systems) and the default format for logging is normally the combined or main 24 | format (this can vary from one distro to another). 25 | 26 | The access_log directive (applicable in the http, server, location, if in location and limit except context) is used to set the log file and the log_format directive 27 | (applicable under the http context only) is used to set the log format. The log format is described by common variables, and variables that generated only at the 28 | time when a log is written. 29 | 30 | The syntax for configuring a log format is: 31 | 32 | log_format format_name 'set_of_variables_to_define_format'; 33 | 34 | and the syntax for configuring access log is: 35 | 36 | access_log /path/to/log_file format_name; #simplest form 37 | OR 38 | access_log /path/to/log_file [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]]; 39 | 40 | The following is a excerpt from the default Nginx configuration file /etc/nginx/nginx.conf on CentOS 7. 41 | 42 | /etc/nginx/nginx.conf 43 | http { 44 | #main log format 45 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 46 | '$status $body_bytes_sent "$http_referer" ' 47 | '"$http_user_agent" "$http_x_forwarded_for"'; 48 | access_log /var/log/nginx/access.log; 49 | } 50 | 51 | This log format yields the following log entry. 52 | 53 | 127.0.0.1 - dbmanager [20/Nov/2017:18:52:17 +0000] "GET / HTTP/1.1" 401 188 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0" 54 | 55 | The following is another useful logging format which we use for tracing requests to our web applications using the some of the default variables, it most importantly 56 | has the request ID and logs client location details (country, country code, region and city). 57 | 58 | /etc/nginx/nginx.conf 59 | log_format custom '$remote_addr - $remote_user [$time_local] ' 60 | '"$request" $status $body_bytes_sent ' 61 | '"$http_referer" "$http_user_agent" ' 62 | '"$http_x_forwarded_for" $request_id ' 63 | '$geoip_country_name $geoip_country_code ' 64 | '$geoip_region_name $geoip_city '; 65 | 66 | You can use it like this: 67 | 68 | access_log /var/log/nginx/access.log custom; 69 | 70 | This will produce a log entry which appears like this. 71 | 72 | 153.78.107.192 - - [21/Nov/2017:08:45:45 +0000] "POST /ngx_pagespeed_beacon?url=https%3A%2F%2Fwww.example.com%2Fads%2Ffresh-oranges-1509260795 HTTP/2.0" 204 0 "https://www.suasell.com/ads/fresh-oranges-1509260795" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0" "-" a02b2dea9cf06344a25611c1d7ad72db Uganda UG Kampala Kampala 73 | 74 | You can specify several logs using the access_log directives on the same level, here we are using more than one log file in the http context. 75 | 76 | /etc/nginx/nginx.conf 77 | http{ 78 | ##default log format 79 | log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 80 | '$status $body_bytes_sent "$http_referer" ' 81 | '"$http_user_agent" "$http_x_forwarded_for"'; 82 | ##request tracing using custom format 83 | log_format custom '$remote_addr - $remote_user [$time_local] ' 84 | '"$request" $status $body_bytes_sent ' 85 | '"$http_referer" "$http_user_agent" ' 86 | '"$http_x_forwarded_for" $request_id ' 87 | '$geoip_country_name $geoip_country_code ' 88 | '$geoip_region_name $geoip_city '; 89 | ##this uses the default log format 90 | access_log /var/log/nginx/access.log; 91 | ##this uses the our custom log format 92 | access_log /var/log/nginx/custom_log custom; 93 | } 94 | 95 | The following are more advanced logging configurations examples, which are useful for log formats that contain compression-related variables and for creating 96 | compressed log files: 97 | 98 | access_log /var/log/nginx/custom_log custom buffer 32k; 99 | access_log /path/to/log.gz compression gzip flush=5m; 100 | 101 | Configuring Error Logs in Nginx 102 | 103 | In case Nginx experiences any glitches, it records information concerning them in the error log. These issues fall under different severity levels: debug, info, 104 | notice, warn, error (this is the default level and works globally), crit, alert, or emerg. 105 | 106 | The default log file is log/error.log, but it is normally located in /var/log/nginx/ on Linux distributions. The error_log directive is used to specify the log file, and it 107 | can be used in the main, http, mail, stream, server, location context (in that order). 108 | 109 | You should also note that: 110 | 111 | ,* Configurations in the main context are always inherited by lower levels in the order above. 112 | ,* and configurations in the lower levels override the configurations inherited from the higher levels. 113 | 114 | You can configure error logging using the following syntax: 115 | 116 | error_log /path/to/log_file log_level; 117 | 118 | For example: 119 | 120 | error_log /var/log/nginx/error_log warn; 121 | 122 | This will instruct Nginx to log all messages of type warn and more severe log level crit, alert, and emerg messages. 123 | 124 | In the next example, messages of crit, alert, and emerg levels will be logged. 125 | 126 | error_log /var/www/example1.com/log/error_log crit; 127 | 128 | Consider the configuration below, here, we have defined error logging on different levels (in the http and server context). In case of an error, the message is written 129 | to only one error log, the one closest to the level where the error has appeared. 130 | 131 | /etc/nginx/nginx.conf 132 | http { 133 | log_format compression '$remote_addr - $remote_user [$time_local] ' 134 | '"$request" $status $body_bytes_sent ' 135 | '"$http_referer" "$http_user_agent" "$gzip_ratio"'; 136 | error_log /var/log/nginx/error_log crit; 137 | server { 138 | listen 80; 139 | server_name example1.com; 140 | #this logs errors messages for example1.com only 141 | error_log /var/log/nginx/example1.error_log warn; 142 | …... 143 | } 144 | server { 145 | listen 80; 146 | server_name example2.com; 147 | #this logs errors messages for example2.com only 148 | error_log /var/log/nginx/example1.error_log; 149 | ……. 150 | } 151 | } 152 | 153 | If you use more than one error_log directives as in the configuration below (same level), the messages are written to all specified logs. 154 | 155 | /etc/nginx/nginx.conf 156 | server { 157 | listen 80; 158 | server_name example1.com; 159 | error_log /var/www/example1.com/log/error_log warn; 160 | error_log /var/log/nginx/example1.error_log crit; 161 | …... 162 | } 163 | 164 | Configuring Conditional Logging in Nginx 165 | 166 | In some cases, we may want Nginx to perform conditional logging of messages. Not every message has to be logged by Nginx, therefore we can ignore 167 | insignificant or less important log entries from our access logs for particular instances. 168 | 169 | We can use the ngx_http_map_module module which creates variables whose values depend on values of other variables. The parameters inside a map block 170 | (which should exist in the http content only) specify a mapping between source and resulting values. 171 | 172 | For this kind of setting, a request will not be logged if the condition evaluates to “0” or an empty string. This example excludes requests with HTTP status codes 173 | 2xx and 3xx. 174 | 175 | /etc/nginx/nginx.conf 176 | http{ 177 | map $status $condition { 178 | ~^[23] 0; 179 | default 1; 180 | } 181 | server{ 182 | access_log /path/to/access.log custom if=$condition; 183 | } 184 | } 185 | 186 | Here is another useful example for debugging a web application in a development phase. This will ignore all messages and only log debug information. 187 | 188 | /etc/nginx/nginx.conf 189 | 190 | http{ 191 | map $info $debuggable { 192 | default 0; 193 | debug 1; 194 | } 195 | server{ 196 | …….. 197 | access_log /var/log/nginx/testapp_debug_access_log debug if=$debuggable; 198 | #logs other requests 199 | access_log /var/log/nginx/testapp_access.log main; 200 | ……. 201 | } 202 | } 203 | 204 | You can find out more information, including logging to syslog [[https://www.nginx.com/resources/admin-guide/logging-and-monitoring/][here]]. 205 | 206 | That’s all for now! In this guide, we explained how to configure custom logging format for access and error logs in Nginx. Use the feedback form below to ask 207 | questions or share you thoughts about this article. 208 | 209 | -------------------------------------------------------------------------------- /raw/How to Easily Remember Linux Commands.org: -------------------------------------------------------------------------------- 1 | #+TITLE: How to Easily Remember Linux Commands 2 | #+URL: https://www.maketecheasier.com/remember-linux-commands/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: history apropos zsh cheatsheet command 5 | #+DATE: [2017-11-21 二 11:17] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | The command line can be daunting for new Linux users. Part of that is remembering the multitude of commands available. After all, in order 11 | to use the command line effectively, you need to know the commands. 12 | 13 | Unfortunately, there’s no getting around the fact that you need to learn the commands, but there are some tools that can help you out when 14 | you’re getting started. 15 | 16 | * History 17 | 18 | [[https://www.maketecheasier.com/assets/uploads/2017/10/rc-bash-history.jpg]] 19 | 20 | The first thing you can use to remember commands that you’ve already used is your own command line history. Most [[https://www.maketecheasier.com/alternative-linux-shells/][Linux shells]], including 21 | the most common default, Bash, create a history file that lists your past commands. For Bash, you can find it at “/home//.bash_history.” 22 | 23 | It’s a plain text file, so you can open it in any text editor and loop back through or even search. 24 | 25 | * Apropos 26 | 27 | There’s actually a command that helps you find other commands. It’s called “apropos,” and it helps you find the appropriate command to 28 | complete the action you search or. For example, if you need to know the command to list the contents of a directory, you can run the 29 | following command: 30 | 31 | #+BEGIN_SRC shell 32 | apropos "list directory" 33 | #+END_SRC 34 | 35 | [[https://www.maketecheasier.com/assets/uploads/2017/10/rc-apropos.jpg]] 36 | 37 | There’s a catch, though. It’s very literal. Add an “s” to “directory,” and try again. 38 | 39 | #+BEGIN_SRC shell 40 | apropos "list directories" 41 | #+END_SRC 42 | 43 | It doesn’t work. What apropos does is search through a list of commands and the accompanying descriptions. If your search doesn’t match 44 | the description, it won’t pick up the command as a result. 45 | 46 | There is something else you can do. By using the -a flag, you can add together search terms in a more flexible way. Try this command: 47 | 48 | #+BEGIN_SRC shell 49 | apropos "match pattern" 50 | #+END_SRC 51 | 52 | [[https://www.maketecheasier.com/assets/uploads/2017/10/rc-apropos-a.jpg]] 53 | 54 | You’d think it’d turn up something, like [[https://www.maketecheasier.com/what-is-grep-and-uses/][grep]]? Instead, you get nothing. Again, apropos is being too literal. Now, try separating the words and using the -a flag. 55 | 56 | #+BEGIN_SRC shell 57 | apropos "match" -a "pattern" 58 | #+END_SRC 59 | 60 | Suddenly, you have many of the results that you’d expect. 61 | 62 | apropos is a great tool, but you always need to be aware of its quirks. 63 | 64 | * ZSH 65 | 66 | [[https://www.maketecheasier.com/assets/uploads/2017/10/rc-zsh.jpg]] 67 | ZSH isn’t really a tool for remembering commands. It’s actually an alternative shell. You can substitute [[https://www.maketecheasier.com/understanding-the-different-shell-in-linux-zsh-shell/][ZSH]] for Bash and use it as your 68 | command line shell. ZSH includes an autocorrect feature that catches you if you enter in a command wrong or misspell something. If you 69 | enable it, it’ll ask you if you meant something close. You can continue to use the command line as you normally would with ZSH, but you 70 | get an extra safety net and some other really nice features, too. The easiest way to get the most of ZSH is with [[https://github.com/robbyrussell/oh-my-zsh][Oh-My-ZSH]]. 71 | 72 | * Cheat Sheet 73 | 74 | The last, and probably simplest, option is to use a [[https://www.maketecheasier.com/premium/cheatsheet/linux-command-line/][cheat sheet]]. There are plenty available online like [[https://www.cheatography.com/davechild/cheat-sheets/linux-command-line/][this one]] that you can use to look 75 | up commands quickly. 76 | 77 | [[https://www.maketecheasier.com/assets/uploads/2013/10/linux-commandline-cheatsheet.gif]] 78 | 79 | You can actually even find them in image form and set one as your desktop wallpaper for quick reference. 80 | 81 | This isn’t the best solution for actually remembering the commands, but when you’re starting out, it can save you from doing a search 82 | online every time you don’t remember a command. 83 | 84 | Rely on these methods when you’re learning, and eventually you’ll find yourself referring to them less and less. No one remembers 85 | everything, so don’t feel bad if you occasionally forget or run into something you haven’t seen before. That’s what these resources and, 86 | of course, the Internet are there for. 87 | -------------------------------------------------------------------------------- /raw/How to Run Multiple Commands on Multiple Linux Servers.org: -------------------------------------------------------------------------------- 1 | #+TITLE: How to Run Multiple Commands on Multiple Linux Servers 2 | #+URL: https://www.tecmint.com/run-multiple-commands-on-multiple-linux-servers/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-21 四 18:19] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | If you are managing multiple Linux servers, and you want to run multiple commands on all the Linux servers, but you have no idea about how to do it. There is no 10 | need to worry, in this simple server management guide, we will show you how to run multiple commands on multiple Linux servers simultaneously. 11 | 12 | To achieve, this you can use the [[https://www.tecmint.com/execute-commands-on-multiple-linux-servers-using-pssh/][pssh (parallel ssh) program]], a command line utility for executing ssh in parallel on a number of hosts. With it, you can send input 13 | to all of the ssh processes, from a shell script. 14 | 15 | Requirements 16 | 17 | 1 [[https://www.tecmint.com/execute-commands-on-multiple-linux-servers-using-pssh/][Install Pssh to Run Commands on Multiple Remote Linux Servers]] 18 | 2 You must be using [[https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/][SSH passwordless authentication]] for all remote servers. 19 | 20 | Create a Shell Script 21 | 22 | Therefore, you need to start by preparing a script which contains the Linux commands you want to execute on the different servers. In this example, we will write a 23 | script that will collect the following information from multiple servers: 24 | 25 | ,* Check uptime of servers 26 | ,* Check who is logged on and what they are doing 27 | ,* List top 5 running processes according to memory usage. 28 | 29 | First create a script called commands.sh with your favorite editor. 30 | 31 | # vi commands.sh 32 | 33 | Next, add the following commands to the script as shown. 34 | 35 | #!/bin/bash 36 | ############################################################################### 37 | #Script Name : commands.sh 38 | #Description : execute multiple commands on multiple servers 39 | #Author : Aaron Kili Kisinga 40 | #Email : [[https://www.tecmint.com/cdn-cgi/l/email-protection][{email protected}]] 41 | ################################################################################ 42 | echo 43 | # show system uptime 44 | uptime 45 | echo 46 | # show who is logged on and what they are doing 47 | who 48 | echo 49 | # show top 5 processe by RAM usage 50 | ps -eo cmd,pid,ppid,%mem,%cpu --sort=-%mem | head -n 6 51 | exit 0 52 | 53 | Save the file and close it. Then make the script executable as shown. 54 | 55 | # chmod +x commands.sh 56 | 57 | Create PSSH Hosts File 58 | 59 | Next, add the list of servers that you want to run the commands on, in a hosts.txt file, in the format [[[https://www.tecmint.com/cdn-cgi/l/email-protection][{email protected}]]]host[:port] or simply give the server IP 60 | addresses. 61 | 62 | But we suggest you use ssh aliases which can be specified in .ssh/config file as explained in how to [[https://www.tecmint.com/configure-custom-ssh-connection-in-linux/][configure custom ssh connections]] to simplify remote access. 63 | 64 | This method is more efficient and reliable, it allows you to specify configuration options (such as host name, identify file, port, username etc..) for each remote 65 | server. 66 | 67 | Following is our sample ssh hosts aliases file a.k.a user specific ssh configuration file. 68 | 69 | # vi ~/.ssh/config 70 | [[https://www.tecmint.com/wp-content/uploads/2017/12/ssh-hosts-aliases-file.png][SSH Hosts Aliases File 71 | SSH Hosts Aliases File]] 72 | 73 | SSH Hosts Aliases File 74 | 75 | Next, create a hosts.txt file, here you can simply specify the aliases (names defined using Host keyword in .ssh/config file) as shown. 76 | 77 | # vi hosts.txt 78 | 79 | Add the server aliases. 80 | 81 | server1 82 | server2 83 | server3 84 | 85 | Run Commands via a Script on Multiple Linux Servers 86 | 87 | Now run the following pssh command by specifying hosts.txt file along with the script that contains multiple commands to run on multiple remote servers. 88 | 89 | # pssh -h hosts.txt -P -I<./commands.sh 90 | 91 | Meaning of the flags used in the above command: 92 | 93 | ,* -h – reads the hosts file. 94 | ,* -P – tells pssh to display output as it arrives. 95 | ,* -I – reads input and sends to each ssh process. 96 | 97 | [[https://www.tecmint.com/wp-content/uploads/2017/12/run-multiple-commands-on-multiple-servers.png][Run Multiple Commands On Remote Servers 98 | Run Multiple Commands On Remote Servers]] 99 | 100 | Run Multiple Commands On Remote Servers 101 | 102 | That’s It! In this article, we showed how to execute multiple commands on multiple servers in Linux. You can share any thoughts relating to this topic via the 103 | comment section below. 104 | 105 | -------------------------------------------------------------------------------- /raw/How to Search DuckDuckGo from the Linux Terminal.org: -------------------------------------------------------------------------------- 1 | #+TITLE: How to Search DuckDuckGo from the Linux Terminal 2 | #+URL: https://www.tecminit.com/search-duckduckgo-from-linux-terminal 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-21 四 12:53] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | Like [[https://www.tecmint.com/google-commandline-search-terminal/][Googler]] (Google Site Search from the command-line), ddgr is a command line utility 11 | that can be used to search for key terms words via DuckDuckGo search engine and a 12 | [[https://www.tecmint.com/command-line-web-browsers/][command line browser]] on your terminal prompt. 13 | 14 | Before installing ddgr command line search engine in Linux, first assure that the Python 15 | 3.4 and Python requests library needed to handle HTTPS requests are installed on your 16 | system, by issuing the following commands. 17 | 18 | ------------------ On CentOS, RHEL & Fedora ------------------ 19 | # yum install epel-release 20 | # yum install python34 python34-requests 21 | ------------------ On Debian & Ubuntu ------------------ 22 | # apt install python3 python3-requests 23 | 24 | In order to open ddgr searches you need to install a command line browser, such as elinks, 25 | links, lynx, w3m or www-browser, in your system. 26 | 27 | Read Also: [[https://www.tecmint.com/command-line-web-browser-download-file-in-linux/][8 Command Line Tools for Browsing Websites]] 28 | 29 | In this guide we’ll configure ddgr search engine to open links via lynx text based browser. 30 | 31 | # yum insall lynx [On CentOS, RHEL & Fedora] 32 | # apt-get install lynx [On Debian & Ubuntu] 33 | 34 | Next, set the BROWSER environment variable system-wide to point to lynx browser, by 35 | issuing the following commands with root privileges. 36 | 37 | # export BROWSER=lynx 38 | # echo “export BROWSER=lynx” >> /etc/profile 39 | 40 | In order to install DuckDuckGo search engine command line utility via official ddgr github 41 | binary package releases, issue the following commands specific to your own Linux 42 | distribution. 43 | 44 | ------------------ On CentOS, RHEL & Fedora ------------------ 45 | # yum install https://github.com/jarun/ddgr/releases/download/v1.1/ddgr-1.1-1.el7.3.centos.x86_64.rpm 46 | ------------------ On Ubuntu 16.04 ------------------ 47 | # wget https://github.com/jarun/ddgr/releases/download/v1.1/ddgr_1.1-1_ubuntu16.04.amd64.deb 48 | # dpkg -i ddgr_1.1-1_ubuntu16.04.amd64.deb 49 | ------------------ On Ubuntu 17.10 ------------------ 50 | # wget https://github.com/jarun/ddgr/releases/download/v1.1/ddgr_1.1-1_ubuntu17.10.amd64.deb 51 | # dpkg -i ddgr_1.1-1_ubuntu17.10.amd64.deb 52 | ------------------ On Debian 9 ------------------ 53 | # wget https://github.com/jarun/ddgr/releases/download/v1.1/ddgr_1.1-1_debian9.amd64.deb 54 | # dpkg -i ddgr_1.1-1_debian9.amd64.deb 55 | 56 | You can also install ddgr on Ubuntu using a PPA repository, which is maintained by the 57 | developer of ddgr project. 58 | 59 | $ sudo add-apt-repository ppa:twodopeshaggy/jarun 60 | $ sudo apt-get update 61 | $ sudo apt-get install ddgr 62 | 63 | How to Search DuckDuckGo from Terminal Using ddgr 64 | 65 | Finally, in order to search a specific keyword in ddgr serach engine, issue the command as 66 | shown in the below example. 67 | 68 | # ddgr tecmint 69 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Search-DuckDuckGo-from-Commandline.png][Search DuckDuckGo from Commandline 70 | Search DuckDuckGo from Commandline]] 71 | 72 | Search DuckDuckGo from Commandline 73 | 74 | To automatically open a specific displayed search result in lynx text-based browser, hit the 75 | corresponding number key and wait for the webpage to load. Sometimes you need to type 76 | “a” in lynx browser in order to always accept website cookies and load the website. 77 | 78 | That’s all! For other information regarding DuckDuckGo command line search engine 79 | utility, visit [[https://github.com/jarun/ddgr][ddgr official github]] page. 80 | -------------------------------------------------------------------------------- /raw/InsecRes - A Tool to Find Insecure Resources on HTTPS Sites.org: -------------------------------------------------------------------------------- 1 | #+TITLE: InsecRes - A Tool to Find Insecure Resources on HTTPS Sites 2 | #+URL: https://www.tecmint.com/insecres-finds-insecure-resources-on-https-sites/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-21 四 18:27] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | After switching your site to HTTPS, you probably want to test if resources such as images, slides, embedded videos and others, are correctly pointed to HTTPS 11 | protocol or displaying warnings about the insecure content on the pages. After some research I found a useful tool for this purpose, called insecuRes. 12 | 13 | InsecuRes is a small, free and open source command line based tool for finding insecure resources on HTTPS sites, written in Go programming language. It utilizes 14 | the power of “multi-threading” (goroutines) to crawl and parse site pages. 15 | 16 | Read Also: [[https://www.tecmint.com/redirect-http-to-https-on-apache/][How to Redirect HTTP to HTTPS on Apache]] 17 | 18 | It crawls all your website pages in parallel, scans and catches: IMG, IFRAME, OBJECT, AUDIO, VIDEO, SOURCE and TRACK resources with full HTTP (insecure) urls. To 19 | prevent blacklisting by web server, it employs a random delay between requests. Additionally, you can redirect its output to a CSV file for later analysis. 20 | 21 | Requirements 22 | 23 | 1 [[https://www.tecmint.com/install-go-in-linux/][Install Go Programming Language in Linux]] 24 | 25 | Install InsecuRes in Linux Systems 26 | 27 | Once Go Programming Language installed on the system, run the command below on the terminal to get insecres. 28 | 29 | $ go get github.com/kkomelin/insecres 30 | 31 | Once you have downloaded and installed insecres, run the command below to scan your site for insecure resources. If it shows no output, that probably means 32 | there are no insecure resources on your site. 33 | 34 | $ $GOPATH/bin/insecres https://example.com 35 | 36 | To save the output in a CSV file for later examination, use the -f flag. 37 | 38 | $ $GOPATH/bin/insecres -f="/path/to/scan_report.csv" https://example.com 39 | 40 | Display usage guide. 41 | 42 | $ $GOPATH/bin/insecres -h 43 | 44 | Some of the features to be added include displayiny result counters and comparing performance of simple regex parsing and tokenized parsing. 45 | 46 | InsecRes Github repository: [[https://github.com/kkomelin/insecres][https://github.com/kkomelin/insecres]] 47 | 48 | In this article, we showed you how to find insecure resources on HTTPS sites, using a simple command line tool called insecres. You can ask questions or share 49 | your thoughts via the comment section below. If you know of any similar tools out there, do share information about them as well. 50 | -------------------------------------------------------------------------------- /raw/Testssl.sh - Testing TLS-SSL Encryption Anywere on Any Port.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Testssl.sh - Testing TLS-SSL Encryption Anywere on Any Port 2 | #+URL: https://www.tecmint.com/testssl-sh-test-tls-ssl-encryption-in-linux-commandline/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-21 四 17:14] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | testssl.sh is a free and open source, feature-rich command line tool used for checking TLS/SSL encryption enabled services for supported ciphers, protocols and 11 | some cryptographic flaws, on Linux/BSD servers. It can be run on MacOS X and Windows using MSYS2 or [[https://www.tecmint.com/install-cygwin-to-run-linux-commands-on-windows-system/][Cygwin]]. 12 | 13 | Features of Testssl.sh 14 | 15 | ,* Easy to install and use; produces clear output. 16 | ,* Highly flexible, it can be used to check any SSL/TLS enabled and STARTTLS services. 17 | ,* Perform a general check or single checks. 18 | ,* Comes with several command line options for various categories of single checks. 19 | ,* Supports different output types, including colored output. 20 | ,* Supports SSL Session ID check. 21 | ,* Supports checking for multiple server certificates. 22 | ,* Offers absolute privacy, it’s only you who can sees the result, not a third party. 23 | ,* Supports logging in (flat) JSON + CSV format. 24 | ,* Supports mass testing in serial (default) or parallel modes. 25 | ,* Supports presetting of command line options via environment variables, and so much more. 26 | 27 | Important: You should be using bash (which comes preinstalled on almost Linux distributions) and a newer OpenSSL version (1.0) is recommended for effective 28 | usage. 29 | 30 | How to Install and Use Testssl.sh in Linux 31 | 32 | You can install testssl.sh by cloning this git repository as shown. 33 | 34 | # git clone --depth 1 https://github.com/drwetter/testssl.sh.git 35 | # cd testssl.sh 36 | 37 | After cloning testssl.sh, the general use case is probably just run the following command to run a test against a website. 38 | 39 | # ./testssl.sh https://www.google.com/ 40 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Test-SSL-TLS-Encryption.png][Test SSL TLS Encryption 41 | Test SSL TLS Encryption]] 42 | 43 | Test SSL TLS Encryption 44 | 45 | To run a check against STARTTLS enabled protocols: ftp, smtp, pop3, imap, xmpp, telnet, ldap, postgres, mysql, use the -t option. 46 | 47 | # ./testssl.sh -t smtp https://www.google.com/ 48 | 49 | By default, all mass tests are done in serial mode, you can enable parallel testing using the --parallel flag. 50 | 51 | # ./testssl.sh --parallel https://www.google.com/ 52 | 53 | If you do not want to use the default system openssl program, use the –openssl flag to specify an alternative. 54 | 55 | # ./testssl.sh --parallel --sneaky --openssl /path/to/your/openssl https://www.google.com/ 56 | 57 | You might want to keep logs for later analysis, testssl.sh has the --log (store log file in the current directory) or --logfile (specify log file location) option for that. 58 | 59 | # ./testssl.sh --parallel --sneaky --logging https://www.google.com/ 60 | 61 | To disable DNS lookup, which can increase test speeds, use the -n flag. 62 | 63 | # ./testssl.sh -n --parallel --sneaky --logging https://www.google.com/ 64 | 65 | Run Single Checks Using testssl.sh 66 | 67 | You can also run single checks for protocols, server defaults, server preferences, headers, various types of vulnerabilities plus many other tests. There are a 68 | number of options provided for this. 69 | 70 | For example, the -e flag enables you to check each local cipher remotely. If you want to make the test much faster, use include the --fast flag; this will omit some 71 | checks, in case you are using openssl for all ciphers, it only displays the first proffered cipher. 72 | 73 | # ./testssl.sh -e --fast --parallel https://www.google.com/ 74 | 75 | The -p option allows for testing TLS/SSL protocols (including SPDY/HTTP2). 76 | 77 | # ./testssl.sh -p --parallel --sneaky https://www.google.com/ 78 | 79 | You can view the server’s default picks and certificate using the -S option. 80 | 81 | # ./testssl.sh -S https://www.google.com/ 82 | 83 | Next, to see the server’s preferred protocol+cipher, use the -P flag. 84 | 85 | # ./testssl.sh -P https://www.google.com/ 86 | 87 | The -U option will help you test all vulnerabilities (if applicable). 88 | 89 | # ./testssl.sh -U --sneaky https://www.google.com/ 90 | 91 | Unfortunately, we can not exploit all the options here, use the the command below to see a list of all options. 92 | 93 | # ./testssl.sh --help 94 | 95 | Find more at testssl.sh Github repository: [[https://github.com/drwetter/testssl.sh][https://github.com/drwetter/testssl.sh]] 96 | 97 | Conclusion 98 | 99 | testssl.sh is a useful security tool that every Linux system administrator needs to have and use for testing TSL/SSL enabled services. If you have any questions or 100 | thoughts to share, use the comment form below. In addition, you can also share with us any similar tools, that you have come across out there. 101 | -------------------------------------------------------------------------------- /raw/Top 10 Linux tools.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Top 10 Linux tools 2 | #+URL: https://www.datamation.com/open-source/slideshows/top-10-linux-tools.html 3 | #+AUTHOR: lujun9972 4 | #+TAGS: linux tools 5 | #+DATE: [2017-11-16 四 18:50] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 11 | The Linux tools you need to do just about anything on the Linux desktop. 12 | * CloneZilla 13 | 14 | Whether you need to clone and deploy a Linux desktop/server or simply make a disk image for restoration, [[http://clonezilla.org/][CloneZilla]] is a great 15 | software choice. One of the things I love about CloneZilla is that you can clone disks for both Linux and Windows. 16 | 17 | CloneZilla allows its users to backup to a local backup drive or via their local network. Compression can also be utilized to save 18 | space or simply let CloneZilla do its job without any compression at all. 19 | 20 | Unlike proprietary disk and partition cloning tools, CloneZilla doesn't rely on fees or license keys. Simply download the software to 21 | bootable media and you're all set. The biggest thing to be wary of with CloneZilla is remembering which drive is the source and which 22 | is the backup destination. 23 | 24 | 25 | * GIMP 26 | 27 | GIMP is a very powerful, yet often misunderstood image manipulation program. The misunderstood element of [[https://www.gimp.org/][GIMP]] is that it's often seen 28 | as a Photoshop alternative. In reality, the two programs have more things different from one another than alike. 29 | 30 | One of the things that makes GIMP so powerful is that you can extend its functionality by using plugins. There are plugins that 31 | provides tablet support, advanced print options, even some limited CMYK color manipulation and more. GIMP shines best when making 32 | edits to RGB color images and tweaking existing photography. 33 | 34 | Outside of the fact that GIMP has a different workflow than Photoshop, it's important to note that the tool set offered also differs. 35 | The one thing the two editors have in common these days is the fact that both are available in a single window mode. 36 | 37 | * Handbrake 38 | 39 | If you're looking to backup your existing DVD collection for safe keeping, then [[https://handbrake.fr/][Handbrake]] is a very important tool for making this 40 | easier. Thanks to Handbrake's clear feature layout and logical presets, ripping your DVD collection onto your hard drive has never 41 | been easier. 42 | 43 | Additional benefits to this software include its ability to clean up video errors, change aspect ratio and cooperate with videos being 44 | ripped into file containers. One amazing feature that must be mentioned is Handbrake's ability to handle DVD chapters. 45 | 46 | If you decide to venture beyond the offered presets, your success with Handbrake may vary from video to video. You'll also find that 47 | Handbrake shines at its best on PCs with enough horsepower to render video quickly and successfully without crashing. 48 | 49 | * GParted 50 | 51 | Before you install a Linux distro, you must first partition the drive it's to be installed on. Obviously, you could do this from the 52 | installation media. But how would you do this on a system that's already installed? Using [[https://gparted.org/][GParted]] is one option that you might 53 | consider. I've found that GParted offers a solid GUI to the otherwise mystifying partitioning process. Even those who know how to 54 | partition from the command line will admit that having a clearly color coded visual representation of their partitions is extremely 55 | beneficial. 56 | 57 | GParted allows you to create, resize and even copy your computer's partition scheme. It supports Linux and Windows file systems. 58 | Additionally, it also makes partitioning your flash drives a snap when using GParted on an existing Linux installation. 59 | 60 | * VirtualBox 61 | 62 | I've used a lot of different applications to run virtual machines over the years. Yet despite my best efforts, I kept coming back to 63 | VirtualBox]]. I highly recommend VirtualBox as it works with just about any distro both as a host and as a guest. 64 | 65 | Another benefit to VirtualBox is that you can pass USB devices through to the guest OS from your host. Not to worry though, you're 66 | still able to keep the mouse and keyboard setup as bi-directional devices thanks to the VirtualBox extensions add-on. 67 | 68 | * HTOP 69 | 70 | While most Linux distros come with a GUI process manager, few of them have the raw functionality found with [[http://hisham.hm/htop/][HTOP]]. Like TOP, HTOP 71 | provides you with a terminal friendly method of monitoring and manipulating your Linux processes. You can use HTOP to sort, filter and 72 | end processes with the utmost of ease. 73 | 74 | For any remotely modern Linux system, you'll find number representation for each of your computer's cores. This is invaluable in 75 | visualizing how your PC runs various programs. The only thing to keep in mind with HTOP is the help feature is about as robust as a 76 | MAN file. The details are there, however the formatting while reading it will feel like a wall of text. 77 | 78 | * Powertop 79 | 80 | When you're freeing yourself from the tether of a plugged in laptop, you may find yourself on the receiving end of inexplicable 81 | battery drain. There are things you can do to address this issue, such as installing tlp to better manage power usage on your Linux 82 | system. 83 | 84 | Powertop]] adds value to the equation of power management in that you can see in a terminal output, what specifically is utilizing 85 | power. Whether its a rogue process or you forgot you had a video rendering (minimized), PowerTop is the best tool for managing your 86 | power consumption on Linux computers. 87 | 88 | * Tilda 89 | 90 | I've run a number of terminals for my Linux boxes. The ones I enjoyed the most were accessible when needed and out of the way when 91 | they weren't. This is why I run [[https://github.com/lanoxx/tilda][Tilda]]. Unlike a desktop environment specific option, Tilda is highly customizable and can be setup to 92 | activate by pressing an assigned hotkey of your choosing. 93 | 94 | Another benefit to using Tilda over say, Guake, is that it's a bit lighter in terms of resources. Both are great programs, but I like 95 | the minimalism of Tilda overall. 96 | 97 | * AptOnCD 98 | 99 | If you're running Ubuntu and have ever needed to install packages on a PC where Internet wasn't available, then I'm willing to bet 100 | AptOnCD]] was on your short list of possible solutions. 101 | 102 | Obviously you'd need to use the Internet at least once to get the packages you wish to add to a CD/DVD, however once this is done 103 | AptOnCD provides you with extremely smooth package portability for just about any situation. 104 | 105 | * Glances 106 | 107 | I would go so far as to suggest that [[https://nicolargo.github.io/glances/][Glances]] is the swiss army knife of the command line utility world. This is the best monitoring 108 | tool for running in a dedicated window. Use Glances to watch for serious errors, CPU spikes, disk IO issues, user vs system load 109 | issues and of course real time drive usage. 110 | 111 | The only downside of Glances is that it's a monitoring tool only. If you see an issues arise, you'll have to deep dive into your logs 112 | or related to do any advanced troubleshooting. 113 | -------------------------------------------------------------------------------- /raw/Top Ways to Learn Linux Online.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Top Ways to Learn Linux Online 2 | #+URL: http://www.linuxandubuntu.com/home/top-ways-to-learn-linux-online 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-11-06 一 16:36] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | Diving into the world of Linux can sometimes appear to be overwhelming to the newcomer. While anything browser-based is essentially the same as it is in 11 | Windows, there are some stark differences once you take the plunge and [[http://www.linuxandubuntu.com/home/how-to-install-linux-mint-from-usb][install Linux for the first time]]. 12 | While, in this author’s opinion, the best way to learn Linux is by simply using it as your daily driver, you may prefer to take a more structured approach by learning 13 | from an online course. With online education becoming ubiquitous in today’s world, there is no shortage of online resources that offer courses to take you from 14 | beginner to power user before you know it. Here are some of our favorites. 15 | 16 | * Free Learning 17 | 18 | ** edX 19 | 20 | ​Founded by Harvard University and MIT in 2012, [[https://www.edx.org/][edX]] is a great source for not only learning Linux, but a huge variety of other subjects including programming and 21 | computer science. Prestigious universities from all over the world offer courses in one of the most popular Massive Open Online Course ([[http://mooc.org/][MOOC]]) sites on the 22 | Internet. You can “audit” courses for free, or pay for an official certificate of completion for your course(s) of choice, which could potentially be valuable to a future 23 | employer. As for the Linux world, you may find the following courses to be quite beneficial and educational. 24 | 25 | + [[https://www.edx.org/course/introduction-linux-linuxfoundationx-lfs101x-1][Introduction to Linux from The Linux Foundation]] 26 | + [[https://www.edx.org/course/fundamentals-red-hat-enterprise-linux-red-hat-rh066x][Fundamentals of Red Hat Enterprise Linux (RHEL) from Red Hat]] 27 | 28 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/edx_orig.png]] 29 | 30 | ** YouTube 31 | 32 | ​It may come as a bit of a shock to some, but YouTube actually has quite a bit more to offer than reaction videos and vloggers begging for likes and subs. Quite a 33 | bit of educational material is available on YouTube free-of-charge. So you could take all that time you’ve been spending watching cat videos and arguing about 34 | politics in the comments, and instead put it towards learning something! One of this author’s favorite YouTube Linux channels is [[https://www.youtube.com/user/JtheLinuxguy][LearnLinux.tv]], ran by [[https://plus.google.com/+JayLaCroix][Jay LaCroix]]. 35 | He covers everything Linux related, including beginner and advanced tutorials, distro reviews, and even hardware reviews. He’s even written a few books! His 36 | tutorials in particular are definitely worth the watch, especially if you’re just learning your way around Linux. Check out the [[https://www.youtube.com/user/JtheLinuxguy/playlists][playlists]] on his channel to see all that 37 | he has to offer. 38 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/learnlinux_orig.png]] 39 | ​Another YouTube channel that this author has found useful is [[https://www.youtube.com/user/elithecomputerguy/featured][Eli the Computer Guy]]. His channel covers a wide variety of computer and IT topics, but his [[https://www.youtube.com/watch?v=_gCwCOhMcog&list=PLD6B6473ACF32C59D][Linux]] 40 | playlist, in particular, is what you’re looking for. And while you’re there, maybe you can pick up a new set of skills along the way. 41 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/eli-the-computer-guy_orig.png]] 42 | ​Of course, you can always just do a YouTube search for “learn Linux” and see what you can find. 43 | ​Once you get the basics of Linux down and you want to move on to learning more about the command line and scripting, there’s a great YouTube series from [[https://www.youtube.com/user/madhurbhatia89][The]] 44 | [[https://www.youtube.com/user/madhurbhatia89][Bad Tutorials]] on [[https://www.youtube.com/playlist?list=PL7B7FA4E693D8E790][Shell Scripting]], meaning writing automated scripts using the default Linux bash shell. 45 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/shell-scripting_orig.png]] 46 | 47 | ** Cybrary 48 | 49 | A largely unknown yet super useful site, [[https://www.cybrary.it][Cybrary]] contains a “cyber library” of all kinds of IT courses. The main focus of Cybrary is for IT Professionals who are 50 | seeking to expand their skill sets and obtain industry certifications. While Cybrary usually focuses on more advanced topics like Networking and Security, there are 51 | a few Linux courses available. They even offer training for the CompTIA Linux+ certification. These courses may not necessarily be geared towards the Linux 52 | newbie, but you may be able to come back here after getting the basics down to expand your knowledge further: 53 | 54 | + [[https://www.cybrary.it/course/comptia-linux-plus/][CompTIA Linux+]] 55 | + [[https://www.cybrary.it/skill-certification-course/fundamental-linux-administration-certification-training-course][Fundamental Linux Administration Certification Course]] 56 | + [[https://www.cybrary.it/skill-certification-course/ethical-hacking-and-penetration-testing-with-kali-linux-certification-training-course][Ethical Hacking and Penetration Testing with Kali Linux]] 57 | 58 | ** The Linux Foundation 59 | 60 | ​The Linux Foundation provides all kinds of Linux pieces of training, from online training courses, in person at training centers in various locations around the world, 61 | or even at Linux Foundation events. They also offer Corporate Linux Training for companies who want to bring the experts to you. If you poke around The Linux 62 | Foundation’s [[https://training.linuxfoundation.org][website]] you’ll find some free training materials, specifically their [[https://training.linuxfoundation.org/free-linux-training/linux-training-videos][training videos]]. They have other listings for [[https://training.linuxfoundation.org/free-linux-training][free online learning]], one of which 63 | includes an aforementioned edX course. 64 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/linuxfoundation_orig.png]] 65 | 66 | ** Linux Survival 67 | 68 | ​[[https://linuxsurvival.com/][Linux Survival]] by Guy Hummel is another free online tutorial for learning the basics of Linux, and it even includes some quizzes for testing your comprehension of 69 | the topics after reading. He also offers a guide to becoming a Linux Administrator, if you’re looking to take your Linux knowledge into the professional realm. 70 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/linuxsurvival_orig.png]] 71 | 72 | ** Vim Adventures 73 | 74 | While not actually Linux itself, Vim is a powerful and widely used terminal based text editor (although GUI versions are available, even for Windows) that is 75 | practically ubiquitous on Linux, regardless of distribution. However, despite it’s popularity and power, it is a bit quirky and has a bit of a learning curve. Once you 76 | get used to it, you’ll likely grow to thoroughly enjoy it, but the learning curve can be off putting to those who would rather just use something similar to Notepad. 77 | Learning Vim, or at least the basic operation of Vim, can be super useful when you need to create or edit configuration files, write some code, or even just write 78 | your own personal notes. Enter [[https://vim-adventures.com/][Vim Adventures]], a browser-based game that teaches you how to use Vim by having you navigate your character through the 2D 79 | world using only the keys and functions of Vim. If only everything in life could be taught through educational games! 80 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/vimadventures_orig.png]] 81 | 82 | ** Codecademy 83 | 84 | ​While more geared towards aspiring programmers, [[https://www.codecademy.com/][Codecademy]] does have a course on the Linux command line that the newcomer to Linux could definitely find 85 | useful. Most of the free courses on Codecademy just offer the basics of each subject while their paid courses go into more depth and detail, but the Command Line 86 | course is perfect for anyone who just wants to get a basic handle on how to Linux command line works. You’ll likely find it to be far more enjoyable than the 87 | Windows command line or even [[http://www.linuxandubuntu.com/home/microsoft-powershell-is-now-available-for-linux][PowerShell]]. Just sign in with your existing Google account and start learning. 88 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/codeacademy_orig.png]] 89 | 90 | ** The Bash Academy 91 | 92 | Again more aimed at teaching the [[https://www.gnu.org/software/bash/manual/html_node/What-is-Bash_003f.html][Bash shell]] rather than Linux itself (similar to the aforementioned Shell Scripting course from The Bad Tutorials), Bash is the 93 | default shell used in most Linux distributions, so learning it and becoming proficient in it could be quite useful, especially in the professional realm where Scripting 94 | and Automation is king. [[http://www.bash.academy/][The Bash Academy]] offers two different flavors of learning: the traditional textbook way called [[http://guide.bash.academy/][The Bash Guide]], or another educational game 95 | aptly titled [[http://play.bash.academy/][The Bash Game]]. 96 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/bashacademy_orig.png]] 97 | 98 | * Conclusion 99 | 100 | ​One of the most beneficial, if not underutilized, aspects of the internet is the wealth of free educational materials available. If your operating system was free, why 101 | pay money to learn how to use it? Although of course, donations to your organizations of choice are always helpful. In addition to all of the above mentioned 102 | educational resources, one final tip is to keep reading Linux blogs like [[http://www.linuxandubuntu.com/home.html][LinuxAndUbuntu]], as you never know what sorts of Linux tricks and tips you’ll come across. 103 | -------------------------------------------------------------------------------- /shell/How to modify scripts behavior on signals using bash traps.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 使用bash trap修改脚本应对信号的行为 2 | #+URL: https://linuxconfig.org/how-to-modify-scripts-behavior-on-signals-using-bash-traps 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-10-28 六 20:20] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | * 简介 11 | 12 | 在编写长期运行的脚本时, 保证它的鲁棒性是很有必要的,这就需要能对系统信号产生反应执行特定的操作. 13 | 我们可以使用bash内置的 =trap= 来做到这一点. 14 | 15 | * 什么是trap? 16 | 17 | trap 是bash提供的一种机制,它允许你自定义脚本在收到信号时的行为. 这项能力十分实用, 比如, 可以用它来保证系统的一致性(consistent state). 18 | 假设一个脚本在运行期间需要创建某些目录: 那么当发送 =SIGINT= 信号到该脚本后,该脚本会终止执行, 留下创建的目录没有被清理掉. 19 | 而 =trap= 可以用来解决这样的问题. 20 | 21 | * Trap语法 22 | 23 | Trap 语法很简单易懂: 首先是 trap , 然后是要执行的动作, 然后指定要监听的信号: 24 | 25 | #+BEGIN_SRC shell 26 | trap [-lp] [[arg] sigspec] 27 | #+END_SRC 28 | 29 | 现在让我们来看看 =trap= 有哪些选项. 30 | 31 | -l 选项会让 =trap= 命令显示出一个信号以及对应编号的列表. 它看起来跟 =kill -l= 命令的执行结果类似: 32 | 33 | #+BEGIN_EXAMPLE 34 | $ trap -l 35 | 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 36 | 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 37 | 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 38 | 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 39 | 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 40 | 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR 41 | 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 42 | 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43 | 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 44 | 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 45 | 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 46 | 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2 47 | 63) SIGRTMAX-1 64) SIGRTMAX 48 | #+END_EXAMPLE 49 | 50 | 一定要记住, =trap= 只能对那些允许捕获的信号设置触发动作: SIGKILL 和 SIGSTOP 这两个信号则既不能捕获也不能忽略. 51 | 52 | 除了真实的信号之外, trap 还支持某些伪信号比如 EXIT, ERR 和 DEBUG, 具体细节我们后面再说. 53 | 现在只需要记住,指定信号时既可以用信号的编号也可以用信号的名称来指定,而且用名称来指定信号时甚至可以省略前面的 =SIG=. 54 | 55 | 现在来说说 =-p= 选项. 该选项不能与出发信号后执行的命令一起使用(否则会报错). 它的作用是显示之前的trap设置. 56 | 若指定了信号名称或者信号编号,则只会显示指定信号的相关设置,否则会显示所有的trap设置: 57 | 58 | #+BEGIN_SRC shell 59 | $ trap 'echo "SIGINT caught!"' SIGINT 60 | #+END_SRC 61 | 62 | 我们就为 =SIGINT= 信号设置了一个trap: 当脚本接受道指定信号时会在屏幕上显示出一条 "SIGINT caught" 信息. 63 | 若我们现在使用 =-p= 参数调用trap, 则会显示刚才我们定义的那条trap信息: 64 | 65 | #+BEGIN_EXAMPLE 66 | $ trap -p 67 | trap -- 'echo "SIGINT caught!"' SIGINT 68 | #+END_EXAMPLE 69 | 70 | 而且,该trap现在是有效的, 若我们通过kill命令或者按下 =Ctrl-c= 发送一个 =SIGINT= 信号, 就会触发相关的命令: 71 | 72 | #+BEGIN_EXAMPLE 73 | ^CSIGINT caught! 74 | #+END_EXAMPLE 75 | 76 | * Trap实战 77 | 78 | 我们现在来写一个简单的脚本来演示一下trap的用法: 79 | 80 | #+BEGIN_SRC shell 81 | #!/usr/bin/env bash 82 | # 83 | # A simple script to demonstrate how trap works 84 | # 85 | set -e 86 | set -u 87 | set -o pipefail 88 | 89 | trap 'echo "signal caught, cleaning..."; rm -i linux_tarball.tar.xz' SIGINT SIGTERM 90 | 91 | echo "Downloading tarball..." 92 | wget -O linux_tarball.tar.xz https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.13.5.tar.xz &> /dev/null 93 | #+END_SRC 94 | 95 | 上面脚本会尝试用wget下载最新的linux kernel tarball到本地目录. 在任务期间, 若收到了 SIGINT 或者 SIGTERM 信号(你可以在统一行指定不止一个信号), 则未下载完成的文件会被删除掉. 96 | 97 | 在这个例子中,信号触发的命令有两个: 第一个是 =echo= 命令将一段信息输出,第二个是 =rm= 命令 (我们带了 =-i= 选项, 因此在实际删除前rm会要求我们确认删除), 这两条命令之间用分号区分. 98 | 除了用这种方式指定多个命令外,你还可以调用函数: 这样可读性更强一些. 99 | 注意,如果你没有提供任何信号触发的命令,就表示忽略该信号! 100 | 101 | 该脚本运行期间收到 =SIGINT= 信号后会有如下输出: 102 | 103 | #+BEGIN_EXAMPLE 104 | $ ./fetchlinux.sh 105 | Downloading tarball... 106 | ^Csignal caught, cleaning... 107 | rm: remove regular file 'linux_tarball.tar.xz'? 108 | 109 | #+END_EXAMPLE 110 | 111 | 还有很重要的一点要注意,当脚本像上面那样被信号终止时, 它的退出码为128 + 信号编号的合. 112 | 如你所见, 上面脚本被 =SIGINT= 终止后,其退出码为130: 113 | 114 | #+BEGIN_EXAMPLE 115 | $ echo $? 116 | 130 117 | #+END_EXAMPLE 118 | 119 | 最后, 你可以通过 =trap= 后跟 =-= 符号, 再跟上信号名称或编号的方式来禁用trap: 120 | 121 | #+BEGIN_EXAMPLE 122 | trap - SIGINT SIGTERM 123 | #+END_EXAMPLE 124 | 125 | 会回复这两个信号最开始的作用. 126 | 127 | * 伪信号 128 | 129 | 如前所述, trap不仅可以为可捕获的信号设置触发动作,还支持一些所谓的"伪信号". 严格来说他们并不是真正的信号,而是表示某种特定的状态: 130 | 131 | ** EXIT 132 | 133 | 在 =trap= 中指定 =EXIT=, 则trap中的命令会在退出shell时执行. 134 | 135 | ** ERR 136 | 137 | 当有命令返回非0状态码时触发, 但不包括以下几种情况(与shell的errexit选项一样): 检查的命令不能是 =until= 或 =while= 循环的一部分,不能使 =if= 语句的一部分,不能是 =&&= 和 =⎪⎪= 序列的一部分, 不能时命令的返回值由 =!= 翻转得到. 138 | 139 | ** DEBUG 140 | 141 | 在执行简单命令, =for=, =case=, =select= 命令, 执行函数的第一条命令之前触发操作. 142 | 143 | ** RETURN 144 | 145 | 当使用 =source= 或 =.= 命令执行函数或脚本后触发操作. 146 | -------------------------------------------------------------------------------- /system/5 tricks for using the sudo command.org: -------------------------------------------------------------------------------- 1 | #+TITLE: sudo命令的5个小技巧 2 | #+URL: https://www.networkworld.com/article/3236499/linux/some-tricks-for-using-sudo.html 3 | #+AUTHOR: lujun9972 4 | #+TAGS: system sudo 5 | #+DATE: [2017-11-15 三 12:56] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | =sudoers= 文件精确控制了用户权限, 不过只需少许努力, 你依然可以从 =sudo= 中获益匪浅. 11 | 在本文中, 我们会演示一些简单而又十分有价值的 =sudo= 用法. 12 | 13 | * Trick 1: Nearly effortless sudo usage 14 | 15 | 在大多数的Linux发行版中,可以很容易地做到让指定用户拥有以root运行命令的能力. 你甚至无需修改 =/etc/sudoers= 文件. 16 | 只需要将用户添加到 =sudo= 或 =admin= 组就行了. 17 | 18 | 在 =/etc/group= 文件中将用户加入 =sudo= 或 =admin= 组中就赋予了那些用户使用 =sudo= 运行命令的权利. 19 | 20 | #+BEGIN_SRC shell 21 | $ grep sudo /etc/group 22 | sudo:x:27:shs,jdoe,peanut 23 | #+END_SRC 24 | 25 | 在标准的 =/etc/sudoers= 配置中, 一旦将用户纳入这两个组中就能立即使用 =sudo= 命令了. 26 | 它的权限由 =/etc/sudoers= 文件中的下面行决定: 27 | 28 | #+BEGIN_EXAMPLE 29 | %sudo ALL=(ALL:ALL) ALL 30 | #+END_EXAMPLE 31 | 32 | 行内的 =%sudo= (或 =%admin=) 部分表示 =sudo= (或 =admin=) 组. 剩下的内容允许组中的成员以任意用户的身份运行任意命令. 这是内建的行为. 33 | 如果你不希望有人拥有这项能力, 那就不要把任何人加入 =sudo= (或 =admin=) 组中. 34 | 35 | #+BEGIN_SRC shell 36 | $ sudo whoami 37 | [sudo] password for shs: 38 | root 39 | #+END_SRC 40 | 41 | * Trick 2: Running commands as other users — not just root 42 | 43 | 虽然大多数人使用 =sudo= 的目的是以root的身份运行命令, 但它也能允许你以其他用户的身份来运行命令. 只要使用 =-u= 参数加上指定的用户名就行了. 44 | 45 | #+BEGIN_SRC shell 46 | $ sudo -u jdoe whoami 47 | [sudo] password for shs: 48 | jdoe 49 | #+END_SRC 50 | 51 | * Trick 3: Changing the default editor for the visudo command 52 | 53 | 必须使用 =visudo= 命令来西修改 =/etc/sudoers= 文件,该命令会帮你避免配置出错导致配置文件不可用(即,损害了 sudo). 54 | 若你不习惯改命令默认使用的编辑器,你可以使用下面命令修改它: 55 | 56 | #+BEGIN_SRC shell 57 | sudo update-alternatives --config editor 58 | #+END_SRC 59 | 60 | 改命令会显示一个编辑器列表,并且当前使用的编辑器前有一个星号标识,在这里你可以选择自己喜欢的编辑器. 61 | 62 | #+BEGIN_SRC shell 63 | $ sudo update-alternatives --config editor 64 | [sudo] password for shs: 65 | There are 3 choices for the alternative editor (providing /usr/bin/editor). 66 | 67 | Selection Path Priority Status 68 | ------------------------------------------------------------ 69 | ,* 0 /bin/nano 40 auto mode 70 | 1 /bin/ed -100 manual mode 71 | 2 /bin/nano 40 manual mode 72 | 3 /usr/bin/vim.tiny 10 manual mode 73 | 74 | Press to keep the current choice[*], or type selection number: 75 | #+END_SRC 76 | 77 | * Trick 4: Switching to root 78 | 79 | 时常会有需要在每个命令前都加上 "sudo" 的时候. 默认的 =/etc/sudoers= 配置中,sudo (或 admin) 组中的成员可以使用命令 =sudo su -= 来获取root权限. 80 | 但使用root账户时请一定小心. 81 | 82 | #+BEGIN_SRC shell 83 | $ sudo su - 84 | [sudo] password for jdoe: 85 | root@stinkbug:~# 86 | #+END_SRC 87 | 88 | * Trick 5: Fixing a corrupt /etc/sudoers file 89 | 90 | 损坏的 =/etc/sudoers= 文件会使得 =sudo= 无法正常工作. 幸运的是有一些简单的方法可以帮到你, visudo 命令本身会提供一些错误的详细信息. 91 | 92 | The problem 93 | 94 | #+BEGIN_SRC shell 95 | shs@stinkbug:/etc$ sudo date 96 | >>> /etc/sudoers: syntax error near line 3 <<< 97 | sudo: parse error in /etc/sudoers near line 3 98 | sudo: no valid sudoers sources found, quitting 99 | sudo: unable to initialize policy plugin 100 | #+END_SRC 101 | 102 | The fix 103 | 104 | #+BEGIN_SRC shell 105 | shs@stinkbug:/etc$ pkexec visudo 106 | >>> /etc/sudoers: syntax error near line 3 <<< 107 | #+END_SRC 108 | -------------------------------------------------------------------------------- /system/How To Check Installed Linux Kernels.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何查看已安装的Linux Kernels 2 | #+URL: https://www.ostechnix.com/check-installed-linux-kernels/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-11-02 四 20:53] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 11 | 想知道你的Linux上安装了那些Linux Kernel? 这篇简易指南将会告诉你在不同Linux操作系统上查看已安装Linux Kernel的方法. 12 | 方法其实没有你想象的那么复杂. 请往下看. 13 | 14 | * Check installed Linux Kernels 15 | 16 | ** On Arch Linux: 17 | 18 | 在 Arch Linux 及其派生版本中,使用下面命令查找已安装的Kernel: 19 | 20 | #+BEGIN_SRC shell 21 | $ pacman -Q linux 22 | #+END_SRC 23 | 24 | 或者 25 | 26 | #+BEGIN_SRC shell 27 | $ pacman -Q | grep linux 28 | #+END_SRC 29 | 30 | 输出为: 31 | 32 | #+BEGIN_EXAMPLE 33 | archlinux-keyring 20171013-1 34 | lib32-util-linux 2.30.1-1 35 | libutil-linux 2.30.2-1 36 | linux 4.13.8-1 37 | linux-api-headers 4.12.7-1 38 | linux-firmware 20170907.a61ac5c-1 39 | syslinux 6.03-7 40 | util-linux 2.30.2-1 41 | #+END_EXAMPLE 42 | 43 | [[http://www.ostechnix.com/wp-content/uploads/2016/03/Check-Installed-Linux-Kernels.png]] 44 | 45 | 从上面输出可以看出, 我的 Arch Linux 运行内核为 4.13.8-1. 46 | 47 | * On RHEL / CentOS / Scientific Linux / Fedora: 48 | 49 | 打开终端, 运行下面命令来查看已安装的 Linux Kernels: 50 | 51 | #+BEGIN_SRC shell 52 | # rpm -qa kernel 53 | #+END_SRC 54 | 55 | 或者 56 | 57 | #+BEGIN_SRC shell 58 | # rpm -qa | grep -i kernel 59 | #+END_SRC 60 | 61 | 输出为: 62 | 63 | #+BEGIN_EXAMPLE 64 | kernel-tools-libs-3.10.0-123.9.3.el7.x86_64 65 | kernel-3.10.0-123.9.3.el7.x86_64 66 | kernel-3.10.0-123.el7.x86_64 67 | kernel-tools-3.10.0-123.9.3.el7.x86_64 68 | kernel-ml-4.4.5-1.el7.elrepo.x86_64 69 | #+END_EXAMPLE 70 | 71 | ** On Debian / Ubuntu / Linux Mint: 72 | 73 | 在 Debian, Ubuntu, Linux Mint, Elementary OS 等基于 DEB 的系统中查看已安装的Linux Kernels,在终端中运行下面命令: 74 | 75 | #+BEGIN_SRC shell 76 | $ dpkg --list | grep linux-image 77 | #+END_SRC 78 | 79 | 输出为: 80 | 81 | #+BEGIN_EXAMPLE 82 | rc linux-image-4.2.0-16-generic 4.2.0-16.19 amd64 Linux kernel image for version 4.2.0 on 64 bit x86 SMP 83 | ii linux-image-4.2.0-30-generic 4.2.0-30.35 amd64 Linux kernel image for version 4.2.0 on 64 bit x86 SMP 84 | ii linux-image-4.4.0-7-generic 4.4.0-7.22 amd64 Linux kernel image for version 4.4.0 on 64 bit x86 SMP 85 | ii linux-image-4.5.0-040500-generic 4.5.0-040500.201603140130 amd64 Linux kernel image for version 4.5.0 on 64 bit x86 SMP 86 | rc linux-image-extra-4.2.0-16-generic 4.2.0-16.19 amd64 Linux kernel extra modules for version 4.2.0 on 64 bit x86 SMP 87 | ii linux-image-extra-4.2.0-30-generic 4.2.0-30.35 amd64 Linux kernel extra modules for version 4.2.0 on 64 bit x86 SMP 88 | ii linux-image-extra-4.4.0-7-generic 4.4.0-7.22 amd64 Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP 89 | ii linux-image-generic 4.4.0.7.8 amd64 Generic Linux kernel image 90 | #+END_EXAMPLE 91 | 92 | ** On SUSE / openSUSE: 93 | 94 | 在SUSE 和 openSUSE 上, 运行命令: 95 | 96 | #+BEGIN_SRC shell 97 | # rpm -qa | grep -i kernel 98 | #+END_SRC 99 | 100 | 输出: 101 | 102 | #+BEGIN_EXAMPLE 103 | kernel-firmware-20160112git-120.1.noarch 104 | kernel-default-4.1.15-8.1.x86_64 105 | kernel-default-devel-4.5.0-1.1.g3c4edc5.x86_64 106 | kernel-devel-4.5.0-1.1.g3c4edc5.noarch 107 | kernel-default-4.5.0-1.1.g3c4edc5.x86_64 108 | kernel-macros-4.5.0-1.1.g3c4edc5.noarch 109 | #+END_EXAMPLE 110 | 111 | 就这些了. 你已经知道怎么找出Linux系统中已安装的那些Kernel了. 112 | 113 | 想查看当前正在运行的Kernel,则运行: 114 | 115 | #+BEGIN_SRC shell 116 | $ uname -r 117 | 4.13.8-1-ARCH 118 | #+END_SRC 119 | 120 | 或者 121 | 122 | #+BEGIN_SRC shell 123 | $ uname -mrs 124 | Linux 4.13.8-1-ARCH x86_64 125 | #+END_SRC 126 | -------------------------------------------------------------------------------- /system/How To Set or Change Hostname in CentOS 7.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何设置/更改CentOS7的主机名 2 | #+URL: https://www.tecmint.com/set-change-hostname-in-centos-7/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-12-21 四 17:05] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 计算机的主机名就是在网络中给计算机分配的一个唯一名字,为的是在网络中唯一标识这台计算机. 计算机主机名可以随你设置, 但应注意以下几点规则: 10 | 11 | + 主机名可以包含字母(从 a 到 z). 12 | + 主机名可以包含数字(从 0 到 9). 13 | + 主机名中可以包含横杠( – )作为特殊字符. 14 | + 主机名中可以包含点号这一特殊字符( . ). 15 | + 主机名必须以字母或数字开头和结尾. 16 | + 主机名是大小写敏感的. 17 | + 主机名长度在2到63个字符之间 18 | + 主机名应该具有描述性(方便地识别出出计算机在网络中哦该的作用, 位置, 地理区域等). 19 | 20 | 在 CentOS7 和 RHEL7 系统上可以通过在终端上输入下面命令来显示计算机名称. 其中的 -s 标志会显示计算机的短名称(只显示主机名称) 而 -f 标志会显示计算机在网络中的全限定域名(只有当计算机是域名的一部分并且设置了全限定域名). 21 | 22 | #+BEGIN_SRC shell 23 | # hostname 24 | # hostname -s 25 | # hostname -f 26 | #+END_SRC 27 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Check-Hostname-in-CentOS-7.png]] 28 | 29 | 你也可以使用 [[https://www.tecmint.com/13-basic-cat-command-examples-in-linux/][cat命令]] 查看 =/etc/hostname= 内容的方式来显示Linux系统主机名. 30 | 31 | #+BEGIN_SRC shell 32 | # cat /etc/hostname 33 | #+END_SRC 34 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Display-CentOS-7-Hostname.png]] 35 | 36 | 要更改或者设置 CentOS 7 的主机名, 使用下面的 =hostnamectl= 命令. 37 | 38 | #+BEGIN_SRC shell 39 | # hostnamectl set-hostname your-new-hostname 40 | #+END_SRC 41 | 42 | 除了 =hostname= 命令外,你也可以使用 =hostnamectl= 命令来显示Linux主机名. 43 | 44 | #+BEGIN_SRC shell 45 | # hostnamectl 46 | #+END_SRC 47 | 48 | 要使新主机名生效, 需要重启系统, 在CentOS7上可以使用下面命令来重启. 49 | 50 | #+BEGIN_SRC shell 51 | # init 6 52 | # systemctl reboot 53 | # shutdown -r 54 | #+END_SRC 55 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Set-CentOS-7-Hostname.png]] 56 | 57 | 另一个设置CentOS7主机名的方法是手工修改 =/etc/hostname= 文件并输入新主机名. 这种方法同样需要重启系统来应用新主机名. 58 | 59 | #+BEGIN_SRC shell 60 | # vi /etc/hostname 61 | #+END_SRC 62 | 63 | 第三种方法是使用 Linux sysctl 接口. 不过这种方法修改的主机名只是暂时性的. 64 | 65 | 这种临时性的主机名很特殊,它只由Liux内核初始化和维护,用于作为静态主机名之外的一个备用机器名称,并且会在系统重启后消失. 66 | 67 | #+BEGIN_SRC shell 68 | # sysctl kernel.hostname 69 | # sysctl kernel.hostname=new-hostname 70 | # sysctl -w kernel.hostname=new-hostname 71 | #+END_SRC 72 | 73 | 使用下面命令可以显示机器的临时主机名. 74 | 75 | #+BEGIN_SRC shell 76 | # sysctl kernel.hostname 77 | # hostnamectl 78 | #+END_SRC 79 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Change-CentOS-7-Hostname.png]] 80 | 81 | 最后, hostnamectl 命令可以通过这些选项来设置不同类型的主机名: =–pretty=, =–static=, 以及 =–transient=. 82 | 83 | 当然,还有很多其他的方法可以 [[https://www.tecmint.com/set-hostname-permanently-in-linux/][更改Linux主机名]], 比如使用 =nmtui= 命令或者手工编辑某些与Linux发行版相关联的配置文件(比如CentOS的/etc/sysconfig/network-scripts/ifcfg-ethX文件), 但是上面的这些方法则对所有Linux发行版都是有效的. 84 | -------------------------------------------------------------------------------- /system/How to Permanently Disable Swap in Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何永久禁用Linux交换空间 2 | #+URL: https://www.tecmint.com/disable-swap-partition-in-centos-ubuntu/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: system swap 5 | #+DATE: [2017-12-21 四 16:58] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 交换或者说交换空间指的是存放在磁盘分区上的物理内存页,也可以理解为当物理内存耗尽时用来扩展系统RAM内存的一种特殊的磁盘文件. 11 | 12 | 使用这种扩展RAM资源的方法, 当没有RAM可用时需要不活动的内存页频繁地导到交换空间去. 然而, 受限于普通硬盘的低速度, 交换空间的传输和访问速度要比RAM慢的多. 13 | 14 | 在一款搭配了SSD硬盘的新机器上保留一部分分区作为交换相对来说要比普通的HDD快的多,但与RAM比起来还是慢了很多. 有些人会建议交换空间的大小应该设置为机器内存的两倍大小. 然而在达到或者超过4GB内存的系统上,交换空间的大小设成2到4GB就够了. 15 | 16 | 若你的服务器上内存充足无需使用交换空间或者交换会极大地拖慢系统的性能, 那么你就应该考虑禁用交换空间了. 17 | 18 | 在开始真正禁用交换空间之前, 首先你需要查看一下内存的负载情况,然后查看交换空间存储在哪个分区上, 输入下面命令. 19 | 20 | #+BEGIN_SRC shell 21 | # free -h 22 | #+END_SRC 23 | 24 | 查看交换分区使用了多少空间. 若使用的空间为0B或者接近0字节, 则可以认为交换空间使用不那么频繁,可以安全地禁用掉. 25 | 26 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Check-Swap-Space.png]] 27 | 28 | 再然后, 输入下面的 =blkid= 命令, 注意 ~TYPE=”swap”~ 这一行表示的是交换分区, 显示结果如下. 29 | 30 | #+BEGIN_SRC shell 31 | # blkid 32 | #+END_SRC 33 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Check-Swap-Partition-Type.png]] 34 | 35 | 再用下面的 =lsblk= 命令搜索并确认交换分区([SWAP]). 36 | 37 | #+BEGIN_SRC shell 38 | # lsblk 39 | #+END_SRC 40 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Search-Confirm-Swap-Partition.png]] 41 | 42 | 确认了交换分区/文件后, 执行下面命令来禁用交换空间. 43 | 44 | #+BEGIN_SRC shell 45 | # swapoff /dev/mapper/centos-swap 46 | #+END_SRC 47 | 48 | 或者禁用 =/proc/swaps= 中的所有交换空间 49 | 50 | #+BEGIN_SRC shell 51 | # swapoff -a 52 | #+END_SRC 53 | 54 | 运行 [[https://www.tecmint.com/check-memory-usage-in-linux/][free命令]] 确认交换空间被禁用了. 55 | 56 | #+BEGIN_SRC shell 57 | # free -h 58 | #+END_SRC 59 | 60 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Disable-Swap-Partition.png]] 61 | 62 | 为了永久禁用交换空间, 打开 =/etc/fstab= 文件, 搜索 swap 行并在前面增加 # (井号) 来注释掉整个行, 如下图所示. 63 | 64 | #+BEGIN_SRC shell 65 | # vi /etc/fstab 66 | #+END_SRC 67 | 68 | [[https://www.tecmint.com/wp-content/uploads/2017/12/Disable-Swap-Partition-Permanently.png]] 69 | 70 | 之后, 重启系统以便使新的交换设置生效,或者直接执行 =mount -a= 命令也行. 71 | 72 | #+BEGIN_SRC shell 73 | # mount -a 74 | #+END_SRC 75 | 76 | 系统重启后, 输入上面提到e的那些命令来看交换空间是否已经永久地被禁用了. 77 | 78 | #+BEGIN_SRC shell 79 | # free -h 80 | # blkid 81 | # lsblk 82 | #+END_SRC 83 | -------------------------------------------------------------------------------- /system/How to Set Up Easy Remote Desktop Access in linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何设置Linux版的远程桌面连接 2 | #+URL: https://www.linux.com/learn/intro-to-linux/2017/11/how-set-easy-remote-desktop-access-linux 3 | #+AUTHOR: lujun9972 4 | #+TAGS: Remote Desktop 5 | #+DATE: [2017-11-13 一 12:43] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | Linux是一个非常灵活的操作系统. 它提供了多种方法来完成一个任务. 比如当你需要在本机显示远程桌面时,你可以通过RDP, VNC, SSH, 还有很多第三方的解决方案来完成. 11 | 一般来说, 你的桌面系统决定了你会采取的方案, 不过有一些方案确实要好的多. 12 | 一旦你理解了现代的桌面系统为此做了多少优化, 你会发现远程管理Linux桌面系统和带GUI的服务器其实十分简单. 13 | 14 | 刚才我说过, 你要如何远程桌面取决于你用的是哪个Linux发行版. 本文我将会讲解如何在 在Ubuntu Desktop 18.04 上登陆 Fedora 26的远程桌面,以及如何在Fedora 26 上登陆 Kubuntu的共享远程桌面. 15 | 有一个大问题就是,有些桌面系统对该技术支持不够好. 比如, =Wayland= 就不支持 VNC. =Elementary OS 桌面系统= 也是一样. 16 | 因此,我这里只会演示在Ubuntu 18.04如何连接到 Fedora 26,以及如何从 Fedora 26 上连接到 Kubuntu 17.10. 17 | 我会用到的工具包括 =remmina=, =krfb=, 以及 =GNOME= 内建的一些工具. 18 | 19 | * 从 Ubuntu 连接到 Fedora 20 | 21 | Fedora 26的最终发行版, 默认使用的是 GNOME 桌面系统, 其设置远程连接的方法十分直接(因为所有东西都默认安装好了). 22 | 你要做的第一件事就是启用 =sharing= 功能. 打开 =GNOME Dash= 然后输入 =sharing=, 就会看到有个 =Sharing= 选项, 点击就能打开这个工具. 23 | 在打开的窗口中将开关点到ON的位置,然后点击 =Screen Sharing=. 在打开的窗口中(图 1), 选中 =Allow connections to control the screen=. 24 | 25 | [[https://www.linux.com/files/images/sharing1jpg]] 26 | 27 | 图 1: Enable Sharing in Fedora 26. 28 | [[https://www.linux.com/licenses/category/used-permission][Used with permission]] 29 | 30 | 你也可以选中 =access options= 中的 =New connections must ask for access and requiring a password=. 31 | 我十分推荐选上该选项,选上它对你几乎没有影响. 而之后, 当有人想连接上你的远程桌面时,只有认证后才能建立连接. 32 | 然后关闭窗口. 33 | 34 | 初始条件下, Fedora防火墙开放了所需的端口, 远程链接直接就能用了. 如果有问题,请回到 =GNOME Dash= 然后输入 =firewall=. 35 | 就会出现一个防火墙图标, 点击它, 然后输入管理员密码. 在弹出的窗口中点击 =Services= 然后向下滚动直到看见 =vnc-server= 为止 (图 2). 36 | 37 | [[https://www.linux.com/files/images/sharing2jpg]] 38 | 39 | 图 2: Enabling the necessary VNC ports through the firewall. 40 | [[https://www.linux.com/licenses/category/used-permission][Used with permission]] 41 | 42 | 点击启用 =vnc-server= 然后再次输入管理员密码. 现在允许连接 VNC 端口了. 43 | 44 | 下面来到 Ubuntu 机器. 我们需要安装 =remmina= 应用(这是一款不错的远程客户端应用). 45 | 由于标准仓库中的版本有一些bug, 我们可以通过以下步骤安装最新版的应用: 46 | 47 | 1. 使用命令 =sudo apt-add-repository ppa:remmina-ppa-team/remmina-next= 添加仓库 48 | 49 | 2. 使用命令 =sudo apt update= 更新apt源 50 | 51 | 3. 使用命令 =sudo apt-get install remmina remmina-plugin-rdp remmina-plugin-gnome libfreerdp-plugins-standard= 安装软件 52 | 53 | 在桌面菜单输入 =remmina= 就能打新安装的软件了. 在地址窗口中(图 3), 从下拉框中选择 =VNC=, 输入Fedora机器的IP地址,然后按下回车. 54 | 55 | [[https://www.linux.com/files/images/sharing3jpg]] 56 | 57 | 图 3: The remmina main window. 58 | [[https://www.linux.com/licenses/category/used-permission][Used with permission]] 59 | 60 | 按下回车后, Fedora 桌面系统就会弹出通知. 点击 =Accept= 后(图 4)就会创建链接,Ubuntu机器上的人就可以控制你的fedora桌面了. 61 | 62 | [[https://www.linux.com/files/images/sharing4jpg]] 63 | 64 | 图 4: Accepting a request to share out the desktop on Fedora 26. 65 | [[https://www.linux.com/licenses/category/used-permission][Used with permission]] 66 | 67 | * 从 Fedora 连接 Kubuntu 68 | 69 | 现在让我们试试从 Fedora 连接到 Kubuntu. 这里我们还是使用remmina作为客户端, 因此我们先要在 Fedora 上安装remmina. 70 | 打开终端并输入命令 =sudo dnf install remmina= 安装即可. 71 | 72 | 安装好remmina后, 就的在 Kubuntu 桌面系统上安装必须的软件了. 这个要安装的软件就是 =krfb=,使用命令 =sudo apt install krfb= 来安装. 73 | 安装好krfb后, 就能在 =KDE= 菜单中输入 =krfb=. 点击筛选出的结果后在打开的窗口中选中 =Enable Desktop Sharing= (图 5). 74 | 75 | [[https://www.linux.com/files/images/sharing5jpg]] 76 | 77 | 图 5: Enabling desktop sharing on Kubuntu, via krfb. 78 | [[https://www.linux.com/licenses/category/used-permission][Used with permission]] 79 | 80 | =krfb= 还会告诉你客户端连接的IP地址和登陆密码. 如果你不喜欢这个密码,也可以点击更改按钮更改该密码. 81 | 82 | 到了这一步, 你的 KDE 桌面已经可以与他人共享了. 回到 Fedora 机器, 打开 GNOME Dash, 输入 remmina 并点击图标打开. 83 | 在下拉框中选择 =VNC=, 输入 Kubuntu 机器上的IP地址然后按下回车. krfb会提示你输入密码. 输入krfb的密码后点击 =OK=. 84 | 在 Kubuntu 桌面上会提示是否接受该连接. 接受后, Fedora 上就会显示出 Kubuntu 桌面来了. 你可以做事了. 85 | 86 | * Simple remote desktop connection 87 | 88 | 当然, 除此之外还有很多其他途径可以创建链接(而且有些桌面系统可能会要比这里说的复杂一些). 89 | 好在现代Linux的桌面发布版都包含了创建远程连接的所有必须的东西,这使得创建远程连接变得前所未有的简单. 90 | 如果你所选择的桌面系统并没有文中的这些工具, 你也可以从众多的 VNC 服务端中挑选其他的替代品(比如[[https://wiki.gnome.org/Projects/Vino][vino]], [[http://tigervnc.org/][TigerVNC]], 和 [[https://www.tightvnc.com/][tightvnc]]). 91 | 使用这些标准的 VNC 服务用起来可能没那么易用,但是一旦配置完成,也是同样可靠的. 92 | -------------------------------------------------------------------------------- /system/How to replicate SELinux policies among Linux machines.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何在Linux机器之间复制SELinux策略 2 | #+URL: http://linuxtechlab.com/replicate-selinux-policies-among-linux-machines/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: system SELinux 5 | #+DATE: [2017-11-06 一 16:56] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 11 | SELinux 或者说 Security Enhaced Linux, 是一套运行在用户空间下的内核修改工具, 它是一种名为MAC(Mandatory access controls)的访问策略的具体实现. 12 | 它约束了服务的特权,因此能够消除由于未检查特权导致的问题. 13 | 14 | SELinux中并没有root用户和超级用户的概念,由于不依赖于setuid/setgid,因此没有Linux安全机制的那些缺陷. 15 | 我在文章 [[http://linuxtechlab.com/beginners-guide-to-selinux/][Beginner’s guide to SELinux]] 中有介绍过SELinux. 想深入了解SELinux的话可以查看那篇文章. 16 | 17 | 本文中, 我们会讨论一下如何将一个系统中的SELinux策略复制到另一个系统. 不过在此之前,让我们还有一些事要做, 18 | 19 | (Also Read:[[http://linuxtechlab.com/linux-disk-cloning-using-dd-cat-commands/][Cloning Disks using dd & cat commands for Linux systems)]] 20 | 21 | * 先决条件 22 | 23 | 为了复制SELinux策略, 我们需要 ‘semange’ 命令. 在CentOS系统中运行以下命令以确定 ‘semange’ 是否已安装. 24 | #+BEGIN_SRC shell 25 | $ semanage –help 26 | #+END_SRC 27 | 28 | 若出现下面错误,则表示尚未安装, 29 | 30 | #+BEGIN_EXAMPLE 31 | -bash: semanage: command not found 32 | #+END_EXAMPLE 33 | 34 | 安装 ‘semanage’ 命令需要安装下面package, 35 | 36 | #+BEGIN_SRC shell 37 | $ sudo yum install policycoreutils-python 38 | #+END_SRC 39 | 40 | 该命令就会安装 ‘semange’ 命令及其依赖. 41 | 42 | * 复制SELinux策略 43 | 44 | 首先将SELinux的所有配置存入文件中, 45 | 46 | #+BEGIN_SRC shell 47 | $ sudo semanage -o /root/local.selinux 48 | #+END_SRC 49 | 50 | 然后将该文件传送到要复制SELinux策略的机器上 51 | 52 | #+BEGIN_SRC shell 53 | $ scp -rv /root/local.selinux root@192.168.1.100:/root 54 | #+END_SRC 55 | 56 | 然后就需要恢复该文件了. 为此我们需要ssh到第二台机器上, 57 | 58 | #+BEGIN_SRC shell 59 | $ ssh root@192.168.1.100 60 | #+END_SRC 61 | 62 | 然后运行下面命令恢复, 63 | 64 | #+BEGIN_SRC shell 65 | # semanage -i /root/local.selinux 66 | #+END_SRC 67 | 68 | 行了, 这就将第一台机器上的SELinux策略恢复到第二台机器上了. 69 | 70 | 注意:- 本文适用于CentOS6, 但CentOS5无法将SELinux配置导出到文件中. 71 | 72 | 另外,我们也需要确定目标机器上的SELinux版本不能低于源机器上的版本,因为 SELinux并不具有向后兼容性. 73 | -------------------------------------------------------------------------------- /system/How to use cron in Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何使用Linux中的cron 2 | #+URL: https://opensource.com/article/17/11/how-use-cron-linux 3 | #+AUTHOR: lujun9972 4 | #+TAGS: crontab 5 | #+DATE: [2017-11-07 二 09:29] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 作为一名系统管理员, 面临的一个挑战就是需要在睡觉的点去跑任务. 11 | 比如,有些任务(包括周期性的任务)需要在大半夜或周末运行, 因为这个点没什么人会去使用计算机资源. 12 | 我不想在非工作时间浪费时间去运行那些命令和脚本. 我也不想大半夜的起来去做悲愤和升级. 13 | 14 | 我使用两个工具来帮助我在预先定义好的时间运行命令,程序和任务. [[https://en.wikipedia.org/wiki/Cron][cron]] 和 at 服务允许系统管理员安排好在指定的时间要运行的任务. 15 | at u服务指定单次的任务. 而 cron 服务可以设定重复性的任务, 比如日任务, 周任务, 月任务. 16 | 17 | 本文, 我会介绍一下 cron 服务,以及它的使用方法. 18 | 19 | * Common (and uncommon) cron uses 20 | 21 | 我使用 cron 服务来规划琐事, 比如每天凌晨2点要做的日常备份. 我也会用它来做一些不那么琐碎的事情. 22 | 23 | + 我多台电脑的系统时间(也就是操作系统的时间)使用 Network Time Protocol (NTP)来同步时间. 24 | 然而 NTP 只会设置系统时间,不会设置硬件时间,这会造成时间的漂移. 因此我使用cron来根据系统时间设置硬件时间. 25 | + 我每个月月初都会运行一个Bash程序来在每台机上创建新的"message of the day" (MOTD). 26 | 这条消息中包含诸如当前磁盘利用率之类的信息. 27 | + 很多系统进程和系统服务, 比如 [[https://sourceforge.net/projects/logwatch/files/][Logwatch]], [[https://github.com/logrotate/logrotate][logrotate]], 以及 [[http://rkhunter.sourceforge.net/][Rootkit Hunter]], 都是使用cron服务来规划任务,每天运行程序的. 28 | 29 | crond守护进程就是提供cron功能的后台服务进程. 30 | 31 | cron 服务会检查 =/var/spool/cron= 和 =/etc/cron.d= 目录中的文件,以及 =/etc/anacrontab= 这个文件. 32 | 这些文件的内容定义了不同间隔时间内要运行的cron jobs. =/var/spool/cron= 中存放的是个人用户定义的cron job文件, 而系统服务和应用产生的cron job文件存放在 =/etc/cron.d= 目录中. 33 | 而 =/etc/anacrontab= 是一个很特别的存在,后面再说. 34 | 35 | * Using crontab 36 | 37 | cron会运行cron table (crontab)中定义的那些命令. 每个用户, 包括root, 都有一个cron文件. 38 | 这些文件默认并不存在, 但是可以使用 =crontab -e= 命令来创建或修改,创建的文件存放在 =/var/spool/cron= 目录中. 39 | 我强烈建议不要用标准编辑器(比如Vi, Vim, Emacs, Nano, 或者其他一些编辑器). 40 | crontab 不仅允许你编辑要定时运行的命令, 还会在你保存退出编辑器后重启crond守护进程. 41 | crontab命令使用vi作为默认编辑器,因为几乎所有的linux系统都装有Vi. 42 | 43 | 新的 cron 文件是空的, 必须从头添加命令. 我将下面job定义的示例添加到cron文件中, 用来做个参考, 这样方便知道命令各部分的意义. 44 | 你也可以这样做. 45 | 46 | #+BEGIN_EXAMPLE 47 | # crontab -e 48 | SHELL=/bin/bash 49 | MAILTO=root@example.com 50 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 51 | # For details see man 4 crontabs 52 | # Example of job definition: 53 | # .---------------- minute (0 - 59) 54 | # | .------------- hour (0 - 23) 55 | # | | .---------- day of month (1 - 31) 56 | # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... 57 | # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat 58 | # | | | | | 59 | # * * * * * user-name command to be executed 60 | # backup using the rsbu program to the internal 4TB HDD and then 4TB external 61 | 01 01 * * * /usr/local/bin/rsbu -vbd1 ; /usr/local/bin/rsbu -vbd2 62 | # Set the hardware clock to keep it in sync with the more accurate system clock 63 | 03 05 * * * /sbin/hwclock --systohc 64 | # Perform monthly updates on the first of the month 65 | # 25 04 1 * * /usr/bin/dnf -y update 66 | ^The crontab command is used to view or edit the cron files. 67 | #+END_EXAMPLE 68 | 69 | 代码前三行设置默认的环境. 设置环境是必须的,因此 cron 本身并不提供任何环境. 70 | =SHELL= 变量指定了命令执行时使用的shell. 本例中指定为 Bash shell. 71 | =MAILTO= 变量设置了cron job结果发送到哪个邮件地址. 这些邮件的内容包括cron job的状态(backups, updates等)以及程序的输出. 72 | 第三行设置了环境的 =PATH= 变量. 不过虽然有在这设置路径,我依然总是为每个执行文件指明完整的路径. 73 | 74 | 上例中还有很多注释行,详细说明了定义cron job的语法. 我会一一讲解这些命令,然后再向你展示一些cron文件中的高级功能. 75 | 76 | #+BEGIN_EXAMPLE 77 | 01 01 * * * /usr/local/bin/rsbu -vbd1 ; /usr/local/bin/rsbu -vbd2 78 | ^这行运行脚本进行系统备份. 79 | #+END_EXAMPLE 80 | 81 | 该行u运行我自己写的一个 Bash shell 脚本, rsbuthat, 来做系统备份. 该工作开始于每天的 1:01 a.m. (01 01). 82 | 时间指示部分的第3,4,5位的星号(*)与文件通配符类似,表示每天,每月,每周; 该行会备份两次; 一份备份到内置硬盘,一份备份到外置U盘,然后放到安全的地方保存. 83 | 84 | 下面命令根据系统时钟设置硬件时钟. 每天的 5:03 a.m. (03 05) 运行. 85 | 86 | #+BEGIN_EXAMPLE 87 | 03 05 * * * /sbin/hwclock --systohc 88 | ^该行根据系统时钟设置硬件时钟. 89 | #+END_EXAMPLE 90 | 91 | 我曾经使用第三行也是最后一个 cron job (现在已经注释掉了) 来在每月一号的04:25 a.m来做一次dnf/yum升级, 不过我把他注释掉了不再运行. 92 | 93 | #+BEGIN_EXAMPLE 94 | # 25 04 1 * * /usr/bin/dnf -y update 95 | ^This line used to perform a monthly update, but I've commented it out. 96 | #+END_EXAMPLE 97 | 98 | * Other scheduling tricks 99 | 100 | 现在让我们尝试一些更有趣的事. 假设你需要在每个周二的3 p.m运行某个特定的任务: 101 | 102 | #+BEGIN_EXAMPLE 103 | 00 15 * * Thu /usr/local/bin/mycronjob.sh 104 | ^该行在每周二下午3点运行 mycronjob.sh 105 | #+END_EXAMPLE 106 | 107 | 或者你需要在季末运行一份季度报表. 而cron服务没有办法直接表示"月份的最后一天",因此你需要使用后一个月的第一天来代替. (这里假设job运行时,报表的数据已经准备好了) 108 | 109 | #+BEGIN_EXAMPLE 110 | 02 03 1 1,4,7,10 * /usr/local/bin/reports.sh 111 | ^This cron job runs quarterly reports on the first day of the month after a quarter ends. 112 | #+END_EXAMPLE 113 | 114 | 下面一行会在9:01 a.m到5:01 p.m之间每小时过1分钟的时候运行命令. 115 | 116 | #+BEGIN_EXAMPLE 117 | 01 09-17 * * * /usr/local/bin/hourlyreminder.sh 118 | ^Sometimes you want to run jobs at regular times during normal business hours. 119 | #+END_EXAMPLE 120 | 121 | 我遇到过一种情况每隔2/3/4个小时运行一次命令. 这可以通过在小时位置的值后面除于一个特定的间隔来实现, 例如 =*/3= 表示每三小时, =6-18/3= 表示在6 a.m 到 6 p.m 这个时间段内的没三个小时运行一次. 122 | 其他的间隔时间也类似; 例如, 分种位置的 =*/15= 表示 "每15分钟运行一次" 123 | 124 | #+BEGIN_EXAMPLE 125 | ,*/5 08-18/2 * * * /usr/local/bin/mycronjob.sh 126 | ^This cron job runs every five minutes during every hour between 8 a.m. and 5:58 p.m. 127 | #+END_EXAMPLE 128 | 129 | 要注意一件事: job只会在除法表达式的结果余数为0的时候运行. 这也是为什么本例中job只会在8 a.m到6 p.m之间每个偶数小时内,每5分钟运行一次(08:05, 08:10, 08:15, 以此类推). 130 | 比如,该job就不会在 9 p.m 到 9:59 a.m之间运行. 131 | 132 | 我相信你应该能举一反三. 133 | 134 | * Limiting cron access 135 | 136 | 允许cron的普通用户可能会犯错误,比如,可能会导致系统资源(内存,CPU之类)浪费. 137 | 为了防止滥用,系统管理员可以限制哪些用户可以使用cron,方法是 创建一个 =/etc/cron.allow= 文件,里面包含所有允许创建cron job的用户. 138 | 不过root不能被禁止. 139 | 140 | 既然禁止了某些非root用户创建cron job的权限,那么root就有必要帮助他们在root的crontab中添加cron job. 141 | "等会!" 你可能会大吃一惊. "这些job都以root用户来运行吗?" 当然不会. 本文第一个例子的注释中的用户名域可以用来指定运行job的用户ID. 142 | 这就预防了以root用户来运行那些非root用户的job. 下面例子中定义了一个job,它以"student"用户来运行: 143 | 144 | #+BEGIN_EXAMPLE 145 | 04 07 * * * student /usr/local/bin/mycronjob.sh 146 | #+END_EXAMPLE 147 | 148 | 如果没有指定用户,那么job以crontab文件所有者的身份运行,本例中就是root. 149 | 150 | * cron.d 151 | 152 | 有些应用,例如 [[http://spamassassin.apache.org/][SpamAssassin]] 和 [[https://github.com/sysstat/sysstat][sysstat]] 会在安装时生成一些cron文件到目录 =/etc/cron.d= 中. 153 | 由于并不存在名为 =spamassassin= 和 =sysstat= 的用户,因此这些程序只能在 =/etc/cron.d= 中存放cron文件. 154 | 155 | 下面是 =/etc/cron.d/sysstat= 文件的内容,它包含了系统活动报告(SAR)相关的一些cron jobs. 这些cron文件的格式与用户cron文件一样. 156 | 157 | #+BEGIN_EXAMPLE 158 | # Run system activity accounting tool every 10 minutes 159 | ,*/10 * * * * root /usr/lib64/sa/sa1 1 1 160 | # Generate a daily summary of process accounting at 23:53 161 | 53 23 * * * root /usr/lib64/sa/sa2 -A 162 | ^The sysstat package installs the /etc/cron.d/sysstat cron file to run programs for SAR. 163 | #+END_EXAMPLE 164 | 165 | 这个sysstat cron 文件定义了两个任务. 第一行每10分钟运行一次 =sa1= 程序来收集存储在 =/var/log/sa= 目录下二进制文件中的数据. 166 | 然后每晚的23:53,运行 =sa2= 程序来生成每日汇总. 167 | 168 | * Scheduling tips 169 | 170 | 我在crontab文件中设置的有些时间看起来似乎蛮随机的—某种程度上来说也确实如此. 171 | 分配cron job是一件颇具挑战性的事情,尤其当有大量job需要分配时. 172 | 我在自己电脑上分配的任务并不多,比我在生产和实验环境中要简单一些. 173 | 174 | 我管理过一个系统,每天晚上有一打的cron job要运行,还有3,4个job会在周末和月首运行. 这真是个挑战, 如果有太多的job在同一时间运行的话—尤其做备份和编译时—系统内存将会耗尽并且填充完所有的交换文件,这会导致系统抖动,影响性能, 从而导致一事无成. 175 | 我们后来增加了内存,改进了任务规划. 还移除了一个糟糕性能需要耗费巨量内存的任务. 176 | 177 | crond服务假定宿主电脑是一直开机的. 也就是说,如果电脑在cron job本该运行的时刻关机了一段时间, 那么这些job只能在下次规划的时间才能再次运行. 178 | 如果这些cron job很关键的话,可能会引起一些问题. 幸运的是我们还有其他工具能让我们在特定间隔后运行jobs: anacron. 179 | 180 | * anacron 181 | 182 | [[https://en.wikipedia.org/wiki/Anacron][anacron]] 的功能与 =crond= 一样, 但是它可以运行那些被跳过的jobs(比如电脑被关机或者上个周期因为某些原因无法运行job). 183 | 这对笔记本电脑以及其他经常会关机或进入休眠模式的电脑来说尤其有用. 184 | 185 | 电脑开机启动后, anacron会检查配置的任务在上轮规划中是否错过了运行. 如果是,那么这些任务会被立即运行, 但只会运行一次(不过实际错过了多少轮). 186 | 举个例子, 如果有个每周任务由于系统在你放假期间关机了导致三周都没有运行, 当你开机后,该任务会且仅会运行一次,而不是三次. 187 | 188 | anacron 程序还提供了其他定义常规任务的方法. 只需要将你要运行的脚本根据间隔时间的需要放到 =/etc/cron.[hourly|daily|weekly|monthly]= 目录中即可. 189 | 它的工作原理是什么? 过程要比看起来简单的多. 190 | 191 | 1. crond服务运行在 =/etc/cron.d/0hourly= 中指定的job. 192 | 193 | #+BEGIN_EXAMPLE 194 | # Run the hourly jobs 195 | SHELL=/bin/bash 196 | PATH=/sbin:/bin:/usr/sbin:/usr/bin 197 | MAILTO=root 198 | 01 * * * * root run-parts /etc/cron.hourly 199 | ^The contents of /etc/cron.d/0hourly cause the shell scripts located in /etc/cron.hourly to run. 200 | #+END_EXAMPLE 201 | 202 | 2. /etc/cron.d/0hourly中定义的cron job每个小时运行一次 =run-parts= 程序. 203 | 3. =run-parts= 程序运行 =/etc/cron.hourly= 目录中的所有脚本. 204 | 4. =/etc/cron.hourly= 目录中包含一个 =0anacron= 脚本, 该脚本使用 =/etdc/anacrontab= 配置文件运行 anacron 程序,配置文件内容为 205 | 206 | #+BEGIN_EXAMPLE 207 | # /etc/anacrontab: configuration file for anacron 208 | # See anacron(8) and anacrontab(5) for details. 209 | SHELL=/bin/sh 210 | PATH=/sbin:/bin:/usr/sbin:/usr/bin 211 | MAILTO=root 212 | # the maximal random delay added to the base delay of the jobs 213 | RANDOM_DELAY=45 214 | # the jobs will be started during the following hours only 215 | START_HOURS_RANGE=3-22 216 | #period in days delay in minutes job-identifier command 217 | 1 5 cron.daily nice run-parts /etc/cron.daily 218 | 7 25 cron.weekly nice run-parts /etc/cron.weekly 219 | @monthly 45 cron.monthly nice run-parts /etc/cron.monthly 220 | ^The contents of /etc/anacrontab file runs the executable files in the cron.[daily|weekly|monthly] directories at the appropriate times. 221 | #+END_EXAMPLE 222 | 223 | 224 | 5. anacron程序每天运行一次 =/etc/cron.daily= 中的程序; 每周运行一次 =/etc/cron.weekly= 中的程序, 每月运行一次 =cron.monthly= 中的程序. 225 | 注意到,每行的延迟时间使得这些任务之间不会相互重叠. 226 | 227 | 我一般不把所有的Bash程序放到 =cron.X= 目录中,而是放到 =/usr/local/bin= 目录中, 这使得我可以方便地在命令行运行这些脚本. 228 | 然后我再创建一个符号链接到合适的 cron 目录中(比如/etc/cron.daily中). 229 | 230 | anacron 程序并不是设计来让程序在特定时间运行的. 相反, 它适用于从特定时间(比如每天3 a.m,每周日,每月的第一天)开始每隔一定时间运行一次程序.(参见上例中START_HOURS_RANGE这一行), on Sunday (to begin the week), 231 | 而且任何循环有缺失, anacron都会立即运行一次缺失的任务. 232 | 233 | * More on setting limits 234 | 235 | 我使用上述这些方法来分配在我电脑上运行的任务. 所有这些任务都需要root权限. 236 | 依我的经验来说,普通用户很少有需要cron job的时候. 其中一个可能的例子是某个开发者需要cron job来自动开始每日编译. 237 | 238 | 限制非root用户使用cron功能很重要. 然而, 若真的有用户需要设置在预定的时间运行任务, cron能让他们实现愿望. 239 | 很多用户不知道如何合理的配置这些任务从而引起差错. 有些差错可能无伤大雅,但大多数差错会引起麻烦. 240 | 241 | 通过让用户与系统管理员沟通, 可以减少 cron job 对其他用户和其他系统功能的破坏. 242 | 243 | 也可以限制单个的用户和组使用的总资源数,但这就另一篇文章的事了,我们以后再说. 244 | 245 | 想了解更多, 可以查看 [[http://man7.org/linux/man-pages/man8/cron.8.html][cron]], [[http://man7.org/linux/man-pages/man5/crontab.5.html][crontab]], [[http://man7.org/linux/man-pages/man8/anacron.8.html][anacron]], [[http://man7.org/linux/man-pages/man5/anacrontab.5.html][anacrontab]], 以及 [[http://manpages.ubuntu.com/manpages/zesty/man8/run-parts.8.html][run-parts]] 的man帮助,其中很好的描述了cron系统工作的原理和相关信息. 246 | -------------------------------------------------------------------------------- /system/The Pinky Finger habits Of Experienced Sysadmins.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 系统管理老手教你小指的妙用 2 | #+URL: ttps://bash-prompt.net/guides/habits-sysadmin/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: common bash bash-completion 5 | #+DATE: [2017-11-07 二 10:21] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 在我的系统管理员生涯中, 凭借着丰富的经验,我总结出了一些在命令行下提高效率的习惯. 11 | 12 | 其中两个习惯跟我的小指头有关,因为两个小指头一个按 [ENTER] 一个按 [TAB] 键. 13 | 14 | * Hit the enter key between every command 15 | 16 | 这个习惯很简单, 只是在命令与命令之间多按几次 [ENTER] 而已. 为什么要这样呢?看看下面两个终端大的输出就能理解了,这两个终端输入的命令都是一样的: 17 | 18 | 首先是没有 [ENTER] 的输出: 19 | 20 | #+BEGIN_EXAMPLE 21 | root@server:~# apt-get update 22 | Hit:1 http://mirror.memset.com/ubuntu xenial InRelease 23 | Get:2 http://mirror.memset.com/ubuntu xenial-updates InRelease [102 kB] 24 | Get:3 http://mirror.memset.com/ubuntu xenial-security InRelease [102 kB] 25 | Fetched 204 kB in 0s (433 kB/s) 26 | Reading package lists... Done 27 | root@server:~# apt-get upgrade 28 | Reading package lists... Done 29 | Building dependency tree 30 | Reading state information... Done 31 | Calculating upgrade... Done 32 | The following packages have been kept back: 33 | libgl1-mesa-dri sysstat 34 | 0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded. 35 | root@server:~# apt-get install openvpn 36 | Reading package lists... Done 37 | Building dependency tree 38 | Reading state information... Done 39 | The following packages were automatically installed and are no longer required: 40 | apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgd3 libjbig0 41 | libjpeg-turbo8 libjpeg8 liblua5.1-0 libtiff5 libvpx3 libxslt1.1 nginx-common nginx-core 42 | Use 'apt autoremove' to remove them. 43 | Suggested packages: 44 | easy-rsa 45 | The following NEW packages will be installed: 46 | openvpn 47 | 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded. 48 | Need to get 0 B/421 kB of archives. 49 | After this operation, 1026 kB of additional disk space will be used. 50 | Preconfiguring packages ... 51 | Selecting previously unselected package openvpn. 52 | (Reading database ... 22196 files and directories currently installed.) 53 | Preparing to unpack .../openvpn_2.3.10-1ubuntu2.1_amd64.deb ... 54 | Unpacking openvpn (2.3.10-1ubuntu2.1) ... 55 | Processing triggers for libc-bin (2.23-0ubuntu9) ... 56 | Processing triggers for systemd (229-4ubuntu21) ... 57 | Processing triggers for ureadahead (0.100.0-19) ... 58 | Processing triggers for man-db (2.7.5-1) ... 59 | Setting up openvpn (2.3.10-1ubuntu2.1) ... 60 | Processing triggers for libc-bin (2.23-0ubuntu9) ... 61 | root@server:~# cd /etc/openvpn/ 62 | root@server:/etc/openvpn# ls 63 | update-resolv-conf 64 | #+END_EXAMPLE 65 | 66 | 然后是, 带有 [ENTER] 的输出: 67 | 68 | #+BEGIN_EXAMPLE 69 | root@server:~# 70 | root@server:~# 71 | root@server:~# apt-get update 72 | Hit:1 http://mirror.memset.com/ubuntu xenial InRelease 73 | Get:2 http://mirror.memset.com/ubuntu xenial-updates InRelease [102 kB] 74 | Get:3 http://mirror.memset.com/ubuntu xenial-security InRelease [102 kB] 75 | Fetched 204 kB in 0s (433 kB/s) 76 | Reading package lists... Done 77 | root@server:~# 78 | root@server:~# 79 | root@server:~# 80 | root@server:~# apt-get upgrade 81 | Reading package lists... Done 82 | Building dependency tree 83 | Reading state information... Done 84 | Calculating upgrade... Done 85 | The following packages have been kept back: 86 | libgl1-mesa-dri sysstat 87 | 0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded. 88 | root@server:~# 89 | root@server:~# 90 | root@server:~# 91 | root@server:~# 92 | root@server:~# apt-get install openvpn 93 | Reading package lists... Done 94 | Building dependency tree 95 | Reading state information... Done 96 | The following packages were automatically installed and are no longer required: 97 | apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgd3 libjbig0 98 | libjpeg-turbo8 libjpeg8 liblua5.1-0 libtiff5 libvpx3 libxslt1.1 nginx-common nginx-core 99 | Use 'apt autoremove' to remove them. 100 | Suggested packages: 101 | easy-rsa 102 | The following NEW packages will be installed: 103 | openvpn 104 | 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded. 105 | Need to get 0 B/421 kB of archives. 106 | After this operation, 1026 kB of additional disk space will be used. 107 | Preconfiguring packages ... 108 | Selecting previously unselected package openvpn. 109 | (Reading database ... 22196 files and directories currently installed.) 110 | Preparing to unpack .../openvpn_2.3.10-1ubuntu2.1_amd64.deb ... 111 | Unpacking openvpn (2.3.10-1ubuntu2.1) ... 112 | Processing triggers for libc-bin (2.23-0ubuntu9) ... 113 | Processing triggers for systemd (229-4ubuntu21) ... 114 | Processing triggers for ureadahead (0.100.0-19) ... 115 | Processing triggers for man-db (2.7.5-1) ... 116 | Setting up openvpn (2.3.10-1ubuntu2.1) ... 117 | Processing triggers for libc-bin (2.23-0ubuntu9) ... 118 | root@server:~# 119 | root@server:~# 120 | root@server:~# cd /etc/openvpn/ 121 | root@server:/etc/openvpn# 122 | root@server:/etc/openvpn# 123 | root@server:/etc/openvpn# 124 | root@server:/etc/openvpn# ls 125 | update-resolv-conf 126 | #+END_EXAMPLE 127 | 128 | 很明显,使用空行分隔命令要容易阅读的多. 129 | 同样的, 当输出写满终端屏幕后,请不要用 =clear= 命令清理掉这些内容, 你应该让自己习惯在终端底部工作. 130 | 131 | 保留有输入过的命令及其输出和错误信息是一笔无可估量的财富,因为你可能会需要时常地返回来看之前做过了什么. 132 | 133 | 一旦你开始敲击回车,很快你就会在工作时不自觉地这么做. 134 | 135 | * Use Bash Complete For All The Things 136 | 137 | Bash complete 是一个帮你补全命令名称,文件路径,文件名称以及命令选项的函数. 138 | 139 | 你应该尽可能的用它,它是命令行中节省时间的最大助力. 它不仅减少你打字的个数,而且减少了输错的可能性. 140 | 141 | 下面的例子假设你安装了 =bash-completion=: 142 | 143 | ** Path completion 144 | 145 | 每个Linux系统管理员应该都听过并且使用过tab补全,但是大多数的管理员并没有发挥它的价值. 146 | 如果要算哪个功能用的最多的话(除了上面的Enter),那么tab补全是当之无愧的赢家. 147 | 它让我把 =c d / v a r / w w w / m a g e n t o= 简化成了 =c d / v [TAB] w [TAB] m [TAB]= 148 | 149 | 一些常用的地址,比如 =/etc/=, =/home/=, =/var/log=, 则变成肌肉记忆,能够快速进入. 150 | 151 | 记住, 如果按一次 [TAB] 不能立即得到正确的路径的话, 那么再按一下 [TAB] 会列出所有匹配的目录, 然后再多输入1到2个字符后,重新按tab进行补全. 152 | 假设我们有两个目录; =/var/www/magento= 和 =/var/www/magellen=, 要cd进入 =/var/www/magento= 可以这样: 153 | 154 | #+BEGIN_EXAMPLE 155 | root@server:~# cd /v[TAB] /w[TAB] /m[TAB] [TAB] 156 | #+END_EXAMPLE 157 | 158 | 这一步会一直补全到两个目录不同的地方: 159 | 160 | #+BEGIN_EXAMPLE 161 | root@server:~# cd /var/www/mage 162 | #+END_EXAMPLE 163 | 164 | 现在, 按两下[TAB], 可以看到所有匹配的目录, 然后输入你想要进入目录的第一个字符,比如 n, 在按一次 =[TAB]= 就会补全所有路径: 165 | 166 | #+BEGIN_EXAMPLE 167 | root@server:~# cd /var/www/m[TAB] 168 | root@server:~# cd /var/www/mage[TAB][TAB] 169 | magellen/ magento/ 170 | root@server:~# cd /var/www/magen[TAB] 171 | root@server:~# cd /var/www/magento/[ENTER] 172 | root@server:/var/www/magento# 173 | #+END_EXAMPLE 174 | 175 | ** File name completion 176 | 177 | 这是路径补全的一个简单扩展. Bash complete 会补全任何以你输入开头的文件名. 178 | 使用 Bash completion 可以减少输错的可能并且提高输入文件名的速度. 179 | 180 | 而且, 在只有一个文件或目录的情况下, Bash complete 会直接补全该文件名或目录而不用输入任何字符. 181 | 182 | ** Command and command option completion 183 | 184 | Bash complete 会检查并补全你 $PATH 中的所有命令. 如果你不记得了完整的命令,只需要i按下两次 [TAB] 就会看到所有匹配的命令了. 185 | 186 | 此外, 对于那些常见命令, Bash complete 还能为你补全参数选项. 187 | 188 | 比如, 使用命令 =systemctl= 重载 =apache2.service= 可以这样: 189 | 190 | #+BEGIN_EXAMPLE 191 | root@server:~# systemc[TAB] rel[TAB] apa[TAB] 192 | #+END_EXAMPLE 193 | 194 | 这种方法可以将常用路径,常用命令变成肌肉记忆,使得它们的输入格外的快速. 195 | -------------------------------------------------------------------------------- /system/how to reset sudo password.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何重置sudo密码 2 | #+URL: http://www.linuxandubuntu.com/home/how-to-reset-sudo-password 3 | #+AUTHOR: lujun9972 4 | #+TAGS: raw 5 | #+DATE: [2017-10-27 五 15:49] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 有时候我们可能会忘掉自己 [[http://www.linuxandubuntu.com/home/category/ubuntu][Ubuntu]] 计算机的登陆密码, 从而无法登陆计算机. 遇到这种情况并不意味着无可奈何,我们有一些办法可以去尝试. 10 | ​你所需要的仅仅是一个可工作的键盘, 几条命令以及物理接触计算机的机会(我们无法远程解决这个问题). 11 | 第一步,你需要重启计算机, 按下 =shift= 直到出现下面所示的屏幕. 屏幕中有很多选项. 由于计算机可能出的问题千奇百怪,你有必要对这些功能都有所了解. 12 | 掌握基础工具的使用总是有好处的. 13 | 下面我将会分别演示一下在双启动和单启动计算机上忘记了sudo密码的情况下该如何解锁计算机. 14 | 这里双启动的意思是,忘记sudo密码的计算机除了Ubuntu外,还装了其他操作系统. 单系统的意思则指的计算机只安装了Ubuntu操作系统. 15 | 两种情况在前期操作上会有少许区别,但后面的操作则完全一样. 16 | 例如, 对于双启动电脑, 启动时会有一个包含Advanced选项的菜单可以选择. 因此双启动电脑能够很容易地通过grub菜单进入到 recovery 菜单项. 剩下的操作则没有区别. 17 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/edited/grub-menu.jpeg]] 18 | 19 | ​若Ubuntu是唯一的操作系统,则需要在启动计算机时按下 =shift= 键不方,进入grub菜单后.然后通过键盘上的导航键选中 “advanced options for Ubuntu option” 选项. 20 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/edited/grub-menu_1.jpeg]] 21 | 22 | 按下 Enter 进入下一屏. 你会看到有很多的选项 23 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/edited/recovery-menu.png]] 24 | 25 | 滚动光标到 “root” 选项(它的描述为Drop to root shell). 该选项让你以root的身份登陆系统,但此时系统处于只读模式. 26 | 然后你会看到一个类似下面这样的命令行界面. 27 | 28 | 请注意: 29 | ​ 30 | 1 - 如果你忘记了用户名,输入命令 “ls /home” (全小写字母) 然后按下回车. 则会显示出当前系统中的有效用户名. 31 | 32 | 2 - 双启动情况下, 电脑启动时无需按住 shift 键Advanced 选项默认就会现实在Grub菜单上,你可以直接通过Grub菜单进入Ubuntu recovery 菜单. 33 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/edited/password-reset-command.png]] 34 | 35 | 在命令行中,输入 =mount -0 rw,remount /=, 这使得用系统进入读写模式. 36 | 37 | 一定要记住,默认情况下, 文件系统以只读模式挂载, 因而无法做出变更. 因此首先要启用读写模式. 38 | ​ 39 | 之后, 输入下面命令: =passwd 加上用户名=. 例如 =passwd linuxandubuntu=. 40 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/edited/password-reset-command_1.png]] 41 | 42 | 这时你无需旧密码就能修改新密码了. 输入两次密码后就完成了! 至此,你成功地修改了密码. 输入 =Exit= 然后按下回车回到正常的系统启动过程. 43 | 你就可以用新密码登陆了. 44 | -------------------------------------------------------------------------------- /tools/3 open source alternatives to MATLAB.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 3个MATLAB的开源替代 2 | #+URL: https://opensource.com/alternatives/matlab 3 | #+AUTHOR: lujun9972 4 | #+TAGS: tools matlab 5 | #+DATE: [2017-11-03 五 14:44] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 对于学数学,物理,工程,经济等需要经常与数字打交道的学生来说, MATLAB 基本上是他们接触编程和科学计算的首要途径. 11 | 12 | MATLAB是一款用于学习的好工具, 不过(按我的经验来说) 很多时候学生和研究人员使用MATLAB的场景并没有对计算有那么高的要求; 13 | 这些任务完全可以使用其他脚本工具来完成,甚至可能都不用用到统计等其他数学相关的包. 14 | 不过话说回来, 由于MATLAB在学术界中几乎无处不在, 带来了大量熟悉该语言,插件和功能的用户群体. 15 | 16 | 然而 MATLAB 是一款专利工具. 你无法接触到它的源代码, 你很难理解它的运行机制也很难对它作出修改. 17 | 而且对于那些非学术界的人来说,它也特别的昂贵, 单拷贝的版权费能达到数千美元. 18 | 19 | 好在, 存在很多开源的替代品. 根据你的具体目标, 总会有一个或多个替代品能够满足你的要求. 20 | 下面是三个可以考虑的替代品: 21 | 22 | GNU Octave 23 | 24 | [[https://www.gnu.org/software/octave/][GNU Octave]] 恐怕是最出名的 MATLAB 替代品了吧. 经过近三十年的发展, Octave已经可以运行在Windows, Mac, 以及 Linux 上—而且在大多数Linux发行版上都有打包. 25 | 如果你想要一款尽可能与 MATLAB 语言接近的项目,那么 Octave 就很适合你; 它致力于确保兼容性, 很多为 MATLAB 开发的项目都可以直接在 Octave 中运行而无需进行任何修改. 26 | 27 | Octave 4自带了一个默认的前端交互程序,但除此之外你也还有很多其他的选择; 有些界面跟MATLAB很接近. Octave的 [[https://en.wikipedia.org/wiki/GNU_Octave][Wikipedia 页]] 中罗列了很多选择. 28 | 29 | Octave 基于 [[http://www.gnu.org/copyleft/gpl.html][GPL]] 发布, 你可以从 GNU [[ftp://ftp.gnu.org/gnu/octave][FTP site]] 上下载到它的源代码. 30 | 31 | Scilab 32 | 33 | [[http://www.scilab.org/][Scilab]] 是另一款数值计算的开源替代品,它支持所有的主流平台: Windows, Mac, 和 Linux. 34 | Scilab 可能是除了 Octave 之外最知名的替代品了, 而且 (跟 Octave 一样) 它的实现也与MATLAB很接近, 不过它并不保证完全的兼容性. 35 | 36 | Scilab 基于 与GPL兼容的 [[http://www.scilab.org/scilab/license][CeCILL]] license 发布, 他的 [[http://www.scilab.org/development/sources/stable][源代码]] 可以在项目网站上找到. 37 | 38 | Sage 39 | 40 | [[http://www.sagemath.org/index.html][SageMath]] 是另一款不错的替代品. 它基于大量知名的Python科学计算库所构建, 而且它的语言在语法上也跟Python很接近. 41 | 它有很多功能,包括一个命令行接口, 基于浏览器的 notebooks, 用于编写内嵌于其他文档中公式的工具, 以及相当多的数学库. 42 | 43 | SageMath 基于 [[http://www.gnu.org/copyleft/gpl.html][GPL]] license 发布, 它的源代码可以在 [[http://www.sagemath.org/download-source.html][项目网站]] 上找到. 44 | 45 | ------------------------------------------------------------------------------------------------------------------------------------------ 46 | 47 | 这份清单仅仅罗列了很少的一些研究人员和学生可用于作为MATLAB的开源替代品.  48 | 根据你的具体需求R, Julia, Python, 以及其他标准编程语言也可以是很不错的选择. 49 | 你也可以考虑以下这些开源工具: 50 | 51 | + [[http://freemat.sourceforge.net/][FreeMat]],一套发布于 [[http://www.gnu.org/copyleft/gpl.html][GPL]] 协议下的用于快速开发,探索科学原型和数据处理的环境. 它可以运行于 Linux, OS X, 和 Windows 上, 不过它可能会有些落伍,因为其最新版本是发布于2013年. 52 | + [[http://www.jirka.org/genius.html][Genius Mathematic Tool]], 一款积极开发的计算器程序和研究工具. 它由 Genius Extension 语言编写而成,可以跑在 Linux 和 Unix 计算机上, 而且基于 [[https://www.gnu.org/licenses/gpl.html][GPL GNU]] license 发布. 53 | + [[http://maxima.sourceforge.net/][Maxima]],另一款MATLAB的替代品,其更新非常频繁. 它构建于 Macsyma(一款由MIT于20世纪60年代开发的"传奇计算机代数系统") 之上, 可以在 Linux, Mac OS X, 和 Windows 上编译, 而且基于  [[https://sourceforge.net/directory/license:gpl/][GPLv2]] 协议发布. 54 | + [[http://www.numpy.org/][NymPy]],Python上用于科学计算的主要package. 它也为SciPy Stack提供了基础的数据结构, 它提供了一个基于Python的数学生态圈, 同时还是一款用于科学和工程上的软件. NymPy 基于 [[http://www.numpy.org/license.html#license][BSD license]] 协议发布, 支持 Windows, Mac OS X, 以及 Linux 平台. 55 | + [[http://www.sympy.org/en/index.html][SymPy]], 另一款基于 [[https://github.com/sympy/sympy/blob/master/LICENSE][BSD]] 协议发布的用于符号数学的Python库. 它可以安装在任何运行了 Python 2.7 及以上版本的电脑上. 它的目标是成为一个完整的计算机代数系统; 它拥有一个很活跃的开发团队,发布也很稳定;而且它也被用在很多其他项目中(包括上面提到的 SageMath). 56 | 57 | 你还有什么其他的MATLAB替代品码? 你比较喜欢哪个呢?理由是什么? 欢迎留言. 58 | -------------------------------------------------------------------------------- /tools/Cryptr - A Simple CLI Utility To Encrypt And Decrypt File.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Cryptr - 一款简单的加解密CLI工具 2 | #+URL: https://www.ostechnix.com/cryptr-simple-cli-utility-encrypt-decrypt-files/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: passwd encrypt decrypt 5 | #+DATE: [2017-11-14 二 19:05] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 想要一个简单,快捷又安全的方法来保护你的文件? 这款名为 “Cryptr” 的shell工具可以帮你加解密文件. 11 | 一切都在命令行中搞定, 而且你也不必成为安全领域高手和Linux专家才能够保护你的数据. 12 | Cryptr 使用 OpenSSL AES-256 cipher block chaining 方法来加密文件. 它基于Apache License, Version 2.0许可证发布可以任你使用. 13 | 14 | * Encrypt And Decrypt Files Using Cryptr 15 | 16 | 安装很简单. 使用下列命令克隆 Cryptr 仓库: 17 | 18 | #+BEGIN_SRC shell 19 | git clone https://github.com/nodesocket/cryptr.git 20 | #+END_SRC 21 | 22 | 该命令将 Cryptr 仓库的内容克隆到当前工作目录中一个名为 cryptr 的目录中 23 | 24 | 然后使用下面命令将 cryptr.bash 文件链接到你的 bin 目录中: 25 | 26 | #+BEGIN_SRC shell 27 | sudo ln -s "$PWD"/cryptr/cryptr.bash /usr/local/bin/cryptr 28 | #+END_SRC 29 | 30 | 这就行了. 下面让我们来看看一些使用案例. 31 | 32 | 在终端运行下面命令会加密一个名为 “test.txt” 的文件. Cryptr 需要你输入两次密码. 33 | 34 | #+BEGIN_SRC shell 35 | $ cryptr encrypt test.txt 36 | enter aes-256-cbc encryption password: 37 | Verifying - enter aes-256-cbc encryption password: 38 | #+END_SRC 39 | 40 | 上面的命令使用AES-256-CBC加密方法来加密指定文件(也就是 test.txt),加密后的文件以 =.aes= 为后缀. 41 | 你可以使用 “ls” 命令来验证文件是否加密成功. 42 | 43 | [[http://www.ostechnix.com/wp-content/uploads/2017/11/cryptr-1.png]] 44 | 45 | 如果有以 =.aes= 结尾的文件, 则表示文件被加密了. 46 | 47 | 使用下面命令可以解密文件. 需要输入正确的密码. 48 | 49 | #+BEGIN_SRC shell 50 | $ cryptr decrypt test.txt.aes 51 | enter aes-256-cbc decryption password: 52 | #+END_SRC 53 | 54 | 你还可以使用环境变量 =CRYPTR_PASSWORD= 来指定用于加密时的密码. 55 | 56 | #+BEGIN_SRC shell 57 | CRYPTR_PASSWORD=BC1rO7K7SspYcLChMr28M cryptr encrypt test.txt 58 | Using environment variable CRYPTR_PASSWORD for the password 59 | #+END_SRC 60 | 61 | 这里, =BC1rO7K7SspYcLChMr28M= 就是文件的密码. 62 | 63 | 类似的, 可以这样解密文件: 64 | 65 | #+BEGIN_SRC shell 66 | $ CRYPTR_PASSWORD=BC1rO7K7SspYcLChMr28M cryptr decrypt test.txt.aes 67 | Using environment variable CRYPTR_PASSWORD for the password 68 | #+END_SRC 69 | 70 | 这一能力在脚本和批量操作时特别有用. 71 | 72 | 想看帮助的话,运行: 73 | 74 | #+BEGIN_SRC shell 75 | $ cryptr help 76 | Usage: cryptr command 77 | 78 | encrypt Encrypt file 79 | decrypt Decrypt encrypted file 80 | help Displays help 81 | version Displays the current version 82 | #+END_SRC 83 | -------------------------------------------------------------------------------- /tools/File better bugs with coredumpctl.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 使用coredumpctl帮你定位bug 2 | #+URL: https://fedoramagazine.org/file-better-bugs-coredumpctl/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: core fedoral 5 | #+DATE: [2017-11-14 二 22:56] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 人生一大不幸就是所有软件都有bug, 有些bug还能让系统崩溃. 当崩溃产生时通常会产生一个名为 =core= 文件的数据文件. 11 | 该文件包含崩溃时的系统数据, 可以帮助我们探查崩溃产生的原因. 12 | 通常开发人员需要 backtrace 的数据来找到导致崩溃的指令流程. 它可以帮助开发人员修复bug,改进系统. 13 | 下面让我们看看在软件崩溃时生成 backtrace 的简单方法. 14 | 15 | * coredumpctl入门 16 | 17 | 大多数 Fedora 系统都使用 [[https://github.com/abrt/abrt][Automatic Bug Reporting Tool (ABRT)]] 来自动在系统崩溃时捕获dump文件. 18 | 然而, 若你禁用了该服务或者删除了相关包, 那么这里说的方法就有用了. 19 | 20 | 系统崩溃后, 首先要保证你运行的是最新升级的软件. 升级通常会修复已知可能导致验证错误和崩溃的bug. 21 | 升级完后, 尝试重现一下导致bug的场景. 22 | 23 | 如果依然崩溃, 或者你运行的本来就是最新的软件, 那么就可以使用 =coredumpctl= 这个工具了. 该工具会帮助定位和处理崩溃. 24 | 要查看系统中的所有core dumps可以运行下面命令: 25 | 26 | #+BEGIN_SRC shell 27 | coredumpctl list 28 | #+END_SRC 29 | 30 | 不要被它的长度所吓到. 有些系统组件只是静静的在幕后崩溃,然后自己又恢复了. 31 | 可以使用 =-since= 参数来过滤出今天产生的dump: 32 | 33 | #+BEGIN_SRC shell 34 | coredumpctl list --since=today 35 | #+END_SRC 36 | 37 | 其中 PID 列包含了标识dump的ID号. 请记住这个编号, 你会在后面再次用到. 如果你不想去记它, 可以用一个变量来保存: 38 | 39 | #+BEGIN_SRC shell 40 | MYPID= 41 | #+END_SRC 42 | 43 | 要查看core dump的信息, 使用下面命令: 44 | 45 | #+BEGIN_SRC shell 46 | coredumpctl info $MYPID 47 | #+END_SRC 48 | 49 | * 安装 debuginfo 包 50 | 51 | Debugging symbols 将core dump中的数据翻译成源码中的指令. 而这个 symbol 数据可能非常大. 52 | 因此, symbols 独立存放在 debuginfo 包中而不会包含在我们常用的那些包中. 53 | 使用下面命令可以决定应该安装哪个 debuginfo 包: 54 | 55 | #+BEGIN_SRC shell 56 | coredumpctl gdb $MYPID 57 | #+END_SRC 58 | 59 | 这条命令会显示很多内容. 如果缺少 debuginfo 包,最后那行信息会告诉你应该用 dnf 来安装那些 debuginfo 包. 60 | 使用 [[https://fedoramagazine.org/howto-use-sudo/][sudo]] 运行下面命令: 61 | 62 | #+BEGIN_SRC shell 63 | sudo dnf debuginfo-install  64 | #+END_SRC 65 | 66 | 然后再试着运行一次 =coredumpctl gdb $MYPID=. 若trace中还有未知的symbol,你可能还会需要重复上一步骤. 67 | 68 | * 捕获 backtrace 69 | 70 | 运行下面命令来记录调试器中的信息: 71 | 72 | #+BEGIN_SRC shell 73 | set logging file mybacktrace.txt 74 | set logging on 75 | #+END_SRC 76 | 77 | 有时可能需要关闭 =pagination= 项. 当处理很长的 backtraces 时这会节省很多时间. 78 | 79 | #+BEGIN_SRC shell 80 | set pagination off 81 | #+END_SRC 82 | 83 | 然后运行 backtrace: 84 | 85 | #+BEGIN_SRC shell 86 | thread apply all bt full 87 | #+END_SRC 88 | 89 | 现在可以输入 =quit= 来退出调试器了. 在 =mybacktrace.txt= 文件中包含了与bug有关的 backtrace 信息.当然你也可以直接把文件内容上传到 pastebin 上去. 90 | 不管怎样, 你都可以为开发者解决问题提供更多的帮助了. 91 | -------------------------------------------------------------------------------- /tools/Googler:A Command Line Tool To Search Google.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Googler:搜索Google的命令行工具 2 | #+URL: http://www.linuxandubuntu.com/home/googler-a-command-line-tool-to-search-google 3 | #+AUTHOR: lujun9972 4 | #+TAGS: tools google 5 | #+DATE: [2017-10-30 一 17:34] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 我们每天都要在网上寻找信息. 你也可以在网上找到任何信息. 因此搜索引擎也被设计成能够帮助我们从垃圾中快速筛选出有用信息的样子. 10 | 常用的搜索引擎有 Google, Bing, 和 DuckDuckGo. 不过它们都有一个共同点,那就是需要用浏览器(比如Firefox和Chromium)来访问. 11 | 一般情况下这都不是什么问题; 但是如果你只有终端环境而没有GUI和浏览器怎么办呢, 如果你有GUI和浏览器但是你只想在不离开终端的情况下做一个快速搜索怎么办呢. 12 | 为此,Googler诞生了. 13 | 注意: googler 并不隶属于 Google . 14 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/googler_orig.png]] 15 | 16 | * 什么是googler? 17 | 18 | googler是一个让你在命令行使用Google (Web & News) 和 Google Site Search 的小工具,它虽然小巧但功能强大. 19 | googler 最初是为想在无X环境下使用google的人所设计的. 你可以将它与像lynx或links这样的基于文本的浏览器整合,以便在命令行直接打开搜索结果. 20 | 但是现在它已经发展成为一个非常方便,非常灵活的工具了. 其功能也有了大大的扩展. 21 | 22 | * 如何安装 Googler? 23 | 24 | googler 需要3.3及之后的 Python. 且仅支持每个次要版本的最新补丁版本(Only the latest patch release of each minor version is supported). 25 | Ubuntu用户以及使用基于Ubuntu发行版的用户可以通过PPA来安装,命令为: 26 | #+BEGIN_SRC shell 27 | sudo add-apt-repository ppa:twodopeshaggy/jarun 28 | sudo apt-get update 29 | sudo apt-get install googler 30 | #+END_SRC 31 | 32 | 还有一个简单得多的方法, Googler只是一个独立的脚本, 你只需要下载这个文件就行了. 33 | #+BEGIN_SRC shell 34 | sudo curl -o /usr/local/bin/googler https://raw.githubusercontent.com/jarun/googler/v3.3/googler && sudo chmod +x /usr/local/bin/googler 35 | #+END_SRC 36 | 37 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/googler-installation_orig.png]] 38 | 39 | #+BEGIN_SRC shell 40 | sudo googler -u 41 | #+END_SRC 42 | 43 | * 怎么用? 44 | 45 | Googler会显示出搜索结果的标题,URL以及摘要,你可以直接从终端调用浏览器访问这些搜索结果. 搜索结果以页的形式组织,你可以上下进行翻页. 46 | 同时你还可以在同一个googler实例上进行连续的搜索. 47 | 48 | 你可以指定搜索结果的数量, 限制所述 bt duration 等等, 而且搜索结果非常清爽,没有那些广告和流氓网址. shell补全功能使得你无需记忆任何参数. 49 | 50 | #+BEGIN_EXAMPLE 51 | usage: googler [-h] [-s N] [-n N] [-N] [-c TLD] [-l LANG] [-x] [-C] 52 | [--colors COLORS] [-j] [-t dN] [-w SITE] [--unfilter] 53 | [-p PROXY] [--noua] [--notweak] [--json] [--show-browser-logs] 54 | [--np] [-u] [--include-git] [-v] [-d] 55 | [KEYWORD [KEYWORD ...]] 56 | #+END_EXAMPLE 57 | 58 | 让我们看一些实际的例子. 59 | 60 | 你可以使用googler搜索任意字符串. 例如这里我尝试搜索最匹配 [[http://www.linuxandubuntu.com/home.html][Linux and Ubuntu news]] 的网站. 61 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/googler-installation_1_orig.png]] 62 | 还有更多 63 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/googler-installation_2_orig.png]] 64 | 65 | 更厉害的是, 你可以使用 =-w= 限制在某个特定的网站中执行搜索(比如我要搜索kde). 我这里同时指定每页只显示3个结果 (默认为10个结果). 66 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/googler-installation_3_orig.png]] 67 | 68 | 你还可以使用 =-N= 选项来搜索与kde相关的新项目. 如下图所示(译者注:下面的图原作者应该是放错了...). 69 | [[http://www.linuxandubuntu.com/uploads/2/1/1/5/21152474/googler-installation_4_orig.png]] 70 | 71 | * 更多的例子 72 | 73 | + Google搜索hello world: 74 | 75 | #+BEGIN_SRC shell 76 | $ googler hello world 77 | #+END_SRC 78 | 79 | + 在站点 =imdb.com= 中搜索关键字 =jungle book=,搜索的结果要在最近14个月内更新过的. 从第3个结果开始显示15个结果: 80 | 81 | #+BEGIN_SRC shell 82 | $ googler -n 15 -s 3 -t m14 -w imdb.com jungle book 83 | #+END_SRC 84 | 85 | + 阅读关于 =gadgets= 相关的最新消息: 86 | 87 | #+BEGIN_SRC shell 88 | ​$ googler -N gadgets 89 | #+END_SRC 90 | 91 | + 查看更多帮助: 92 | 93 | #+BEGIN_SRC shell 94 | $ googler -h 95 | #+END_SRC 96 | 97 | 或者 98 | 99 | #+BEGIN_SRC shell 100 | $ man googler 101 | #+END_SRC 102 | 103 | * 功能一览 104 | 105 | ** 1 - 与文本浏览器实现整合 106 | 107 | googler天然与文本浏览器相适应,只需要设置一下 =BROWSER= 环境变量即可. 像这样: 108 | #+BEGIN_SRC shell 109 | $ export BROWSER=w3m 110 | #+END_SRC 111 | 若只是临时设置,可以这样 112 | #+BEGIN_SRC shell 113 | $ BROWSER=w3m googler query 114 | #+END_SRC 115 | 116 | ** 2 - 终端阅读模式或者说阅读者视图(Terminal Reading Mode or Reader View) 117 | 118 | googler可以很方便地与其他工具整合, 给你提供一个无干扰的阅读环境. 详细信息请参见 [[https://github.com/jarun/googler/wiki/Terminal-Reading-Mode-or-Reader-View][这里]]. 119 | 120 | ** 3 - 配色 121 | 122 | googler允许你通过一个留个字符的字符串来自定义配色方案, 其格式与 BSD =LSCOLORS= 一至. 123 | 124 | ** 4 - 以及 125 | 126 | + 快速,纯净(没有广告, 流氓网址(stray URL)以及其他乱七八糟的东西), 可以自定义配色 127 | + 支持Google关键字 128 | + 直接在浏览器中打开排名第一的搜索结果 129 | + 文档齐全, man 页面中包含很多案例演示 130 | + 连续搜索: 可以在不退出的情况下开始新的搜索 131 | 132 | * 结论 133 | 134 | ​googler的受众范围有限,但如果你更喜欢终端,它是一个不错的好工具. 135 | 虽然用的不多,但是我很喜欢 googler,我会一直留着它. 136 | 想了解更多关于 googler 的信息, 请访问它的 [[https://github.com/jarun/googler#installation][github page]]. 137 | -------------------------------------------------------------------------------- /tools/How To Control Media Players From Commandline In Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: 如何在Linux命令行控制媒体播放器 2 | #+URL: https://www.ostechnix.com/control-media-players-commandline-linux/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: commandline media 5 | #+DATE: [2017-11-08 三 20:27] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 各位音乐爱好者们! 进他我学到一样新东西,那就是在类Unix系统下的命令行控制媒体播放器. 11 | 你可以播放,暂停,在播放和暂停间切换, 调高/调低音量, 切上一首/下一首媒体文件, 停止媒体播放等动作. 12 | 所偶这些都在终端内完成! 很酷吧? 本文将告诉你两个这样的工具. 13 | 14 | * 1. Playerctl 15 | 16 | =Playerctl= 是一个在终端制媒体播放的命令行工具. 你可以用它播放,暂停,在播放和暂停间切换, 调高/调低音量, 切上一首/下一首媒体文件, 停止媒体播放等. 17 | 通过 Playerctl, 我们可以管理任何实现了 [[http://specifications.freedesktop.org/mpris-spec/latest/][MPRIS]] D-Bus 接口规范的媒体播放器. 下面是一些常见的能被 Playerctl 管理的播放器: 18 | 19 | + Audacious, 20 | + Bmp, 21 | + Spotify, 22 | + Mplayer/SMplayer, 23 | + VLC, 24 | + Xmms2. 25 | 26 | ** 安装 27 | 28 | Playerctl 存在于所有现代Linux发行版的官方仓库中. 你可以使用发行版的默认包管理器来安装它. 29 | 30 | Arch Linux 上: 31 | 32 | #+BEGIN_SRC shell 33 | sudo pacman -S playerctl 34 | #+END_SRC 35 | 36 | Debian, Ubuntu 及其衍生版上: 37 | 38 | #+BEGIN_SRC shell 39 | sudo apt-get install playerctl 40 | #+END_SRC 41 | 42 | Fedora 上: 43 | 44 | #+BEGIN_SRC shell 45 | sudo dnf install playerctl 46 | #+END_SRC 47 | 48 | openSUSE 上: 49 | 50 | #+BEGIN_SRC shell 51 | sudo zypper install playerctl 52 | #+END_SRC 53 | 54 | 如果你在官方仓库中找不到, 还可以通过源代码来手工编译和安装. 最新的源代码可以在 [[https://github.com/acrisci/playerctl/releases][发布页面]] 上找到. 55 | 56 | ** 用法 57 | 58 | 首先, 使用下面命令列出所有可以控制的播放器(译注:必须是正在运行的播放器): 59 | 60 | #+BEGIN_SRC shell 61 | playerctl -l 62 | #+END_SRC 63 | 64 | 或者, 65 | 66 | #+BEGIN_SRC shell 67 | playerctl --list-all 68 | #+END_SRC 69 | 70 | 输出: 71 | 72 | #+BEGIN_EXAMPLE 73 | vlc 74 | smplayer 75 | #+END_EXAMPLE 76 | 77 | 你可以查看指定播放器的状态: 78 | 79 | #+BEGIN_SRC shell 80 | $ playerctl status vlc 81 | Stopped 82 | 83 | $ playerctl status smplayer 84 | Playing 85 | #+END_SRC 86 | 87 | 如你所见, 当前有两个可以控制的播放器. Vlc 处于停止状态, smplayer 处于播放状态. 88 | 89 | 用下面命令来进行播放: 90 | 91 | #+BEGIN_SRC shell 92 | playerctl play -p smplayer 93 | #+END_SRC 94 | 95 | 或者, 96 | 97 | #+BEGIN_SRC shell 98 | playerctl play --player smplayer 99 | #+END_SRC 100 | 101 | 在只运行了一个播放器则无需使用 “-p” 或 “–player” 来指定播放器. Playerctl 会自动选择这个播放器来播放. 102 | 103 | 要暂停播放(假设你只运行了一个播放器), 则运行: 104 | 105 | #+BEGIN_SRC shell 106 | playerctl pause smplayer 107 | #+END_SRC 108 | 109 | 播放下一首: 110 | 111 | #+BEGIN_SRC shell 112 | playerctl next smplayer 113 | #+END_SRC 114 | 115 | 播放上一首: 116 | 117 | #+BEGIN_SRC shell 118 | playerctl previous smplayer 119 | #+END_SRC 120 | 121 | 切换播放与暂停: 122 | 123 | #+BEGIN_SRC shell 124 | playerctl play-pause smplayer 125 | #+END_SRC 126 | 127 | 若播放器处于暂停状态则会继续播放,若播放器处于播放状态则会暂停播放. 128 | 129 | 停止播放: 130 | 131 | #+BEGIN_SRC shell 132 | playerctl stop smplayer 133 | #+END_SRC 134 | 135 | 查看帮助: 136 | 137 | #+BEGIN_SRC shell 138 | $ playerctl --help 139 | Usage: 140 | playerctl [OPTION…] COMMAND - Controller for MPRIS players 141 | For true players only: spotify, vlc, audacious, bmp, xmms2, and others. 142 | 143 | Help Options: 144 | -h, --help Show help options 145 | 146 | Application Options: 147 | -p, --player=NAME The name of the player to control (default: the first available player) 148 | -l, --list-all List the names of running players that can be controlled 149 | -V, --version Print version information and exit 150 | 151 | Available Commands: 152 | play Command the player to play 153 | pause Command the player to pause 154 | play-pause Command the player to toggle between play/pause 155 | stop Command the player to stop 156 | next Command the player to skip to the next track 157 | previous Command the player to skip to the previous track 158 | position [OFFSET][+/-] Command the player to go to the position or seek forward/backward OFFSET in seconds 159 | volume [LEVEL][+/-] Print or set the volume to LEVEL from 0.0 to 1.0 160 | status Get the play status of the player 161 | metadata [KEY] Print metadata information for the current track. Print only value of KEY if passed 162 | #+END_SRC 163 | 164 | 165 | 可以去项目的Github页面了解更多信息, 地址列在后面. 166 | 167 | * 2. OmniPause 168 | 169 | =OmniPause= 是一个python写的通过DBus来控制多媒体播放器的应用程序. 相比 Playerctl, OmniPause 出现的比较晚,尚处于早期的开发阶段. 170 | 不过它的功能很全面,能做到跟 Playerctl 一样的事情. 171 | 172 | ** 安装 173 | 174 | OmniPause 是由 Python 编写的, 因此你需要安装先安装以下依赖. 这些包在所有的Linux发行版的官方仓库上都有, 完全可以用默认的包管理器来安装. So, you can install them using the default package manager. 175 | 176 | + python2 177 | + dbus-python 178 | 179 | 之后,克隆该项目: 180 | 181 | #+BEGIN_SRC shell 182 | git clone https://github.com/mel00010/OmniPause.git 183 | #+END_SRC 184 | 185 | 进入项目目录: 186 | 187 | #+BEGIN_SRC shell 188 | cd OmniPause/ 189 | #+END_SRC 190 | 191 | 运行下面命令安装之. 192 | 193 | #+BEGIN_SRC shell 194 | sudo make install 195 | #+END_SRC 196 | 197 | 上面命令会拷贝 omnipause.py 程序到 =/usr/local/bin/omnipause= 中. 198 | 199 | ** 用法 200 | 201 | 使用方法与 Playerctl 一样. 不过功能稍弱. 只支持以下几个功能: 202 | 203 | + play, 204 | + pause, 205 | + next, 206 | + previous, 207 | + toggle, 208 | + stop. 209 | 210 | 暂停所有正在运行的媒体播放器: 211 | 212 | #+BEGIN_SRC shell 213 | omnipause pause 214 | #+END_SRC 215 | 216 | 重启被暂停的媒体播放器: 217 | 218 | #+BEGIN_SRC shell 219 | omnipause play 220 | #+END_SRC 221 | 222 | 停止所有的播放器: 223 | 224 | #+BEGIN_SRC shell 225 | omnipause stop 226 | #+END_SRC 227 | 228 | 所有正在播放的媒体播放器播放下一首: 229 | 230 | #+BEGIN_SRC shell 231 | omnipause next 232 | #+END_SRC 233 | 234 | 所有正在播放的播放器播放上一首: 235 | 236 | #+BEGIN_SRC shell 237 | omnipause previous 238 | #+END_SRC 239 | 240 | 切换所有正在运行播放器的状态: 241 | 242 | #+BEGIN_SRC shell 243 | omnipause toggle 244 | #+END_SRC 245 | 246 | 如你所见, 你可以使用一个命令控制所有正在运行的媒体播放器. 很简单吧. 不过与 Playerctl 不同, 它没有选项停止指定的播放器,也没有调大/调小音量的功能. 247 | 如果你需要这些功能,还是使用 playerctl 程序吧. 248 | 249 | * 相关资源: 250 | 251 | + [[https://github.com/acrisci/playerctl][Playerctl GitHub page]] 252 | + [[https://github.com/mel00010/OmniPause][OmniPause GitHub page]] 253 | -------------------------------------------------------------------------------- /tools/How to Install and Use TeamViewer on Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: TeamViewer使用指南 2 | #+URL: https://itsfoss.com/teamviewer-linux/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: teamviewer remote 5 | #+DATE: [2017-11-20 一 15:22] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | [[https://www.teamviewer.com][TeamViewer]] 是一款远程桌面应用,主要用于快速而安全地连接上其他系统. 她允许你远程登陆他人的桌面, 传输文件, 共享屏幕乃至举行视频会议. 11 | 12 | 它由于简洁性与易用性而风靡于世, 常用于为远程计算机提供技术支持. 13 | 14 | TeamView是跨平台的软件,同时支持 Windows, Mac OS X, Linux, iOS 以及 Android 甚至还支持web浏览器. 15 | 虽然 TeamViewer 是专利软件, 但它可以免费用于非商业用途,而且功能几乎与付费版本一样. 16 | 17 | * TeamViewer的特点 18 | 19 | + 远程控制系统 20 | + 支持视频会议, 群聊, 桌面共享. 21 | + 安全的连接,支持256 bit AES session 编码 以及 2048 bit RSA 密钥交换. 22 | + Wake-on-LAN feature allows switching on your computer remotely. 23 | + 支持重启系统/服务器. 24 | + 便利的多屏切换. 25 | 26 | * 在Linux上安装TeamViewer 27 | 28 | 对于基于Debain或Ubuntu的Linux发行版,TeamViewer 提供了 .deb 二进制文件. 29 | 对于Fedora和SUSE,它也提供了 .rpm 包. 30 | 对于其他Linux发行版则可以使用 tar包来安装. 31 | 32 | 你可以从下面这个官方下载页面下载 TeamViewer: 33 | 34 | [[https://www.teamviewer.com/en/download/linux/][Download TeamViewer]] 35 | 36 | 我是在Ubuntu上安装 TeamViewer,因此我选择下载 .deb 文件. 双击下载的包就会弹出图形化的安装界面,按照指示一步步下去就行了. 37 | 38 | 若你遇到有依赖问题, 我建议你试着用 [[https://itsfoss.com/gdebi-default-ubuntu-software-center/][GDebi package installer]] 来安装. 39 | 40 | 另外, 如果你更喜欢终端操作, 可以进入下载目录然后运行下面命令: 41 | 42 | #+BEGIN_SRC shell 43 | sudo dpkg -i teamviewer* 44 | #+END_SRC 45 | 46 | 如果由于缺少依赖而导致安装失败, 则输入下面命令. 47 | 48 | #+BEGIN_SRC shell 49 | sudo apt-get install -f 50 | #+END_SRC 51 | 52 | 安装好后, 你就可以从应用菜单中打开 TeamViewer 了,或者也可以在控制台运行下面命令: 53 | 54 | #+BEGIN_SRC shell 55 | teamviewer 56 | #+END_SRC 57 | 58 | * 连接其他系统 59 | 60 | 在使用TeamViewer远程连接到其他系统之前,你需要了解一些东西: 61 | 62 | + 主机和目标系统上都需要安装有 TeamViewer. 63 | + 主机和目标机器可以是任何TeamViewer支持的操作系统. 例如,你可以用它从你的Linux系统连接到其他Windows系统上. 64 | + 默认情况下, 每个系统都有一个ID,并且应用启动时会给每个系统生成一个随机的4位密码. 65 | + 若你想连接远程系统,你需要知道目标系统的ID以及密码. 66 | + 类似的, 若你要让其他人连接到你的系统中, 你需要提供给他你系统的Id和密码. 67 | + 两个系统都要连接上Internte. 68 | + 你无需创建TeamViewer用于就能使用它. 69 | 70 | 现在让我们看看具体要怎么做: 71 | 72 | ** 步骤 1 73 | 74 | 在主机和目标系统上都启动 TeamViewer. 启动后你将会看到系统ID以及登陆密码. 远程系统也是一样. 75 | 76 | 这写信息很重要,当远程连接时需要这些信息. 77 | 78 | [[https://itsfoss.com/wp-content/uploads/2017/11/1-1.png]] 79 | An ID and Password is displaced on the screen 80 | 81 | ** 步骤 2 82 | 83 | 确保主机和目标机器都安装有 TeamViewr后. 你还需要得到目标系统的ID和密码. 84 | 然后打开TeamViewer在 “Remote Control” 下面ID的位置输入对方ID, 然后点击 “Connect to partner”: 85 | 86 | [[https://itsfoss.com/wp-content/uploads/2017/11/using-teamviewer-linux.png]] 87 | Enter the ID of the target device 88 | 89 | 当然, TeamViewer还会要你输入目标系统的密码. 90 | 91 | [[https://itsfoss.com/wp-content/uploads/2017/11/using-teamviewer-linux-1.png]] 92 | 93 | 输入正确密码后点击 "Log On", 你就连接上目标系统了. 94 | 95 | ** 步骤 3 96 | 97 | 连接上目标系统后, 你就能完全控制目标系统了. 我在一个Ubuntu系统上面创建了一个远程桌面连接,连接上另一台 Elementary OS 系统,然后在上面运行了一个命令! 98 | 99 | [[https://itsfoss.com/wp-content/uploads/2017/11/running-TeamViewer-800x434.jpg]] 100 | Connected to elementary OS from Ubuntu system 101 | 102 | 最上面一栏可以修改TeamViewer配置. 在 Actions 标签页下, 你可以关闭session,重启设备甚至邀请其他参与者. 103 | 104 | [[https://itsfoss.com/wp-content/uploads/2017/11/3-768x151.png]] 105 | 106 | View 标签页中的功能最有用. 你可以选择让屏幕自适应, 还是速度优先还是质量优先,还能选择目标系统的屏幕分辨率. 107 | 108 | [[https://itsfoss.com/wp-content/uploads/2017/11/4-768x135.png]] 109 | 110 | Files & Extras 让你可以截屏或者录制会话. 你可以通过拖拽的方式或者文件管理器来在系统间分享文件. 111 | 112 | [[https://itsfoss.com/wp-content/uploads/2017/11/5.png]] 113 | 114 | * 关于 TeamViewer 的其他说明 115 | 116 | 下面这些方法可以改善TeamViewer的使用体验. 117 | 118 | ** 1. Using TeamViewer account for easy access 119 | 120 | 可以通过ID和密码来控制你的系统. 然而通过注册一个免费用户可以让你存储这些认证, 从而实现快速连接系统而无需每次都输入那么一堆东西. 121 | 122 | ** 2. Recording a session 123 | 124 | You can always record a TeamViewer session for a later access or for the records. 125 | 连接上 TeamViewer 后, 进入工具栏中的 Extras,然后就能开始,暂停,停止录制了. 126 | 录制完成后,TeamViewer会提示你保存它. 127 | 128 | ** 3. Multiple Sessions support 129 | 130 | TeamViewer 同时支持多个会话, 你可以在不断开第一个系统的情况下控制第二个系统. 131 | 点击左上角的+号就可以添加其他机器了. 对于那些从事IT支持的人, 该功能相当有用. 132 | 133 | ** 4. Easy file transfer 134 | 135 | 在 TeamViewer 菜单栏上选择 "File Transfer" 可以在系统之间分享文件. 你也可以选中文件然后拖进 File 框中. 136 | 这个功能很重要,这样你就可以无需物理接触就能把应用放到目标机器上并安装它了. 137 | 138 | ** 5. Manage Visual Settings 139 | 140 | 你可以在 "Visual Settings" 中设置图像质量,缩放大小以及屏幕分辨率,以此里优化你的连接. 141 | 该功能在 View 菜单中. 为了避免延误, 你可以在 Quality 中选择 Optimize speed, 或者禁用 GUI 动画. 142 | 143 | ** 6. Connect with a smartphone 144 | 145 | TeamViewer 应用还支持 iOS, Android 以及 Windows 10 手机,这使地你可以在任何时间任何地方都可以查看你的系统. 146 | 我可以连上系统然后查看下载是否完成,甚至可以更改播放的音乐而无需接触系统. 147 | 148 | 下图演示了我是如何在手机上控制系统的. 149 | 150 | [[https://itsfoss.com/wp-content/uploads/2017/11/Remote-desktop-768x432.png]] 151 | 152 | * 最后总结 153 | 154 | TeamViewer 是个很棒的工具,它可以用来帮助别人排查问题也可以用手机监控自己的系统. 155 | 而且它还支持几乎所有的系统. 156 | 157 | 你是 TeamViewer 用户? 你还有其他远程连接的工具吗? 欢迎留言! 158 | -------------------------------------------------------------------------------- /tools/Packup - A Script To Quickly Share Updates Via USB Drive In Arch Linux.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Packup - 一款通过U盘快速共享Arch Linux升级包的脚本 2 | #+URL: https://www.ostechnix.com/install-packages-offline-arch-linux/ 3 | #+AUTHOR: lujun9972 4 | #+TAGS: archlinux tools 5 | #+DATE: [2017-11-06 一 12:59] 6 | #+LANGUAGE: zh-CN 7 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 8 | 9 | 10 | 不久前, 我们发布了一片关于如何 [[https://www.ostechnix.com/install-softwares-offline-ubuntu-16-04/][在Ubuntu及其衍生版中离线安装package]] 的文章. 今天我们要来聊聊在Arch Linux上如何实现同样的事情. 11 | 若你拥有大量的Arch Linux系统,通过这种方式可以节省大量的互联网带宽. 你无需重复地通过网络下载package和升级系统. 12 | 只需要升级一台Arch Linux系统 (假设我们称之为主系统或者服务段系统) 然后将下载的更新包分发给其他Arch系统就行了. 13 | 其他系统是否有互联网连接并不重要. 这就是 Packup 的方便之处. 它是一个能让你通过U盘/外置硬盘分享更新的脚本 14 | 其主要目的在于减少互联网带宽的消耗并且让那些离线的系统也能用pacman或pacaur作为包管理器. 15 | 本教程简要描述一下如何通过U盘和外部磁盘将升级包共享给离线的 Arch Linux 系统. 16 | 17 | Packup – A Script To Quickly Share Updates Via USB Drive In Arch Linux 18 | 19 | 为了方便展示, 我们使用两个 Arch Linux 系统, 一个有互联网连接,一个没有互联网连接. 20 | 同时我们还需要一个空间足够U盘或者外置硬盘. 21 | 22 | * 共同的步骤(在两台Arch Linux上都要操作) 23 | 24 | 在所有系统上都安装 =NodeJS=. NodeJS在默认的仓库中就有, 因此你可以使用如下Pacman命令安装. 25 | 26 | #+BEGIN_SRC shell 27 | sudo pacman -S nodejs npm 28 | #+END_SRC 29 | 30 | 如果你想要传输AUR package, 你还需要安装 Pacaur. 具体方法请查看以下链接. 31 | 32 | + [[https://www.ostechnix.com/install-pacaur-arch-linux/][How To Install Pacaur In Arch Linux]] 33 | 34 | * 在线系统上的步骤 35 | 36 | 将U盘或外置硬盘接入在线系统. 切换到U盘挂载目录并克隆 Packup 项目. 37 | 38 | #+BEGIN_SRC shell 39 | cd /run/media/sk/bce5f14a-097a-41c5-88ec-c38e20410182/ 40 | 41 | git clone https://github.com/cookiengineer/packup; 42 | #+END_SRC 43 | 44 | Packup GitHub 仓库内容就会克隆到你的U盘或外置硬盘的一个名为 “Packup” 的目录中. 45 | 46 | 进入 “Packup” 目录: 47 | 48 | #+BEGIN_SRC shell 49 | cd packup/ 50 | #+END_SRC 51 | 52 | 运行下面命令来备份所有本地可用的package以及package索引到U盘中. 53 | 54 | #+BEGIN_SRC shell 55 | ./backup.js; 56 | #+END_SRC 57 | 58 | 根据可用package的数量,这个步骤可能会花一点时间. 59 | 60 | 最后运行命令: 61 | 62 | #+BEGIN_SRC shell 63 | sync; 64 | #+END_SRC 65 | 66 | 在拔出U盘之前,请一定记得运行上面这条命令. 67 | 68 | 现在可以拔出U盘了,然后开始操作离线的系统. 69 | 70 | * 离线系统操作步骤 71 | 72 | 插入U盘,并进入 “Packup” 目录. 这里我把U盘挂载到 /mnt 中. 73 | 74 | #+BEGIN_SRC shell 75 | cd /mnt/packup/ 76 | #+END_SRC 77 | 78 | 下一步,更新pacman的索引信息: 79 | 80 | #+BEGIN_SRC shell 81 | sudo cp ./sync/*.db /var/lib/pacman/sync/; 82 | #+END_SRC 83 | 84 | 然后, 运行下面命令: 85 | 86 | #+BEGIN_SRC shell 87 | ./upgrade.js; 88 | #+END_SRC 89 | 90 | 该命令会现实用于手工从本地更新package的pacman命令(使用pacman -U). 91 | 92 | #+BEGIN_SRC shell 93 | :: Execute this to upgrade from local package cache: 94 | 95 | cd "/run/.../packup"; sudo pacman -U gcc-7.1.1-4-x86_64.pkg.tar.xz gdb-common-8.0-1-x86_64.pkg.tar.xz 96 | #+END_SRC 97 | 98 | 另外, 如果你有缺失的package需要从主系统上下载(在线系统), 它还会现实你需要在另一台机上要执行的命令(使用 “pacman -Sw –cachedir”). 99 | 100 | #+BEGIN_SRC shell 101 | :: Execute this to download upgrades into local package cache: 102 | 103 | cd "/run/.../packup"; sudo pacman -Sw --cachedir "/run/.../packup" geoip ghostscript; 104 | #+END_SRC 105 | 106 | 你可以在在线系统上执行上面输出的命令,就会下载缺失的包,然后在离线系统上再次运行一次更新命令来更新package. 很不错吧! 107 | 108 | 完了之后, 你可以按下面方法清理U盘上的旧package. 109 | 110 | #+BEGIN_SRC shell 111 | cd /path/to/usb/drive/packup/ 112 | 113 | ./clean.js; 114 | 115 | sync; 116 | #+END_SRC 117 | 118 | 在拔出U盘前别忘了运行 “sync” 命令. 119 | 120 | 就是这样. 如你所见, Packup 非常简单, 但却非常有用,值得常备身边. 如果你有很多的 Arch Linux 系统, 这个工具会帮你节省大量的互联网带宽. 121 | 122 | 真赞! 123 | -------------------------------------------------------------------------------- /tools/sosreport in RHEL.org: -------------------------------------------------------------------------------- 1 | #+TITLE: RHEL sosreport简介 2 | #+AUTHOR: lujun9972 3 | #+TAGS: sosreport redhat 4 | #+DATE: [2017-11-14 二 22:02] 5 | #+LANGUAGE: zh-CN 6 | #+OPTIONS: H:6 num:nil toc:t \n:nil ::t |:t ^:nil -:nil f:t *:t <:nil 7 | 8 | #+URL: https://kerneltalks.com/tools/all-you-need-to-know-about-sosreport/ 9 | 10 | sosreport对很多RedHat爱好者来说应该并不陌生! 它是一款在RedHat Linux下帮你收集系统信息打成一个tar包的工具,你可以将这个tar包发给供应商来定位问题. 11 | 12 | 当你给RedHat开个case时, 他们会第一时间找你要 sosreport. 本文中我们会演示如何生成 sosreport 以及如何阅读 sosreport. 13 | 14 | 如果 sosreport 包并未安装,你会看到如下错误: 15 | 16 | #+BEGIN_SRC shell 17 | root@kerneltalks # sosreport 18 | -bash: sosreport: command not found 19 | #+END_SRC 20 | 21 | 使用yum安装 sos 包. 你可以按照 [[https://kerneltalks.com/tools/package-installation-linux-yum-apt/][这里]] 说明的安装步骤来安装. 以下是安装日志供你参考. 22 | 23 | #+BEGIN_SRC shell 24 | root@kerneltalks # yum install sos 25 | Loaded plugins: amazon-id, rhui-lb, search-disabled-repos 26 | Resolving Dependencies 27 | --> Running transaction check 28 | ---> Package sos.noarch 0:3.4-6.el7 will be installed 29 | --> Processing Dependency: bzip2 for package: sos-3.4-6.el7.noarch 30 | --> Running transaction check 31 | ---> Package bzip2.x86_64 0:1.0.6-13.el7 will be installed 32 | --> Finished Dependency Resolution 33 | 34 | Dependencies Resolved 35 | 36 | =================================================================================================================================================== 37 | ===================== 38 | Package Arch Version 39 | Repository Size 40 | =================================================================================================================================================== 41 | ===================== 42 | Installing: 43 | sos noarch 3.4-6.el7 rhui-REGION-rhel-server-releases 44 | 381 k 45 | Installing for dependencies: 46 | bzip2 x86_64 1.0.6-13.el7 rhui-REGION-rhel-server-releases 47 | 52 k 48 | 49 | Transaction Summary 50 | =================================================================================================================================================== 51 | ===================== 52 | Install 1 Package (+1 Dependent package) 53 | 54 | Total download size: 433 k 55 | Installed size: 1.4 M 56 | Is this ok [y/d/N]: y 57 | Downloading packages: 58 | (1/2): sos-3.4-6.el7.noarch.rpm | 59 | 381 kB 00:00:00 60 | (2/2): bzip2-1.0.6-13.el7.x86_64.rpm | 61 | 52 kB 00:00:00 62 | -------------------------------------------------------------------------------------------------------------------------------------------------- 63 | ---------------------- 64 | Total 610 kB/s | 65 | 433 kB 00:00:00 66 | Running transaction check 67 | Running transaction test 68 | Transaction test succeeded 69 | Running transaction 70 | Installing : bzip2-1.0.6-13.el7.x86_64 71 | 1/2 72 | Installing : sos-3.4-6.el7.noarch 73 | 2/2 74 | Verifying : sos-3.4-6.el7.noarch 75 | 1/2 76 | Verifying : bzip2-1.0.6-13.el7.x86_64 77 | 2/2 78 | 79 | Installed: 80 | sos.noarch 0:3.4-6.el7 81 | 82 | Dependency Installed: 83 | bzip2.x86_64 0:1.0.6-13.el7 84 | 85 | Complete! 86 | #+END_SRC 87 | 88 | --------------------------------------------------------------------------------------------------------------------------------------------------- 89 | 90 | * 如何生成 sosreport 91 | 92 | 你只需要运行 =sosreport= 命令就能生成 sosreport 了. 它默认将报告放在 =/var/tmp= 中,因此你需要保证 =/var= 挂载点中有足够的空闲空间. 93 | 94 | 输出文件遵照 =sosreport-name.caseID-yyyymmddhhmmss.tar.xz= 这样的命名规则,其中 – 95 | 96 | 1. name 就是你提供的名称,默认为主机名 97 | 2. caseID 如果你没有提供则为空 98 | 3. 日期格式为 yyyymmdd 99 | 4. 时间格式为 hhmmss 100 | 101 | 这是一个压缩过的tar包. 运行sosreport命令后,它会要你输入名称以及case ID,然后开始执行模块收集所有的系统信息并保存道tar包中. 102 | 103 | #+BEGIN_SRC shell 104 | root@kerneltalks # sosreport 105 | 106 | sosreport (version 3.4) 107 | 108 | This command will collect diagnostic and configuration information from 109 | this Red Hat Enterprise Linux system and installed applications. 110 | 111 | An archive containing the collected information will be generated in 112 | /var/tmp/sos.iNadXY and may be provided to a Red Hat support 113 | representative. 114 | 115 | Any information provided to Red Hat will be treated in accordance with 116 | the published support policies at: 117 | 118 | https://access.redhat.com/support/ 119 | 120 | The generated archive may contain data considered sensitive and its 121 | content should be reviewed by the originating organization before being 122 | passed to any third party. 123 | 124 | No changes will be made to system configuration. 125 | 126 | Press ENTER to continue, or CTRL-C to quit. 127 | 128 | Please enter your first initial and last name [kerneltalks]: Shrikant Lavhate 129 | Please enter the case id that you are generating this report for []: 12345678 130 | 131 | Setting up archive ... 132 | Setting up plugins ... 133 | Running plugins. Please wait ... 134 | 135 | Running 74/74: yum... er... 136 | Creating compressed archive... 137 | 138 | Your sosreport has been generated and saved in: 139 | /var/tmp/sosreport-ShrikantLavhate.12345678-20171105171210.tar.xz 140 | 141 | The checksum is: 502b698f6052964ca1c2d348ea7e67a4 142 | 143 | Please send this file to your support representative. 144 | #+END_SRC 145 | 146 | 147 | 命令还会输出结果文件的验证码. 这有助于对方验证文件的完整性. 148 | 149 | 150 | #+BEGIN_SRC shell 151 | root@kerneltalks # ll /var/tmp/sosreport-ShrikantLavhate.12345678-20171105171210.tar.xz 152 | -rw-------. 1 root root 8519732 Nov 5 17:12 /var/tmp/sosreport-ShrikantLavhate.12345678-20171105171210.tar.xz 153 | #+END_SRC 154 | 155 | 156 | 157 | * 如何阅读 sosreport 158 | 159 | 生成的报告是一个tar包. 你可以可以自己 [[https://kerneltalks.com/commands/how-create-tar-file-linux-unix/][un-tar]]  这个tar包,然后自己阅读里面的内容. 160 | 161 | 162 | #+BEGIN_SRC shell 163 | root@kerneltalks # tar xvf /var/tmp/sosreport-ShrikantLavhate.12345678-20171105171210.tar.xz 164 | #+END_SRC 165 | 166 | 167 | 解压tar包后,你会看到一个以tar包同名的目录. 其中有好多文件和子目录. 168 | 169 | #+BEGIN_SRC shell 170 | root@kerneltalks # ls -lrt sosreport-ShrikantLavhate.12345678-20171105171210 171 | total 16 172 | drwxr-xr-x. 5 root root 42 Jul 11 15:57 usr 173 | dr-xr-xr-x. 3 root root 19 Jul 11 16:07 boot 174 | dr-xr-xr-x. 10 root root 4096 Nov 5 12:19 proc 175 | dr-xr-xr-x. 10 root root 112 Nov 5 12:19 sys 176 | drwxr-xr-x. 4 root root 28 Nov 5 12:19 var 177 | drwxr-xr-x. 2 root root 18 Nov 5 12:19 dev 178 | dr-xr-xr-x. 7 root root 78 Nov 5 12:24 lib 179 | dr-xr-x---. 2 root root 29 Nov 5 16:23 root 180 | drwxr-xr-x. 34 root root 4096 Nov 5 17:08 etc 181 | lrwxrwxrwx. 1 root root 29 Nov 5 17:12 mount -> sos_commands/filesys/mount_-l 182 | lrwxrwxrwx. 1 root root 27 Nov 5 17:12 df -> sos_commands/filesys/df_-al 183 | lrwxrwxrwx. 1 root root 27 Nov 5 17:12 uptime -> sos_commands/general/uptime 184 | lrwxrwxrwx. 1 root root 28 Nov 5 17:12 uname -> sos_commands/kernel/uname_-a 185 | drwx------. 3 root root 18 Nov 5 17:12 sos_strings 186 | lrwxrwxrwx. 1 root root 25 Nov 5 17:12 lsmod -> sos_commands/kernel/lsmod 187 | lrwxrwxrwx. 1 root root 45 Nov 5 17:12 java -> sos_commands/java/alternatives_--display_java 188 | lrwxrwxrwx. 1 root root 29 Nov 5 17:12 hostname -> sos_commands/general/hostname 189 | lrwxrwxrwx. 1 root root 31 Nov 5 17:12 dmidecode -> sos_commands/hardware/dmidecode 190 | lrwxrwxrwx. 1 root root 25 Nov 5 17:12 date -> sos_commands/general/date 191 | lrwxrwxrwx. 1 root root 32 Nov 5 17:12 route -> sos_commands/networking/route_-n 192 | lrwxrwxrwx. 1 root root 30 Nov 5 17:12 ps -> sos_commands/process/ps_auxwww 193 | lrwxrwxrwx. 1 root root 41 Nov 5 17:12 netstat -> sos_commands/networking/netstat_-W_-neopa 194 | lrwxrwxrwx. 1 root root 22 Nov 5 17:12 last -> sos_commands/last/last 195 | lrwxrwxrwx. 1 root root 34 Nov 5 17:12 ip_addr -> sos_commands/networking/ip_-o_addr 196 | lrwxrwxrwx. 1 root root 24 Nov 5 17:12 free -> sos_commands/memory/free 197 | lrwxrwxrwx. 1 root root 130 Nov 5 17:12 installed-rpms -> sos_commands/rpm/sh_-c_rpm_--nodigest_-qa_--qf_NAME_-_VERSION_-_RELEASE_ 198 | ._ARCH_INSTALLTIME_date_awk_-F_printf_-59s_s_n_1_2_sort_-f 199 | lrwxrwxrwx. 1 root root 38 Nov 5 17:12 chkconfig -> sos_commands/services/chkconfig_--list 200 | -rw-r--r--. 1 root root 1481 Nov 5 17:12 version.txt 201 | drwx------. 2 root root 37 Nov 5 17:12 sos_reports 202 | drwx------. 2 root root 35 Nov 5 17:12 sos_logs 203 | drwx------. 43 root root 4096 Nov 5 17:12 sos_commands 204 | drwxr-xr-x. 3 root root 19 Nov 5 17:12 run 205 | #+END_SRC 206 | 207 | 在 =sos_reports= 目录中你会看到 =sos.txt= 和 =sos.html= 文件. 208 | 209 | 在 =sos.txt= 文件中,你可以看到所有加载了的插件,执行过的命令,被sosreport拷贝的文件. 在 =sos.html= 文件中所有这些内容都通过超链接连接到目录中的原始内容. 210 | 这样你可以你可以直接查看脚本命令的输出结果和拷贝过的文件. 211 | 212 | sosreport 探测到的任何警告都会在这些文件的开始位置高亮显示出来. 213 | 214 | 本文基于3.4版的 sosreport. 如果你的版本不同,那么可能信息会有少许的差异. 215 | --------------------------------------------------------------------------------