Common Linux shell commands (2)

Source: Internet
Author: User
Tags linux shell commands

Vi. user and group commands

1. groupadd command

Function: adds a group.

Groupadd test1 add test1 Group

Groupadd-g 1111 test2 add test2 group with id 1111

2. useradd command

Function: Add a user

Useradd user1 Add User user1, home is/home/user1, group is user1

Useradd-g test1-m-d/home/test1 test1 Add User test1, home is/home/test1, group is test1

User list: displays the list of logged-in users

3. passwd command

Function: Change the user password.

Passwd user1: change the password of user1.

Passwd-d root: Delete the password of the root user

4. userdel command

Function: delete a user.

Userdel user1 Delete user1 user

5. chown command

Function: Change the owner of a file or directory.

Chown user1/dir: Set the/dir directory to all

Chown-R user1.user1/dir: set all the files and directories in the/dir directory to user1 and set the group to user1. -R recursion to each file and directory below

6. chgrp command

Function: changes all groups of files or directories.

Chgrp user1/dir set the/dir directory to all

7. chmod command

Function: Change User Permissions.

Chmod a + x file sets the file to executable, and the script file must be set in this way. Otherwise, it must be executed using bash file.

Chmod 666 file: Set the file to read/write.

Chmod 750 file: sets the file as the full permission of the owner. The file can be read and executed in the same group. Other files have no permissions.

8. id command

Function: displays user information, including uid and gid.

# Id zhoulj

Uid = 500 (zhoulj) gid = 500 (zhoulj) groups = 500 (zhoulj)

9. finger command

Function: displays information for use.

Note: This command is not available in debian.

# Finger zhoulj

Login: zhoulj Name:

Directory:/home/zhoulj Shell:/bin/bash

On since Sun May 21 07:59 (CST) on pts/0 from 192.168.1.4

No mail.

No Plan.

VII. Compression commands

1. gzip commands

Function: compress the file in gz format.

Note: The generated file overwrites the source file.

Gzip-v <filename> compresses the file and displays the progress

-D <filename> extract

Gnuzip-f <filename> extract

For example:

# Gzip a. sh

# Ll

-Rwxr-xr-x 1 root 71 Aug 17 21:08 a.sh.gz

# Gzip-d a.sh.gz

# Ll

-Rwxr-xr-x 1 root 48 December 18 21:08 a. sh

2. zip commands

Function: zip commands for compression and decompression

Zip <DSTfilename> <SRCfilename>

Unzip <filename>

For example:

# Zip a.sh.zip a. sh

Adding: a. sh (stored 0%)

# Ll

-Rw-r-1 root 188 May 21 10:37 a.sh.zip

# Unzip a.sh.zip

Archive: a.sh.zip

Replace a. sh? [Y] es, [n] o, [A] ll, [N] one, [r] ename: r

New name: a1.sh

Extracting: a1.sh

# Ll

-Rwxr-xr-x 1 root 48 December 18 21:08 a1.sh3 and bzip2 commands

Function: bzip2 compression command,

Note: The generated file overwrites the source file.

Bzip2 <filename>

Bunzip2 <filename>

For example:

# Bzip2 a. sh

# Ll

-Rwxr-xr-x 1 root 85 December 18 21:08 a.sh.bz2

# Bunzip2 a.sh.bz2

# Ll

-Rwxr-xr-x 1 root 48 December 18 21:08 a. sh

4. tar command

Function: Archive, compress, etc. It is important and will be used frequently.

-Cvf <DSTfilename.tar> <SRCfilename> compresses the file or directory

-Xvf <SRCfilename> decompress the file or directory

-Zcvf <DSTfilename> <SRCfilename> compressed file or, in the format of tar.gz

-Zxvf <DSTfilename> <SRCfilename> uncompressed file or, in the format of tar.gz

-Zcvf <DST. tgz> <SRCfilename> compresses the file or, in the format of tgz

-Zxvf <DST. tgz> <SRCfilename> decompress the file or, in the format of tgz

Example:

# Tar cvf abc.tar *. sh

# Tar xvf abc.tar

# Tar czvf abc.tar.gz *. sh

# Ll

-Rw-r-1 root 20480 May 21 10:50 abc.tar

-Rw-r-1 root 1223 May 21 10:53 abc.tar.gz

# Tar xzvf abc.tar.gz

8. Network-related commands

1. ifconfig command

Function: displays the information for modifying the NIC.

Ifconfig displays network information

Ifconfig eth0 displays eth0 Network Information

Modify Network Information:

Ifconfig eth0 192.168.1.1 netmask 255.255.255.0 set the IP address 192.168.1.1 of NIC 1, mask 255.255.255.0

Ifconfig eth0: 1 192.168.1.2 bind the second address of Network Card 1 to 192.168.1.2

Ifconfig eth0: x 192.168.1.n the nth address of Network Card 1 bound to 192.168.1.n

For example:

# Ifconfig eth0: 1 192.168.1.11

# Ifconfig

Eth0 Link encap: Ethernet HWaddr 00: 0C: 29: 06: 9C: 24

Inet addr: 192.168.1.5 Bcast: 192.168.1.255 Mask: 255.255.255.0

Up broadcast running multicast mtu: 1500 Metric: 1

RX packets: 4220 errors: 0 dropped: 0 overruns: 0 frame: 0

TX packets: 3586 errors: 0 dropped: 0 overruns: 0 carrier: 0

Collisions: 0 FIG: 1000

RX bytes: 342493 (334.4 Kb) TX bytes: 469020 (458.0 Kb)

Interrupt: 9 Base address: 0 ×1400

Eth0: 1 Link encap: Ethernet HWaddr 00: 0C: 29: 06: 9C: 24

Inet addr: 192.168.1.11 Bcast: 192.168.1.255 Mask: 255.255.255.0

Up broadcast running multicast mtu: 1500 Metric: 1

Interrupt: 9 Base address: 0 ×1400

2. route command

Function: displays the current html "target = _ blank> route settings

The current route settings are displayed on the route page.

Route add-net 10.0.0.0 netmask route 255.0.0 gw 192.168.1.254 add static route

Route del-net 10.0.0.0 netmask route 255.0.0 gw 192.168.1.254 Add a static route

Route add default gw 192.168.1.1 metric1 set 192.168.1.1 as the default route

Route del default deletes the default route

Example:

# Route add-net 10.0.0.0 netmask 255.255.0.0 gw 192.168.1.254

# Netstat-nr

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

10.0.0.0 192.168.1.254 & nb

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.