diff --git a/sources/tech/20180306 Most Useful Linux Commands You Can Run in Windows 10.md b/sources/tech/20180306 Most Useful Linux Commands You Can Run in Windows 10.md deleted file mode 100644 index 6a2fd8ef69..0000000000 --- a/sources/tech/20180306 Most Useful Linux Commands You Can Run in Windows 10.md +++ /dev/null @@ -1,145 +0,0 @@ -translated by cyleft - -Most Useful Linux Commands You Can Run in Windows 10 -====== - -![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/wsl-commands.png?itok=91oEXdO8) - -In the previous articles of this series, we talked about [getting started with WSL on Windows 10.][1] In the last article of the series, we will talk about some of the widely used Linux commands on Windows 10. - -Before we dive further into the topic, let’s make it clear who this is for. This article is meant for greenhorn developers who use Windows 10 machines but want to learn about Linux as it’s the dominant platform in the cloud, whether it be Azure, AWS, or private cloud. In a nutshell, it’s intended for Windows 10 users who are new to Linux. - -Which commands you need will depend on your own workload. Your mileage may vary from mine. The goal of the article is to get you comfortable with Linux in Windows 10. Also bear in mind that WSL doesn’t provide access to hardware components like sound cards or GPU. Officially. But Linux users never take a no for an answer. Many users have managed to not only gain access to sound cards and GPU, they also managed to run desktop Linux apps on Windows. But that’s not the scope of this article. We may talk about it at some point, but not today. - -Here are a few tasks to get started. - -### How to keep your Linux system up to date - -Since you are running Linux inside of Windows, you are stripped of all the security that Linux systems offer. In addition, if you don’t keep your Linux systems patched, you will expose your Windows machines to those threats. Always keep your Linux machines up to date. - -WSL officially supports openSUSE, SUSE Linux Enterprise and Ubuntu. You can install other distributions as well, but I can get all of my work done with either of these two as all I need is access to some basic Linux utilities. - -**Update openSUSE Leap:** -``` -sudo zypper up - -``` - -If you want a system upgrade, you can do that after running the above command: -``` -sudo zypper dup - -``` - -**Update Ubuntu machine:** -``` -sudo apt-get update - -sudo apt-get dist-upgrade - -``` - -You are safe and secure. Since updates on Linux systems are incremental, I run system updates on a daily basis. It’s mostly a few KB or a few MB of updates without any downtime, unlike Windows 10 updates where you need to reboot your system. - -### Managing files and folders - -Once your system is updated, we can look at some mundane, or not so mundane tasks. - -The second most important task is to manage your local and remote files using Linux. I must admit that as much as I prefer GUI apps, there are certain tasks, where terminal offers more value and reliability. Try moving 1TB of files using the Explorer app. Good luck. I always use the rsync command to transfer the bulk of files. The good news is that with rsync, if you do stop it in the middle, you can resume from where you left off. - -Although you can use cp or mv commands to copy or move files, I prefer rsync as it offers more flexibility over the others and learning it will also help you in transferring files between remote machines. There are three basic tasks that I mostly perform. - -**Copy entire directory using rsync:** -``` -rsync -avzP /source-directory /destination directory - -``` - -**Move files using rsync:** -``` -rsync --remove-source-files -avzP /source-directory /destination-directory - -``` - -This command will delete files from the source directory after successful copying to the destination directory. - -**Sync two directories:** - -I keep a copy of all of my files on more than one location. However, I continue to add and delete files from the primary location. It could become a challenge to keep all other locations synced without using some application dedicated to file sync, rsync simplifies the process. This is the command that you need to keep two directories synced. Keep it mind that it’s a one way sync -- from source to destination. -``` -rsync --delete -avzP /source-directory /destination-directory - -``` - -The above commands deletes the file in the destination folder if they are not found in the source folder. In other way it creates a mirror copy of the source directory. - -### Automate file backup - -Yes, keeping up with back up is a mundane task. In order to keep my drives fully synced I add a cron job that runs the rsync command at night to keep all directories synced. I do, however, keep one external drive that is synced manually on a weekly basis. I don’t use the --delete flag as it may delete some files that I might have wanted. I use that flag manually. - -**To create a cron job, open crontab:** -``` -crontab -e - -``` - -I run this at night when both systems are idle as moving huge amount of files can slow your system down. The command runs at 1 am every morning. You can change it appropriately: -``` -# 0 1 * * * rsync -avzP /source-directory /destination-directory - -``` - -This is the structure for a cron job using crontab: -``` -# m h dom mon dow command - -``` - -Here m = minute, h = hour, dom= day of the month, mon= month; dow= day of the week. - -We are running this command at 1 am every day. You could choose to run in a certain day of the week or day of the month (so it will run on the 5th of every month, for example) and so on. You can read more about crontab [here][2]. - -### Managing your remote servers - -One of the reasons you are running WSL on your system is that you manage Linux systems on cloud and WSL provides you with native Linux tools. The first thing you need is to remotely log into your Linux server using the ssh command. - -Let’s say my server is 192.168.0.112; the dedicated port is 2018 (never use the default 22 port); the Linux user of that server is swapnil and password is i-wont-tell-you. -``` -ssh -p2018 swapnil@192.168.0.112 - -``` - -It will ask for the password and, eureka, you are logged into your Linux server. Now you can perform all the tasks that you want to perform as you are literally inside that Linux machine. No need to use puTTY. - -You can easily transfer files between your local machine and remote machine using the rsync command. Instead of source or destination directory, depending on whether you are uploading the files to the server or downloading them to local machine, you can use [username@IP][3]-address-of-server:/path-of-directory. - -So if I want to copy some text files to the home directory of my server, here is the command: -``` -rsync -avzP /source-directory-on-local-machine ‘ssh -p2018’ swapnil@192.168.0.112:/home/swapnil/Documents/ - -``` - -It will copy all files to the Documents directory of my remote server. - -### Conclusion - -The idea of this tutorial was to demonstrate that WSL allows you to perform a wide range of Linux-y tasks on your Windows 10 systems. In most cases, it increases productivity and performance. Now, the whole world of Linux is open to you for exploration on your Windows 10 system. Go ahead and explore it. If you have any questions, or if you would like me to cover more areas of WSL, please share your thoughts in the comments below. - -Learn more about the [Administering Linux on Azure (LFS205)][4] course and sign up [here][5]. - --------------------------------------------------------------------------------- - -via: https://www.linux.com/blog/learn/2018/3/most-useful-linux-commands-you-can-run-windows-10 - -作者:[SAPNIL BHARTIYA][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:https://www.linux.com/users/arnieswap -[1]:https://www.linux.com/blog/learn/2018/2/how-get-started-using-wsl-windows-10 -[2]:http://www.adminschoice.com/crontab-quick-reference -[3]:mailto:username@IP -[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/administering-linux-on-azure -[5]:http://bit.ly/2FpFtPg diff --git a/translated/tech/20180306 Most Useful Linux Commands You Can Run in Windows 10.md b/translated/tech/20180306 Most Useful Linux Commands You Can Run in Windows 10.md new file mode 100644 index 0000000000..f0dc91b294 --- /dev/null +++ b/translated/tech/20180306 Most Useful Linux Commands You Can Run in Windows 10.md @@ -0,0 +1,144 @@ + +运行在 Windows 10 系统中绝对实用的 Linux 命令 +====== + +![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/wsl-commands.png?itok=91oEXdO8) + +在本系列早先的文章中,我们讨论了关于如何在 [Windows 10 上开启 WSL 之旅][1] 的内容。作为本系列的最后一篇文章,我们准备探讨一些能在 Windows 10 上广泛使用的 Linux 命令。 + +话题深入之前,请先让我们明确本教程所适用的人群。本文适用于使用 Windows 10 系统的初级开发者,帮助其了解学习关于 Azure、AWS 或是私有云的 Linux 平台。换句话说,就是为了帮助初次接触 Linux 系统的 Windows 10 用户。 + +您的工作量决定了您所需要的命令,而我的需求可能和您的不一样。本文旨在帮助您在 Windwos 10 上舒服的使用 Linux。不过请牢记,WSL 并不提供硬件访问的功能,比如声卡、GPU,至少官方是这么描述的。但是这可能并不能阻止 Linux 用户的折腾精神。很多用户不仅完成了硬件访问,甚至已经在 Windows 10 上安装上了 Linux 桌面程序。但是本文并不会涉及这些内容,我们可能会讨论这些,但不是现在。 + +下面是我们需要着手的任务。 + +### 如何让您的 Linux 系统保持到最新的版本 + +因为 Linux 运行在了 Windows 系统中,所以您将被剥夺 Linux 系统所提供的所有安全服务。另外,如果不及时给 Linux 系统打补丁,Windows 设备将被迫暴露在外界威胁中,所以还请保持您的 Linux 设备到最新版本。 + +WSL 官方支持 openSUSE、SUSE Linux Enterprise 和 Ubuntu。您也可以安装其他发行版,但是我只需要它们当中的两个就可以完成我的所有工作,毕竟,我只需要访问一些 Linux 基础程序。 + +**更新 openSUSE Leap:** +``` +sudo zypper up + +``` + +如果您想升级系统,您可以运行下面的命令: +``` +sudo zypper dup + +``` + +**更新 Ubuntu:** +``` +sudo apt-get update + +sudo apt-get dist-upgrade + +``` + +由于 Linux 系统的更新是渐进式的,所以更新系统成为了我的日常。Windows 10 的更新通常需要重启系统,而 Linux 不同,一般只有 KB 或是 MB 级的更新,无需重启。 + +### 管理文件目录 + +系统更新之后,我们还剩余一些非必要或是不那么重要的任务。 + +系统更新之外的第二重要的任务是使用 Linux 管理本地和远程文件。我承认我更青睐图形界面程序,但是终端能提供更可靠、更有价值的服务。使用 Explorer 程序,尝试移动 1 TB 的文件,祝你好运。数据量大的话,我通常使用 rsync 命令来移动它们。如果中断任务,rsync 可以在上次停止的节点继续工作。 + +虽然您可能更习惯使用 cp 或是 mv 命令复制、移动文件,但是我还是喜欢灵活的 rsync 命令,了解 rsync 对远程文件传输也有帮助。使用 rsync 大半为了完成下面三个任务: + +**使用 rsync 复制整个目录:** +``` +rsync -avzP /source-directory /destination directory + +``` + +**使用 rsync 移动文件:** +``` +rsync --remove-source-files -avzP /source-directory /destination-directory + +``` + +在成功复制目标目录之后,此命令将删除源文件。 + +**使用 rsync 同步文件:** + +我的文件可能在多处存储。但是,我只会在主要位置中增加或是删除。如果不使用专业的软件,同步文件可能会给用户带来挑战,而 rsync 刚好可以简化这个过程。这个命令可以让两个目录文件内容同步,留个印象,也许用得上。 +``` +rsync --delete -avzP /source-directory /destination-directory + +``` + +如果原目录中没有找到文件,上述命令将删除目标目录中的文件,并通过另一种方式创建源目录的镜像复制。 + +### 文件自动备份 + +保持文件备份是一项普通的工作。为了保持我的设备的完全同步,我运行了一个 cron 作业在夜间持续同步我的所有目录。保持一个外部驱动,每周我都会手动同步。由于可能删掉我不想删除的文件,所以我并没有使用 --delete 选项。 + +**创建 cron 作业, 打开 crontab:** +``` +crontab -e + +``` + +移动大文件时,我会选择在系统空闲的深夜执行该命令。此命令将在每天早上 1 点运行,您大概可以这样修改它: +``` +# 0 1 * * * rsync -avzP /source-directory /destination-directory + +``` + +这是使用 crontab 的定时作业的命令结构: +``` +# m h dom mon dow command + +``` + +在此,m = 分钟, h = 小时, dom= 本月的某天, mon= 月; dow= 本周的某天。 + +我们将在每天早上 1 点运行这条命令。您可以选择 dow 或是 dom(比如,每月 5 号)等。您可以在 [这里][2] 阅读更多相关内容。 + +### 管理远程服务器 + +在 Windows 系统上使用 WSL 的优势之一就是能方便管理远程 Linux 服务器,WSL 能提供原生的 Linux 工具给您。首先,您需要使用 ssh 命令登陆远程 Linux 服务器。 + +比如,我的服务器 ip 是 192.168.0.112;端口为 2018(不是默认的 22 端口);Linux 用户名是 swapnil,密码是 `就不告诉你`。 +``` +ssh -p2018 swapnil@192.168.0.112 + +``` + +它会向您请求用户密码,然后您就可以登陆到 Linux 服务器了。现在您可以执行任意您想执行的所有操作,且不需使用额外的 puTTY 程序。 + +使用 rsync ,您可以很轻易的将本地文件传输到远程设备。源文件还是目标目录取决于您是上传文件到服务器,还是下载文件到本地目录,您可以使用 [username@IP][3]。 + +如果我想在服务器中复制一些文本内容到 home 目录,参照这里的目录: +``` +rsync -avzP /source-directory-on-local-machine ‘ssh -p2018’ swapnil@192.168.0.112:/home/swapnil/Documents/ + +``` + +这将会在远程服务器中复制文件到 `Documents` 目录。 + +### 总结 + +本教程主要是为了证明您可以通过 Windows 10 系统的 WSL 完成 Linux 系的很大一部分的任务。通常来说,它提高了生产效率。现在,Linux 的世界已经向 Windwos 10 系统打开怀抱了,尽情探索吧。如果您有任何疑问,或是想了解 WSL 涉及到的其他层面,欢迎在下方的评论区分享您的想法。 + +在 [Administering Linux on Azure (LFS205)][4] 课程中了解更多,可以在 [这里][5] 注册。 + +-------------------------------------------------------------------------------- + +via: https://www.linux.com/blog/learn/2018/3/most-useful-linux-commands-you-can-run-windows-10 + +作者:[SAPNIL BHARTIYA][a] +译者:[CYLeft](https://github.com/CYLeft) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:https://www.linux.com/users/arnieswap +[1]:https://www.linux.com/blog/learn/2018/2/how-get-started-using-wsl-windows-10 +[2]:http://www.adminschoice.com/crontab-quick-reference +[3]:mailto:username@IP +[4]:https://training.linuxfoundation.org/linux-courses/system-administration-training/administering-linux-on-azure +[5]:http://bit.ly/2FpFtPg