亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
1. Loop Command
2. Output redirection
3. Compress files
4. Counting
5. Generate numbers
6. Manage your SSH keys
7、查找過去的命令
8、將多個命令作為一個整體傳遞
Home Operation and Maintenance Nginx Eight Shell commands to make you a Linux command line master in no time

Eight Shell commands to make you a Linux command line master in no time

Jun 17, 2023 am 09:38 AM
Order code bash

Having a solid programming foundation is obviously an essential quality for a good software engineer. It is very important to master at least one programming language, whether it is an interpreted language such as Python, or a compiled language such as C. However, this is only one aspect of becoming a truly well-rounded engineer. Those basics are of no use if you're lost in the shell environment.

The flexible application of Bash commands allows you to enter areas that traditional programming languages ??cannot cover. Sometimes, you don't actually need to use a more powerful programming language. Using the Shell, you can accomplish the tasks you need faster and more easily, without the need for additional dependencies.

八個 Shell 命令,讓你瞬間成為 Linux 命令行大師

In this article, we will explore some very useful Bash commands. These commands can help you avoid writing more code than you actually need. Next time you encounter a problem, try these commands.

1. Loop Command

linuxmi@linuxmi:~/www.linuxmi.com$ while true; do echo "hello $(date)"; sleep 1; done

八個 Shell 命令,讓你瞬間成為 Linux 命令行大師

You don’t have to jump into a huge programming language just to loop something. Getting output at regular intervals or iterating over basic data is easy to do in Bash.

This line of code demonstrates how to build a simple infinite while loop in the Shell. You just splice everything together with a semicolon and you're done. You are free to change the command executed and adjust the sleep timer accordingly.

When you run this command, you should see the date change every second on your terminal.

2. Output redirection

linuxmi@linuxmi:~/www.linuxmi.com$ echo "hello linux迷 www.linuxmi.com" | tee linuxmi.rs | less

八個 Shell 命令,讓你瞬間成為 Linux 命令行大師

The tee command can achieve functions that require multiple lines of code in other languages. Using this handy little tool, you can send certain input to a file or other command, which can then be passed to another command. It's actually like installing a "T" valve in your water pipe. You can direct a portion of the output out and it will continue to flow down the pipe.

The above example sends the "hello linux fan www.linuxmi.com" text obtained from the echo command to the linuxmi.rs file, and then proceeds to send it to less. One way to rewrite it is: you will get a file with the output content, and you can view it on the screen using the less command.

3. Compress files

linuxmi@linuxmi:~/www.linuxmi.com$ tar -czvf linuxmi.tar.gz linuxmi.sh

八個 Shell 命令,讓你瞬間成為 Linux 命令行大師

Moving files and directories on the command line is an important skill. If you're working on something and need to move it between hosts, or just want to compress a file for offline storage, the tar command is your friend.

Using the above commands and options, you can compress a directory into a new tar.gz compressed package. Now you can bring your files quickly.

4. Counting

linuxmi@linuxmi:~/www.linuxmi.com$ echo -e "linuxmi\n linuxmi.com\n www.linuxmi.com\n www.93139.com" > linuxmi.txt | wc -l

八個 Shell 命令,讓你瞬間成為 Linux 命令行大師

Want to know how many lines there are in the file? Very simple. Use wc utility. "Word count" is what it actually means, but it can also be used to count many other things, such as the number of lines.

The above snippet outputs four lines of text to a file and then uses wc to count the number of lines. This tool is useful if you need to manipulate a certain number of lines or confirm whether a process has written new lines to a file.

5. Generate numbers

linuxmi@linuxmi:~/www.linuxmi.com$ seq 95 100

八個 Shell 命令,讓你瞬間成為 Linux 命令行大師

So simple, but very helpful. Generating numbers in Bash is very easy, just use the seq utility. This neat little command outputs a sequence of numbers that you can use in loops, text files, or anywhere else you need a list of numbers.

You can also change the delimiter if needed:

seq -s " " 1 10

or

echo {0..10}

This will separate all numbers with spaces instead of the default newline. You can also use the echo command and the .. operator to obtain the same type of results.

