日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

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

發(fā)布時(shí)間:2023/11/29 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux bash命令_Ultimate Linux命令行指南-Full Bash教程 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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命令行最終指南。 本教程將向您展示一些關(guān)鍵的Linux命令行技術(shù),并向您介紹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,也是命令語言解釋器。 外殼程序只是執(zhí)行命令的宏處理器。 默認(rèn)情況下,它是大多數(shù)Linux發(fā)行版中使用最廣泛的shell,它是Korn shell(ksh)和C shell(csh)的后繼產(chǎn)品。

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

Linux操作系統(tǒng)可以通過命令行完成許多事情。 一些例子是…

  • Editing files

    編輯檔案
  • Adjusting the volume of the operating system

    調(diào)整操作系統(tǒng)的音量
  • Fetching web pages from the internet

    從互聯(lián)網(wǎng)上獲取網(wǎng)頁
  • Automating work you do every day

    每天執(zhí)行的工作自動(dòng)化

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

您可以在此處通過GNU文檔和tldp指南閱讀有關(guān)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):

您可以通過打開終端來在大多數(shù)Linux和OS X操作系統(tǒng)上開始使用bash。 讓我們考慮一個(gè)簡(jiǎn)單的hello world示例。 打開您的終端,并編寫以下行($符號(hào)之后的所有內(nèi)容):

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文件,然后從命令行運(yùn)行它們。 假設(shè)您有一個(gè)包含以下內(nèi)容的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對(duì)待的特殊指令。

為什么在腳本文件的開頭使用#!/ 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.

這是因?yàn)樽尳换ナ酵鈿こ绦蛑罏殡S后的程序運(yùn)行哪種解釋器是一種約定。 第一行告訴Unix,該文件將由/ bin / bash執(zhí)行。 這是幾乎每個(gè)Unix系統(tǒng)上Bourne shell的標(biāo)準(zhǔn)位置。 將#!/ bin / bash添加為腳本的第一行,告訴操作系統(tǒng)調(diào)用指定的shell來執(zhí)行腳本中后面的命令。 #! 通常被稱為“哈希爆炸”,“爆炸”或“爆炸”。 盡管僅當(dāng)您將腳本作為可執(zhí)行文件運(yùn)行時(shí)才執(zhí)行。 例如,當(dāng)您鍵入./scriptname.extension ,它將在第一行中查找解釋程序,而以bash scriptname.sh身份運(yùn)行腳本時(shí),第一行將被忽略。

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

然后,您可以像這樣運(yùn)行腳本:為使文件可執(zhí)行,應(yīng)在sudo chmod + x“ filename”下調(diào)用此命令。

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”.

該腳本只有兩行。 第一個(gè)指示用于運(yùn)行文件的解釋器(在本例中為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:

有時(shí)腳本不會(huì)被執(zhí)行,并且上面的命令將返回錯(cuò)誤。 這是由于在文件上設(shè)置的權(quán)限。 為了避免這種使用:

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

And then execute the script.

然后執(zhí)行腳本。

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

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

Cat是Unix操作系統(tǒng)中最常用的命令之一。

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用于順序讀取文件并將其打印到標(biāo)準(zhǔn)輸出。 這個(gè)名字是從它的功能,騙子 enate文件導(dǎo)出。

用法 (Usage)

cat [options] [file_names]

Most used options:

最常用的選項(xiàng):

  • -b, numer non-blank output lines

    -b ,非空白的輸出行數(shù)

  • -n, number all output lines

    -n編號(hào)所有輸出線

  • -s, squeeze multiple adjacent blank lines

    -s ,擠壓多個(gè)相鄰的空白行

  • -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的內(nèi)容:

cat file.txt

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

連接兩個(gè)文件的內(nèi)容,并在終端中顯示結(jié)果:

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:

有一些非常有用的參數(shù)可以幫助實(shí)現(xiàn)這一點(diǎn):

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

    . 引用當(dāng)前目錄,例如./projects

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

    ..可以用于向上移動(dòng)一個(gè)文件夾,使用cd .. ,并且可以組合用于向上移動(dòng)多個(gè)級(jí)別../../my_folder

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

    /是系統(tǒng)訪問核心文件夾(例如system , users等)的根目錄。

  • ~ 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 。 通過將其包含在路徑的開頭,將其移回相對(duì)于此路徑引用的文件夾,例如~/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用于打印前十行(默認(rèn)情況下)或一個(gè)或多個(gè)文件指定的任何其他數(shù)量。 Cat用于順序讀取文件并將其打印到標(biāo)準(zhǔn)輸出。 即打印出整個(gè)文件的全部?jī)?nèi)容。 -這并非總是必要的,也許您只想檢查文件的內(nèi)容以查看它是否正確,或者檢查它確實(shí)不是空的。 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

如果調(diào)用的文件多于文件上的文件,那么將顯示每個(gè)文件的前十行,除非指定了特定的行數(shù)。 使用以下選項(xiàng)選擇顯示文件頭是可選的

用法 (Usage)

head [options] [file_name(s)]

Most used options:

最常用的選項(xiàng):

  • -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的前十行(默認(rèn))

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的操作系統(tǒng)上的命令,用于列出目錄的內(nèi)容,例如文件夾和文件名。

用法 (Usage)

cat [options] [file_names]

Most used options:

最常用的選項(xiàng):

  • -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的縮寫,是用于顯示給定的命令的上線參考手冊(cè)bash命令。

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

男子將顯示給定的命令的reletive手冊(cè)頁(以下簡(jiǎn)稱 UAL )。

用法 (Usage)

man [options] [command]

Most used options:

最常用的選項(xiàng):

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

    -f ,打印給定命令的簡(jiǎn)短描述

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

    -a ,連續(xù)顯示手冊(cè)中包含的所有可用的入門手冊(cè)頁

(Example)

Display the man page of ls:

顯示ls的手冊(cè)頁:

man ls

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

Moves files and folders.

移動(dòng)文件和文件夾。

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.

第一個(gè)參數(shù)是您要移動(dòng)的文件,第二個(gè)參數(shù)是將其移動(dòng)到的位置。

Commonly used options:

常用選項(xiàng):

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

    -f強(qiáng)制移動(dòng)它們并覆蓋文件,而無需與用戶檢查。

  • -i to prompt confirmation before overwriting files.

    -i在覆蓋文件之前提示確認(rèn)。

That's all. Go forth and use Linux.

就這樣。 繼續(xù)并使用Linux。

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

linux bash命令

總結(jié)

以上是生活随笔為你收集整理的linux bash命令_Ultimate Linux命令行指南-Full Bash教程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。