Linux basic Commands

Source: Internet
Author: User
Tags diff file copy first string

Do mobile phone testing, or to understand some of the Linux commands, it is convenient to view or find the files inside the phone.

In some cases, you cannot find it through the file browser, and you have to open the root permission to view it through a Linux command.

On this basis it is necessary to know some Linux base commands.

Here are some common commands that bloggers have used to sort out Linux systems.

Linux System common Commands

(1) REDHAT4.0 the command name is case-sensitive, for example: file and file are different.

(2) The file name can have a maximum of 256 characters and can contain numbers, ".", "_", "-", plus some other characters.

(3) file name with "." Files are hidden files, which are generally not displayed when viewed with the LS or dir commands.

(4) "/" refers to the root directory, so that all other directories of the parent directory

Linux Simple Command

1. History Command

# The History screen outputs the last (1000) commands that the current user executes in command-line mode.

2. pwd command

# pwd Screen output current working directory.

3. hostname command

# hostname Screen Output The name of the current local host.

4. uname command

# uname–a output Local Computer information

5. whoami command

#whoami output The current user's login account

6. Date command

# Date Prints the current date, time, and time zone of the operating system.

The-s parameter is used to modify the current date and time

# Date–s 2007-10-17

# Date–s 18:05:00

7. uptime command

# Uptime Output The total time since the last boot to the current system.

8. free command

# Free output memory usage information.

Total represents the overall memory size, and used and free represent the amount of memory that is used and the idle memory, and share refers to memories that can be shared by multiple processes. Buffers and cached are used to keep recently accessed files and data, which can be scaled down when other processes require more memory. The free command also outputs information about the swap space.

9. ls,dir command

Used to list the contents of the current directory, the dir command is an alias for the LS command, and the resulting files are displayed in different colors that represent different file types.

Color

File type

Dark blue

Directory

Light Grey

General documents

Green

Executable file

Purple

Graphics files

Red

Compress files

Light Blue

Link file

Yellow

Device files

Brown

Fifo

If you need to list all the contents of the current directory, you can use the "-al" parameter.

Ten. cd command

To change the current directory, enter only "CD" without specifying a directory name to switch to the current user's home directory. "cd-" will switch to the directory that was last accessed by the user. "CD.." Will fall back to the top level directory (parent directory) of the current directory.

one . Clear command

Clears the character terminal screen contents.

A . su command to replace user identities

# su UserID

The system prompts for a password, and when the password is validated, the system will be transferred to the system environment of the new user identity. Default change to root user

shutdown–h now command

# shutdown [-h][-time][-i] shuts down the computer, the use of permissions is super User

-H power off after shutdown

-time setting the time before shutdown

-I display system information when shutdown

halt ,reboot command

# Halt [-f][-d][-p][-i] shutdown system, access is Superuser

-F does not call shutdown and forces shutdown or restart

-I turn off all network interfaces before shutting down the machine

-P Turn off the power while shutting down the machine

-D shut down the system but leave no record

# reboot [-n][-w][d][-i] Restart the computer, using permissions is System administrator

-N Do not write log back to hard disk until restart

-W is not really a reboot, just writes the records in the/var/log/wtmp file

-D do not write records to the/var/log/wtmp file

-I re-start to stop all network-related equipment

File and Directory Operations commands

1. cp Command

File Copy command

# cp–r/root/sample/./

Copy the directory/root/sample to the current directory. Where the-r parameter indicates that the contents of the entire directory tree can be replicated

2. mv command

You can use this command to move and rename files and directories.

# Mv/root/sample/sample.txt./

Move the/root/sample/sample.txt file to the current directory

3. rm Command

Deletes the specified file. The user must have permission to perform this operation. For example, root users and files belong to the master user.

# rm–f * will delete all files under the current working directory. And there are no confirmation prompts.

# RM–R/ROOT/ZJZ is able to recursively delete the contents of the specified directory and all subdirectories

4. mkdir command

Creates a new directory that you specify.

#mkdir/ROOT/ZJZ

5. rmdir command

Delete an empty directory.

# RMDIR/ROOT/ZJZ

File check and edit commands

1. cat commands

Text File View and connect tool for viewing the contents of a text file. Command format: Cat file

Often used in conjunction with more, head, tail, less, and pipe commands, such as:

Cat File | More, cat file | Head, cat File | Tail, cat File | Less

Option Description:

-B number of non-null output lines

-N to the output of all line numbering

-e displays $ at the end of each line

-S does not output multiple lines of blank lines

Example: View the contents of the profile file in the/etc directory, number all lines of the output, and append the $ symbol at the end of each line

# Cat–e/ect/profile

Cat can display the contents of multiple files simultaneously, such as displaying the contents of two files on a single cat command:

# Cat/etc/fstab/etc/profile

For files with more content, you can use the pipe "|" Transfer to more tools, paging for viewing:

