Common Linux shell commands and shell commands

Source: Internet
Author: User
Tags linux shell commands

Common Linux shell commands and shell commands

I. Basic commands

1. Shut down immediately and restart again. Execute the following command:

Shutdown-r now or reboot

2. Shut down immediately and execute the following command:

Shutdown-h now or poweroff

3. Wait for two minutes to shut down and restart again. Execute the following command:

Shutdown-r 2

4. Wait for 2 minutes and run the following command:

Shutdown-h 2

5. Use the historical commands of the current user to perform the following operations:

History

Each used command and its serial number are displayed. You can use the serial number to execute the command repeatedly.

For example, enter! 1. Press enter. 1st historical commands will be executed again.

You can also use the up/down cursor key to call up a history command and press the Enter key to execute it again.

You can also use the up/down cursor key to call up a history command. After modification, press the Enter key to execute the command.

6. Clear the History commands of the current user and execute the following command:

History-c

In this case, you cannot call any history commands by using the up cursor key.

7. Run the following command to display the kernel version:

Uname-r

Note: The kernel version is different from the software release version.

For example, the kernel version of RHEL 5.4 is 2.6.18-164. el5, and the software release version is 5.4.

8. Clear the screen and execute the following command:

Clear

9. Run the following command to display the operating system clock:

Date

10. Load the disc to/media and execute the following command:

Mount/dev/cdrom/media

11. Uninstall the CD and run the following command:

Umount/dev/cdrom or umount/media

Note: Do not run this command in/media or its sub-directories; otherwise, a "Device Busy error" may occur ".

12. view the storage device and run the following command:

Fdisk-l

13. Attach a USB flash drive to/media

Mount/dev/sdb1/media

14. Uninstall the USB flash drive and run the following command:

Umount/dev/sdb1 or umount/media

Note: Do not run this command in/media or its sub-directories; otherwise, a "Device Busy error" may occur ".

15. Interrupt shell commands

Ctrl + C

 

Ii. File directory operation commands

1. display the current absolute path and run the following command:

Pwd

2. Change the current directory. For example, run the following command:

Cd/etc/yum

The current directory will be changed to/etc/yum.

3. Return to the parent directory of the current directory and execute the following command:

Cd ..

4. Create a directory. For example, run the following command:

Mkdir/usr/tigger

5. Delete the directory. For example, run the following command:

Rmdir/usr/tigger

Note: when using the rmdir command, the directory to be deleted must be empty.

6. list the contents in the directory. For example, run the following command:

Ls/

7. list all contents in the directory (including hidden files or point files). For example, run the following command:

Ls/root-

The file names starting with "." are displayed. They are called dot files. If you run the "ls/root" command, you cannot see them.

8. list the contents in the directory in long format and run the following command:

Ls/boot-l

Note: in Linux, if a command has several switches, you can combine these switches. For example, the command ls-a-l works the same as the command ls-al or ls-la.

9. Create an empty file. For example, run the following command:

Touch/a. dat

10. copy the file. For example, run the following command:

Cp/etc/host. conf/root

The host. conf file in the/etc directory is copied to the/root directory, and the file name remains unchanged.

11. Copy the entire sub-directory without changing the directory name. For example, run the following command:

Cp-r/usr/include/root will copy the entire subdirectory/usr/include (without changing the directory name) to the/root directory.

12. Copy the entire sub-directory (change the directory name). For example, run the following command:

Cp-r/usr/include/root/include2

The entire sub-directory/usr/include will be copied to the directory/root, and the directory name will be changed from include to include2.

13. Move the file or rename the file. For example, run the following command:

Rename a file:

Mv/root/host. conf/root/myfile

Move files:

Mv/root/myfile/

Rename a mobile file at the same time:

Mv/myfile/root/myfile2

14. delete an object. For example, run the following command:

Rm/root/myfile2

Press y to confirm.

Rm-f/a. dat does not require confirmation.

15. delete a non-empty directory. For example, run the following command:

Mkdir/root/mysub/new

Rmdir/root/mysub

The system prompts that the directory is not empty.

Rm-rf/root/mysub

