Merge pull request #11 from LCTT/master

Update from LCTT
This commit is contained in:
perfiffer 2021-08-24 23:30:25 +08:00 committed by GitHub
commit fa8f25ef46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 1789 additions and 1061 deletions

View File

@ -0,0 +1,130 @@
[#]: subject: "Access OpenVPN from a client computer"
[#]: via: "https://opensource.com/article/21/7/openvpn-client"
[#]: author: "D. Greg Scott https://opensource.com/users/greg-scott"
[#]: collector: "lujun9972"
[#]: translator: "perfiffer"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-13714-1.html"
如何在免费 WiFi 中保护隐私(四)
======
> 在 Linux 上安装好“虚拟专用网络” 之后,是时候使用它了。
![](https://img.linux.net.cn/data/attachment/album/202108/24/101214ng2afee2gmefgj5z.jpg)
0penVPN 在两点之间创建了一个加密通道,以阻止第三方访问你的网络流量数据。通过设置你的 “虚拟专用网络” 服务,你可以成为你自己的 “虚拟专用网络” 服务商。许多流行的 “虚拟专用网络” 服务都使用 0penVPN所以当你可以掌控自己的网络时为什么还要将你的网络连接绑定到特定的提供商呢
本系列的 [第一篇文章][3] 安装了一个“虚拟专用网络” 的服务器,[第二篇文章][4] 介绍了如何安装和配置一个 0penVPN 服务软件,[第三篇文章][5] 解释了如何配置防火墙并启动你的 0penVPN 服务。第四篇也是最后一篇文章将演示如何从客户端计算机使用你的 0penVPN 服务器。这就是你做了前三篇文章中所有工作的原因!
### 创建客户端证书
请记住0penVPN 的身份验证方法要求服务器和客户端都拥有某些东西(证书)并知道某些东西(口令)。是时候设置它了。
首先,为你的客户端计算机创建一个客户端证书和一个私钥。在你的 0penVPN 服务器上,生成证书请求。它会要求你输入密码;确保你记住它:
```
$ cd /etc/openvpn/ca
$ sudo /etc/openvpn/easy-rsa/easyrsa \
gen-req greglaptop
```
本例中,`greglaptop` 是创建证书的客户端计算机主机名。
无需将请求导入证书颁发机构CA因为它已经存在。审查它以确保请求存在
```
$ cd /etc/openvpn/ca
$ /etc/openvpn/easy-rsa/easyrsa \
show-req greglaptop
```
你也可以以客户端身份签署请求:
```
$ /etc/openvpn/easy-rsa/easyrsa \
sign-req client greglaptop
```
### 安装 0penVPN 客户端软件
在 Linux 系统上,网络管理器可能已经包含了一个 0penVPN 客户端。如果没有,你可以安装插件:
```
$ sudo dnf install NetworkManager-openvpn
```
在 Windows 系统上,你必须从 0penVPN 下载网页下载和安装 0penVPN 客户端。启动安装程序并按照提示操作。
### 复制证书和私钥到客户端
现在你的客户端需要你为其生成的身份验证凭据。你在服务器上生成了这些,因此你必须将它们传输到你的客户端。我推荐使用 SSH 来完成传输。在 Linux 系统上,通过 `scp` 命令实现。在 Windows 系统上,你可以以管理员身份运行 [WinSCP][6] 来推送证书和密钥。
假设客户端名称为 `greglaptop`,那么证书和私钥的文件名以及服务的位置如下:
```
/etc/openvpn/ca/pki/issued/greglaptop.crt
/etc/openvpn/ca/pki/private/greglaptop.key
/etc/openvpn/ca/pki/issued/ca.crt
```
在 Linux 系统上,复制这些文件到 `/etc/pki/tls/certs` 目录。在 Windows 系统上,复制它们到 `C:\Program Files\OpenVPN\config` 目录。
### 复制和自定义客户端配置文件
在 Linux 系统上,你可以复制服务器上的 `/etc/openvpn/client/OVPNclient2020.ovpn` 文件到 `/etc/NetworkManager/system-connections/` 目录,或者你也可以导航到系统设置中的网络管理器添加一个“虚拟专用网络” 连接。
连接类型选择“<ruby>证书TLS<rt>Certificates(TLS)</rt></ruby>”。告知网络管理器你从服务器上复制的证书和密钥。
![VPN displayed in Network Manager][7]
在 Windows 系统上,以管理员身份运行 WinSCP将服务器上的客户端配置模板 `/etc/openvpn/client/OVPNclient2020.ovpn` 文件复制到客户端上的 `C:\Program Files\OpenVPN\config` 目录。然后:
* 重命名它以匹配上面的证书。
* 更改 CA 证书、客户端证书和密钥的名称以匹配上面从服务器复制的名称。
* 修改 IP 信息,以匹配你的网络。
你需要超级管理员权限来编辑客户端配置文件。最简单的方式就是以管理员身份启动一个 CMD 窗口,然后从管理员 CMD 窗口启动记事本来编辑此文件。
### 将你的客户端连接到服务器
在 Linux 系统上,网络管理器会显示你的 “虚拟专用网络” 连接。选择它进行连接。
![Add a connection in Network Manager][9]
在 Windows 系统上,启动 0penVPN 图形用户界面。它会在任务栏右侧的 Windows 系统托盘中生成一个图标,通常位于 Windows 桌面的右下角。右键单击图标以连接、断开连接或查看状态。
对于第一次连接,编辑客户端配置文件的 `remote` 行以使用 0penVPN 服务器的内部 IP 地址。通过右键单击 Windows 系统托盘中的 0penVPN 图标并单击“<ruby>连接<rt>Connect</rt></ruby>”,从办公室网络内部连接到服务器。调试此连接,这应该可以找到并解决问题,而不会出现任何防火墙问题,因为客户端和服务器都在防火墙的同一侧。
接下来,编辑客户端配置文件的 `remote` 行以使用 0penVPN 服务器的公共 IP 地址。将 Windows 客户端连接到外部网络并进行连接。调试有可能的问题。
### 安全连接
恭喜!你已经为其他客户端系统准备好了 0penVPN 网络。对其余客户端重复设置步骤。你甚至可以使用 Ansible 来分发证书和密钥并使其保持最新。
本文基于 D.Greg Scott 的 [博客][10],经许可后重新使用。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/openvpn-client
作者:[D. Greg Scott][a]
选题:[lujun9972][b]
译者:[perfiffer](https://github.com/perfiffer)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/greg-scott
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop-music-headphones.png?itok=EQZ2WKzy (Woman programming)
[2]: https://openvpn.net/
[3]: https://linux.cn/article-13680-1.html
[4]: https://linux.cn/article-13702-1.html
[5]: https://linux.cn/article-13707-1.html
[6]: https://winscp.net/eng/index.php
[7]: https://opensource.com/sites/default/files/uploads/network-manager-profile.jpg (VPN displayed in Network Manager)
[8]: https://creativecommons.org/licenses/by-sa/4.0/
[9]: https://opensource.com/sites/default/files/uploads/network-manager-connect.jpg (Add a“虚拟专用网络” connection in Network Manager)
[10]: https://www.dgregscott.com/how-to-build-a-vpn-in-four-easy-steps-without-spending-one-penny/

View File

@ -0,0 +1,188 @@
[#]: subject: "Monitor your Linux system in your terminal with procps-ng"
[#]: via: "https://opensource.com/article/21/8/linux-procps-ng"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-13713-1.html"
在终端监控你的 Linux 系统
======
> 如何找到一个程序的进程 IDPID。最常见的 Linux 工具是由 procps-ng 包提供的,包括 `ps`、`pstree`、`pidof` 和 `pgrep` 命令。
![](https://img.linux.net.cn/data/attachment/album/202108/24/092948gyyv6nvbn77x7y6o.jpg)
在 [POSIX][2] 术语中,<ruby>进程<rt>process</rt></ruby>是一个正在进行的事件,由操作系统的内核管理。当你启动一个应用时就会产生一个进程,尽管还有许多其他的进程在你的计算机后台运行,包括保持系统时间准确的程序、监测新的文件系统、索引文件,等等。
大多数操作系统都有某种类型的系统活动监视器因此你可以了解在任何特定时刻有哪些进程在运行。Linux 有一些供你选择,包括 GNOME 系统监视器和 KSysGuard。这两个软件在桌面环境都很有用但 Linux 也提供了在终端监控系统的能力。不管你选择哪一种,对于那些积极管理自己电脑的人来说,检查一个特定的进程是一项常见的任务。
在这篇文章中,我演示了如何找到一个程序的进程 IDPID。最常见的工具是由 [procps-ng][3] 包提供的,包括 `ps`、`pstree`、`pidof` 和 `pgrep` 命令。
### 查找一个正在运行的程序的 PID
有时你想得到一个你知道正在运行的特定程序的进程 IDPID。`pidof` 和 `pgrep` 命令可以通过命令名称查找进程。
`pidof` 命令返回一个命令的 PID它按名称搜索确切的命令
```
$ pidof bash
1776 5736
```
`pgrep` 命令允许使用正则表达式:
```
$ pgrep .sh
1605
1679
1688
1776
2333
5736
$ pgrep bash
5736
```
### 通过文件查找 PID
你可以用 `fuser` 命令找到使用特定文件的进程的 PID。
```
$ fuser --user ~/example.txt
/home/tux/example.txt: 3234(tux)
```
### 通过 PID 获得进程名称
如果你有一个进程的 PID 编号,但没有生成它的命令,你可以用 `ps` 做一个“反向查找”:
```
$ ps 3234
PID TTY STAT TIME COMMAND
5736 pts/1 Ss 0:00 emacs
```
### 列出所有进程
`ps` 命令列出进程。你可以用 `-e` 选项列出你系统上的每一个进程:
```
PID TTY TIME CMD
1 ? 00:00:03 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
6 ? 00:00:00 kworker/0:0H-events_highpri
[...]
5648 ? 00:00:00 gnome-control-c
5656 ? 00:00:00 gnome-terminal-
5736 pts/1 00:00:00 bash
5791 pts/1 00:00:00 ps
5792 pts/1 00:00:00 less
(END)
```
### 只列出你的进程
`ps -e` 的输出可能会让人不知所措,所以使用 `-U` 来查看一个用户的进程:
```
$ ps -U tux | less
PID TTY TIME CMD
3545 ? 00:00:00 systemd
3548 ? 00:00:00 (sd-pam)
3566 ? 00:00:18 pulseaudio
3570 ? 00:00:00 gnome-keyring-d
3583 ? 00:00:00 dbus-daemon
3589 tty2 00:00:00 gdm-wayland-ses
3592 tty2 00:00:00 gnome-session-b
3613 ? 00:00:00 gvfsd
3618 ? 00:00:00 gvfsd-fuse
3665 tty2 00:01:03 gnome-shell
[...]
```
这样就减少了 200 个(可能是 100 个,取决于你运行的系统)需要分类的进程。
你可以用 `pstree` 命令以不同的格式查看同样的输出:
```
$ pstree -U tux -u --show-pids
[...]
├─gvfsd-metadata(3921)─┬─{gvfsd-metadata}(3923)
│ └─{gvfsd-metadata}(3924)
├─ibus-portal(3836)─┬─{ibus-portal}(3840)
│ └─{ibus-portal}(3842)
├─obexd(5214)
├─pulseaudio(3566)─┬─{pulseaudio}(3640)
│ ├─{pulseaudio}(3649)
│ └─{pulseaudio}(5258)
├─tracker-store(4150)─┬─{tracker-store}(4153)
│ ├─{tracker-store}(4154)
│ ├─{tracker-store}(4157)
│ └─{tracker-store}(4178)
└─xdg-permission-(3847)─┬─{xdg-permission-}(3848)
└─{xdg-permission-}(3850)
```
### 列出进程的上下文
你可以用 `-u` 选项查看你拥有的所有进程的额外上下文。
```
$ ps -U tux -u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
tux 3545 0.0 0.0 89656 9708 ? Ss 13:59 0:00 /usr/lib/systemd/systemd --user
tux 3548 0.0 0.0 171416 5288 ? S 13:59 0:00 (sd-pam)
tux 3566 0.9 0.1 1722212 17352 ? S<sl 13:59 0:29 /usr/bin/pulseaudio [...]
tux 3570 0.0 0.0 664736 8036 ? SLl 13:59 0:00 /usr/bin/gnome-keyring-daemon [...]
[...]
tux 5736 0.0 0.0 235628 6036 pts/1 Ss 14:18 0:00 bash
tux 6227 0.0 0.4 2816872 74512 tty2 Sl+14:30 0:00 /opt/firefox/firefox-bin [...]
tux 6660 0.0 0.0 268524 3996 pts/1 R+ 14:50 0:00 ps -U tux -u
tux 6661 0.0 0.0 219468 2460 pts/1 S+ 14:50 0:00 less
```
### 用 PID 排除故障
如果你在某个特定的程序上有问题,或者你只是好奇某个程序在你的系统上还使用了什么资源,你可以用 `pmap` 查看运行中的进程的内存图。
```
$ pmap 1776
5736: bash
000055f9060ec000 1056K r-x-- bash
000055f9063f3000 16K r---- bash
000055f906400000 40K rw--- [ anon ]
00007faf0fa67000 9040K r--s- passwd
00007faf1033b000 40K r-x-- libnss_sss.so.2
00007faf10345000 2044K ----- libnss_sss.so.2
00007faf10545000 4K rw--- libnss_sss.so.2
00007faf10546000 212692K r---- locale-archive
00007faf1d4fb000 1776K r-x-- libc-2.28.so
00007faf1d6b7000 2044K ----- libc-2.28.so
00007faf1d8ba000 8K rw--- libc-2.28.so
[...]
```
### 处理进程 ID
procps-ng 软件包有你需要的所有命令,以调查和监控你的系统在任何时候的使用情况。无论你是对 Linux 系统中各个分散的部分如何结合在一起感到好奇,还是要对一个错误进行调查,或者你想优化你的计算机的性能,学习这些命令都会为你了解你的操作系统提供一个重要的优势。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/linux-procps-ng
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/system-monitor-splash.png?itok=0UqsjuBQ (System monitor)
[2]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
[3]: https://gitlab.com/procps-ng

View File

@ -0,0 +1,161 @@
[#]: subject: "Schedule a task with the Linux at command"
[#]: via: "https://opensource.com/article/21/8/linux-at-command"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-13710-1.html"
用 Linux 的 at 命令来安排一个任务
======
> at 命令是一种在特定时间和日期安排一次性任务的 Linux 终端方法。
![](https://img.linux.net.cn/data/attachment/album/202108/23/144542rmmyzwxsnanm4wpj.jpg)
计算机擅长 [自动化][2],但不是每个人都知道如何使自动化工作。不过,能够在特定的时间为电脑安排一个任务,然后忘记它,这确实是一种享受。也许你有一个文件要在特定的时间上传或下载,或者你需要处理一批还不存在但可以保证在某个时间存在的文件,或者需要监控设置,或者你只是需要一个友好的提醒,在下班回家的路上买上面包和黄油。
这就是 `at` 命令的用处。
### 什么是 Linux at 命令?
`at` 命令是在 Linux 终端让你在特定时间和日期安排一次性工作的方法。它是一种自发的自动化,在终端上很容易实现。
### 安装 at
在 Linux 上,`at` 命令可能已经安装了。你可以使用 `at -V` 命令来验证它是否已经安装。只要返回一个版本号,就说明你已经安装了 `at`
```
$ at -V
at version x.y.z
```
如果你试图使用 `at`,但没有找到该命令,大多数现代的 Linux 发行版会为你提供缺少的 `at` 软件包。
你可能还需要启动 `at` 守护程序,称为 `atd`。在大多数 Linux 系统中,你可以使用 `systemctl` 命令来启用该服务,并将它们设置为从现在开始自动启动:
```
$ sudo systemctl enable --now atd
```
### 用 at 交互式地安排一个作业
当你使用 `at` 命令并加上你希望任务运行的时间,会打开一个交互式 `at` 提示符。你可以输入你想在指定时间运行的命令。
做个比喻,你可以把这个过程看作是一个日历应用,就像你在你的手机上使用的那样。首先,你在某一天的某个时间创建一个事件,然后指定你想要发生什么。
例如,可以试试创建一个未来几分钟的任务,来给自己计划一个备忘录。这里运行一个简单的任务,以减少失败的可能性。要退出 `at` 提示符,请按键盘上的 `Ctrl+D`
```
$ at 11:20 AM
warning: commands will be executed using /bin/sh
at> echo "hello world" > ~/at-test.txt
at> <EOT>
job 3 at Mon Jul 26 11:20:00 2021
```
正如你所看到的,`at` 使用直观和自然的时间定义。你不需要用 24 小时制的时钟,也不需要把时间翻译成 UTC 或特定的 ISO 格式。一般来说,你可以使用你自然想到的任何符号,如 `noon`、`1:30 PM`、`13:37` 等等,来描述你希望一个任务发生的时间。
等待几分钟,然后在你创建的文件上运行 `cat` 或者 `tac` 命令,验证你的任务是否已经运行:
```
$ cat ~/at-test.txt
hello world
```
### 用 at 安排一个任务
你不必使用 `at` 交互式提示符来安排任务。你可以使用 `echo``printf` 向它传送命令。在这个例子中,我使用了 `now` 符号,以及我希望任务从现在开始延迟多少分钟:
```
$ echo "echo 'hello again' >> ~/at-test.txt" | at now +1 minute
```
一分钟后,验证新的命令是否已被执行:
```
$ cat ~/at-test.txt
hello world
hello again
```
### 时间表达式
`at` 命令在解释时间时是非常宽容的。你可以在许多格式中选择,这取决于哪一种对你来说最方便:
* `YYMMDDhhmm[.ss]`(两位的年份、月、日、小时、分钟,及可选的秒)
* `CCYYMMDDhhmm[.ss]`(四位的年份、月、日、时、分钟,及可选的秒)
* `now`(现在)
* `midnight`(午夜 00:00
* `noon`(中午 12:00
* `teatime`(下午 16 点)
* `AM`(上午)
* `PM`(下午)
时间和日期可以是绝对时间,也可以加一个加号(`+`),使其与 `now` 相对。当指定相对时间时,你可以使用你可能用过的词语:
* `minutes`(分钟)
* `hours`(小时)
* `days`(天)
* `weeks`(星期)
* `months`(月)
* `years`(年)
### 时间和日期语法
`at` 命令对时间的输入相比日期不那么宽容。时间必须放在第一位,接着是日期,尽管日期默认为当前日期,并且只有在为未来某天安排任务时才需要。
这些是一些有效表达式的例子:
```
$ echo "rsync -av /home/tux me@myserver:/home/tux/" | at 3:30 AM tomorrow
$ echo "/opt/batch.sh ~/Pictures" | at 3:30 AM 08/01/2022
$ echo "echo hello" | at now + 3 days
```
### 查看你的 at 队列
当你爱上了 `at`,并且正在安排任务,而不是在桌子上的废纸上乱写乱画,你可能想查看一下你是否有任务还在队列中。
要查看你的 `at` 队列,使用 `atq` 命令:
```
$ atq
10 Thu Jul 29 12:19:00 2021 a tux
9 Tue Jul 27 03:30:00 2021 a tux
7 Tue Jul 27 00:00:00 2021 a tux
```
要从队列中删除一个任务,使用 `atrm` 命令和任务号。例如,要删除任务 7
```
$ atrm 7
$ atq
10 Thu Jul 29 12:19:00 2021 a tux
9 Tue Jul 27 03:30:00 2021 a tux
```
要看一个计划中的任务的实际内容,你需要查看 `/var/spool/at` 下的内容。只有 root 用户可以查看该目录的内容,所以你必须使用 `sudo` 来查看或 `cat` 任何任务的内容。
### 用 Linux at 安排任务
`at` 系统是一个很好的方法,可以避免忘记在一天中晚些时候运行一个作业,或者在你离开时让你的计算机为你运行一个作业。与 `cron` 不同的是,它不像 `cron` 那样要求任务必须从现在起一直按计划运行到永远,因此它的语法比 `cron` 简单得多。
等下次你有一个希望你的计算机记住并管理它的小任务,试试 `at` 命令。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/linux-at-command
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_todo_clock_time_team.png?itok=1z528Q0y (Team checklist)
[2]: https://opensource.com/article/20/11/orchestration-vs-automation

View File

@ -0,0 +1,126 @@
[#]: subject: "Linux Phones: Here are Your Options"
[#]: via: "https://itsfoss.com/linux-phones/"
[#]: author: "Ankush Das https://itsfoss.com/author/ankush/"
[#]: collector: "lujun9972"
[#]: translator: "wxy"
[#]: reviewer: "wxy"
[#]: publisher: "wxy"
[#]: url: "https://linux.cn/article-13711-1.html"
如何选择一台 Linux 手机
======
![](https://img.linux.net.cn/data/attachment/album/202108/23/155159e5s33xo63tz5jddz.jpg)
> 未来取代安卓或 iOS 的可能是 Linux 手机,但如今,有哪些选择可以尝试一下呢?
虽然安卓是基于 Linux 内核的,但它经过了大量修改。因此,这意味着它不是一个完全意义上的基于 Linux 的操作系统。
谷歌正在努力使安卓内核更接近主线 Linux 内核,但这仍然是一个遥远的梦想。
那么,在这种情况下,如果你正在寻找一款 Linux 手机、一款由 Linux 操作系统驱动的智能手机,有哪些可以选择呢?
这并不是一个容易做出的决定,因为你的选择非常有限。因此,我试图推荐一些最好的、不同于主流选择的 Linux 手机。
### 如今你可以使用的顶级 Linux 手机
值得注意的是,这里提到的 Linux 手机或许无法取代你的安卓或 iOS 设备。因此,在做出购买决定之前,请确保你做了一些背景研究。
**注意:** 你需要仔细检查这些 Linux 手机是否可以购买到、预期的发货日期和使用风险。它们大多数只适合于发烧友或早期试用者。
#### 1、PinePhone
![][1]
[PinePhone][2] 是最有性价比和最受欢迎的选择之一,我觉得它是一个有前途的 Linux 手机。
它并不局限于单一的操作系统。你可以尝试使用带有 Plasma mobile OS 的 Manjaro、UBports、Sailfish OS 等系统。PinePhone 的配置不错,它包括一个四核处理器和 2G 或3G 的内存。它支持使用可启动的 microSD 卡来帮助你安装系统,还可选 16/32GB eMMC 存储。
其显示屏是一个基本的 1440×720p IPS 屏幕。你还可以得到特殊的隐私保护,如蓝牙、麦克风和摄像头的断路开关。
PinePhone 还为你提供了使用六个可用的 pogo 引脚添加自定义的硬件扩展的方式。
其基本版2GB 内存和 16GB 存储)默认加载了 Manjaro价格为 149 美元而融合版3GB 内存和 32GB 存储)价格为 199 美元。
#### 2、Fairphone
![][3]
与这个清单上的其他选择相比,[Fairphone][6] 在商业上是成功的。它不是一款 Linux 智能手机,但它具有定制版的安卓系统,即 Fairphone OS并且可以选择 [开源安卓系统替代品][5] 之一 [/e/ OS][4]。如果你想使用 Linux 操作系统,也有一些社区移植版本,但可能有点碰运气。
Fairphone 有两个不同的版本,提供了一些不错的配置规格。你会发现 Fairphone 3+ 有一个 4800 万像素的相机传感器和一个全高清显示屏。另外,你还会发现先进的高通处理器为该设备提供了动力。
他们专注于制造可持续发展的智能手机,并使用了一定量的回收塑料制造。这也为了方便维修。
因此,它不仅是一个非主流智能手机的选择,而且如果你选择了它,你也将为保护环境出了力。
### 3、Librem 5
![][7]
[Librem 5][9] 是一款非常注重用户隐私的智能手机,同时它采用了开源的操作系统,即 PureOS并非基于安卓。
它所提供的配置规格还不错,有 3GB 内存和四核 Cortex A53 芯片组。但是,这无法与主流选择相竞争。因此,你可能不会觉得它物美价廉。
它的目标是那些对尊重隐私的智能手机感兴趣的发烧友。
与其他产品类似Librem 5 也专注于通过提供用户可更换的电池使手机易于维修。
在隐私方面,你会注意到有蓝牙、相机和麦克风的断路开关。他们还承诺了未来几年的安全更新。
### 4、Pro 1X
![][10]
[Pro 1X][11] 是一款有趣的智能手机,同时支持 Ubuntu Touch、Lineage OS 和安卓。
它不仅是一款 Linux 智能手机,而且是一款带有独立 QWERTY 键盘的手机,这在现在是很罕见的。
Pro 1 X 的配置规格不错,包括了一个骁龙 662 处理器和 6GB 内存。它还带有一块不错的 AMOLED 全高清显示屏。
它的相机不是特别强大,但在大多数情况下应该是足够了。
### 5、Volla Phone
![][12]
[Volla Phone][13] 是一个有吸引力的产品,运行在 UBports 的 Ubuntu Touch。
它配备了预制的 “虚拟专用网络” ,并专注于简化用户体验。它的操作系统是定制的,因此,可以快速访问所有重要的东西,而无需自己组织。
它的配置规格令人印象深刻,包括了一个八核联发科处理器和 4700 毫安时的电池。你会得到类似于一些最新的智能手机上的设计。
### 总结
Linux 智能手机不是到处都能买到的,当然也还不适合大众使用。
因此,如果你是一个发烧友,或者想支持这种手机的发展,你可以考虑购买一台。
你已经拥有一台这种智能手机了吗?请不要犹豫,在下面的评论中分享你的经验。
--------------------------------------------------------------------------------
via: https://itsfoss.com/linux-phones/
作者:[Ankush Das][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/ankush/
[b]: https://github.com/lujun9972
[1]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/PinePhone-3.jpg?resize=800%2C800&ssl=1
[2]: https://www.pine64.org/pinephone/
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/08/fairphone.png?resize=360%2C600&ssl=1
[4]: https://itsfoss.com/e-os-review/
[5]: https://itsfoss.com/open-source-alternatives-android/
[6]: https://shop.fairphone.com/en/
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/08/librem-5.png?resize=800%2C450&ssl=1
[8]: https://itsfoss.com/librem-linux-phone/
[9]: https://puri.sm/products/librem-5/
[10]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/08/pro1x.jpg?resize=800%2C542&ssl=1
[11]: https://www.fxtec.com/pro1x
[12]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/08/volla-smartphone.jpg?resize=695%2C391&ssl=1
[13]: https://www.indiegogo.com/projects/volla-phone-free-your-mind-protect-your-privacy#/

View File

@ -0,0 +1,118 @@
[#]: subject: "KDE Plasma 5.23 New Features and Release Dates"
[#]: via: "https://www.debugpoint.com/2021/08/kde-plasma-5-23/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
KDE Plasma 5.23 New Features and Release Dates
======
We round up the features of KDE Plasma 5.23 (upcoming) in this post,
with major highlights and download/testing instructions.
KDE Plasma desktop is the most popular and top class Linux desktop environment today. The main reason is adaptation, rapid iteration of its development, performance improvements. Since the release of [KDE Plasma 5.22][1], the team is busy with merging changes and testing new features for upcoming KDE Plasma 5.23. It is currently under development with a tentative schedule as below.
### KDE Plasma 5.23 Schedule
KDE Plasma releases on Oct 7, 2021. Heres the overall schedule:
* Beta Sep 16, 2021
* Final Release Oct 7, 2021
Like every Plasma release, this iteration also promises a wide range of changes to core Plasma Shell, KDE Applications, code cleanups, performance improvements, hundreds of bug fixes, Wayland improvements and more. We collected some important features in this post to give you an idea on whats incoming. Lets take a look.
### KDE Plasma 5.23 New Features
* This release is powered by Qt version 5.15, KDE Frameworks version 5.86.
##### Plasma Shell and App Updates
* The KDE Plasma Kickoff brings a huge set of updates that includes bug fixes, low RAM usage, look and feel updates, keyboard and mouse navigation improvements.
* Kickoff menu can be set to keep open using a pin option.
* Kickoff tabs not changes (from Applications to Places) when you scroll.
* Press CTRL+F to directly focus to the search bar in Kickoff.
* The action button captions in Kickoff (shut down, etc.) can be turned off via an option to show only icons.
* You can now either choose list or grid view for all Kickoff items (not only Favorites).
![New Kickoff Options in KDE Plasma 5.23][2]
![Changes in kickoff][3]
* A new QML-based Overview effect is introduced (much like GNOME 3.38 workspace view) which shows the opened windows (have a look at this video). I could not find the merge request no for this for further detail, and its still not in unstable.
_Video credit: KDE team_
* This overview effect may replace the existing Present Windows effect and the Desktop Grid effect as well (planned).
* A more visible No Touchpad found message is introduced when there is no touchpad.
* You can now have the Power Profile settings in Plasma UI (Battery and Brightness window). This power profile features landed since Linux Kernel 5.12 for Dell and Lenovo laptops. So, if you have the latest brands of these Laptops, you can now set your power profiles either more performance mode or power saving mode. _[Note: Fedora 35 expected to bring this feature for GNOME 41 (probably)]_
![New power profiles][4]
* If you have multiscreen setup with say vertical and landscape screen, then the login screen now properly synced and aligned. This was much needed features.
* A new Breeze theme is expected with style updates.
* A brand-new wallpaper is expected, like prior releases (the competition is still going on).
* A new setting to resize system tray icons when your hardware is changed from Laptop mode to Tablet mode.
* You can now have the ability to choose Bluetooth status on login always enabled, always disabled, or remember the previous status. This status ca be carried over the version upgrades.
* Users can now change the displayed name of sensors on a per-face basis.
* The scrollbar handle in Breeze style is now a little thicker than previous editions.
* A new option in Dolphin file manager enables you to show hidden files first before folders.
* You can delete selected items in clipboard popup using DEL key.
* KDE now enables you to contribute to store.kde.org with your designed icons, themes directly from the Plasma desktop.
##### Wayland Updates
* When you launch applications, the cursor now shows the animated icon feedback in Wayland sessions.
* Copying text from notification now works.
* Middle click paste now works in Wayland and XWayland applications.
Remember, there are hundreds of bug fixes, improvements that lands in each release. These are merely scratching the surface which I collected. So, make sure to visit GitLab or KDE Planets to learn more in detail about changes in applications and Plasma shell.
### Unstable Edition Download
You can experience all the above features right now via KDE Neon Unstable edition via below link. Download the .iso and test. Make sure to report bugs if you found any. This unstable edition is not for serious usage or production deployments.
[KDE NEON UNSTABLE EDITION][5]
### Closing Notes
KDE Plasma 5.23 keeps improving under the hood with new features in every release. Although, this release is not going to be a massive one, but all these optimizations, improvements eventually sums up to the stability, adaptation and better user experience. And more Wayland updates (seriously, Wayland compatibility always seems “work in progress” like for a decade now. Thats another topic for discussion).
Cheers.
* * *
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/2021/08/kde-plasma-5-23/
作者:[Arindam][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lujun9972
[1]: https://www.debugpoint.com/2021/06/kde-plasma-5-22-release/
[2]: https://www.debugpoint.com/blog/wp-content/uploads/2021/08/New-Kickoff-Options-in-KDE-Plasma-5.23.jpeg
[3]: https://www.debugpoint.com/blog/wp-content/uploads/2021/08/Changes-in-kickoff.jpeg
[4]: https://www.debugpoint.com/blog/wp-content/uploads/2021/08/New-power-profiles.jpeg
[5]: https://neon.kde.org/download

View File

@ -1,177 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (fisherue )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (5 ways to improve your Bash scripts)
[#]: via: (https://opensource.com/article/20/1/improve-bash-scripts)
[#]: author: (Alan Formy-Duval https://opensource.com/users/alanfdoss)
5 ways to improve your Bash scripts
======
Find out how Bash can help you tackle the most challenging tasks.
![A person working.][1]
A system admin often writes Bash scripts, some short and some quite lengthy, to accomplish various tasks.
Have you ever looked at an installation script provided by a software vendor? They often add a lot of functions and logic in order to ensure that the installation works properly and doesnt result in damage to the customers system. Over the years, Ive amassed a collection of various techniques for enhancing my Bash scripts, and Id like to share some of them in hopes they can help others. Here is a collection of small scripts created to illustrate these simple examples.
### Starting out
When I was starting out, my Bash scripts were nothing more than a series of commands, usually meant to save time with standard shell operations like deploying web content. One such task was extracting static content into the home directory of an Apache web server. My script went something like this:
```
cp january_schedule.tar.gz /usr/apache/home/calendar/
cd /usr/apache/home/calendar/
tar zvxf january_schedule.tar.gz
```
While this saved me some time and typing, it certainly was not a very interesting or useful script in the long term. Over time, I learned other ways to use Bash scripts to accomplish more challenging tasks, such as creating software packages, installing software, or backing up a file server.
### 1\. The conditional statement
Just as with so many other programming languages, the conditional has been a powerful and common feature. A conditional is what enables logic to be performed by a computer program. Most of my examples are based on conditional logic.
The basic conditional uses an "if" statement. This allows us to test for some condition that we can then use to manipulate how a script performs. For instance, we can check for the existence of a Java bin directory, which would indicate that Java is installed. If found, the executable path can be updated with the location to enable calls by Java applications.
```
if [ -d "$JAVA_HOME/bin" ] ; then
    PATH="$JAVA_HOME/bin:$PATH"
```
### 2\. Limit execution
You might want to limit a script to only be run by a specific user. Although Linux has standard permissions for users and groups, as well as SELinux for enabling this type of protection, you could choose to place logic within a script. Perhaps you want to be sure that only the owner of a particular web application can run its startup script. You could even use code to limit a script to the root user. Linux has a couple of environment variables that we can test in this logic. One is **$USER**, which provides the username. Another is **$UID**, which provides the users identification number (UID) and, in the case of a script, the UID of the executing user.
#### User
The first example shows how I could limit a script to the user jboss1 in a multi-hosting environment with several application server instances. The conditional "if" statement essentially asks, "Is the executing user not jboss1?" When the condition is found to be true, the first echo statement is called, followed by the **exit 1,** which terminates the script.
```
if [ "$USER" != 'jboss1' ]; then
     echo "Sorry, this script must be run as JBOSS1!"
     exit 1
fi
echo "continue script"
```
#### Root
This next example script ensures that only the root user can execute it. Because the UID for root is 0, we can use the **-gt** option in the conditional if statement to prohibit all UIDs greater than zero.
```
if [ "$UID" -gt 0 ]; then
     echo "Sorry, this script must be run as ROOT!"
     exit 1
fi
echo "continue script"
```
### 3\. Use arguments
Just like any executable program, Bash scripts can take arguments as input. Below are a few examples. But first, you should understand that good programming means that we dont just write applications that do what we want; we must write applications that _cant_ do what we _dont_ want. I like to ensure that a script doesnt do anything destructive in the case where there is no argument. Therefore, this is the first check that y. The condition checks the number of arguments, **$#**, for a value of zero and terminates the script if true.
```
if [ $# -eq 0 ]; then
    echo "No arguments provided"
    exit 1
fi
echo "arguments found: $#"
```
#### Multiple arguments
You can pass more than one argument to a script. The internal variables that the script uses to reference each argument are simply incremented, such as **$1**, **$2**, **$3**, and so on. Ill just expand my example above with the following line to echo the first three arguments. Obviously, additional logic will be needed for proper argument handling based on the total number. This example is simple for the sake of demonstration.
```
`echo $1 $2 $3`
```
While were discussing these argument variables, you might have wondered, "Did he skip zero?"
Well, yes, I did, but I have a great reason! There is indeed a **$0** variable, and it is very useful. Its value is simply the name of the script being executed.
```
`echo $0`
```
An important reason to reference the name of the script during execution is to generate a log file that includes the scripts name in its own name. The simplest form might just be an echo statement.
```
`echo test >> $0.log`
```
However, you will probably want to add a bit more code to ensure that the log is written to a location with the name and information that you find helpful to your use case.
### 4\. User input
Another useful feature to use in a script is its ability to accept input during execution. The simplest is to offer the user some input.
```
echo "enter a word please:"
 read word
 echo $word
```
This also allows you to provide choices to the user.
```
read -p "Install Software ?? [Y/n]: " answ
 if [ "$answ" == 'n' ]; then
   exit 1
 fi
   echo "Installation starting..."
```
### 5\. Exit on failure
Some years ago, I wrote a script for installing the latest version of the Java Development Kit (JDK) on my computer. The script extracts the JDK archive to a specific directory, updates a symbolic link, and uses the alternatives utility to make the system aware of the new version. If the extraction of the JDK archive failed, continuing could break Java system-wide. So, I wanted the script to abort in such a situation. I dont want the script to make the next set of system changes unless the archive was successfully extracted. The following is an excerpt from that script:
```
tar kxzmf jdk-8u221-linux-x64.tar.gz -C /jdk --checkpoint=.500; ec=$?
if [ $ec -ne 0 ]; then
     echo "Installation failed - exiting."
     exit 1
fi
```
A quick way for you to demonstrate the usage of the **$?** variable is with this short one-liner:
```
`ls T; ec=$?; echo $ec`
```
First, run **touch T** followed by this command. The value of **ec** will be 0. Then, delete **T**, **rm T**, and repeat the command. The value of **ec** will now be 2 because ls reports an error condition since **T** was not found.
You can take advantage of this error reporting to include logic, as I have above, to control the behavior of your scripts.
### Takeaway
We might assume that we need to employ languages, such as Python, C, or Java, for higher functionality, but thats not necessarily true. The Bash scripting language is very powerful. There is a lot to learn to maximize its usefulness. I hope these few examples will shed some light on the potential of coding with Bash.
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/improve-bash-scripts
作者:[Alan Formy-Duval][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/alanfdoss
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003784_02_os.comcareers_os_rh2x.png?itok=jbRfXinl (A person working.)

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (unigeorge)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
@ -169,7 +169,7 @@ via: https://opensource.com/article/20/9/ssh
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[unigeorge](https://github.com/unigeorge)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,143 +0,0 @@
[#]: subject: "Access OpenVPN from a client computer"
[#]: via: "https://opensource.com/article/21/7/openvpn-client"
[#]: author: "D. Greg Scott https://opensource.com/users/greg-scott"
[#]: collector: "lujun9972"
[#]: translator: "perfiffer"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Access OpenVPN from a client computer
======
After building your own VPN on Linux, it's time to finally use it.
![Woman programming][1]
OpenVPN creates an encrypted tunnel between two points, preventing a third party from accessing your network traffic. By setting up your virtual private network (VPN) server, you become your own VPN provider. Many popular VPN services already use [OpenVPN][2], so why tie your connection to a specific provider when you can have complete control yourself?
The [first article][3] in this series set up a server for your VPN, the [second article][4] demonstrated how to install and configure the OpenVPN server software, while the [third article][5] explained how to configure your firewall and start the OpenVPN server software. This fourth and final article demonstrates how to use your OpenVPN server from client computers. This is the reason you did all the work in the previous three articles!
### Create client certificates
Remember that the method of authentication for OpenVPN requires both the server and the client to _have_ something (certificates) and to _know_ something (a password). It's time to set that up.
First, create a client certificate and a private key for your client computer. On your OpenVPN server, generate a certificate request. It asks for a passphrase; make sure you remember it:
```
$ cd /etc/openvpn/ca
$ sudo /etc/openvpn/easy-rsa/easyrsa \
gen-req greglaptop
```
In this example, `greglaptop` is the client computer for which this certificate is being created.
There's no need to import the request into the certificate authority (CA) because it's already there. Review it to make sure:
```
$ cd /etc/openvpn/ca
$ /etc/openvpn/easy-rsa/easyrsa \
show-req greglaptop
```
You can sign as the client, too:
```
$ /etc/openvpn/easy-rsa/easyrsa \
sign-req client greglaptop
```
### Install the OpenVPN client software
On Linux, Network Manager may already have an OpenVPN client included. If not, you can install the plugin:
```
`$ sudo dnf install NetworkManager-openvpn`
```
On Windows, you must download and install the OpenVPN client from the OpenVPN download site. Launch the installer and follow the prompts.
### Copy certificates and private keys to the client
Now your client needs the authentication credentials you generated for it. You generated these on the server, so you must transport them over to your client. I tend to use SSH for this. On Linux, that's the `scp` command. On Windows, you can use [WinSCP][6] as administrator to pull the certificates and keys.
Assuming the client is named `greglaptop`, here are the file names and server locations:
```
/etc/openvpn/ca/pki/issued/greglaptop.crt
/etc/openvpn/ca/pki/private/greglaptop.key
/etc/openvpn/ca/pki/issued/ca.crt
```
On Linux, copy these to the `/etc/pki/tls/certs/` directory. On Windows, copy them to the `C:\Program Files\OpenVPN\config` directory.
### Copy and customize the client configuration file
On Linux, you can either copy the `/etc/openvpn/client/OVPNclient2020.ovpn` file on the server to `/etc/NetworkManager/system-connections/`, or you can navigate to Network Manager in System Settings and add a VPN connection. 
For the connection type, select **Certificates**. Point Network Manager to the certificates and keys you copied from the server.
![VPN displayed in Network Manager][7]
(Seth Kenlon, [CC BY-SA 4.0][8])
On Windows, run WinSCP as administrator to copy the client configuration template `/etc/openvpn/client/OVPNclient2020.ovpn` on the server to `C:\Program Files\OpenVPN\config` on the client. Then:
* Rename it to match the certificate above.
* Change the names of the CA certificate, client certificate, and key to match the names copied above from the server.
* Edit the IP information to match your network.
You need super administrative permissions to edit the client config files. The easiest way to get this might be to launch a CMD window as administrator and then launch Notepad from the administrator CMD window to edit the files.
### Connect your client to the server
On Linux, Network manager displays your VPN. Select it to connect.
 
![Add a VPN connection in Network Manager][9]
(Seth Kenlon, [CC BY-SA 4.0][8])
On Windows, start the OpenVPN graphical user interface (GUI). It produces a graphic in the Windows System Tray on the right side of the taskbar, usually in the lower-right corner of your Windows desktop. Right-click the graphic to connect, disconnect, or view the status.
For the first connection, edit the "remote" line of your client config file to use the _inside IP address_ of your OpenVPN server. Connect to the server from inside your office network by right-clicking on the OpenVPN GUI in the Windows System Tray and clicking **Connect**. Debug this connection. This should find and fix problems without any firewall issues getting in the way because both the client and server are on the same side of the firewall.
Next, edit the "remote" line of your client config file to use the _public IP address_ for your OpenVPN server. Bring the Windows client to an outside network and connect. Debug any issues.
### Connect securely
Congratulations! You have an OpenVPN network ready for your other client systems. Repeat the setup steps for the rest of your clients. You might even use Ansible to distribute certs and keys and keep them up to date. 
* * *
_This article is based on D. Greg Scott's [blog][10] and is reused with permission._
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/7/openvpn-client
作者:[D. Greg Scott][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/greg-scott
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/programming-code-keyboard-laptop-music-headphones.png?itok=EQZ2WKzy (Woman programming)
[2]: https://openvpn.net/
[3]: https://opensource.com/article/21/7/vpn-openvpn-part-1
[4]: https://opensource.com/article/21/7/vpn-openvpn-part-2
[5]: https://opensource.com/article/21/7/vpn-openvpn-part-3
[6]: https://winscp.net/eng/index.php
[7]: https://opensource.com/sites/default/files/uploads/network-manager-profile.jpg (VPN displayed in Network Manager)
[8]: https://creativecommons.org/licenses/by-sa/4.0/
[9]: https://opensource.com/sites/default/files/uploads/network-manager-connect.jpg (Add a VPN connection in Network Manager)
[10]: https://www.dgregscott.com/how-to-build-a-vpn-in-four-easy-steps-without-spending-one-penny/

View File

@ -1,87 +0,0 @@
[#]: subject: "Automatically Synchronize Subtitle With Video Using SubSync"
[#]: via: "https://itsfoss.com/subsync/"
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Automatically Synchronize Subtitle With Video Using SubSync
======
Let me share a scenario. You are trying to watch a movie or video and you need subtitles. You download the subtitle only to find that the subtitle is not properly synchronized. There are no other good subtitles available. What to do now?
You can [synchronize subtitles in VLC by pressing G or H keys][1]. It adds a delay to the subtitles. This could work if the subtitle is out of synch by the same time interval throughout the video. But if thats not the case, SubSync could be of great help here.
### SubSync: Subtitle Speech Synchronizer
[SubSync][2] is a nifty open source utility available for Linux, macOS and Windows.
It synchronizes the subtitle by listening to the audio track and thats how it works the magic. It will work even if the audio track and the subtitle are in different languages. If necessary, it could also be translated but I did not test this feature.
I made a simple test by using a subtitle which was not in synch with the video I was playing. To my surprise, it worked pretty smooth and I got perfectly synched subtitles.
Using SubSync is simple. You start the application and it asks to add the subtitle file and the video file.
![User interface for SubSync][3]
Youll have to specif the language of the subtitle and the video on the interface. It may download additional assets based on the language in use.
![SubSync may download additional packages for language support][4]
Please keep in mind that it takes some time to synchronize the subtitles, depending on the length of the video and subtitle. You may grab your cup of tea/coffee or beer while you wait for the process to complete.
You can see the synchronization status in progress and even save it before it gets completed.
![SubSync synchronization in progress][5]
Once the synchronization completes, you hit the save button and either save the changes to the original file or save it as a new subtitle file.
![Synchronization completed][6]
I cannot say that it will work in all the cases but it worked for the sample test I ran.
### Installing SubSync
SubSync is a cross-platform application and you can get the installer files for Windows and macOS from its [download page][7].
For Linux users, SubSync is available as a Snap package. If your distribution has Snap support enabled, use the following command to install SubSync:
```
sudo snap install subsync
```
Please keep in mind that it will take some time to download SubSync snap package. So have a good internet connection or plenty of patience.
### In the end
Personally, I am addicted to subtitles. Even if I am watching movies in English on Netflix, I keep the subtitles on. It helps understand each dialogue clearly, specially if there is a strong accent. Without subtitles I could never understand a [word from Mickey ONeil (played by Brad Pitt) in the movie Snatch][8]. Dags!!
Using SubSync is a lot easier than [using Subtitle Editor][9] for synchronizing subtitles. After [Penguin Subtitle Player][10], this is another great tool for someone like me who searches the entire internet for rare or recommended (mystery) movies from different countries.
If you are a subtitle user, I have a feeling you would like this tool. If you do use it, please share your experience with it in the comment section.
--------------------------------------------------------------------------------
via: https://itsfoss.com/subsync/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/how-to-synchronize-subtitles-with-movie-quick-tip/
[2]: https://subsync.online/
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/08/subsync-interface.png?resize=593%2C280&ssl=1
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/subsync-subtitle-synchronize.png?resize=522%2C189&ssl=1
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/08/subsync-subtitle-synchronize-1.png?resize=424%2C278&ssl=1
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/subsync-subtitle-synchronize-2.png?resize=424%2C207&ssl=1
[7]: https://subsync.online/en/download.html
[8]: https://www.youtube.com/watch?v=tGDO-9hfaiI
[9]: https://itsfoss.com/subtitld/
[10]: https://itsfoss.com/penguin-subtitle-player/

View File

@ -1,150 +0,0 @@
[#]: subject: "Build a JAR file with fastjar and gjar"
[#]: via: "https://opensource.com/article/21/8/fastjar"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Build a JAR file with fastjar and gjar
======
Utilities like fastjar, gjar, and jar help you manually or
programmatically build JAR files, while other toolchains such as Maven
and Gradle offer features for dependency management.
![Someone wearing a hardhat and carrying code ][1]
One of the many advantages of Java, in my experience, is its ability to deliver applications in a neat and tidy package (called a JAR, or _Java archive_.) JAR files make it easy for users to download and launch an application they want to try, easy to transfer that application from one computer to another (and Java is cross-platform, so sharing liberally can be encouraged), and easy to understand for new programmers to look inside a JAR to find out what makes a Java app run.
There are many ways to create a JAR file, including toolchain solutions such as Maven and Gradle, and one-click build features in your IDE. However, there are also stand-alone commands such as `jarfast`, `gjar`, and just plain old `jar`, which are useful for quick and simple builds, and to demonstrate what a JAR file needs to run.
### Install
On Linux, you may already have the `fastjar`, `gjar`, or `jar` commands as part of an OpenJDK package, or GCJ (GCC-Java.) You can test whether any of these commands are installed by typing the command with no arguments: 
```
$ fastjar
Try 'fastjar --help' for more information.
$ gjar
jar: must specify one of -t, -c, -u, -x, or -i
jar: Try 'jar --help' for more information
$ jar
Usage: jar [OPTION...] [ [--release VERSION] [-C dir] files] ...
Try `jar --help' for more information.
```
I have all of them installed, but you only need one. All of these commands are capable of building a JAR.
On a modern Linux system such as Fedora, typing a missing command causes your OS to prompt you to install it for you.
Alternately, you can just [install Java][2] from [AdoptOpenJDK.net][3] for Linux, MacOS, and Windows.
### Build a JAR 
First, you need a Java application to build.
To keep things simple, create a basic "hello world" application in a file called hello.java:
```
class Main {
public static void main([String][4][] args) {
    [System][5].out.println("Hello Java World");
}}
```
It's a simple application that somewhat trivializes the real-world importance of managing external dependencies. Still, it's enough to get started with the basic concepts you need to create a JAR.
Next, create a manifest file. A manifest file describes the Java environment of the JAR. In this case, the most important information is identifying the main class, so the Java runtime executing the JAR knows where to find the application's entry point. 
```
$ mdir META-INF
$ echo "Main-Class: Main" &gt; META-INF/MANIFEST.MF 
```
### Compiling Java bytecode
Next, compile your Java file into Java bytecode.
```
`$ javac hello.java`
```
Alternately, you can use the Java component of GCC to compile:
```
`$ gcj -C hello.java`
```
Either way, this produces the file `Main.class`:
```
$ file Main.class
Main.class: compiled Java class data, version XX.Y
```
### Creating a JAR 
You have all the components you need so that you can create the JAR file.
I often include the Java source code as a reference for curious users, but all that's _required_ is the `META-INF` directory and the class files.
The `fastjar` command uses syntax similar to the [`tar` command][6].
```
`$ fastjar cvf hello.jar META-INF Main.class`
```
Alternately, you can use `gjar` in much the same way, except that `gjar` requires you to specify your manifest file explicitly:
```
`$ gjar cvf world.jar Main.class -m META-INF/MANIFEST.MF`
```
Or you can use the `jar` command. Notice this one doesn't require a Manifest file because it auto-generates one for you, but for safety I define the main class explicitly:
```
`$ jar --create --file hello.jar --main-class=Main Main.class`
```
Test your application:
```
$ java -jar hello.jar
Hello Java World
```
### Easy packaging
Utilities like `fastjar`, `gjar`, and `jar` help you manually or programmatically build JAR files, while other toolchains such as Maven and Gradle offer features for dependency management. A good IDE may integrate one or more of these features.
Whatever solution you use, Java provides an easy and unified target for distributing your application code.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/fastjar
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/build_structure_tech_program_code_construction.png?itok=nVsiLuag (Someone wearing a hardhat and carrying code )
[2]: https://opensource.com/article/19/11/install-java-linux
[3]: https://adoptopenjdk.net/
[4]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
[5]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
[6]: https://opensource.com/article/17/7/how-unzip-targz-file

View File

@ -2,7 +2,7 @@
[#]: via: "https://opensource.com/article/21/8/ncdu-check-free-disk-space-linux"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "

View File

@ -2,7 +2,7 @@
[#]: via: "https://opensource.com/article/21/8/add-printer-linux"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: translator: "fisherue "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
@ -93,7 +93,7 @@ via: https://opensource.com/article/21/8/add-printer-linux
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[fisherue](https://github.com/fisherue)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -0,0 +1,137 @@
[#]: subject: "How to Monitor Log Files in Real Time in Linux [Desktop and Server]"
[#]: via: "https://www.debugpoint.com/2021/08/monitor-log-files-real-time/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
How to Monitor Log Files in Real Time in Linux [Desktop and Server]
======
This tutorial explains how you can monitor Linux log files (desktop,
server or applications) in real time for diagnosis and troubleshooting
purpose.Basic SyntaxUsage
When you ran into problems in your Linux desktop, or server or any application, you first look into the respective log files. The log files are generally a stream of text and messages from applications with a timestamp attached to it. It helps you to narrow down specific instances and helps you find the cause of any problem. It can also help to get assistance from the web as well.
In general, all log files are located in /var/log. This directory contains log files with extension .log for specific applications, services, and it also contains separate other directories which contains their log files.
![log files in var-log][1]
So, that said, if you want to monitor a bunch of log files Or, a specific one heres are some ways how you can do it.
### Monitor Log Files in real time Linux
#### Using tail command
Using the tail command is the most basic way of following a log file in real time. Specially, if you are in a server with only just a terminal, no GUI. This is very helpful.
Examples:
```
tail /path/to/log/file
```
![Monitoring multiple log files via tail][2]
Use the switch -f to follow the log file, which updates in real time. For example, if you want to follow syslog, you can use the following command.
```
tail -f /var/log/syslog
```
You can monitor multiple log files using a single command using
```
tail -f /var/log/syslog /var/log/dmesg
```
If you want to monitor http or sftp or any server, you can also their respective log files in this command.
Remember, above commands requires admin privileges.
#### Using lnav (The Logfile Navigator)
![lnav Running][3]
The lnav is a nice utility which you can use to monitor log files in a more structured way with color coded messages. This is not installed by default in Linux systems. You can install it using the below command:
```
sudo apt install lnav (Ubuntu)
sudo dnf install lnav (Fedora)
```
The good thing about lnav is, if you do not want to install it, you can just download its pre-compiled executable and run in anywhere. Even from a USB stick. No setup is required, plus loaded with features. Using lnav you can query the log files via SQL among other cool features which you can learn on it [official website][4].
[][5]
SEE ALSO:   This App is An Advanced Log File Viewer - lnav
Once installed, you can simply run lnav from terminal with admin privilege, and it will show all the logs from /var/log by default and start monitoring in real time.
#### A note about journalctl of systemd
All modern Linux distributions today use systemd, mostly. The systemd provides basic framework and components which runs Linux operating system in general. The systemd provides journal services via journalctl which helps to manage logs from all systemd services. You can also monitor respective systemd services and logs in real time using the following command.
```
journalctl -f
```
Here are some of the specific journalctl commands which you can use for several cases. You can combine these with -f switch above to start monitoring in real time.
* To emergency system messages use
```
journalctl -p 0
```
* Show errors with explanations
```
journalctl -xb -p 3
```
* Use time controls to filter out
```
journalctl --since "2020-12-04 06:00:00"
journalctl --since "2020-12-03" --until "2020-12-05 03:00:00"
journalctl --since yesterday
journalctl --since 09:00 --until "1 hour ago"
```
If you want to learn more about and want to find out details about journalctl I have written a [guide here][6].
### Closing Notes
I hope these commands and tricks helps you find out the root cause of your problem/errors in your desktop or servers. For more details, you can always refer to the man pages and play around with various switches. Let me know using the comment box below, if you have any comments or what do you think about this article.
Cheers.
* * *
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/2021/08/monitor-log-files-real-time/
作者:[Arindam][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lujun9972
[1]: https://www.debugpoint.com/blog/wp-content/uploads/2021/08/log-files-in-var-log-1024x312.jpeg
[2]: https://www.debugpoint.com/blog/wp-content/uploads/2021/08/Monitoring-multiple-log-files-via-tail-1024x444.jpeg
[3]: https://www.debugpoint.com/blog/wp-content/uploads/2021/08/lnav-Running-1024x447.jpeg
[4]: https://lnav.org/features
[5]: https://www.debugpoint.com/2016/11/advanced-log-file-viewer-lnav-ubuntu-linux/
[6]: https://www.debugpoint.com/2020/12/systemd-journalctl/

View File

@ -1,134 +0,0 @@
[#]: subject: "Linux Phones: Here are Your Options"
[#]: via: "https://itsfoss.com/linux-phones/"
[#]: author: "Ankush Das https://itsfoss.com/author/ankush/"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Linux Phones: Here are Your Options
======
_**Brief:**_ _Linux phones could be the future to replace Android or iOS, but what are some of your options to give it a try?_
While Android is based on a Linux kernel, it has been heavily modified. So, that does not make it a full-fledged Linux-based operating system.
Google is trying to get the Android kernel close to the mainline Linux kernel, but that is still a distant dream.
So, in that case, what are some of the options if you are looking for a Linux phone? A smartphone powered by a Linux operating system.
It is not an easy decision to make because the options are super limited. Hence, I try to highlight some of the best Linux phones and a few different options from the mainstream choices.
### Top Linux phones you can use today
It is worth noting that the Linux phones mentioned here may not be able to replace your Android or iOS devices. So, make sure that you do some background research before making a purchase decision.
**Note:** You need to carefully check the availability, expected shipping date, and risks of using a Linux phone. Most of the options are only suitable for enthusiasts or early adopters.
#### 1\. PinePhone
![][1]
PinePhone is one of the most affordable and popular choices to consider as a promising Linux phone.
It is not limited to a single operating system. You can try it with Manjaro with Plasma mobile OS, UBports, Sailfish OS, and others. PinePhone packs in some decent specifications that include a Quad-core processor and 2/3 Gigs of RAM. It does support a bootable microSD card to help you with installation, along with 16/32 GB eMMC storage options.
The display is a basic 1440×720p IPS screen. You also get special privacy protection tweaks like kill switches for Bluetooth, microphones, and cameras.
PinePhone also gives you an option to add custom hardware extensions using the six pogo pins available.
The base edition (2 GB RAM and 16 GB storage) comes loaded with Manjaro by default and costs $149. And, the convergence edition (3 GB RAM / 32 GB storage) costs $199.
[PinePhone][2]
#### 2\. Fairphone
![][3]
Compared to others on the list, Fairphone is a commercial success. It is not a Linux smartphone, but it features a customized version of Android, i.e., Fairphone OS, and the option to opt for [/e/ OS][4], one of the [open-source Android alternatives][5]. Some community ports are available if you want to use the Linux operating system, but it could be a hit and miss.
The Fairphone offers some decent specs, considering there are two different variants. You will find a 48 MP camera sensor for Fairphone 3+ and a full-HD display. Not to forget, you will also find decent Qualcomm processors powering the device.
They focus on making smartphones that are sustainable and have been built using some amount of recycled plastic. Fairphone is also meant to be easily repairable.
So, it is not just an option away from mainstream smartphones, but you will also be helping with protecting the environment if you opt for it.
[Fairphone][6]
### 3\. Librem 5
![][7]
[Librem 5][8] is a smartphone that focuses heavily on user privacy while featuring an open-source operating system, i.e., PureOS, not based on Android.
The specifications offered are decent, with 3 Gigs of RAM and a quad-core Cortex A53 chipset. But, this is not something geared to compete with mainstream options. Hence, you may not find it as a value for money offering.
It is aimed at enthusiasts who are interested in testing privacy-respecting smartphones in the process.
Similar to others, Librem 5 also focuses on making the phone easily repairable by offering user-replaceable batteries.
For privacy, you will notice kill switches for Bluetooth, Cameras, and microphones. They also promise security updates for years to come.
[Librem 5][9]
### 4\. Pro 1X
![][10]
An interesting smartphone that supports Ubuntu Touch, Lineage OS, and Android as well.
It is not just a Linux smartphone but a mobile phone with a separate QWERTY keypad, which is rare to find these days.
The Pro 1 X features a decent specification, including a Snapdragon 662 processor coupled with 6 GB of RAM. You also get a respectable AMOLED Full HD display with the Pro 1 X.
The camera does not pack in anything crazy, but should be good enough for the most part.
[Pro 1X][11]
### 5\. Volla Phone
![][12]
An attractive offering that runs on Ubuntu Touch by UBports.
It comes with a pre-built VPN and focuses on making the user experience easy. The operating system has been customized so that everything essential should be accessible quickly without organizing anything yourself.
It packs in some impressive specifications that include an Octa-core MediaTek processor along with a 4700 mAh battery. You get a notch design resembling some of the latest smartphones available.
[Volla Phone][13]
### Wrapping Up
Linux smartphones are not readily available and certainly not yet suitable for the masses.
So, if you are an enthusiast or want to support the development of such phones, you can consider getting one of the devices.
Do you already own one of these smartphones? Please dont hesitate to share your experiences in the comments below.
--------------------------------------------------------------------------------
via: https://itsfoss.com/linux-phones/
作者:[Ankush Das][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/ankush/
[b]: https://github.com/lujun9972
[1]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/PinePhone-3.jpg?resize=800%2C800&ssl=1
[2]: https://www.pine64.org/pinephone/
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/08/fairphone.png?resize=360%2C600&ssl=1
[4]: https://itsfoss.com/e-os-review/
[5]: https://itsfoss.com/open-source-alternatives-android/
[6]: https://shop.fairphone.com/en/
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/08/librem-5.png?resize=800%2C450&ssl=1
[8]: https://itsfoss.com/librem-linux-phone/
[9]: https://puri.sm/products/librem-5/
[10]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/08/pro1x.jpg?resize=800%2C542&ssl=1
[11]: https://www.fxtec.com/pro1x
[12]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/08/volla-smartphone.jpg?resize=695%2C391&ssl=1
[13]: https://www.indiegogo.com/projects/volla-phone-free-your-mind-protect-your-privacy#/

View File

@ -0,0 +1,107 @@
[#]: subject: "Access your iPhone on Linux with this open source tool"
[#]: via: "https://opensource.com/article/21/8/libimobiledevice-iphone-linux"
[#]: author: "Don Watkins https://opensource.com/users/don-watkins"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Access your iPhone on Linux with this open source tool
======
Communicate with iOS devices from Linux by using Libimobiledevice.
![A person looking at a phone][1]
The iPhone and iPad aren't by any means open source, but they're popular devices. Many people who own an iOS device also happen to use a lot of open source, including Linux. Users of Windows and macOS can communicate with an iOS device by using software provided by Apple, but Apple doesn't support Linux users. Open source programmers came to the rescue back in 2007 (just a year after the iPhone's release) with Libimobiledevice (then called libiphone), a cross-platform solution for communicating with iOS. It runs on Linux, Android, Arm systems such as the Raspberry Pi, Windows, and even macOS.
Libimobiledevice is written in C and uses native protocols to communicate with services running on iOS devices. It doesn't require any libraries from Apple, so it's fully free and open source.
Libimobiledevice is an object-oriented API, and there are a number of terminal utilities that come bundled with it for your convenience. The library supports Apple's earliest iOS devices all the way up to its latest models. This is the result of years of research and development. Applications in the project include **usbmuxd**, **ideviceinstaller**, **idevicerestore**, **ifuse**, **libusbmuxd**, **libplist**, **libirecovery**, and **libideviceactivation**.
### Install Libimobiledevice on Linux
On Linux, you may already have **libimobiledevice** installed by default. You can find out through your package manager or app store, or by running one of the commands included in the project:
```
`$ ifuse --help`
```
You can install **libimobiledevice** using your package manager. For instance, on Fedora or CentOS:
```
`$ sudo dnf install libimobiledevice ifuse usbmuxd`
```
On Debian and Ubuntu:
```
`$ sudo apt install usbmuxd libimobiledevice6 libimobiledevice-utils`
```
Alternatively, you can [download][2] and install **libimobiledevice** from source code.
### Connecting your device
Once you have the required packages installed, connect your iOS device to your computer.
Make a directory as a mount point for your iOS device.
```
`$ mkdir ~/iPhone`
```
Next, mount the device:
```
`$ ifuse ~/iPhone`
```
Your device prompts you to trust the computer you're using to access it.
![iphone prompts to trust the computer][3]
Figure 1: The iPhone prompts you to trust the computer.
Once the trust issue is resolved, you see new icons on your desktop.
![iphone icons appear on desktop][4]
Figure 2: New icons for the iPhone appear on the desktop.
Click on the **iPhone** icon to reveal the folder structure of your iPhone.
![iphone folder structure displayed][5]
Figure 3: The iPhone folder structure is displayed.
The folder I usually access most frequently is **DCIM**, where my iPhone photos are stored. Sometimes I use these photos in articles I write, and sometimes there are photos I want to enhance with open source applications like Gimp. Having direct access to the images instead of emailing them to myself is one of the benefits of using the Libimobiledevice utilities. I can copy any of these folders to my Linux computer. I can create folders on the iPhone and delete them too.
### Find out more
[Martin Szulecki][6] is the lead developer for the project. The project is looking for developers to add to their [community][7]. Libimobiledevice can change the way you use your peripherals, regardless of what platform you're on. It's another win for open source, which means it's a win for everyone.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/libimobiledevice-iphone-linux
作者:[Don Watkins][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/don-watkins
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/idea_innovation_mobile_phone.png?itok=RqVtvxkd (A person looking at a phone)
[2]: https://github.com/libimobiledevice/libimobiledevice/
[3]: https://opensource.com/sites/default/files/1trust_0.png
[4]: https://opensource.com/sites/default/files/2docks.png
[5]: https://opensource.com/sites/default/files/2iphoneicon.png
[6]: https://github.com/FunkyM
[7]: https://libimobiledevice.org/#community

View File

@ -0,0 +1,87 @@
[#]: subject: "Apps for daily needs part 4: audio editors"
[#]: via: "https://fedoramagazine.org/apps-for-daily-needs-part-4-audio-editors/"
[#]: author: "Arman Arisman https://fedoramagazine.org/author/armanwu/"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Apps for daily needs part 4: audio editors
======
![][1]
Photo by [Brooke Cagle][2] on [Unsplash][3]
Audio editor applications or digital audio workstations (DAW) were only used in the past by professionals, such as record producers, sound engineers, and musicians. But nowadays many people who are not professionals also need them. These tools are used for narration on presentations, video blogs, and even just as a hobby. This is especially true now since there are so many online platforms that facilitate everyone sharing audio works, such as music, songs, podcast, etc. This article will introduce some of the open source audio editors or DAW that you can use on Fedora Linux. You may need to install the software mentioned. If you are unfamiliar with how to add software packages in Fedora Linux, see my earlier article [Things to do after installing Fedora 34 Workstation][4]. Here is a list of a few apps for daily needs in the audio editors or DAW category.
### Audacity
Im sure many already know Audacity. It is a popular multi-track audio editor and recorder that can be used for post-processing all types of audio. Most people use Audacity to record their voices, then do editing to make the results better. The results can be used as a podcast or a narration for a video blog. In addition, people also use Audacity to create music and songs. You can record live audio through a microphone or mixer. It also supports 32 bit sound quality.
Audacity has a lot of features that can support your audio works. It has support for plugins, and you can even write your own plugin. Audacity provides many built-in effects, such as noise reduction, amplification, compression, reverb, echo, limiter, and many more. You can try these effects while listening to the audio directly with the real-time preview feature. The built in plugin-manager lets you manage frequently used plugins and effects.
![][5]
More information is available at this link: <https://www.audacityteam.org/>
* * *
### LMMS
LMMS or Linux MultiMedia Studio is a comprehensive music creation application. You can use LMMS to produce your music from scratch with your computer. You can create melodies and beats according to your creativity, and make it better with selection of sound instruments and various effects. There are several built-in features related to musical instruments and effects, such as 16 built-in sythesizers, embedded ZynAddSubFx, drop-in VST effect plug-in support, bundled graphic and parametric equalizer, built-in analyzer, and many more. LMMS also supports MIDI keyboards and other audio peripherals.
![][6]
More information is available at this link: <https://lmms.io/>
* * *
### Ardour
Ardour has capabilities similar to LMMS as a comprehensive music creation application. It says on its website that Ardour is a DAW application that is the result of collaboration between musicians, programmers, and professional recording engineers from around the world. Ardour has various functions that are needed by audio engineers, musicians, soundtrack editors, and composers.
Ardour provides complete features for recording, editing, mixing, and exporting. It has unlimited multichannel tracks, non-linear editor with unlimited undo/redo, a full featured mixer, built-in plugins, and much more. Ardour also comes with video playback tools, so it is also very helpful in the process of creating and editing soundtracks for video projects.
![][7]
More information is available at this link: <https://ardour.org/>
* * *
### TuxGuitar
TuxGuitar is a tablature and score editor. It comes with a tablature editor, score viewer, multitrack display, time signature management, and tempo management. It includes various effects, such as bend, slide, vibrato, etc. While TuxGuitar focuses on the guitar, it allows you to write scores for other instruments. It can also serve as a basic MIDI editor. You need to have an understanding of tablature and music scoring to be able to use it.
![][8]
More information is available at this link: <http://www.tuxguitar.com.ar/>
* * *
### Conclusion
This article presented four audio editors as apps for your daily needs and use on Fedora Linux. Actually there are many other audio editors, or DAW, that you can use on Fedora Linux. You can also use Mixxx, Rosegarden, Kwave, Qtractor, MuseScore, musE, and many more. Hopefully this article can help you investigate and choose the right audio editor or DAW. If you have experience using these applications, please share your experiences in the comments.
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/apps-for-daily-needs-part-4-audio-editors/
作者:[Arman Arisman][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/armanwu/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2021/07/FedoraMagz-Apps-4-Audio-816x345.jpg
[2]: https://unsplash.com/@brookecagle?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[3]: https://unsplash.com/s/photos/meeting-on-cafe-computer?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText
[4]: https://fedoramagazine.org/things-to-do-after-installing-fedora-34-workstation/
[5]: https://fedoramagazine.org/wp-content/uploads/2021/08/audio-audacity-1024x575.png
[6]: https://fedoramagazine.org/wp-content/uploads/2021/08/audio-lmms-1024x575.png
[7]: https://fedoramagazine.org/wp-content/uploads/2021/08/audio-ardour-1024x592.png
[8]: https://fedoramagazine.org/wp-content/uploads/2021/08/audio-tuxguitar-1024x575.png

View File

@ -0,0 +1,166 @@
[#]: subject: "Write a chess game using bit-fields and masks"
[#]: via: "https://opensource.com/article/21/8/binary-bit-fields-masks"
[#]: author: "Jim Hall https://opensource.com/users/jim-hall"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Write a chess game using bit-fields and masks
======
Using bit-fields and masks is a common method to combine data without
using structures.
![Chess pieces on a chess board][1]
Let's say you were writing a chess game in C. One way to track the pieces on the board is by defining a structure that defines each possible piece on the board, and its color, so every square contains an element from that structure. For example, you might have a structure that looks like this:
```
struct chess_pc {
   int piece;
   int is_black;
}
```
With this programming structure, your program will know what piece is in every square and its color. You can quickly identify if the piece is a pawn, rook, knight, bishop, queen, or king—and if the piece is black or white. But there's a more straightforward way to track the same information while using less data and memory. Rather than storing a structure of two `int` values for every square on a chessboard, we can store a single `int` value and use binary _bit-fields_ and _masks_ to identify the pieces and color in each square.
### Bits and binary
When using bit-fields to represent data, it helps to think like a computer. Let's start by listing the possible chess pieces and assigning a number to each. I'll help us along to the next step by representing the number in its binary form, the way the computer would track it. Remember that binary numbers are made up of _bits_, which are either zero or one.
* `00000000:` empty (0)
* `00000001:` pawn (1)
* `00000010:` rook (2)
* `00000011:` knight (3)
* `00000100:` bishop (4)
* `00000101:` queen (5)
* `00000110:` king (6)
To list all pieces on a chessboard, we only need the three bits that represent (from right to left) the values 1, 2, and 4. For example, the number 6 is binary `110`. All of the other bits in the binary representation of 6 are zeroes.
And with a bit of cleverness, we can use one of those extra always-zero bits to track if a piece is black or white. We can use the number 8 (binary `00001000`) to indicate if a piece is black. If this bit is 1, it's black; if it's 0, it's white. That's called a _bit-field_, which we can pull out later using a binary _mask_.
### Storing data with bit-fields
To write a chess program using bit-fields and masks, we might start with these definitions:
```
/* game pieces */
#define EMPTY 0
#define PAWN 1
#define ROOK 2
#define KNIGHT 3
#define BISHOP 4
#define QUEEN 5
#define KING 6
/* piece color (bit-field) */
#define BLACK 8
#define WHITE 0
/* piece only (mask) */
#define PIECE 7
```
When you assign a value to a square, such as when initializing the chessboard, you can assign a single `int` value to track both the piece and its color. For example, to store a black rook in position 0,0 of an array, you would use this code:
```
  int board[8][8];
..
  board[0][0] = BLACK | ROOK;
```
The `|` is a binary OR, which means the computer will combine the bits from two numbers. For every bit position, if that bit from _either_ number is 1, the result for that bit position is also 1. Binary OR of the value `BLACK` (8, or binary `00001000`) and the value `ROOK` (2, or binary `00000010`) is binary `00001010`, or 10:
```
    00001000 = 8
 OR 00000010 = 2
    ________
    00001010 = 10
```
Similarly, to store a white pawn in position 6,0 of the array, you could use this:
```
`  board[6][0] = WHITE | PAWN;`
```
This stores the value 1 because the binary OR of `WHITE` (0) and `PAWN` (1) is just 1:
```
    00000000 = 0
 OR 00000001 = 1
    ________
    00000001 = 1
```
### Getting data out with masks
During the chess game, the program will need to know what piece is in a square and its color. We can separate the piece using a binary mask.
For example, the program might need to know the contents of a specific square on the board during the chess game, such as the array element at `board[5][3]`. What piece is there, and is it black or white? To identify the chess piece, combine the element's value with the `PIECE` mask using the binary AND:
```
  int board[8][8];
  int piece;
..
  piece = board[5][3] &amp; PIECE;
```
The binary AND operator (`&`) combines two binary values so that for any bit position, if that bit in _both_ numbers is 1, then the result is also 1. For example, if the value of `board[5][3]` is 11 (binary `00001011`), then the binary AND of 11 and the mask PIECE (7, or binary `00000111`) is binary `00000011`, or 3. This is a knight, which also has the value 3.
```
    00001011 = 11
AND 00000111 = 7
    ________
    00000011 = 3
```
Separating the piece's color is a simple matter of using binary AND with the value and the `BLACK` bit-field. For example, you might write this as a function called `is_black` to determine if a piece is either black or white:
```
int
is_black(int piece)
{
  return (piece &amp; BLACK);
}
```
This works because the value `BLACK` is 8, or binary `00001000`. And in the C programming language, any non-zero value is treated as True, and zero is always False. So `is_black(board[5][3])` will return a True value (8) if the piece in array element `5,3` is black and will return a False value (0) if it is white.
### Bit fields
Using bit-fields and masks is a common method to combine data without using structures. They are worth adding to your programmer's "tool kit." While data structures are a valuable tool for ordered programming where you need to track related data, using separate elements to track single On or Off values (such as the colors of chess pieces) is less efficient. In these cases, consider using bit-fields and masks to combine your data more efficiently.
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/binary-bit-fields-masks
作者:[Jim Hall][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jim-hall
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/life-chess-games.png?itok=U1lWMZ0y (Chess pieces on a chess board)

25
sources/tech/20210824 .md Normal file
View File

@ -0,0 +1,25 @@
[#]: subject: ""
[#]: via: "https://www.2daygeek.com/upgrade-opensuse-from-15-2-to-15-3/"
[#]: author: " "
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
======
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/upgrade-opensuse-from-15-2-to-15-3/
作者:[][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:
[b]: https://github.com/lujun9972

View File

@ -0,0 +1,126 @@
[#]: subject: "Ulauncher: A Super Useful Application Launcher for Linux"
[#]: via: "https://itsfoss.com/ulauncher/"
[#]: author: "Ankush Das https://itsfoss.com/author/ankush/"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Ulauncher: A Super Useful Application Launcher for Linux
======
_**Brief:**_ _Ulauncher is a fast application launcher with extension and shortcut support to help you quickly access application and files in Linux._
An application launcher lets you quickly access or open an app without hovering over the application menu icons.
By default, I found the application launcher with Pop!_OS super handy. But, not every Linux distribution offers an application launcher out-of-the-box.
Fortunately, there is a solution with which you can add the application launcher to most of the popular distros out there.
### Ulauncher: Open Source Application Launcher
![][1]
Ulauncher is a quick application launcher built using Python while utilizing GTK+.
It gives a decent amount of customization and control options to tweak. Overall, you can adjust its behavior and experience to suit your taste.
Let me highlight some of the features that you can expect with it.
### Ulauncher Features
The options that you get with Ulauncher are super accessible and easy to customize. Some key highlights include:
* Fuzzy search algorithm, which lets you find applications even if you misspell them
* Remembers your last searched application in the same session
* Frequently used apps display (optional)
* Custom color themes
* Preset color themes that include a dark theme
* Shortcut to summon the launcher can be easily customized
* Browse files and directories
* Support for extensions to get extra functionality (emoji, weather, speed test, notes, password manager, etc.)
* Shortcuts for browsing sites like Google, Wikipedia, and Stack Overflow
It provides almost every helpful ability that you may expect in an application launcher, and even better.
### How to Use Ulauncher in Linux?
By default, you need to press **Ctrl + Space** to get the application launcher after you open it from the application menu for the first time.
Start typing in to search for an application. And, if you are looking for a file or directory, start typing with “**~**” or “**/**” (ignoring the quotes).
![][2]
There are default shortcuts like “**g XYZ**” where XYZ is the search term you want to search for in Google.
![][3]
Similarly, you can search for something directly taking you to Wikipedia or Stack Overflow, with “**wiki**” and “**so**” shortcuts, respectively.
Without any extensions, you can also calculate things on the go and copy the results directly to the keyboard.
![][4]
This should come in handy for quick calculations without needing to launch the calculator app separately.
You can head to its [extensions page][5] and browse for useful extensions along with screenshots that should instruct you how to use it.
To change how it works, enable frequent applications display, and adjust the theme — click on the gear icon on the right side of the launcher.
![][6]
You can set it to auto-start. But, if it does not work on your Systemd enabled distro, you can refer to its GitHub page to add it to the service manager.
The options are self-explanatory and are easy to customize, as shown in the screenshot below.
![][7]
### Installing Ulauncher in Linux
Ulauncher provides a **.deb** package for Debian or Ubuntu-based distributions. You can explore [how to install Deb][8] [f][8][iles][8] if youre new to Linux.
In either case, you can also add its PPA and install it via terminal by following the commands below:
```
sudo add-apt-repository ppa:agornostal/ulauncher
sudo apt update
sudo apt install ulauncher
```
You can also find it available in the [AUR][9] for Arch and Fedoras default repositories.
For more information, you can head to its official website or the [GitHub page][10].
[Ulauncher][11]
Ulauncher should be an impressive addition to any Linux distro. Especially, if you want the functionality of a quick launcher like Pop!_OS offers, this is a fantastic option to consider.
_Have you tried Ulauncher yet? You are welcome to share your thoughts on how this might help you get things done quickly._
--------------------------------------------------------------------------------
via: https://itsfoss.com/ulauncher/
作者:[Ankush Das][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/ankush/
[b]: https://github.com/lujun9972
[1]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/08/ulauncher.png?resize=800%2C512&ssl=1
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/08/ulauncher-directory.png?resize=800%2C503&ssl=1
[3]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/08/ulauncher-google.png?resize=800%2C449&ssl=1
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/ulauncher-calculator.png?resize=800%2C429&ssl=1
[5]: https://ext.ulauncher.io
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/ulauncher-gear-icon.png?resize=800%2C338&ssl=1
[7]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/08/ulauncher-settings.png?resize=800%2C492&ssl=1
[8]: https://itsfoss.com/install-deb-files-ubuntu/
[9]: https://itsfoss.com/aur-arch-linux/
[10]: https://github.com/Ulauncher/Ulauncher/
[11]: https://ulauncher.io

View File

@ -0,0 +1,177 @@
[#]: collector: "lujun9972"
[#]: translator: "fisherue"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
[#]: subject: "5 ways to improve your Bash scripts"
[#]: via: "https://opensource.com/article/20/1/improve-bash-scripts"
[#]: author: "Alan Formy-Duval https://opensource.com/users/alanfdoss"
5 步提升你的脚本程序
======
巧用 Bash 脚本程序能帮助你完成很多极具挑战的任务。
![A person working.工作者图片][1]
系统管理员经常写脚本程序,不论长短,这些脚本可以完成某种任务。
你是否曾经查看过某个软件发行方提供的安装用的脚本 (script) 程序?为了能够适应不同用户的系统配置,顺利完成安装,这些脚本程序经常包含很多函数和逻辑分支。多年来,我已经集合了提升我的脚本程序的一些技巧,这里分享几个技巧,希望能对朋友们也有用。这里列出一组短脚本示例,展示给大家做脚本样本。
### 初步尝试
我尝试写一个脚本程序时,原始程序往往就是一组命令行,通常就是调用标准命令完成诸如更新网页内容之类的工作,这样可以节省时间。其中一个类似的工作是解压文件到阿帕奇 (Apache) 网站服务器的主目录里,我的最初脚本程序大概是下面这样:
```
cp january_schedule.tar.gz /usr/apache/home/calendar/
cd /usr/apache/home/calendar/
tar zvxf january_schedule.tar.gz
```
这帮我节省了时间,也减少了键入多条命令操作。时日久了,我掌握了另外的技巧,可以用 Bash 脚本程序完成更难的一些工作,比如说创建软件安装包、安装软件、备份文件系统等工作。
### 1\. 条件分支结构
和众多其他编程语言一样,脚本程序的条件分支结构同样是强大的常用技能。条件分支结构赋予了计算机程序逻辑能力,我的很多实例都是基于条件逻辑分支。
基本的条件分支结构就是 IF 条件分支结构。通过判定是否满足特定条件,可以控制程序选择执行相应的脚本命令段。比如说,想要判断系统是否安装了 Java ,可以通过判断系统有没有一个 Java 库目录;如果找到这个目录,就把这个目录路径添加到可运行程序路径,也就可以调用 Java 库应用了。
```
if [ -d "$JAVA_HOME/bin" ] ; then
    PATH="$JAVA_HOME/bin:$PATH"
```
### 2\. 限定运行权限
你或许想只允许特定的用户才能执行某个脚本程序。除了 Linux 的权限许可管理,比如对用户和用户组设定权限、通过 SELinux 设定此类的保护权限等,你还可以在脚本里设置逻辑判断来设置执行权限。类似的情况可能是,你需要确保只有网站程序的所有者才能执行相应的网站初始化操作脚本。甚至你可以限定只有根用户才能执行某个脚本。这个可以通过在脚本程序里设置逻辑判断实现, Linux 提供的几个环境变量可以帮忙。其中一个是保存用户名称的变量 **$USER**, 另一个是保存用户识别码的变量 **$UID** 。在脚本程序里,执行用户的 UID 值就保存在 **$UID** 变量里。
#### 用户名判别
第一个例子里,我在一个多用户环境里指定只有用户 jboss1 可以执行脚本程序。条件 if 语句猜测判断,‘要求执行这个脚本程序的用户不是 jboss1?’ 如果我猜测的没错,就会输出提示“用户不是 jboss1 ”然后直接退出这个脚本程序返回码为1 **exit 1**
```
if [ "$USER" != 'jboss1' ]; then
     echo "Sorry, this script must be run as JBOSS1!"
     exit 1
fi
echo "continue script"
```
#### 根用户判别
接下来的例子是要求只有根用户才能执行脚本程序。根用户的用户识别码 (UID) 是0,设置的条件判断采用大于操作符 (**-gt**) ,所有 UID 值大于0的用户都被禁止执行该脚本程序。
```
if [ "$UID" -gt 0 ]; then
     echo "Sorry, this script must be run as ROOT!"
     exit 1
fi
echo "continue script"
```
### 3\. 带参数执行程序
可执行程序可以附带参数作为执行选项,命令行脚本程序也是一样,下面给出几个例子。在这之前,我想告诉你,能写出好的程序并不只是写出我们想要它执行什么就执行什么的程序,程序还需要按照我们不想让它执行什么它可以按我们的意愿能够不执行相应操作。如果运行程序时没有提供参数造成程序缺少足够信息,我愿意脚本程序不要做任何破坏性的操作。因而,程序的第一步就是确认命令行是否提供了参数,判定的条件就是参数 **$# **的值是否为 0 ,如果是(意味着没有提供参数),就直接终止脚本程序并退出操作。
```
if [ $# -eq 0 ]; then
    echo "No arguments provided"
    exit 1
fi
echo "arguments found: $#"
```
#### 多个运行参数
可以传递给脚本程序的参数不知一个。脚本使用内部变量指代这些参数,内部变量名用非负整数递增标识,也就是 **$1**,** $2**,** $3 **等等递增。我只是扩展前面的程序,输出显示用户提供的前三个参数。显然,要针对所有的每个参数有对应的响应需要更多的逻辑判断,这里的例子只是简单展示参数的使用。
```
`echo $1 $2 $3`
```
我们在讨论这些参数变量名,你或许有个疑问,“参数变量名怎么跳过了**$0**,(而直接从**$1**开始)?”
是的,是这样,这是有原因的。变量名 **$0** 确实存在,也非常有用,它储存的是被执行的脚本程序的名称。
```
`echo $0`
```
程序执行过程中有一个变量名指代程序名称,很重要的一个原因是,可以在生成的日志文件名称里包含程序名称,最简单的方式应该是调用一个 "echo" 语句。
```
`echo test >> $0.log`
```
当然,你或许要增加一些代码,确保这个日志文件存放在你希望的路径,日志名称包含你认为有用的信息。
### 4\. 交互输入
脚本程序的另一个好用的特性是可以在执行过程中接受输入,最简单的情况是让用户可以输入一些信息。
```
echo "enter a word please:"
 read word
 echo $word
```
这样也可以让用户在程序执行中作出选择。
```
read -p "Install Software ?? [Y/n]: " answ
 if [ "$answ" == 'n' ]; then
   exit 1
 fi
   echo "Installation starting..."
```
### 5\. 出错退出执行
几年前,我写了各脚本,想在自己的电脑上安装最新版本的 Java 开发工具包 (JDK) 。这个脚本把 JDK 文件解压到指定目录,创建更新一些符号链接,再做一下设置告诉系统使用这个最新的版本。如果解压过程出现错误,在执行后面的操作就会使 Java 系统破坏不能使用。因而,这种情况下需要终止程序。如果解压过程没有成功,就不应该再继续进行之后的更新操作。下面语句段可以完成这个功能。
```
tar kxzmf jdk-8u221-linux-x64.tar.gz -C /jdk --checkpoint=.500; ec=$?
if [ $ec -ne 0 ]; then
     echo "Installation failed - exiting."
     exit 1
fi
```
下面的一行语句组可以快速展示变量 **$?** 的用法。
```
`ls T; ec=$?; echo $ec`
```
先用 **touch T** 命令创建一个文件名为 **T** 的文件,然后执行这个文件行,变量 **ec **的值会是0。然后,用 **rm T **命令删除文件,在执行示例的文件行,变量 **ec** 的值会是2,因为文件 T 不存在,命令 **ls **找不到指定文件报错,相应返回值是2。
在逻辑条件里利用这个出错标识,参照前文我使用的条件判断,可以使脚本文件按需完成设定操作。
### 结语
要完成复杂的功能,或许我们觉得应该使用诸如 Python, C, 或 Java 这类的高级编程语言,然而并不尽然,脚本编程语言也很强大,可以完成类似任务。要充分发挥脚本的作用,有很多需要学习的,希望这里的几个例子能让你意识到脚本编程的功能。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/improve-bash-scripts
作者:[Alan Formy-Duval][a]
选题:[lujun9972][b]
译者:[fisherue](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/alanfdoss
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003784_02_os.comcareers_os_rh2x.png?itok=jbRfXinl "工作者图片"

View File

@ -1,196 +0,0 @@
[#]: subject: "Monitor your Linux system in your terminal with procps-ng"
[#]: via: "https://opensource.com/article/21/8/linux-procps-ng"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
用 procps-ng 在终端监控你的 Linux 系统
======
如何找到一个程序的进程 IDPID。最常见的 Linux 工具是由 procps-ng 包提供的,包括 ps、pstree、pidof 和 pgrep 命令。
![System monitor][1]
在[POSIX][2]术语中,进程是一个正在进行的事件,由操作系统的内核管理。当你启动一个应用时就会产生一个进程,尽管还有许多其他的进程在你的计算机后台运行,包括保持系统时间准确的程序,监测新的文件系统,索引文件,等等。
大多数操作系统都有某种类型的系统活动监视器因此你可以了解在任何特定时刻有哪些进程在运行。Linux 有一些供你选择,包括 GNOME 系统监视器和 KSysGuard。这两个软件在桌面上都很有用但 Linux 也提供了在终端监控系统的能力。不管你选择哪一种,对于那些积极管理自己电脑的人来说,检查一个特定的进程是一项常见的任务。
在这篇文章中,我演示了如何找到一个程序的进程 IDPID。最常见的工具是由 [procps-ng][3] 包提供的,包括 `ps`、`pstree`、`pidof` 和 `pgrep` 命令。
### 查找一个正在运行的程序的 PID
有时你想得到一个你知道正在运行的特定程序的进程 IDPID。`pidof` 和 `pgrep` 命令通过命令名称查找进程。
`pidof` 命令返回一个命令的 PID按名称搜索确切的命令
```
$ pidof bash
1776 5736
```
`pgrep` 命令允许使用正则表达式regex
```
$ pgrep .sh
1605
1679
1688
1776
2333
5736
$ pgrep bash
5736
```
### 通过文件查找 PID
你可以用 `fuser` 命令找到使用特定文件的进程的 PID。
```
$ fuser --user ~/example.txt
/home/tux/example.txt: 3234(tux)
```
### 通过 PID 获得进程名称
如果你有一个进程的 PID _编号_,但没有生成它的命令,你可以用 `ps` 做一个“反向查找”:
```
$ ps 3234
PID TTY STAT TIME COMMAND
5736 pts/1 Ss 0:00 emacs
```
### 列出所有进程
`ps` 命令列出进程。你可以用 `-e` 选项列出你系统上的每一个进程:
```
$ ps -e | less
PID TTY TIME CMD
1 ? 00:00:03 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
6 ? 00:00:00 kworker/0:0H-events_highpri
[...]
5648 ? 00:00:00 gnome-control-c
5656 ? 00:00:00 gnome-terminal-
5736 pts/1 00:00:00 bash
5791 pts/1 00:00:00 ps
5792 pts/1 00:00:00 less
(END)
```
### 只列出你的进程
`ps -e` 的输出可能会让人不知所措,所以使用 `-U` 来查看一个用户的进程:
```
$ ps -U tux | less
PID TTY TIME CMD
3545 ? 00:00:00 systemd
3548 ? 00:00:00 (sd-pam)
3566 ? 00:00:18 pulseaudio
3570 ? 00:00:00 gnome-keyring-d
3583 ? 00:00:00 dbus-daemon
3589 tty2 00:00:00 gdm-wayland-ses
3592 tty2 00:00:00 gnome-session-b
3613 ? 00:00:00 gvfsd
3618 ? 00:00:00 gvfsd-fuse
3665 tty2 00:01:03 gnome-shell
[...]
```
这样就减少了 200 个(可能是 100 个,取决于你运行的系统)需要分类的进程。
你可以用 `pstree` 命令以不同的格式查看同样的输出:
```
$ pstree -U tux -u --show-pids
[...]
├─gvfsd-metadata(3921)─┬─{gvfsd-metadata}(3923)
│ └─{gvfsd-metadata}(3924)
├─ibus-portal(3836)─┬─{ibus-portal}(3840)
│ └─{ibus-portal}(3842)
├─obexd(5214)
├─pulseaudio(3566)─┬─{pulseaudio}(3640)
│ ├─{pulseaudio}(3649)
│ └─{pulseaudio}(5258)
├─tracker-store(4150)─┬─{tracker-store}(4153)
│ ├─{tracker-store}(4154)
│ ├─{tracker-store}(4157)
│ └─{tracker-store}(4178)
└─xdg-permission-(3847)─┬─{xdg-permission-}(3848)
└─{xdg-permission-}(3850)
```
### 列出进程的上下文
你可以用 `-u` 选项查看你拥有的所有进程的额外上下文。
```
$ ps -U tux -u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
tux 3545 0.0 0.0 89656 9708 ? Ss 13:59 0:00 /usr/lib/systemd/systemd --user
tux 3548 0.0 0.0 171416 5288 ? S 13:59 0:00 (sd-pam)
tux 3566 0.9 0.1 1722212 17352 ? S&lt;sl 13:59 0:29 /usr/bin/pulseaudio [...]
tux 3570 0.0 0.0 664736 8036 ? SLl 13:59 0:00 /usr/bin/gnome-keyring-daemon [...]
[...]
tux 5736 0.0 0.0 235628 6036 pts/1 Ss 14:18 0:00 bash
tux 6227 0.0 0.4 2816872 74512 tty2 Sl+14:30 0:00 /opt/firefox/firefox-bin [...]
tux 6660 0.0 0.0 268524 3996 pts/1 R+ 14:50 0:00 ps -U tux -u
tux 6661 0.0 0.0 219468 2460 pts/1 S+ 14:50 0:00 less
```
### 用 PID 排除故障
如果你在某个特定的程序上有问题,或者你只是好奇某个程序在你的系统上还使用了什么,你可以用 `pmap` 查看运行中的进程的内存图。
```
$ pmap 1776
5736: bash
000055f9060ec000 1056K r-x-- bash
000055f9063f3000 16K r---- bash
000055f906400000 40K rw--- [ anon ]
00007faf0fa67000 9040K r--s- passwd
00007faf1033b000 40K r-x-- libnss_sss.so.2
00007faf10345000 2044K ----- libnss_sss.so.2
00007faf10545000 4K rw--- libnss_sss.so.2
00007faf10546000 212692K r---- locale-archive
00007faf1d4fb000 1776K r-x-- libc-2.28.so
00007faf1d6b7000 2044K ----- libc-2.28.so
00007faf1d8ba000 8K rw--- libc-2.28.so
[...]
```
### 处理进程 ID
**procps-ng** 软件包有你需要的所有命令,以调查和监控你的系统在任何时候的使用情况。无论你是对 Linux 系统中所有分散的部分如何结合在一起感到好奇,还是对一个错误进行调查,或者你想优化你的计算机的性能,学习这些命令都会为你了解你的操作系统提供一个重要的优势。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/linux-procps-ng
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/system-monitor-splash.png?itok=0UqsjuBQ (System monitor)
[2]: https://opensource.com/article/19/7/what-posix-richard-stallman-explains
[3]: https://gitlab.com/procps-ng

View File

@ -1,169 +0,0 @@
[#]: subject: "Schedule a task with the Linux at command"
[#]: via: "https://opensource.com/article/21/8/linux-at-command"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
用 Linux 的命令来安排一个任务
======
at 命令是一种在特定时间和日期安排一次性任务的终端方法。
![Team checklist][1]
计算机擅长[自动化][2],但不是每个人都知道如何使自动化工作。不过,能够在特定的时间为电脑安排一个任务,然后忘记它,这确实是一种奢侈。也许你有一个文件要在特定的时间上传或下载,或者你需要处理一批还不存在但保证在某个时间存在的文件,或者需要监控的设置,或者你只是需要一个友好的提醒,在下班回家的路上拿起面包和黄油。
That's what the `at`command is for.
这就是 `at` 命令的用处。
### 什么是 Linux at 命令?
`at` 命令是 Linux 终端允许你在特定时间和日期安排一次性工作的方法。它是一种自发的自动化,在终端上很容易实现。
### 安装 at
在 Linux 上,`at` 命令可能已经安装了。你可以使用 `at -V` 命令来验证它是否已经安装。只要返回一个版本,就说明你已经安装了 `at`
```
$ at -V
at version x.y.z
```
如果你试图使用 `at`,但没有找到该命令,大多数现代的 Linux 发行版会提供缺少的 `at` 包。
### 用 at 交互式地安排一个作业
当你使用 `at` 命令和你希望任务运行的时间时,你会打开一个交互式 `at` 提示。你可以输入你想在你指定的时间运行的命令。
如果有帮助的话,你可以把这个过程看作是一个日历应用,就像你可能在你的手机上使用的那样。首先,你在某一天的某个时间创建一个事件,然后指定你想要发生什么。
例如,尝试通过创建一个未来几分钟的任务来计划给自己的备忘录。让任务变得简单,以减少失败的可能性。要退出 `at` 提示,请按键盘上的 **Ctrl+D**
```
$ at 11:20 AM
warning: commands will be executed using /bin/sh
at&gt; echo "hello world" &gt; ~/at-test.txt
at&gt; &lt;EOT&gt;
job 3 at Mon Jul 26 11:20:00 2021
```
正如你所看到的,`at` 使用直观和自然的时间定义。你不需要知道 24 小时制的时钟,也不需要把时间翻译成 UTC 或特定的 ISO 格式。一般来说,你可以使用你自然想到的任何符号,如 _noon_、_1:30 PM_、_13:37_ 等等,来描述你希望一个任务发生的时间。
等待几分钟,然后在你创建的文件上运行 `cat` 或者 `tac` 命令,验证你的任务是否已经运行:
```
$ cat ~/at-test.txt
hello world
```
### 用 at 安排一个任务
你不必使用 `at` 交互式提示符来安排任务。你可以使用 `echo``printf` 向它传送命令。在这个例子中,我使用了 _now_ 符号,以及我希望任务从现在开始延迟多少分钟:
```
`$ echo "echo 'hello again' >> ~/at-test.txt" | at now +1 minute`
```
一分钟后,验证新的命令是否已被执行:
```
$ cat ~/at-test.txt
hello world
hello again
```
### 时间表达式
`at` 命令在解释时间时是非常宽容的。你可以在许多格式中选择,这取决于哪一种对你来说最方便:
* `YYMMDDhhmm`[.ss]
(缩写的年、月、日、小时、分钟,也可选择秒)
* `CCYYMMDDhhmm`[.ss]
(完整的年、月、日、时、分,也可选择的秒)
* `now`
* `midnight`
* `noon`
* `teatime`4 PM
* `AM`
* `PM`
时间和日期可以是绝对的也可以加一个加号_+_使其与 _now_ 相对。当指定相对时间时,你可以使用你可能已经使用的词语:
* `minutes`
* `hours`
* `days`
* `weeks`
* `months`
* `years`
### 时间和日期语法
`at` 命令对日期的输入相比日期不那么宽容。时间必须放在第一位,接着是日期,尽管日期默认为当前日期,并且只有在为未来某天安排任务时才需要。
这些是一些有效表达式的例子:
```
$ echo "rsync -av /home/tux me@myserver:/home/tux/" | at 3:30 AM tomorrow
$ echo "/opt/batch.sh ~/Pictures" | at 3:30 AM 08/01/2022
$ echo "echo hello" | at now + 3 days
```
### 查看你的 at 队列
当你接受了 `at`,并且正在安排任务,而不是在桌子上的废纸上乱写乱画,你可能想查看一下你是否有任务还在队列中。
要查看你的 `at` 队列,使用 `atq` 命令:
```
$ atq
10 Thu Jul 29 12:19:00 2021 a tux
9 Tue Jul 27 03:30:00 2021 a tux
7 Tue Jul 27 00:00:00 2021 a tux
```
要从队列中删除一个任务,使用 `atrm` 命令和任务号。例如,要删除任务 7
```
$ atrm 7
$ atq
10 Thu Jul 29 12:19:00 2021 a tux
9 Tue Jul 27 03:30:00 2021 a tux
```
要看一个计划中的任务的实际内容,你需要查看 `at` spool。只有 root 用户可以查看 `at` spool所以你必须使用 `sudo` 来查看 spool 或 `cat` 任何任务的内容。
### 用 Linux at 安排任务
`at` 系统是一个很好的避免忘记在一天中晚些时候运行一个作业,或者在你离开时让你的计算机为你运行一个作业的方法。与 `cron` 不同的是,它不像 `cron` 那样要求任务必须从现在起一直按计划运行到永远,因此它的语法比 `cron` 简单得多。
等下次你有一个希望你的计算机记住并管理它的小任务,试试 `at` 命令。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/linux-at-command
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/checklist_todo_clock_time_team.png?itok=1z528Q0y (Team checklist)
[2]: https://opensource.com/article/20/11/orchestration-vs-automation

View File

@ -0,0 +1,87 @@
[#]: subject: "Automatically Synchronize Subtitle With Video Using SubSync"
[#]: via: "https://itsfoss.com/subsync/"
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
使用 SubSync 自动将字幕与视频同步化
======
让我分享一个场景。你正试图观看一部电影或视频,你需要字幕。你下载了字幕,却发现字幕没有正确同步。没有其他好的字幕可用。现在该怎么做?
你可以[在 VLC 中按 G 或 H 键来同步字幕][1]。它为字幕增加了一个延迟。如果字幕在整个视频中以相同的时间间隔不同步这可能会起作用。但如果不是这种情况SubSync 在这里会有很大帮助。
### SubSync: 字幕语音同步器
[SubSync][2] 是一个灵巧的开源工具,可用于 Linux、macOS 和 Windows。
它通过收听音轨来同步字幕,这就是它的神奇之处。即使音轨和字幕使用的是不同的语言,它也能发挥作用。如果有必要,它也可以被翻译,但我没有测试这个功能。
我做了一个简单的测试,使用一个与我正在播放的视频不同步的字幕。令我惊讶的是,它工作得很顺利,我得到了完美的同步字幕。
使用 SubSync 很简单。你启动应用,它要求你添加字幕文件和视频文件。
![User interface for SubSync][3]
你必须在界面上指定字幕和视频的语言。它可能会根据使用的语言下载额外的资源。
![SubSync may download additional packages for language support][4]
请记住,同步字幕需要一些时间,这取决于视频和字幕的长度。在等待过程完成时,你可以拿起你的茶/咖啡或啤酒。
你可以看到正在进行的同步状态,甚至可以在完成之前保存它。
![SubSync synchronization in progress][5]
同步完成后,你就可以点击保存按钮,把修改的内容保存到原文件中,或者把它保存为新的字幕文件。
![Synchronization completed][6]
我不能说它在所有情况下都能工作,但在我运行的样本测试中它是有效的。
### 安装 SubSync
SubSync 是一个跨平台的应用,你可以从它的[下载页面][7]获得 Windows 和 MacOS 的安装文件。
对于 Linux 用户SubSync 是作为一个 Snap 包提供的。如果你的发行版已经启用了 Snap 支持,使用下面的命令来安装 SubSync
```
sudo snap install subsync
```
请记住,下载 SubSync snap 包将需要一些时间。所以要有一个良好的网络连接或足够的耐心。
### 最后
就我个人而言,我对字幕很上瘾。即使我在 Netflix 上看英文电影,我也会把字幕打开。它有助于清楚地理解每段对话,特别是在有强烈口音的情况下。如果没有字幕,我永远无法理解[电影 Snatch 中 Mickey O'Neil由 Brad Pitt 扮演)的一句话][8]。
使用 SubSync 比[使用 Subtitle Editor][9] 同步字幕要容易得多。在[企鹅字幕播放器][10]之后,对于像我这样在整个互联网上搜索不同国家的稀有或推荐(神秘)电影的人来说,这是另一个很棒的工具。
如果你是一个“字幕用户”,我感觉你会喜欢这个工具。如果你使用过它,请在评论区分享你的使用经验。
--------------------------------------------------------------------------------
via: https://itsfoss.com/subsync/
作者:[Abhishek Prakash][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://itsfoss.com/author/abhishek/
[b]: https://github.com/lujun9972
[1]: https://itsfoss.com/how-to-synchronize-subtitles-with-movie-quick-tip/
[2]: https://subsync.online/
[3]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2021/08/subsync-interface.png?resize=593%2C280&ssl=1
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/subsync-subtitle-synchronize.png?resize=522%2C189&ssl=1
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2021/08/subsync-subtitle-synchronize-1.png?resize=424%2C278&ssl=1
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2021/08/subsync-subtitle-synchronize-2.png?resize=424%2C207&ssl=1
[7]: https://subsync.online/en/download.html
[8]: https://www.youtube.com/watch?v=tGDO-9hfaiI
[9]: https://itsfoss.com/subtitld/
[10]: https://itsfoss.com/penguin-subtitle-player/

View File

@ -0,0 +1,149 @@
[#]: subject: "Build a JAR file with fastjar and gjar"
[#]: via: "https://opensource.com/article/21/8/fastjar"
[#]: author: "Seth Kenlon https://opensource.com/users/seth"
[#]: collector: "lujun9972"
[#]: translator: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
用 fastjar 和 gjar 构建一个 JAR 文件
======
fastjar、gjar 和 jar 等工具可以帮助你手动或以编程方式构建 JAR 文件,而其他工具链,如 Maven
和 Gradle 提供了依赖性管理的功能。
![Someone wearing a hardhat and carrying code ][1]
JAR 文件使用户很容易下载和启动他们想尝试的应用,很容易将该应用从一台计算机转移到另一台计算机(而且 Java 是跨平台的,所以可以鼓励自由分享),而且对于新的程序员来说,很容易理解 JAR 文件的内容,以找出使 Java 应用运行的原因。
创建 JAR 文件的方法有很多,包括 Maven 和 Gradle 等工具链解决方案,以及 IDE 中的一键构建功能。然而,也有一些独立的命令,如 `jarfast`、`gjar` 和普通的 `jar`,它们对于快速和简单的构建是很有用的,并且可以演示 JAR 文件运行所需要的东西。
### 安装
在 Linux 上,你可能已经有了 `fastjar`、`gjar` 或 `jar` 命令,作为 OpenJDK 包或 GCJGCC-Java的一部分。你可以通过输入不带参数的命令来测试这些命令是否已经安装
```
$ fastjar
Try 'fastjar --help' for more information.
$ gjar
jar: must specify one of -t, -c, -u, -x, or -i
jar: Try 'jar --help' for more information
$ jar
Usage: jar [OPTION...] [ [--release VERSION] [-C dir] files] ...
Try `jar --help' for more information.
```
我安装了所有这些命令,但你只需要一个。所有这些命令都能够构建一个 JAR。
在 Fedora 等现代 Linux 系统上,输入一个缺失的命令会使你的操作系统提示安装。
另外,你可以直接从 [AdoptOpenJDK.net][3] 为 Linux、MacOS 和 Windows [安装 Java][2]。
### 构建 JAR
首先,你需要构建一个 Java 应用。
为了简单起见,在一个名为 hello.java 的文件中创建一个基本的 “hello world” 应用:
```
class Main {
public static void main([String][4][] args) {
[System][5].out.println("Hello Java World");
}}
```
这是一个简单的应用,在某种程度上淡化了管理外部依赖关系在现实世界中的重要性。不过,这也足以让你开始了解创建 JAR 所需的基本概念了。
接下来,创建一个清单文件。清单文件描述了 JAR 的 Java 环境。在这种情况下,最重要的信息是识别主类,这样执行 JAR 的 Java 运行时就知道在哪里可以找到应用的入口点。
```
$ mdir META-INF
$ echo "Main-Class: Main" &gt; META-INF/MANIFEST.MF
```
### 编译 Java 字节码
接下来,把你的 Java 文件编译成 Java 字节码。
```
`$ javac hello.java`
```
另外,你也可以使用 GCC 的 Java 组件来编译:
```
`$ gcj -C hello.java`
```
无论哪种方式,都会产生文件 `Main.class`
```
$ file Main.class
Main.class: compiled Java class data, version XX.Y
```
### 创建 JAR
你有了所有需要的组件,这样你就可以创建 JAR 文件了。
我经常包含 Java 源码给好奇的用户参考但_所有_需要的只是 `META-INF` 目录和类文件。
`fastjar` 命令使用类似于 [`tar` 命令][6]的语法。
```
`$ fastjar cvf hello.jar META-INF Main.class`
```
另外,你也可以用 `gjar`,方法大致相同,只是 `gjar` 需要你明确指定清单文件:
```
`$ gjar cvf world.jar Main.class -m META-INF/MANIFEST.MF`
```
或者你可以使用 `jar` 命令。注意这个命令不需要 Manifest 文件,因为它会自动为你生成一个,但为了安全起见,我明确定义了主类:
```
`$ jar --create --file hello.jar --main-class=Main Main.class`
```
测试你的应用:
```
$ java -jar hello.jar
Hello Java World
```
### 轻松打包
`fastjar`、`gjar` 和 `jar` 这样的工具可以帮助你手动或以编程方式构建 JAR 文件,而其他工具链如 Maven 和 Gradle 则提供了依赖性管理的功能。一个好的 IDE 可能会集成这些功能中的一个或多个。
无论你使用什么解决方案Java 都为分发你的应用代码提供了一个简单而统一的目标。
--------------------------------------------------------------------------------
via: https://opensource.com/article/21/8/fastjar
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/build_structure_tech_program_code_construction.png?itok=nVsiLuag (Someone wearing a hardhat and carrying code )
[2]: https://opensource.com/article/19/11/install-java-linux
[3]: https://adoptopenjdk.net/
[4]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+string
[5]: http://www.google.com/search?hl=en&q=allinurl%3Adocs.oracle.com+javase+docs+api+system
[6]: https://opensource.com/article/17/7/how-unzip-targz-file