Linux4:useradd, Userdel, passwd, Groupadd, Chgrp, Chown, DF, Du, sort, wget

Source: Internet
Author: User
Tags disk usage


Add a new user account, only the root account can be operated

-D Directory: Specify the home directory (default in Home), if this directory does not exist, you can use-m to create the main directory

-G user group: Specify the user group to which the user belongs

-G user group: Specify additional groups to which the user belongs

-S Shell file: Specify the shell that the user logged in with

For example:

useradd-d/usr/sam-m Sam: Create a home directory for the login Sam/usr/sam

Useradd-s/bin/sh-g group-g adm,root sam: Create a log-in user Sam, who logs on to the shell as/bin/sh, belongs to group user groups, and belongs to user group ADM and root, but group is its primary group


Delete user account

-R: One of the most commonly used options, the user's home directory is deleted together

For example:

Userdel-r Sam: Remove the SAM in the file system (/etc/password,/etc/shadow,/etc/group) while deleting the user's home directory


Manage the user's password, the user account has just been created without a password, locked by the system, can not be used, it must be given a password before it can be used, even if the empty password. Superuser can specify passwords for themselves and other users, and ordinary users can only specify their own passwords

-L: Lock password

-U: Password unlock

-D: No password for the account

-F: Force user to change password at next logon

For example:

passwd: Modify the current user password, if it is superuser, then do not need to know the original password, ordinary users to change the password will first ask the original password

passwd sam: superuser specifies password for user Sam

passwd-d Sam: Superuser removes the user Sam password so that Sam does not need a password for the next logon

Passwd-l Sam: Super users lock Sam so they can't log in


Add a new user group

-G: Specify user group identification number GID

-O: Typically used with-G, indicates that the GID of the new user group can be the same as the existing user group GID

For example:

Groupadd group1: Adding a user group Group1,gid is adding 1 to the currently existing GID max value

GROUPADD-G 101 group1: Add a user group group1 and specify its GID to be 101


Use group name or group ID GID to change the group of files or directories, super users. The changed group name must exist within the/etc/group file

-C: Output debug information When a change occurs

-F: Do not display error messages

-r: Processes the specified directory and all its subdirectories, sub-Files

-V: Detailed processing information is displayed at run time

For example:

Chgrp-v bin Log1.log: Changes the Log1.log group to bin and displays detailed processing information

CHGRP--reference=log2.log Log1.log: Change the Log1.log group attribute to refer to Log2.log

Chgrp-r bin test: Change the group property of all directories and their subdirectories under test to Bin

Chgrp-r test: Change the test group properties according to the group ID GID


Change the owner and group of the file, the owner can use the user name or user ID, group name or group ID. The Chown command is typically a system administrator, and a system administrator often copies files to another user's directory, giving them permission to use the file.

-C: Display part of the changed information

-F: Ignore error messages

-r: Processes the specified directory and all its subdirectories, sub-Files

-V: Show detailed processing information

For example:

Chown mail:mail Log1.log: Change the owner of the Log1.log and the owning group as mail

Chown:mail Log1.log: Change Log1.log's file group to mail

Chown-r-V root:mail test6: Change the owner of the Test6 folder and all files/folders under root, group mail, display processing information when modified


Displays the available space for the specified disk file, and if you do not specify a file name, all available space for the currently suspended filesystem will be displayed. Default display unit is KB

-A: Show all file system lists

-H: Display in a convenient reading format

-L: Show only local file system

For example:

DF: Show disk usage

DF-T: List File system types

Df-h: Displays current disk space and usage in a convenient, readable way

DF-T ext3: Show file usage under disk ext3


Displays disk usage for each file and directory, with the default display in KB

-B: Display unit in byte

-K: Display units in kilobytes

-M: Display units in megabytes

-S: Show Totals only

-H: Improve the readability of information in K, M, G units

For example:

Du: Displays the space occupied by a directory or file, showing only the directory size of subdirectories under the current directory and the total size of the current directory (the total size of the current directory is at the bottom)

Du ABC: Displays the space occupied by the ABC directory

Du log1.log log2.log log3.log: Shows the space occupied by multiple files

Du-s: Show only the sum size

Du | Sort-nr | MORE: Sort by space size and use more output

Du--max-depth=1: Output the space occupied by subdirectories in the current directory


Sort according to different data types, ascending by default

-B: Ignores whitespace starting at each line

-C: Check that the files are sorted in order

-F: Ignore uppercase and lowercase letters when arranging

-N: Sort by numeric size

-o< output file;: The sorted result is saved in the specified file

-r: Sort in reverse order

For example:

Sort Seq.txt: Compare and Sort by ASCII values, and finally output them in ascending order

Sort-u seq.txt: Compare, Sort, de-duplicate by ASCII value, and finally output them in ascending order

Sort-r Seq.txt: The front is ascending, plus-R becomes descending.

Sort-r number.txt-o number.txt: number.txt content in reverse order overwrite Number.txt, if the other file name is directly output to the specified file

Sort-n number.txt: Sort the values in the Number.txt numerically, so there is no 10<2.

Sort-n-K 2-t ': ' fruit.txt: Separates each line in the fruit.txt with ': ' and sorts by value in the 2nd column


Used to download resources from the network, if you do not specify a directory, the download resource defaults to the current directory. Wget Support:

1. Breakpoint Download

2. Support both FTP and HTTP

3. Support Proxy Server

4. Simple setting

-B: Run back to background after start

-O: Write the record to the file

-A: Append the record to the file

-tries=number: Set maximum number of attempted connections, 0 means no limit, 20 times default

-timeout=second: Sets the number of seconds for response timeout

For example:

wget URL: Use wget to download a single file from a URL, there will be a progress bar

Wget-o URL: Download a file and name it in

wget--limit-rate=300k URL: Limit download rate to 300K download a file

Wget-c URL: A breakpoint continues to upload a file to prevent network interruption when downloading large files

Wget-b URL: Download a file in the background, tail-f wget-log View Download Progress

wget--user-agent= "XXX" URL: Use pseudo proxy name to download

wget--tries=40 URL: Download a file, failed to retry 40 times

wget--reject=gif URL: Download a file, but do not download GIF files for filtering the specified format

Wget-o Download.log URL: Writes the download log to Download.log

wget--ftp-user=username--ftp-password=password URL: Specify user name, password, download a file using FTP

Linux4:useradd, Userdel, passwd, Groupadd, Chgrp, Chown, DF, Du, sort, wget

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: 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.