10.Linux command Explanation

Source: Internet
Author: User

10.Linux command Explanation

Course Requirements:

1. Learn about the use of common commands for Linux systems.

Laboratory Equipment:

Software:

1. A VMware virtual machine with RHEL6 installed.

Hardware:

1.PC Machine one set.

Background knowledge:

1. Description of Linux commands:

Linux commands are commands for managing a Linux system. For Linux systems, whether the CPU, memory, disk drives, keyboards, mice, or users are all files, the Linux System Management command is the core of its normal operation, similar to the previous DOS command. There are two types of Linux commands in the system: built-in shell commands and Linux commands. The first thing to know is a noun "console", which is a human-computer interface, such as DOS, that we usually see using the character-manipulation interface. We say console commands, which are commands that can be entered via the character interface to the operating system. It is important to note that, unlike DOS commands, Linux commands (including filenames, etc.) are sensitive to capitalization. Then look at what "shell" is, and actually the shell is a command interpreter that interprets the commands entered by the user and sends them to the kernel. In addition, the shell has its own programming language for editing commands, which allows the user to write a program composed of shell commands to organize a large number of shell commands into a script file for automated processing purposes.

2. Linux Common Command classification:

(1) User Management Class command: Useradd, Userdel, passwd, Su, Groupadd, Groupdel.

(2) File directory Class command: LS, CD, Touch, CP, MV, RM, chmod, mkdir, Du, pwd.

(3) Compression packing class command: gzip, bzip2, tar.

(4) Disk Management: Mount, Umount, DF, touch, Ln.

(5) Find Class command: Find, grep.

(6) Process Management Class command: PS, kill, free, top.

(7) Other common commands: RPM, |, man, shutdown.

Here are some examples of how to use these common commands through experimental steps.

Experimental steps:

User Management class Commands:

1. Add Users: Useradd

Format: useradd [options] User name

Example: Useradd David

Add a user named David, and when the user is created successfully, a directory with the same name as the user name is generated in the/home/directory.

Figure 3-79

Useradd command

2. Delete User: Userdel

Format: Userdel [options] [user name]

Example: Userdel–r David

Deleting a user named David, the "-r" option causes the user directory in the/home directory to also be deleted.

Figure 3-80

Userdel command

3. Change Password: passwd format: passwd [options] [Username] Example: passwd Davide Modify the password of the David user.

Figure 3-81

passwd command

4. Switch User: Su

Format: su [options] [user name]

Example: Su–david

Switch to the David user and bring the user's environment variables in simultaneously; 3-82; When used by the general

User is required to enter the root user password when switching to root.

Figure 3-82

SU command

5. Add User group: Groupadd

Format: groupadd [options] [user name]

Example: Groupadd group1

Add a group named "Group1" and add the user group to the last line of/etc/group

The user group group1 information.

6. Delete a user group: Groupdel

Format: groupadd [options] [user name]

Example: Groupadd group1

Delete Group named "group1", delete user group after/etc/group

Group1 's information.

File and Directory class commands:

7. View Catalog: LS

Format: LS [options] [directory or file]

Example:

1.ls/home

Displays files and directories (without hidden files) in the/home directory

2. Ls–a/home

Displays all files and directories (with hidden files) in the/home directory

3. Ls–l/home

Display details of files and directories in the/home directory

Figure 3-83

ls command

8. Change the Working directory: CD

Format: CD directory name

Example:

1. cd/home/

Enter/home Directory

2. cd.

Go back to the top level directory

Figure 3-84

ADB command

9. File creation: Touch

Format: Touch [options] File name

Example: Touch test

Create the test file in the/home directory first

Figure 3-85

Touch command

10. Copy files/directories: CP

Format: CP [option] source file or directory destination file or directory

Example:

1. cp/home/test/tmp/

Copy the test file from the/home directory to the/tmp directory

2. cp–r/home/smb/tmp/

Copy the Dir1 directory under the/home directory to the/tmp directory

Figure 3-86

CP command

11. Change file Permissions: chmod

Format: chmod [who] [+ |-| =] [mode] File name

Parameters:

Who

U represents the owner of the file.

G represents the same group of users as the file owner.

O means "other users".

A means "all users". It is the system default value.

Mode

+ Add a permission

-Cancel a permission

= Give given permission

Example: chmod g+w test

Figure 3-87

chmod command

12. Create Directory: mkdir

Format: mkdir [options] Directory name

Example:

1.mkdir/home/workdir

Create the Workdir directory in the/home directory/Home Workdir

2. Mkdir–p/home/dir1/dri4/dir3/dir2

Create the/home/dir1/dir2 directory, and if Dir1 does not exist, first create the Dir1

Figure 3-88

mkdir command

13. View Catalog: Du

Format: Du directory name

Example: du/tmp

Figure 3-89

Du command

14. View current path: pwd

Format: pwd

Example: pwd

Displays the absolute path of the current working directory

Figure 3-90

MV Command uses

Compress Packaging class commands

In a Linux environment, the file name extension for compressed files is usually *.tar; *.tar.gz;

*.tgz; *.gz; *.bz2. Files with different suffix names need to be handled with different commands.

*.gz<-> gzip Command Compressed files

*.bz2<-> bzip2 Command Compressed files

*.tar<-> tar command packaged files

*.tar.gz<-> tar after packaging, then gzip compressed files

*.tar.bz2<-> tar command is packaged and then bzip2 compressed file

15. Compression Decompression: gzip

Format: gzip [option] File name

Example:

1.gzip/root/anaconda-ks.cfg

Compress files

2. gzip–d/root/anaconda-ks.cfg.gz

Unzip the file

Figure 3-91

gzip command

16. Compression Decompression: bzip2

Format: bzip2 [options] File name