The system has no error message.

Ls/root

The directory/root has no mysub directory.

16. Split the screen to display the file content. For example, execute the following command:

More/etc/services

Press the Space key to display the next screen. Press the q key to return the command line status.

Note: When more is used as the pipeline command, it can be combined with other commands, such as ls/etc | more history | more

17. display the file content. For example, run the following command:

 

More _ FileName displays the content on one screen at a time, with spaces or press enter to display the next screen.

Less _ FileName: The content displayed on one screen at a time. The content is displayed with spaces or press Enter.

Cat _ FileName: displays all content at a time

Cat _ File1 _ File2> File3 writes the content of File1 and File2 to File3 and overwrites the original content of File3.

Cat _ File >>_file2: append the content of File1 to file2. the original content of File2 remains unchanged.

Head _ FileName only displays the first 10 lines of the file

Head-n _ FileName displays the first n rows of the file.

 

Tail _ FileName only displays the last 10 lines of the file

Tail-n _ FileName displays the last n rows of the file.

Nl _ FileName displays all the file content at a time in the form of a file number. Ignore spaces.

 

18. Merge files. For example, execute the following command:

Cat/etc/resolv. conf/etc/yum. conf>/B. dat

Run the following command for verification:

Ls-l/B. dat

The length of the file is 814 bytes.

You can also use two commands to implement the same function:

Cat/etc/resolv. conf>/c. dat

The file length is 26 bytes.

Cat/etc/yum. conf>/c. dat

The file is 814 bytes in length.

Note:> and> is a redirection symbol. If the redirected file already exists,

If yes, the new content will overwrite the original content,

Use> to add new content to the end of the original content.

19. File Search

Find [path] [Options]

20. Search for file content

Grep

 

Iii. vi Editor

Create or modify a text file. For example, run the following command:

Vi/B. dat

The vi editor has two modes: Command mode and edit mode.

After vi is started, it enters the command mode. In command mode, press the I key to enter the edit mode.

Press <Esc> in edit mode to return to command mode.

Press the I key to start editing.

After editing, press <Esc> to return to the command mode.

Enter wq and press enter to save the file and exit. or enter q! Then press the Enter key to save the disk and exit.

To delete the row where the cursor is located, return to command mode and press the d key twice.

To delete several rows starting from the row where the cursor is located, for example, five rows, return to command mode, press the 5 key, and then press the d key twice. The deleted content also enters the vi buffer.

To paste the content of the vi buffer to the end of the current position, return to command mode, and then press p.

To cancel the last operation, return to command mode and press u. You can repeatedly press the u key to cancel the most recent operations.

To copy the row where the cursor is located to the vi buffer, return to command mode and press y twice.

To copy several rows (for example, five rows) starting from the row where the cursor is located to the vi buffer, return to command mode, press the 5 key, and then press the y key twice.

To search down a string, such as HOSTNAME, from the current position, first return to command mode, then enter/HOSTNAME, and press Enter.

To continue searching, enter/and press Enter.

 

Vi will generate a temporary file when editing a file, which starts with "." and ends with ". swp.

The file is automatically deleted when it Exits normally. If it exits unexpectedly, such as a sudden power failure, the file will not be deleted.

In this case, you only need to manually delete the file.

: Set nu display row number

: Setnonu cancel row number

 

Iv. package installation commands

1. view all installed software packages and run the following command:

Rpm-qa | more

2. view all software packages whose names contain a string. For example, run the following command:

Rpm-qa | grep net

3. Verify all installed software packages and run the following command:

Rpm-Va

Note: This command lists all the files that have been modified by the system and the user since the package is installed.

4. view the purpose of a software package that has been installed. For example, run the following command:

Rpm-qi net-tools-1.60-37.EL4.8

5. Check the software package of a file in the system. For example, run the following command:

Rpm-qf/sbin/ifconfig

Results should show that the file belongs to the net-tools-1.60-102.el6.i686

6. Install a software package. For example, run the following command:

Rpm-ivh ************. rpm

Note:-v indicates the display information option, and-h indicates the display process option.

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.