6. Manage your SSH keys

linuxmi@linuxmi:~/www.linuxmi.com$ eval $(ssh-agent) && ssh-add && ssh-add -l

八個 Shell 命令,讓你瞬間成為 Linux 命令行大師

A basic understanding of SSH keys and how to manage them is absolutely necessary. You may find that understanding the ssh-add and ssh-agent utilities can be more beneficial than you think.

The above command performs several important operations:

  • eval命令將為你執(zhí)行ssh-agent,并確保它在后臺運行。
  • ssh-add命令將添加你的默認(rèn)SSH密鑰。如果你為默認(rèn)密鑰設(shè)置了密碼,它將提示你輸入密碼。
  • 最后,ssh-add -l命令顯示當(dāng)前在你的代理中添加的所有密鑰。

這個簡單的一行命令確保你的代理工作正常,并包含了正確的密鑰。當(dāng)你需要連接到某個服務(wù)或獲取一些代碼時,下一步就可以直接開始了。

7、查找過去的命令

linuxmi@linuxmi:~/www.linuxmi.com$ history | grep "top"

八個 Shell 命令,讓你瞬間成為 Linux 命令行大師

或者按下CTRL + R,然后輸入top

還記得很久以前運行的那個命令嗎?我也不記得了。在歷史記錄中搜索它吧。

如果你像我一樣記憶力不太好,那么history命令非常有用。它會顯示當(dāng)前終端會話中所有已運行的命令列表。反向交互式搜索或grep工具的真正威力在于能夠找到之前執(zhí)行的命令。

如果你只是想查看命令歷史記錄而不是執(zhí)行它,你可以使用grep搜索。要統(tǒng)一搜索和執(zhí)行操作,你可以使用CTRL + R的反向交互式搜索歷史記錄組合鍵。一旦按下快捷鍵,一個交互提示符就會出現(xiàn),當(dāng)你開始輸入命令時,控制臺會顯示相應(yīng)的匹配命令。

8、將多個命令作為一個整體傳遞

linuxmi@linuxmi:~/www.linuxmi.com$ history | grep "top"

八個 Shell 命令,讓你瞬間成為 Linux 命令行大師

有時Bash會變得有點奇怪。變量插值可能出錯,嵌套引號可能會混亂且難以跟蹤。情況將變得更加復(fù)雜,尤其是當(dāng)你需要在不同的二進制文件或服務(wù)中傳遞命令字符串時。在這種情況下,你可以使用bash命令將一組命令作為單個實體進行評估。

這個指令將接收純文本字符串,然后按照常規(guī)的Bash語法來進行解析。對于外部shell來說,你只是運行一個命令并傳遞一個參數(shù),但實際上你是在指示Bash解析多個命令的字符串并執(zhí)行它們。

The above is the detailed content of Eight Shell commands to make you a Linux command line master in no time. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

How to run SUDO commands in Windows 11/10 How to run SUDO commands in Windows 11/10 Mar 09, 2024 am 09:50 AM

The sudo command allows users to run commands in elevated privilege mode without switching to superuser mode. This article will introduce how to simulate functions similar to sudo commands in Windows systems. What is the Shudao Command? Sudo (short for "superuser do") is a command-line tool that allows users of Unix-based operating systems such as Linux and MacOS to execute commands with elevated privileges typically held by administrators. Running SUDO commands in Windows 11/10 However, with the launch of the latest Windows 11 Insider preview version, Windows users can now experience this feature. This new feature enables users to

What to do if the blue screen code 0x0000001 occurs What to do if the blue screen code 0x0000001 occurs Feb 23, 2024 am 08:09 AM

What to do with blue screen code 0x0000001? The blue screen error is a warning mechanism when there is a problem with the computer system or hardware. Code 0x0000001 usually indicates a hardware or driver failure. When users suddenly encounter a blue screen error while using their computer, they may feel panicked and at a loss. Fortunately, most blue screen errors can be troubleshooted and dealt with with a few simple steps. This article will introduce readers to some methods to solve the blue screen error code 0x0000001. First, when encountering a blue screen error, we can try to restart