Example:

1.bzip2/root/anaconda-ks.cfg

Compress files

2. bzip2–d/root/anaconda-ks.cfg.bz2

Unzip the file.

Figure 3-92

BZIP2 Packaging and compressing

17. Package Compression: Tar

Format: tar [options] directory or file

Example:

1. Tar cvf tmp.tar/tmp

To package the TMP directory as a file

2. Tar xvf Tmp.tar

Unpack the packaged files

3. Tar cvzf tmp.tar.gz/tmp

To compress the TMP directory into a single file

4. Tar xvzf tmp.tar.gz

Unzip the packaged compressed file

Figure 3-93

Tar pack command

Figure 3-94

Tar Package compression command

For convenience, some printing information is omitted.

Disk Management class commands

18. Load storage Device: Mount

Format: Mount [options] Device name mount Directory

Example: mount/dev/cdrom/mnt

Mount the/dev/cdrom to the/MNT directory

Note: Before mounting, you will first configure "VM"-"Settings ..." on the Virtual Machine-"CD/DVD (IDE)"-

"Connection" Select the image using RedHat; 3-96 is shown

Figure 3-95

Mount command

Figure 3-96 VM Settings

19. Unmount Disc: Umount

Format: Umount mount Directory

Example: umount/mnt

Figure 3-97 Umount Command

Important: Before executing the umount, ensure that the image is mounted in the MNT directory and that the user has exited the MNT directory, which will cause the uninstallation to fail.

20. View Disk: DF

Format: DF [option]

Example: DF–HL

Figure 3-98

DF command

21. File Link: ln

In a Linux system, there is a link file similar to "shortcuts" in Windows. Link files are also classified as "soft links" and "hard links". Soft link is also called symbolic link, this file contains the path name of another file, can be any file or directory, can be linked to different file system files, the symbol file to read or write operations, the system will automatically convert the operation to the source file, delete the linked file, the system just delete the linked file, The source file itself is not deleted. A hard link is another name for a file that already exists, and a hard-link file reads and writes and deletes the same result as a soft link. But if we delete the source file of the hard-link file, the hard-link file still exists, and the content of the wish is preserved.

There are two restrictions on hard-link files

1). Do not allow the creation of hard links to the directory;

2). You can create a hard link only between files in the same file system.

Format: ln [options] File name Link name

Example:

1.ln Oldfile Hlink

Create a hard link for the Oldfile file hlink

Figure 3-99

LN creates a hard link

2.ln–s Oldfile Slink

Create a soft link for the Oldfile file slink

Figure 3-100

Create a soft link

Find Class command

22. Find Files/directories: find

Format: Find find path-name file name

Example:

find/root/-name Install.log

Look for a file named Intall.log in the root directory to find the port used for TFTP in all network ports.

Figure 3-101

Find command

23. Find string: grep

Format: grep "string" Path [options]

Example:

1.grep "VolGroup"/root-rn

Looking for a file that contains the string "XML" under the current path

2. grep "volgrou*"/root-rn

Looking for a file containing a string starting with "he" under the current path

Figure 3-102

grep command

Process Management class commands

24. Viewing process: PS

Format: PS [options]

Example: PA aux.

The process display information is divided into 7 columns: User (user name), PID (Process ID),%CPU (CPU utilization of the process),%MEM (the size of the virtual memory used by the process), RSS (the size of the resident set used by the process, or the size of the actual RAM).

Kbytes bytes) TTY (the terminal associated with the process). STAT (Status of the process: the process state is represented by a character, R: run; S: Sleep; I: idle; Z: Zombie; D: non-disruptive; T: termination; P: Wait for the Exchange page; W: no resident page; X: Dead process; <: Less than high-priority processes; N: low-priority process; L: Memory lock page; s: Process leader; L: multi-process; +: Process group in background) START, (Process start time and date) times, (the total CPU time used by the process), and command (the commands being executed).

Figure 3-103

PS command

25. Kill Process: Kill

Format: Kill [SELECT] PID

Example:

1.VI hello.c

2.ps aux

3.kill [VI hello.c process PID]

Figure 3-104

Kill command

26. View Memory: Free

Format: free [options]

Example: Free

The Mem line is total (amount of physical memory) from left to right, used (memory already used. More

Plus, it should be the amount of memory that contains the data, free memory, no data empty memory

Shared memory number), buffers (this is actually a write cache), cached (

Cache for read operations).

Figure 3-105

Free command

CPU occupancy: Top

Format: top [options]

Example: Top

The top command dynamically displays the CPU's share, pressing "Ctrl" +c or "Q" to exit.

Figure 3-106

Top command

28. Software Management: RPM

Format: RPM [options] [package]

Example:

1.rpm–ivh/mnt/packages/xinetd-2.3.14-34.el6.i686.rpm

Installing xinetd-2.3.14-34.el6.i686.rpm

2. Rpm–qa

View all packages that are already installed on the system

3. rpm–exinetd-2.3.14-34.el6.i686

Uninstall the xinetd-2.3.14-34.el6.i686 that you have installed.

Figure 3-107

Package Selection

29. Pipe Operators: |

Format: Command 1 | Command 2

Example:

Rpm–qa | grep tar

Query all the packages installed in the system and find the package with the string "tar" from it.

Figure 3-108

Pipe operators

30. View Help: Man

Format: Man command name

Example: Man find

To view the use of the Find command

Figure 3-109

Find command Help documentation

31. Shut down the Linux system: shutdown [Options] Time

Example: Shutdown now

Shut down now.

Summarize:

Learn the basic usage of common commands under Linux in this lesson and learn how to use it when new commands are encountered.

Man Handbook find how to use it.

?

?

?

?

10.Linux command Explanation

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.