交互式命令行如何换行三引号
为什么使用命令行? (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](https://img-service.csdnimg.cn/img_convert/043aaafdecba932ce231cba0026654a7.png)
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](https://img-service.csdnimg.cn/img_convert/cc1a575572d2ff9777283d4cf75b59c0.png)
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 fuser
into 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:
我喜欢写有关基本数据科学概念的文章,并喜欢使用不同的算法和数据科学工具。 您可以在LinkedIn和Twitter上与我联系。 在“ Medium”上关注我,或注册我的时事通讯,以随时了解最新的数据科学文章,例如:
交互式命令行如何换行三引号