linux bash命令_Ultimate Linux命令行指南-Full Bash教程

linux bash命令

Welcome to our ultimate guide to the Linux Command Line. This tutorial will show you some of the key Linux command line technologies and introduce you to the Bash scripting language.

欢迎使用我们的Linux命令行最终指南。 本教程将向您展示一些关键的Linux命令行技术,并向您介绍Bash脚本语言。

什么是Bash? (What is Bash?)

Bash (short for Bourne Again SHell) is a Unix shell, and a command language interpreter. A shell is simply a macro processor that executes commands. It’s the most widely used shell packaged by default for most Linux distributions, and a successor for the Korn shell (ksh) and the C shell (csh).

Bash (Bourne Again SHell的缩写)是Unix shell,也是命令语言解释器。 外壳程序只是执行命令的宏处理器。 默认情况下,它是大多数Linux发行版中使用最广泛的shell,它是Korn shell(ksh)和C shell(csh)的后继产品。

Many things that can be done Linux operating system can be done via command line. Some examples are…

Linux操作系统可以通过命令行完成许多事情。 一些例子是…

  • Editing files

    编辑档案
  • Adjusting the volume of the operating system

    调整操作系统的音量
  • Fetching web pages from the internet

    从互联网上获取网页
  • Automating work you do every day

    每天执行的工作自动化

You can read more about bash here, via the GNU Documentation, and via the tldp guide.

您可以在此处通过GNU文档和tldp指南阅读有关bash的更多信息。

在命令行上使用bash(Linux,OS X) (Using bash on the command line (Linux, OS X))

You can start using bash on most Linux and OS X operating systems by opening up a terminal. Let’s consider a simple hello world example. Open up your terminal, and write the following line (everything after the $ sign):

您可以通过打开终端来在大多数Linux和OS X操作系统上开始使用bash。 让我们考虑一个简单的hello world示例。 打开您的终端,并编写以下行($符号之后的所有内容):

zach@marigold:~$ echo "Hello world!"
Hello world!

As you can see, we used the echo command to print the string “Hello world!” to the terminal.

如您所见,我们使用echo命令来打印字符串“ Hello world!”。 到终端。

编写bash脚本 (Writing a bash script)

You can also put all of your bash commands into a .sh file, and run them from the command line. Say you had a bash script with the following contents:

您还可以将所有bash命令放入.sh文件,然后从命令行运行它们。 假设您有一个包含以下内容的bash脚本:

#!/bin/bash
echo "Hello world!"

It’s worth noting that first line of the script starts with #!. It is a special directive which Unix treats differently.

值得注意的是,脚本的第一行以#!开头#! 。 这是Unix对待的特殊指令。

为什么在脚本文件的开头使用#!/ bin / bash? (Why did we use #!/bin/bash at the beginning of the script file?)

That is because it is a convention to let the interactive shell know what kind of interpreter to run for the program that follows. The first line tells Unix that the file is to be executed by /bin/bash. This is the standard location of the Bourne shell on just about every Unix system. Adding #!/bin/bash as the first line of your script, tells the OS to invoke the specified shell to execute the commands that follow in the script. #! is often referred to as a “hash-bang”, “she-bang” or “sha-bang”. Though it is only executed if you run your script as an executable. For example, when you type ./scriptname.extension, it will look at the top line to find out the interpreter, whereas, running the script as bash scriptname.sh, first line is ignored.

这是因为让交互式外壳程序知道为随后的程序运行哪种解释器是一种约定。 第一行告诉Unix,该文件将由/ bin / bash执行。 这是几乎每个Unix系统上Bourne shell的标准位置。 将#!/ bin / bash添加为脚本的第一行,告诉操作系统调用指定的shell来执行脚本中后面的命令。 #! 通常被称为“哈希爆炸”,“爆炸”或“爆炸”。 尽管仅当您将脚本作为可执行文件运行时才执行。 例如,当您键入./scriptname.extension ,它将在第一行中查找解释程序,而以bash scriptname.sh身份运行脚本时,第一行将被忽略。

Then you could run the script like so: For make file executable you should call this command under sudo chmod +x “filename”.

然后,您可以像这样运行脚本:为使文件可执行,应在sudo chmod + x“ filename”下调用此命令。

zach@marigold:~$ ./myBashScript.sh
Hello world!

The script only has two lines. The first indicates what interpreter to use to run the file (in this case, bash). The second line is the command we want to use, echo, followed by what we want to print which is “Hello World”.

