Some shell commands ~

Source: Internet
Author: User

Bash is used for shell programming. Bash is free and easy to use. Bash-Bourne again shell

File named myshell. Sh

Before executing a file, you must first obtain the following permissions:

Chomod 777 myshell. Sh

1. display file content

#!/bin/bashcat myshell.sh

Run the following command:

./Myshell. Sh

Display result:

#! /Bin/bash

Cat myshell. Sh

2. count the number of lines, words, and characters in a file.

An existing file Vivi,

The file content is as follows:

Hello, world!

Vivi

The content of the shell file is as follows:

#!/bin/bashwc -l vivi wc -w viviwc -c vivi

Run the following command:

./Myshell. Sh

Display result:

Root @ vivi-Ideapad-Z460 :~ #./Myshell. Sh
3 Vivi
3 Vivi
20 Vivi

[Observed. The statistics on the number of rows include empty rows, and the empty rows in the middle include empty rows at the end. The number of words is determined by space or empty rows. Character statistics, not understanding... It seems that there is always one more .....]

WC Vivi

The result is 3 3 20 Vivi.

-L indicates the number of rows in line.

3. file copy

cp myshell.sh vivi

Vivi content has changed ....

4. File Movement

mv vivi cici

In this way, a Cici file is generated in your working directory. The content in the file is the same as that in Vivi ....

5. Sort the rows in the file

Sort filename

Result displayed on the terminal:

Root @ vivi-Ideapad-Z460 :~ #./Myshell. Sh
Hello, world!
Leehom
This is a wonderful world!
Vivi

6. Obtain the file type.

File Vivi

Root @ vivi-Ideapad-Z460 :~ #./Myshell. Sh
Vivi: ASCII text

7

The pipeline (|) uses the output of a command as the input of another command.

Grep "Leehom" Vivi | WC-l

Search Leehom in Vivi and count the number of lines displayed in Leehom.

10 redirection

Redirection: output the command result to a file instead of a standard output (screen ).

> Write the file and overwrite the old file.

> Add it to the end of the file to retain the content of the old file.

Use a backslash to output a command as a command line parameter of another command.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.