# Cat/etc/fstab/etc/profile | More

Cat can connect the contents of multiple files and output them to a new file.

# cat T01.txt t02.txt t03.txt >t04.txt

# Cat T04.txt

If you enter an existing T04.txt file, the original content in the T04.txt will be emptied.

The cat command can also append multiple files to a file that already exists.

# cat T01.txt t02.txt t03.txt >> t04.txt

# Cat T04.txt

2. more commands

More is one of our most commonly used tools, according to the size of the window to display the output of the content, but also to indicate the percentage of the file.

Parameter description:

+num starting from Num line

-num defines the screen size as num lines

-C clear the screen from the top and then display

-D Prompt Press space to continue, ' Q ' to quit (pressing SPACEBAR to continue, press Q to exit)

-I ignores ctrl+i (page break) characters

-P pages are changed by clearing the window instead of scrolling. Similar to-c parameters

-S displays a contiguous number of empty rows as a row

-U Remove the underline from the contents of the file

Example: displaying the contents of a document starting at the top of the terminal and displaying a prompt

# More–dc/etc/profile

When we look at a larger file, we use more action instructions, such as: ctrl+f down a screen, ctrl+b return to the previous screen; = output the current line number;: F output File name and line number; Q quit more

3. head command

Displays the text file contents of the specified length from the head. Format: head–n row numeric file name

# Head–n 10/etc/profile

4. tail command

Displays the text file contents of the specified length from the trailer. Format: tail–n row numeric file name

5. vi command

VI is an important text editing tool in the RedHat4.0 system.

    • command to enter VI

VI filename Opens or creates a new file, placing the cursor at the beginning of the first

VI +n filename Opens the file, placing the cursor at the beginning of nth

VI + filename Opens the file, placing the cursor at the beginning of the last line

VI +/pattern filename Opens the file, placing the cursor at the first string matching the pattern

VI Filename1......filenamen open multiple files and edit them sequentially

    • Move Cursor Class command

h or BACKSPACE key cursor moves left one character

L or SPACEBAR to move right one character

J or CTRL + N cursor moves up one line

Enter cursor moves down one line

The cursor moves to the end of the sentence

(The cursor moves to the beginning of the sentence

0 cursor moves to the beginning of the line

$ cursor moves to end of line

The cursor moves to the beginning of the paragraph

{cursor moves to end of paragraph

NG cursor moves to the beginning of nth

n+ cursor down n rows

N-the cursor moves up n rows

    • Screen Scrolling class command

Ctrl+u the first half screen to the file

Ctrl+d half screen to file end

Ctrl+f one screen to the end of the file

Ctrl+b one screen to the top of the file

Nz rolls the nth row to the top of the screen, rolls the current line to the top of the screen when n is not specified

    • Insert and delete text class commands

I insert text before the cursor

I insert text at the beginning of the current

A inserts text after the cursor

A at the end of the current line

o A new line below the current line

O a new line above the current line

R replaces the current character

R replaces the current character and its subsequent characters until the ESC key is pressed

NDW Delete the n-1 words at the beginning and after the cursor

Do delete to beginning of line

d$ Delete to end of line

NDD deletes the current row and its subsequent n-1 rows

Ctrl+u Delete all input text under input mode

VI after editing, you can use ": Wq" when exiting to save the current file and exit, ": q! "Do not Save Exit,": Q "Simple exit

6. diff Command

To find out the differences between the two files, the command format: diff file1 File2

7. grep command

Search for and display specific strings, which are typically used to filter the display results to avoid displaying too much unnecessary information. Its command format is: grep string file, which filters the contents of the sweaty string from the file. This command is often used with pipeline commands to filter the output of the screen.

In practice, the blogger did not use so many orders, do not know whether the blogger does not need or ability is not enough to use. Oh, my God.

In practice, the Linux command uses a relatively small number of points, only to look at the file inside the time will be used. Used to do manual function is not used.

The most used is the LS, ls-all CD command, used to reach a certain path, and then view the file information in that directory.

Take a look at some simple things to do:

1. Connect the phone, install the driver, turn on debug mode. After the connection, there will be a message, click OK

2. Premise root phone, some test machine can be through some method root, not the test machine, you need to use other tools to root. Some files require permission. such as/data/local

After 3.root, connect the phone, enter in cmd: ADB devices, see if the device is recognized

4. The identification will list the device number. Input command: adb shell.

Note: Show # for root permission, show $ for no root permission

5. It is possible to enter a file directory by CD command, the following red box indicates that I have entered into the/data/local directory

6. View the file information of the directory, using two methods Ls/ls-al command view, the results show. Ls-al's command is to display all information about the files in the directory

7. If you want to drag the file out, the ADB pull command is used, the following figure is to drag the contents of the/data/local/tmp to the D disk. After completion, the dragged file is displayed on the D drive.

Other features have yet to be discovered.

Study hard and share it.

Linux basic Commands

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.