该脚本只有两行。 第一个指示用于运行文件的解释器(在本例中为bash)。 第二行是我们要使用的命令,echo,然后是我们要打印的“ Hello World”。

Sometimes the script won’t be executed, and the above command will return an error. It is due to the permissions set on the file. To avoid that use:

有时脚本不会被执行,并且上面的命令将返回错误。 这是由于在文件上设置的权限。 为了避免这种使用:

zach@marigold:~$ chmod u+x myBashScript.sh

And then execute the script.

然后执行脚本。

Linux命令行:Bash Cat (Linux Command Line: Bash Cat)

Cat is one of the most frequently used commands in Unix operating systems.

Cat是Unix操作系统中最常用的命令之一。

Cat is used to read a file sequentially and print it to the standard output. The name is derived from its function to concatenate files.

Cat用于顺序读取文件并将其打印到标准输出。 这个名字是从它的功能,骗子 enate文件导出。

用法 (Usage)

cat [options] [file_names]

Most used options:

最常用的选项:

  • -b, numer non-blank output lines

    -b ,非空白的输出行数

  • -n, number all output lines

    -n编号所有输出线

  • -s, squeeze multiple adjacent blank lines

    -s ,挤压多个相邻的空白行

  • -v, display nonprinting characters, except for tabs and the end of line character

    -v ,显示非打印字符,制表符和行尾字符除外

(Example)

Print in terminal the content of file.txt:

在终端中打印file.txt的内容:

cat file.txt

Concatenate the content of the two files and display the result in terminal:

连接两个文件的内容,并在终端中显示结果:

cat file1.txt file2.txt

Linux命令行:Bash cd (Linux Command Line: Bash cd)

Change Directory to the path specified, for example cd projects.

将目录更改为指定的路径,例如cd projects

There are a few really helpful arguments to aid this:

有一些非常有用的参数可以帮助实现这一点:

  • . refers to the current directory, such as ./projects

    . 引用当前目录,例如./projects

  • .. can be used to move up one folder, use cd .., and can be combined to move up multiple levels ../../my_folder

    ..可以用于向上移动一个文件夹,使用cd .. ,并且可以组合用于向上移动多个级别../../my_folder

  • / is the root of your system to reach core folders, such as system, users, etc.

    /是系统访问核心文件夹(例如systemusers等)的根目录。

  • ~ is the home directory, usually the path /users/username. Move back to folders referenced relative to this path by including it at the start of your path, for example ~/projects.

    ~是主目录,通常是路径/users/username 。 通过将其包含在路径的开头,将其移回相对于此路径引用的文件夹,例如~/projects

Linux命令行:Bash头 (Linux Command Line: Bash head)

Head is used to print the first ten lines (by default) or any other amount specified of a file or files. Cat is used to read a file sequentially and print it to the standard output. ie prints out the entire contents of the entire file. - that is not always necessary, perhaps you just want to check the contents of a file to see if it is the correct one, or check that it is indeed not empty. The head command allows you to view the first N lines of a file.

Head用于打印前十行(默认情况下)或一个或多个文件指定的任何其他数量。 Cat用于顺序读取文件并将其打印到标准输出。 即打印出整个文件的全部内容。 -这并非总是必要的,也许您只想检查文件的内容以查看它是否正确,或者检查它确实不是空的。 head命令允许您查看文件的前N行。

if more than on file is called then the first ten lines of each file is displayed, unless specific number of lines are specified. Choosing to display the file header is optional using the option below

如果调用的文件多于文件上的文件,那么将显示每个文件的前十行,除非指定了特定的行数。 使用以下选项选择显示文件头是可选的

用法 (Usage)

head [options] [file_name(s)]

Most used options:

最常用的选项:

  • -n N, prints out the first N lines of the file(s)

    -n N ,打印出文件的前N行

  • -q, doesn’t print out the file headers

    -q ,不打印出文件头

  • -v, always prints out the file headers

    -v ,总是打印出文件头

(Example)

head file.txt

Prints in terminal the first ten lines of file.txt (default)

在终端中打印file.txt的前十行(默认)

head -n 7 file.txt

Prints in terminal the first seven lines of file.txt

在终端中打印file.txt的前七行

head -q -n 5 file1.txt file2.txt

Print in terminal the first 5 lines of file1.txt, followed by the first 5 lines of file2.txt

在终端中打印file1.txt的前5行,然后打印file2.txt的前5行

Linux Command Line: Bash ls

Linux命令行:Bash ls

ls is a command on Unix-like operating systems to list contents of a directory, for example folder and file names.

