Parameters for common shell commands

Source: Internet
Author: User
Tags echo command parent directory readable linux

1, LS: Similar to the DOS under the dir command

LS The most commonly used parameter has three:-a-l-F.

Ls–a

Files on Linux are treated as hidden files by the system, with the LS command is not visible to them, and with ls-a in addition to displaying generic filenames, even hidden files are displayed.

Ls–l

This parameter displays more detailed file information.

Ls–f

Use this argument to add more symbols representing file types to the back of the file, for example, * to execute,/to represent the directory, @ to represent the linked file, because the-f argument is used. But now basically all Linux distributions of LS have built the-f parameter, that is to say, we can see various resolution symbols without entering this parameter.

-A

With-A but does not list "." (represents the current directory) and ".." (Represents the parent directory of the current directory).

2, CD: To switch the user's current working directory

CD AAA enters AAA catalogue

After the CD command does not specify a directory, it switches to the current user's home directory

CD ~ function with CD does not specify directory, switch to the current user's home directory

CD-command followed by a minus sign, it will fall back to the directory before the switch---this is more practical, but most people don't know

3. CP: Copy command

Copy one file to another directory: CP 1.txt. /test2

Copy a file to this directory and rename it: CP 1.txt 2.txt

Copy a folder A and rename it to b:cp-r a B

4. RM command

RM commands are used to delete files, similar to Dos del/erase commands, with three parameters commonly used for RM commands:-i,-r,-f.

– I: The system will ask for confirmation before deleting the file, and the file will be deleted after the user returns. It is important to note that the files deleted under Linux are unrecoverable and must be carefully identified before deleting them.

–R: This parameter supports directory deletion, and features similar to RMDIR commands.

–f: Contrary to-I argument,-F indicates forced deletion

5, Du, DF command

The du command can display the disk space occupied by the current directory, and the DF command can display the current disk space remaining.

If the du command does not have any arguments, then the entire disk is returned and the directory is used on disk if the directory is added later.

DU-HS the specified directory to view the total size of the specified directory

Du-hs./* View the size of all folders and files under the current directory

Both of these commands support the-K,-M and-H arguments, which are similar to-K and-M, representing units of display, one for K bytes and one for megabytes, and H for Human-readable, which is a friendly, readable display.

6, Cat command

The function of the cat command is to display or link a generic ASCII text file. Cat is a shorthand for concatenate, similar to the type command below DOS. Usage is as follows:

Cat file1 display file1 file contents

Cat file1 file2 Display file1,file2 contents in turn

Cat file1 file2 > File3 combines file1, file2 content, and redirects (>) to file3 files.

">" is the right redirector, which indicates that the left command result is entered as the right-hand command, noting that if the right file is an existing file, its original content will be emptied and the left-hand command output. If you want to write as an append, use the >> redirection character instead.

If the ">" Left does not specify a file, such as: Cat >file1, will wait for user input, input finished and then press [Ctrl]+[c] or [ctrl]+[d], the user's input will be written to File1.

7. Echo Command

The echo command is used less frequently than LS and cat, especially in shell scripting.

Syntax: Echo [-ne][string]

Function: Echo will send the input string to the standard output, separated by a white space character between the output strings, and at the end with a line feed.

Parameters:

-N automatically wraps at the end when the string is displayed

-E supports escape characters in the following format,-E does not support escape characters in the following format

\a a warning sound; note: a backslash.

\b Deletes the previous character;

\c finally does not add line symbol;

\f the line but the cursor still stays in the original position;

\ n Wraps and the cursor moves to the beginning of the line;

\ r The cursor moves to the beginning of the line, but does not wrap;

\ t Insert tab;

\v is the same as/F;

\ \ insert \ character;

\NNN inserts the ASCII character represented by the NNN (octal);

Example: (The following example should be useful for backslashes)

oracle@hjtest:~/hgd> echo "123" "456"

123 456

oracle@hjtest:~/hgd> echo "123/n456"

123/n456

oracle@hjtest:~/hgd> echo-e "123/n456"

123

456

oracle@hjtest:~/hgd> echo-e "123/n456"

123/n456

oracle@hjtest:~/hgd> echo-e "123///456"

123//456

oracle@hjtest:~/hgd> echo-e "123///456"

123/456

oracle@hjtest:~/hgd> echo-e "123/100456"

123@456

Precautions:

Under Bash used by Linux, single quotes ' and double quotes are different, single quotes Ignore all escapes, and double quotes do not ignore the following special characters:

Dollar signs ($), back quotes ('), backslashes (/), Excalmatory mark (!)

Examples are as follows:

oracle@hjtest:~> echo "' TEST '"

-bash:test:command not found

oracle@hjtest:~> Echo ' TEST '

' TEST '

oracle@hjtest:~> echo "$TEST"

oracle@hjtest:~> Echo ' $TEST '

$TEST

oracle@hjtest:~> echo "//test"

/test

oracle@hjtest:~> Echo '//test '

TEST

oracle@hjtest:~> echo "Hello!"

echo "Hello"

Hello

oracle@hjtest:~> Echo ' hello! '

Hello!

8, More,less,clear

N more,less Command

These two commands are used to view files, if a file is too long, display content beyond a screen, with cat command only to see the final content, with more and less two commands can be paged view. The more directive allows pages to be paused for more than one page, and the user presses the button before continuing to display the next page. and less in addition to more functions, you can also use the arrow keys to scroll up or down the file, more convenient to browse and read.

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.