How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 How to check the MAC address of the network card in Win11? How to use the command to obtain the MAC address of the network card in Win11 Feb 29, 2024 pm 04:34 PM

This article will introduce readers to how to use the command prompt (CommandPrompt) to find the physical address (MAC address) of the network adapter in Win11 system. A MAC address is a unique identifier for a network interface card (NIC), which plays an important role in network communications. Through the command prompt, users can easily obtain the MAC address information of all network adapters on the current computer, which is very helpful for network troubleshooting, configuring network settings and other tasks. Method 1: Use "Command Prompt" 1. Press the [Win+X] key combination, or [right-click] click the [Windows logo] on the taskbar, and in the menu item that opens, select [Run]; 2. Run the window , enter the [cmd] command, and then

How to delete win11 widgets? One command to uninstall Windows 11 widgets function tips How to delete win11 widgets? One command to uninstall Windows 11 widgets function tips Apr 11, 2024 pm 05:19 PM

Widgets are a new feature of the Win11 system. They are turned on by default. However, it is inevitable that some users do not use widgets very much and want to disable them because they take up space. So how should they do this? The editor below will teach you how to operate it, and you can try it out. What are widgets? Widgets are small cards that display dynamic content from your favorite apps and services on your Windows desktop. They appear on the widget board, where you can discover, pin, unpin, arrange, resize, and customize widgets to reflect your interests. The widget board is optimized to display relevant widgets and personalized content based on usage. Open the widget panel from the left corner of the taskbar, where you can see live weather

Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Where is hyperv enhanced session mode? Tips for enabling or disabling Hyper-V enhanced session mode using commands in Win11 Feb 29, 2024 pm 05:52 PM

In Win11 system, you can enable or disable Hyper-V enhanced session mode through commands. This article will introduce how to use commands to operate and help users better manage and control Hyper-V functions in the system. Hyper-V is a virtualization technology provided by Microsoft. It is built into Windows Server and Windows 10 and 11 (except Home Edition), allowing users to run virtual operating systems in Windows systems. Although virtual machines are isolated from the host operating system, they can still use the host's resources, such as sound cards and storage devices, through settings. One of the key settings is to enable Enhanced Session Mode. Enhanced session mode is Hyper

GE universal remote codes program on any device GE universal remote codes program on any device Mar 02, 2024 pm 01:58 PM

If you need to program any device remotely, this article will help you. We will share the top GE universal remote codes for programming any device. What is a GE remote control? GEUniversalRemote is a remote control that can be used to control multiple devices such as smart TVs, LG, Vizio, Sony, Blu-ray, DVD, DVR, Roku, AppleTV, streaming media players and more. GEUniversal remote controls come in various models with different features and functions. GEUniversalRemote can control up to four devices. Top Universal Remote Codes to Program on Any Device GE remotes come with a set of codes that allow them to work with different devices. you may

How to use LSOF to monitor ports in real time How to use LSOF to monitor ports in real time Mar 20, 2024 pm 02:07 PM

LSOF (ListOpenFiles) is a command line tool mainly used to monitor system resources similar to Linux/Unix operating systems. Through the LSOF command, users can get detailed information about the active files in the system and the processes that are accessing these files. LSOF can help users identify the processes currently occupying file resources, thereby better managing system resources and troubleshooting possible problems. LSOF is powerful and flexible, and can help system administrators quickly locate file-related problems, such as file leaks, unclosed file descriptors, etc. Via LSOF Command The LSOF command line tool allows system administrators and developers to: Determine which processes are currently using a specific file or port, in the event of a port conflict

How to use Copilot to generate code How to use Copilot to generate code Mar 23, 2024 am 10:41 AM

As a programmer, I get excited about tools that simplify the coding experience. With the help of artificial intelligence tools, we can generate demo code and make necessary modifications as per the requirement. The newly introduced Copilot tool in Visual Studio Code allows us to create AI-generated code with natural language chat interactions. By explaining functionality, we can better understand the meaning of existing code. How to use Copilot to generate code? To get started, we first need to get the latest PowerPlatformTools extension. To achieve this, you need to go to the extension page, search for "PowerPlatformTool" and click the Install button

See all articles