ls是类似Unix的操作系统上的命令,用于列出目录的内容,例如文件夹和文件名。

用法 (Usage)

cat [options] [file_names]

Most used options:

最常用的选项:

  • -a, all files and folders, including ones that are hidden and start with a .

    -a ,所有文件和文件夹,包括隐藏的文件和文件夹,并以.开头.

  • -l, List in long format

    -l ,以长格式列出

  • -G, enable colorized output.

    -G ,启用彩色输出。

例: (Example:)

List files in freeCodeCamp/guide/

freeCodeCamp/guide/列出文件

ls                                                                ⚬ master
CODE_OF_CONDUCT.md bin                package.json       utils
CONTRIBUTING.md    gatsby-browser.js  plugins            yarn.lock
LICENSE.md         gatsby-config.js   src
README.md          gatsby-node.js     static
assets             gatsby-ssr.js      translations

Linux命令行:Bash man (Linux Command Line: Bash man)

Man, the abbreviation of manual, is a bash command used to display on-line reference manuals of the given command.

人, UAL的缩写,是用于显示给定的命令的上线参考手册bash命令。

Man displays the reletive man page (short for manual page) of the given command.

男子将显示给定的命令的reletive手册页(以下简称 UAL )。

用法 (Usage)

man [options] [command]

Most used options:

最常用的选项:

  • -f, print a short description of the given command

    -f ,打印给定命令的简短描述

  • -a, display, in succession, all of the available intro manual pages contained within the manual

    -a ,连续显示手册中包含的所有可用的入门手册页

(Example)

Display the man page of ls:

显示ls的手册页:

man ls

Linux命令行:Bash mv (Linux Command Line: Bash mv)

Moves files and folders.

移动文件和文件夹。

mv source target
mv source ... directory

The first argument is the file you want to move, and the second is the location to move it to.

第一个参数是您要移动的文件,第二个参数是将其移动到的位置。

Commonly used options:

常用选项:

  • -f to force move them and overwrite files without checking with the user.

    -f强制移动它们并覆盖文件,而无需与用户检查。

  • -i to prompt confirmation before overwriting files.

    -i在覆盖文件之前提示确认。

That's all. Go forth and use Linux.

就这样。 继续并使用Linux。

翻译自: https://www.freecodecamp.org/news/linux-command-line-bash-tutorial/

linux bash命令

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/390916.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【知识科普】解读闪电/雷电网络,零基础秒懂!

知识科普,解读闪电/雷电网络,零基础秒懂! 闪电网络的技术是革命性的,将实现即时0手续费的小金额支付。第一步是解决扩容问题,第二部就是解决共通性问题,利用原子交换协议和不同链条的状态通道结合&#xff…

spring框架里面applicationContext.xml 和spring-servlet.xml 的区别

问题:spring框架里面applicationContext.xml 和spring-servlet.xml 的区别 在Spring框架中applicationContext.xml和Spring -servlet.xml有任何关系吗? DispatcherServlet可以使用到在applicationContext.xml中声明的属性文件吗? 另外,为什么我需要*…

Alpha 冲刺 (5/10)

【Alpha go】Day 5! Part 0 简要目录 Part 1 项目燃尽图Part 2 项目进展Part 3 站立式会议照片Part 4 Scrum 摘要Part 5 今日贡献Part 1 项目燃尽图 Part 2 项目进展 已分配任务进度博客检索功能:根据标签检索流程图 -> 实现 -> 测试近期比…

多维空间可视化_使用GeoPandas进行空间可视化

多维空间可视化Recently, I was working on a project where I was trying to build a model that could predict housing prices in King County, Washington — the area that surrounds Seattle. After looking at the features, I wanted a way to determine the houses’ …

蛮力写算法_蛮力算法解释

蛮力写算法Brute Force Algorithms are exactly what they sound like – straightforward methods of solving a problem that rely on sheer computing power and trying every possibility rather than advanced techniques to improve efficiency.蛮力算法听起来确实像是–…

NoClassDefFoundError和ClassNotFoundException之间有什么区别?是由什么导致的?

问题: NoClassDefFoundError和ClassNotFoundException之间有什么区别?是由什么导致的? NoClassDefFoundError和ClassNotFoundException之前的区别是什么? 是什么导致它们被抛出?这些问题我们要怎么样解决? 当我在为了引入新的jar包而修改现有代码…

关于Tensorflow安装opencv和pygame

