交互式命令行如何换行三引号_如何在命令行上创建和查看交互式备忘单

交互式命令行如何换行三引号

为什么使用命令行? (Why Command-line?)

If you haven’t used the command-line already, you should start to learn some basic command-line tools. Here are the reasons why:

如果尚未使用命令行,则应该开始学习一些基本的命令行工具。 原因如下:

  • Command-line is useful for data scientists. With the command-line, many things you usually do such as moving files, copy files, unzip files, create new files could be done much quicker.

    命令行对数据科学家很有用。 使用命令行,您通常可以执行许多操作,例如移动文件,复制文件,解压缩文件,创建新文件。
  • You can even explore your data with the command-line! Here is a great resource for it. Jupyter notebook is commonly used for this task but sometimes, it will be more beneficial for you to use command-lines when you write scripts for your projects.

    您甚至可以使用命令行浏览数据! 这是一个很好的资源 。 Jupyter笔记本通常用于此任务,但有时,在为项目编写脚本时使用命令行会更有益。

  • You can create a bash script to automate the tasks that you have done repetitively. For example, I created a bash script to restructure my Django project file. Instead of moving the files around, creating the virtual environment, installing required packages, all I need to do is to call createapp.sh and everything is set up for me in a second!

    您可以创建一个bash脚本来自动执行您重复执行的任务 。 例如,我创建了一个bash脚本来重组Django项目文件。 无需四处移动文件,创建虚拟环境,安装所需的软件包,我要做的就是调用createapp.sh ,一切都将在第二秒钟为我完成!

