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.pswp.cn/news/390916.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390916.shtml
英文地址,請注明出處:http://en.pswp.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子句用…