1.安装opencv https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv C:\ProgramData\Anaconda3\Lib\site-packages>pip install opencv_python-3.3.1-cp36-cp36m-win_amd64.whlProcessing c:\programdata\anaconda3\lib\site-packages\opencv_python-3.3.1-cp36-cp36m-win_a…

内置的常用协议实现模版

SuperSocket内置的常用协议实现模版 中文(中国)Toggle Dropdownv1.6Toggle Dropdown关键字: TerminatorReceiveFilter, CountSpliterReceiveFilter, FixedSizeReceiveFilter, BeginEndMarkReceiveFilter, FixedHeaderReceiveFilter 阅读了前面一篇文档之…

机器学习 来源框架_机器学习的秘密来源:策展

机器学习 来源框架成功的机器学习/人工智能方法 (Methods for successful Machine learning / Artificial Intelligence) It’s widely stated that data is the new oil, and like oil, data needs the right refinement to evolve to be utilised perfectly. The power of ma…

linux gcc 示例_最好的Linux示例

linux gcc 示例Linux is a powerful operating system that powers most servers and most mobile devices. In this guide, we will show you examples of how to use some of its most powerful features. This involves using the Bash command line.Linux是功能强大的操作系…

帆软报表和jeecg的进一步整合--ajax给后台传递map类型的参数

下面是页面代码&#xff1a; <% page language"java" contentType"text/html; charsetUTF-8" pageEncoding"UTF-8"%> <%include file"/context/mytags.jsp"%> <% String deptIds (String)request.getAttribute("…

@Nullable 注解的用法

问题&#xff1a;Nullable 注解的用法 我看到java中的一些方法声明为: void foo(Nullable Object obj){…}在这里Nullable是什么意思?这是不是意味着输入可以为空? 没有这个注解&#xff0c;输入仍然可以是null&#xff0c;所以我猜这不是它的用法? 回答一 它清楚地说明…

WebLogic调用WebService提示Failed to localize、Failed to create WsdlDefinitionFeature

在本地Tomcat环境下调用WebService正常&#xff0c;但是部署到WebLogic环境中&#xff0c;则提示警告&#xff1a;[Failed to localize] MEX0008.PARSING_MDATA_FAILURE<SOAP_1_2 ......警告&#xff1a;[Failed to localize] MEX0008.PARSING_MDATA_FAILURE<SOAP_1_1 ..…

呼吁开放外网_服装数据集:呼吁采取行动

呼吁开放外网Getting a dataset with images is not easy if you want to use it for a course or a book. Yes, there are many datasets with images, but few of them are suitable for commercial or educational use.如果您想将其用于课程或书籍&#xff0c;则获取带有图像…

git push命令_Git Push命令解释

git push命令The git push command allows you to send (or push) the commits from your local branch in your local Git repository to the remote repository.git push命令允许您将提交(或推送 )从本地Git存储库中的本地分支发送到远程存储库。 To be able to push to you…

在Java里面使用Pairs或者二元组

问题&#xff1a;在Java里面使用Pairs或者二元组 在Java里面&#xff0c;我的Hashtable要用到一个元组结构。在Java里面&#xff0c;我可以使用的什么数据结构呢&#xff1f; Hashtable<Long, Tuple<Set<Long>,Set<Long>>> table ...回答一 我不认…

github 搜索技巧

1、关键词 指定开发语言 bitcoin language:javascript 2、关键词 stars 数量 forks 数量 bitcoin stars:>100 forks:>50

React JS 组件间沟通的一些方法

刚入门React可能会因为React的单向数据流的特性而遇到组件间沟通的麻烦&#xff0c;这篇文章主要就说一说如何解决组件间沟通的问题。 1.组件间的关系 1.1 父子组件 ReactJS中数据的流动是单向的&#xff0c;父组件的数据可以通过设置子组件的props传递数据给子组件。如果想让子…

数据可视化分析票房数据报告_票房收入分析和可视化

数据可视化分析票房数据报告Welcome back to my 100 Days of Data Science Challenge Journey. On day 4 and 5, I work on TMDB Box Office Prediction Dataset available on Kaggle.欢迎回到我的100天数据科学挑战之旅。 在第4天和第5天&#xff0c;我将研究Kaggle上提供的TM…

sql limit子句_SQL子句解释的位置:之间,之间,类似和其他示例

sql limit子句什么是SQL Where子句&#xff1f; (What is a SQL Where Clause?) WHERE子句(和/或IN &#xff0c; BETWEEN和LIKE ) (The WHERE Clause (and/or, IN , BETWEEN , and LIKE )) The WHERE clause is used to limit the number of rows returned.WHERE子句用…