#!/usr/bin/env bash
APPNAME="$1"
mkdir $APPNAME
cd $APPNAME
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install Django
django-admin startproject $APPNAME
mv $APPNAME/manage.py ./
mv $APPNAME/$APPNAME/* $APPNAME
rm -r $APPNAME/$APPNAME/
  • You want to identify why your code takes a long time to execute. That is when it is helpful to have a dynamic real-time view of a running system to identify how much CPU, memory you are using. top is one of the most powerful command-line tools for this task

    您想确定为什么您的代码需要很长时间才能执行。 在这种情况下,具有正在运行的系统的动态实时视图有助于识别正在使用的CPU和内存量。 top是完成此任务的最强大的命令行工具之一

Image for post

With the above reasons, it is undeniable that the command-line is useful. However, it is impossible to remember all the commands. That is why Google is my friend when it comes to remembering commands.

由于上述原因,不可否认命令行是有用的。 但是,不可能记住所有命令。 这就是为什么Google在记住命令时是我的朋友。

But googling takes time because you need to: open the browser, search among all the websites such as StackOverflow to find the command. Is there a faster way than this?

但是谷歌搜索需要花费时间,因为您需要:打开浏览器,在所有网站(例如StackOverflow)中搜索以找到命令。 有没有比这更快的方法?

作弊 (Cheat)

Yes, there is a faster way than googling and it involves cheat (not cheating). Cheat allows you to create and view interactive cheatsheets on the command-line. What does it mean? It means when you type this on your terminal

是的,有一种比谷歌搜索更快的方法,它涉及作弊(而不是作弊)。 Cheat允许您在命令行上创建和查看交互式备忘单。 这是什么意思? 这意味着当您在终端上键入此内容时

cheat mv

This is what you will see

这就是你会看到的

# To move a file from one place to another:
mv <src> <dest># To move a file from one place to another and automatically overwrite if the destination file exists:
# (This will override any previous -i or -n args)
mv -f <src> <dest># To move a file from one place to another but ask before overwriting an existing file:
# (This will override any previous -f or -n args)
mv -i <src> <dest># To move a file from one place to another but never overwrite anything:
# (This will override any previous -f or -i args)
mv -n <src> <dest># To move listed file(s) to a directory
mv -t <dest> <file>...

Pretty cool! Many options of command mv are listed with descriptions!

太酷了! 描述中列出了命令mv许多选项!

Even though this repository is useful, it is not obvious in the repository how to set this up. Thanks to this answer on StackOverFlow, I finally figure out the way. In this article, I will show you more detailed instructions on how to set up cheat and how to use it.

尽管此存储库很有用,但在存储库中如何设置它并不明显。 多亏了StackOverFlow的这个答案 ,我终于找到了解决方法。 在本文中,我将向您展示有关如何设置作弊以及如何使用作弊的更详细的说明。

建立 (Setup)

  • Download the executable from the releases page

    发布页面下载可执行文件

  • Extract the zip file

    解压缩zip文件
  • Make it executable. Without this command, you will not be able to execute the downloaded file

    使它可执行。 没有此命令,您将无法执行下载的文件
chmod +x <downloaded_file> # No gzip extension this time
  • Find the directories in your path

    在您的路径中找到目录
echo $PATH | tr ":" "\n"

This is what shown in my screen

这就是我的屏幕上显示的内容

Image for post
  • Copy the downloaded file in one of the above directories. Any of them will work. In my case, I copied the file in /usr/local/bin

    将下载的文件复制到上述目录之一。 他们中的任何一个都可以。 就我而言,我将文件复制到/usr/local/bin

cp <downloaded_file> /usr/local/bin/cheat

cheat at the end of the directory indicates the name you will use to call the file

目录末尾的cheat符号表示您将用来调用文件的名称

  • Put config file into ./config file

    将配置文件放入./config文件

cheat --init > ~/.config/cheat/conf.yml
  • Place /.config/cheat/conf.yml in path

    /.config/cheat/conf.yml放在路径中

export CHEAT_CONFIG_PATH="~/config/cheat/conf.yml"export EDITOR="/usr/bin/nano"

Awesome! Now you are ready to use cheat!

太棒了! 现在您可以使用作弊了!

用法 (Usage)

Just type cheat on the terminal, you will see different options to use cheat

只需在终端上输入cheat功能,您就会看到使用作弊功能的不同选项

It is extremely easy to use cheat.If you want to view a cheatsheet such as tar , you will use

cheat.非常容易使用cheat. 如果要查看tar的备忘单,则可以使用

cheat tar

And all the options and descriptions for command tar will show up on the terminal. Use cheat -l to see all available cheatsheets.

并且命令tar所有选项和描述将显示在终端上。 使用备忘-l查看所有可用备忘单。

If you want to edit or create a new cheatsheet, you can use cheat -e <cheatsheet_name>. For example, I want to save the cheatsheet for fuser,a powerful command line utility to locate processes, I will add fuserinto my cheatsheet like this

如果要编辑或创建新的cheat -e <cheatsheet_name> ,可以使用cheat -e <cheatsheet_name> 。 例如,我想保存fuser,的备忘单fuser,是一个功能强大的命令行实用程序,用于定位进程,我将像这样将fuser添加到我的速写中

cheat -e fuser

Editor for fuser will open. All you need to is do write the descriptions and commands

fuser器的编辑fuser将打开。 您只需要编写说明和命令即可

#View port
fuser <portnumber>/tcp#Kill port
fuser -k <portnumber>/tcp

Then type ‘ESC’ and ‘:wq’ to write and quit the editor.

然后键入“ ESC”和“:wq”以编写并退出编辑器。

Now when you type cheat fuser , you will see the descriptions and commands you have just written! From now on, you don’t need to search on Google this command anymore. How convenient!

现在,当您输入cheat fuser ,您将看到刚刚编写的描述和命令! 从现在开始,您不再需要在Google上搜索此命令。 多么方便!

结论 (Conclusion)

Congratulations! You have just learned how to create and view interactive cheatsheets on the command-line. This tool will save you a lot of time on googling so try it out if you have not already done so.

恭喜你! 您刚刚学习了如何在命令行上创建和查看交互式备忘单。 该工具将为您节省大量的谷歌搜索时间,因此请尝试一下(如果尚未这样做)。

Star this repo if you want to check out the codes for all of the articles I have written.

如果您想查看我编写的所有文章的代码,请给此回购加注星号。

I like to write about basic data science concepts and play with different algorithms and data science tools. You could connect with me on LinkedIn and Twitter. Follow me on Medium or sign up for my newsletter to stay informed with my latest data science articles like these:

我喜欢写有关基本数据科学概念的文章,并喜欢使用不同的算法和数据科学工具。 您可以在LinkedInTwitter上与我联系。 在“ Medium”上关注我,或注册我的时事通讯,以随时了解最新的数据科学文章,例如:

翻译自: https://towardsdatascience.com/how-to-create-and-view-interactive-cheatsheets-on-the-command-line-6578641039ff

交互式命令行如何换行三引号

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值