[Linux][4_文件,打包和用户管理]

举报
John2021 发表于 2021/10/23 14:50:32 2021/10/23
【摘要】 Linux文件查看    Linux系统中使用以下命令来查看文件的内容:    cat 由第一行开始显示文件内容    tac 从最后一行开始显示,可以看出 tac 是 cat 的倒著写!    nl 显示的时候,顺道输出行号!    more 一页一页的显示文件内容    less 与 more 类似,但是比 more 更好的是,他可以往前翻页!    head 只看头几行    tail...

Linux文件查看

    Linux系统中使用以下命令来查看文件的内容:
    cat 由第一行开始显示文件内容
    tac 从最后一行开始显示,可以看出 tac 是 cat 的倒著写!
    nl 显示的时候,顺道输出行号!
    more 一页一页的显示文件内容
    less 与 more 类似,但是比 more 更好的是,他可以往前翻页!
    head 只看头几行
    tail 只看尾巴几行
    wc 统计文件行数

cat

man中的解释:
    Concatenate FILE(s) to standard output.
    With no FILE, or when FILE is -, read standard input.
        -A, --show-all           equivalent to -vET
        -b, --number-nonblank    number nonempty output lines, overrides -n
        -e                       equivalent to -vE
        -E, --show-ends          display $ at end of each line
        -n, --number             number all output lines
        -s, --squeeze-blank      suppress repeated empty output lines
        -t                       equivalent to -vT
        -T, --show-tabs          display TAB characters as ^I
        -u                       (ignored)
        -v, --show-nonprinting   use ^ and M- notation, except for LFD and TAB
            --help     display this help and exit
            --version  output version information and exit

tac

    man中的解释:
    Write each FILE to standard output, last line first.
    With no FILE, or when FILE is -, read standard input.
    Mandatory arguments to long options are mandatory for short options too.
    -b, --before             attach the separator before instead of after
    -r, --regex              interpret the separator as a regular expression
    -s, --separator=STRING   use STRING as the separator instead of newline
        --help     display this help and exit
        --version  output version information and exit

nl

    man中的解释:
    Write each FILE to standard output, with line numbers added.
    With no FILE, or when FILE is -, read standard input.
    Mandatory arguments to long options are mandatory for short options too.
    -b, --body-numbering=STYLE      use STYLE for numbering body lines
    -d, --section-delimiter=CC      use CC for logical page delimiters
    -f, --footer-numbering=STYLE    use STYLE for numbering footer lines
    -h, --header-numbering=STYLE    use STYLE for numbering header lines
    -i, --line-increment=NUMBER     line number increment at each line
    -l, --join-blank-lines=NUMBER   group of NUMBER empty lines counted as one
    -n, --number-format=FORMAT      insert line numbers according to FORMAT
    -p, --no-renumber               do not reset line numbers for each section
    -s, --number-separator=STRING   add STRING after (possible) line number
    -v, --starting-line-number=NUMBER  first line number for each section
    -w, --number-width=NUMBER       use NUMBER columns for line numbers
        --help     display this help and exit
        --version  output version information and exit

more

    man中的解释:
    A file perusal filter for CRT viewing.
    Options:
    -d          display help instead of ringing bell
    -f          count logical rather than screen lines
    -l          suppress pause after form feed
    -c          do not scroll, display text and clean line ends
    -p          do not scroll, clean screen and display text
    -s          squeeze multiple blank lines into one
    -u          suppress underlining
    -<number>   the number of lines per screenful
    +<number>   display file beginning from line number
    +/<string>  display file beginning from search string match

        --help     display this help
    -V, --version  display version

less

    man中的解释:
    Write each FILE to standard output, last line first.
    With no FILE, or when FILE is -, read standard input.
    Mandatory arguments to long options are mandatory for short options too.
    -b, --before             attach the separator before instead of after
    -r, --regex              interpret the separator as a regular expression
    -s, --separator=STRING   use STRING as the separator instead of newline
        --help     display this help and exit
        --version  output version information and exit

head

    man中的解释:
    Print the first 10 lines of each FILE to standard output.
    With more than one FILE, precede each with a header giving the file name.
    With no FILE, or when FILE is -, read standard input.
    Mandatory arguments to long options are mandatory for short options too.
    -c, --bytes=[-]NUM       print the first NUM bytes of each file;
                                with the leading '-', print all but the last
                                NUM bytes of each file
    -n, --lines=[-]NUM       print the first NUM lines instead of the first 10;
                                with the leading '-', print all but the last
                                NUM lines of each file
    -q, --quiet, --silent    never print headers giving file names
    -v, --verbose            always print headers giving file names
    -z, --zero-terminated    line delimiter is NUL, not newline
        --help     display this help and exit
        --version  output version information and exit

tail

    man中的解释:
    Print the last 10 lines of each FILE to standard output.
    With more than one FILE, precede each with a header giving the file name.
    With no FILE, or when FILE is -, read standard input.
    Mandatory arguments to long options are mandatory for short options too.
    -c, --bytes=[+]NUM       output the last NUM bytes; or use -c +NUM to
                                output starting with byte NUM of each file
    -f, --follow[={name|descriptor}]
                            output appended data as the file grows;
                                an absent option argument means 'descriptor'
    -F                       same as --follow=name --retry
    -n, --lines=[+]NUM       output the last NUM lines, instead of the last 10;
                                or use -n +NUM to output starting with line NUM
        --max-unchanged-stats=N
                            with --follow=name, reopen a FILE which has not
                                changed size after N (default 5) iterations
                                to see if it has been unlinked or renamed
                                (this is the usual case of rotated log files);
                                with inotify, this option is rarely useful
        --pid=PID            with -f, terminate after process ID, PID dies
    -q, --quiet, --silent    never output headers giving file names
        --retry              keep trying to open a file if it is inaccessible
    -s, --sleep-interval=N   with -f, sleep for approximately N seconds
                                (default 1.0) between iterations;
                                with inotify and --pid=P, check process P at
                                least once every N seconds
    -v, --verbose            always output headers giving file names
    -z, --zero-terminated    line delimiter is NUL, not newline
        --help     display this help and exit
        --version  output version information and exit

wc

    man中的解释:
    more than one FILE is specified.  A word is a non-zero-length sequence of
    characters delimited by white space.

    With no FILE, or when FILE is -, read standard input.

    The options below may be used to select which counts are printed, always in
    the following order: newline, word, character, byte, maximum line length.
    -c, --bytes            print the byte counts
    -m, --chars            print the character counts
    -l, --lines            print the newline counts
        --files0-from=F    read input from the files specified by
                            NUL-terminated names in file F;
                            If F is - then read names from standard input
    -L, --max-line-length  print the maximum display width
    -w, --words            print the word counts
        --help     display this help and exit
        --version  output version information and exit

Linux打包和压缩

tar

    man中的解释:
    GNU 'tar' saves many files together into a single tape or disk archive, and can
    restore individual files from the archive.

    Examples:
    tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.
    tar -tvf archive.tar         # List all files in archive.tar verbosely.
    tar -xf archive.tar          # Extract all files from archive.tar.

    Local file name selection:

        --add-file=FILE        add given FILE to the archive (useful if its name
                                starts with a dash)
    -C, --directory=DIR        change to directory DIR
        --exclude=PATTERN      exclude files, given as a PATTERN
        --exclude-backups      exclude backup and lock files
        --exclude-caches       exclude contents of directories containing
                                CACHEDIR.TAG, except for the tag file itself
        --exclude-caches-all   exclude directories containing CACHEDIR.TAG
        --exclude-caches-under exclude everything under directories containing
                                CACHEDIR.TAG
        --exclude-ignore=FILE  read exclude patterns for each directory from
                                FILE, if it exists
        --exclude-ignore-recursive=FILE
                                read exclude patterns for each directory and its
                                subdirectories from FILE, if it exists
        --exclude-tag=FILE     exclude contents of directories containing FILE,
                                except for FILE itself
        --exclude-tag-all=FILE exclude directories containing FILE
        --exclude-tag-under=FILE   exclude everything under directories
                                containing FILE
        --exclude-vcs          exclude version control system directories
        --exclude-vcs-ignores  read exclude patterns from the VCS ignore files
        --no-null              disable the effect of the previous --null option
        --no-recursion         avoid descending automatically in directories
        --no-unquote           do not unquote input file or member names
        --no-verbatim-files-from   -T treats file names starting with dash as
                                options (default)
        --null                 -T reads null-terminated names; implies
                                --verbatim-files-from
        --recursion            recurse into directories (default)
    -T, --files-from=FILE      get names to extract or create from FILE
        --unquote              unquote input file or member names (default)
        --verbatim-files-from  -T reads file names verbatim (no escape or option
                                handling)
    -X, --exclude-from=FILE    exclude patterns listed in FILE

    File name matching options (affect both exclude and include patterns):

        --anchored             patterns match file name start
        --ignore-case          ignore case
        --no-anchored          patterns match after any '/' (default for
                                exclusion)
        --no-ignore-case       case sensitive matching (default)
        --no-wildcards         verbatim string matching
        --no-wildcards-match-slash   wildcards do not match '/'
        --wildcards            use wildcards (default)
        --wildcards-match-slash   wildcards match '/' (default for exclusion)

    Main operation mode:

    -A, --catenate, --concatenate   append tar files to an archive
    -c, --create               create a new archive
    -d, --diff, --compare      find differences between archive and file system
        --delete               delete from the archive (not on mag tapes!)
    -r, --append               append files to the end of an archive
    -t, --list                 list the contents of an archive
        --test-label           test the archive volume label and exit
    -u, --update               only append files newer than copy in archive
    -x, --extract, --get       extract files from an archive

    Operation modifiers:

        --check-device         check device numbers when creating incremental
                                archives (default)
    -g, --listed-incremental=FILE   handle new GNU-format incremental backup
    -G, --incremental          handle old GNU-format incremental backup
        --hole-detection=TYPE  technique to detect holes
        --ignore-failed-read   do not exit with nonzero on unreadable files
        --level=NUMBER         dump level for created listed-incremental archive
    -n, --seek                 archive is seekable
        --no-check-device      do not check device numbers when creating
                                incremental archives
        --no-seek              archive is not seekable
        --occurrence[=NUMBER]  process only the NUMBERth occurrence of each file
                                in the archive; this option is valid only in
                                conjunction with one of the subcommands --delete,
                                --diff, --extract or --list and when a list of
                                files is given either on the command line or via
                                the -T option; NUMBER defaults to 1
        --sparse-version=MAJOR[.MINOR]
                                set version of the sparse format to use (implies
                                --sparse)
    -S, --sparse               handle sparse files efficiently

    Overwrite control:

    -k, --keep-old-files       don't replace existing files when extracting,
                                treat them as errors
        --keep-directory-symlink   preserve existing symlinks to directories when
                                extracting
        --keep-newer-files     don't replace existing files that are newer than
                                their archive copies
        --no-overwrite-dir     preserve metadata of existing directories
        --one-top-level[=DIR]  create a subdirectory to avoid having loose files
                                extracted
        --overwrite            overwrite existing files when extracting
        --overwrite-dir        overwrite metadata of existing directories when
                                extracting (default)
        --recursive-unlink     empty hierarchies prior to extracting directory
        --remove-files         remove files after adding them to the archive
        --skip-old-files       don't replace existing files when extracting,
                                silently skip over them
    -U, --unlink-first         remove each file prior to extracting over it
    -W, --verify               attempt to verify the archive after writing it

    Select output stream:

        --ignore-command-error ignore exit codes of children
        --no-ignore-command-error   treat non-zero exit codes of children as
                                error
    -O, --to-stdout            extract files to standard output
        --to-command=COMMAND   pipe extracted files to another program

    Handling of file attributes:

        --atime-preserve[=METHOD]   preserve access times on dumped files, either
                                by restoring the times after reading
                                (METHOD='replace'; default) or by not setting the
                                times in the first place (METHOD='system')
        --clamp-mtime          only set time when the file is more recent than
                                what was given with --mtime
        --delay-directory-restore   delay setting modification times and
                                permissions of extracted directories until the end
                                of extraction
        --group=NAME           force NAME as group for added files
        --group-map=FILE       use FILE to map file owner GIDs and names
        --mode=CHANGES         force (symbolic) mode CHANGES for added files
        --mtime=DATE-OR-FILE   set mtime for added files from DATE-OR-FILE
    -m, --touch                don't extract file modified time
        --no-delay-directory-restore
                                cancel the effect of --delay-directory-restore
                                option
        --no-same-owner        extract files as yourself (default for ordinary
                                users)
        --no-same-permissions  apply the user's umask when extracting permissions
                                from the archive (default for ordinary users)
        --numeric-owner        always use numbers for user/group names
        --owner=NAME           force NAME as owner for added files
        --owner-map=FILE       use FILE to map file owner UIDs and names
    -p, --preserve-permissions, --same-permissions
                                extract information about file permissions
                                (default for superuser)
        --same-owner           try extracting files with the same ownership as
                                exists in the archive (default for superuser)
    -s, --preserve-order, --same-order
                                member arguments are listed in the same order as
                                the files in the archive
        --sort=ORDER           directory sorting order: none (default), name or
                                inode

    Handling of extended file attributes:

        --acls                 Enable the POSIX ACLs support
        --no-acls              Disable the POSIX ACLs support
        --no-selinux           Disable the SELinux context support
        --no-xattrs            Disable extended attributes support
        --selinux              Enable the SELinux context support
        --xattrs               Enable extended attributes support
        --xattrs-exclude=MASK  specify the exclude pattern for xattr keys
        --xattrs-include=MASK  specify the include pattern for xattr keys

    Device selection and switching:

    -f, --file=ARCHIVE         use archive file or device ARCHIVE
        --force-local          archive file is local even if it has a colon
    -F, --info-script=NAME, --new-volume-script=NAME
                                run script at end of each tape (implies -M)
    -L, --tape-length=NUMBER   change tape after writing NUMBER x 1024 bytes
    -M, --multi-volume         create/list/extract multi-volume archive
        --rmt-command=COMMAND  use given rmt COMMAND instead of rmt
        --rsh-command=COMMAND  use remote COMMAND instead of rsh
        --volno-file=FILE      use/update the volume number in FILE

    Device blocking:

    -b, --blocking-factor=BLOCKS   BLOCKS x 512 bytes per record
    -B, --read-full-records    reblock as we read (for 4.2BSD pipes)
    -i, --ignore-zeros         ignore zeroed blocks in archive (means EOF)
        --record-size=NUMBER   NUMBER of bytes per record, multiple of 512

    Archive format selection:

    -H, --format=FORMAT        create archive of the given format

    FORMAT is one of the following:

        gnu                      GNU tar 1.13.x format
        oldgnu                   GNU format as per tar <= 1.12
        pax                      POSIX 1003.1-2001 (pax) format
        posix                    same as pax
        ustar                    POSIX 1003.1-1988 (ustar) format
        v7                       old V7 tar format

        --old-archive, --portability
                                same as --format=v7
        --pax-option=keyword[[:]=value][,keyword[[:]=value]]...
                                control pax keywords
        --posix                same as --format=posix
    -V, --label=TEXT           create archive with volume name TEXT; at
                                list/extract time, use TEXT as a globbing pattern
                                for volume name

    Compression options:

    -a, --auto-compress        use archive suffix to determine the compression
                                program
    -I, --use-compress-program=PROG
                                filter through PROG (must accept -d)
    -j, --bzip2                filter the archive through bzip2
    -J, --xz                   filter the archive through xz
        --lzip                 filter the archive through lzip
        --lzma                 filter the archive through xz --format=lzma
        --lzop                 filter the archive through lzop
        --no-auto-compress     do not use archive suffix to determine the
                                compression program
    -z, --gzip, --gunzip, --ungzip   filter the archive through gzip
    -Z, --compress, --uncompress   filter the archive through compress

    Local file selection:

        --backup[=CONTROL]     backup before removal, choose version CONTROL
    -h, --dereference          follow symlinks; archive and dump the files they
                                point to
        --hard-dereference     follow hard links; archive and dump the files they
                                refer to
    -K, --starting-file=MEMBER-NAME
                                begin at member MEMBER-NAME when reading the
                                archive
        --newer-mtime=DATE     compare date and time when data changed only
    -N, --newer=DATE-OR-FILE, --after-date=DATE-OR-FILE
                                only store files newer than DATE-OR-FILE
        --one-file-system      stay in local file system when creating archive
    -P, --absolute-names       don't strip leading '/'s from file names
        --suffix=STRING        backup before removal, override usual suffix ('~'
                                unless overridden by environment variable
                                SIMPLE_BACKUP_SUFFIX)

    File name transformations:

        --strip-components=NUMBER   strip NUMBER leading components from file
                                names on extraction
        --transform=EXPRESSION, --xform=EXPRESSION
                                use sed replace EXPRESSION to transform file
                                names

    Informative output:

        --checkpoint[=NUMBER]  display progress messages every NUMBERth record
                                (default 10)
        --checkpoint-action=ACTION   execute ACTION on each checkpoint
        --full-time            print file time to its full resolution
        --index-file=FILE      send verbose output to FILE
    -l, --check-links          print a message if not all links are dumped
        --no-quote-chars=STRING   disable quoting for characters from STRING
        --quote-chars=STRING   additionally quote characters from STRING
        --quoting-style=STYLE  set name quoting style; see below for valid STYLE
                                values
    -R, --block-number         show block number within archive with each message

        --show-defaults        show tar defaults
        --show-omitted-dirs    when listing or extracting, list each directory
                                that does not match search criteria
        --show-snapshot-field-ranges
                                show valid ranges for snapshot-file fields
        --show-transformed-names, --show-stored-names
                                show file or archive names after transformation
        --totals[=SIGNAL]      print total bytes after processing the archive;
                                with an argument - print total bytes when this
                                SIGNAL is delivered; Allowed signals are: SIGHUP,
                                SIGQUIT, SIGINT, SIGUSR1 and SIGUSR2; the names
                                without SIG prefix are also accepted
        --utc                  print file modification times in UTC
    -v, --verbose              verbosely list files processed
        --warning=KEYWORD      warning control
    -w, --interactive, --confirmation
                                ask for confirmation for every action

    Compatibility options:

    -o                         when creating, same as --old-archive; when
                                extracting, same as --no-same-owner

    Other options:

    -?, --help                 give this help list
        --restrict             disable use of some potentially harmful options
        --usage                give a short usage message
        --version              print program version

gzip

    man中的解释:
    Compress or uncompress FILEs (by default, compress FILES in-place).

    Mandatory arguments to long options are mandatory for short options too.

    -c, --stdout      write on standard output, keep original files unchanged
    -d, --decompress  decompress
    -f, --force       force overwrite of output file and compress links
    -h, --help        give this help
    -k, --keep        keep (don't delete) input files
    -l, --list        list compressed file contents
    -L, --license     display software license
    -n, --no-name     do not save or restore the original name and timestamp
    -N, --name        save or restore the original name and timestamp
    -q, --quiet       suppress all warnings
    -r, --recursive   operate recursively on directories
        --rsyncable   make rsync-friendly archive
    -S, --suffix=SUF  use suffix SUF on compressed files
        --synchronous synchronous output (safer if system crashes, but slower)
    -t, --test        test compressed file integrity
    -v, --verbose     verbose mode
    -V, --version     display version number
    -1, --fast        compress faster
    -9, --best        compress better

    With no FILE, or when FILE is -, read standard input.

bzip2

    man中的解释:
    bzip2, a block-sorting file compressor.  Version 1.0.6, 6-Sept-2010.

    usage: bzip2 [flags and input files in any order]

    -h --help           print this message
    -d --decompress     force decompression
    -z --compress       force compression
    -k --keep           keep (don't delete) input files
    -f --force          overwrite existing output files
    -t --test           test compressed file integrity
    -c --stdout         output to standard out
    -q --quiet          suppress noncritical error messages
    -v --verbose        be verbose (a 2nd -v gives more)
    -L --license        display software version & license
    -V --version        display software version & license
    -s --small          use less memory (at most 2500k)
    -1 .. -9            set block size to 100k .. 900k
    --fast              alias for -1
    --best              alias for -9

    If invoked as `bzip2', default action is to compress.
                as `bunzip2',  default action is to decompress.
                as `bzcat', default action is to decompress to stdout.

    If no file names are given, bzip2 compresses or decompresses
    from standard input to standard output.  You can combine
    short flags, so `-v -4' means the same as -v4 or -4v, &c.

用户管理

用户与用户组的概念

Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统。

用户的账号一方面可以帮助系统管理员对使用系统的用户进行跟踪,并控制他们对系统资源的访问;另一方面也可以帮助用户组织文件,并为用户提供安全性保护

每个用户账号都拥有一个惟一的用户名和各自的口令。

用户在登录时键入正确的用户名和口令后,就能够进入系统和自己的主目录。

实现用户账号的管理,要完成的工作主要有如下几个方面:

            用户账号的添加、删除与修改。
            用户口令的管理。
            用户组的管理。

每个用户都有一个用户组,系统可以对一个用户组中的所有用户进行集中管理。不同Linux 系统对用户组的规定有所不同,如Linux下的用户属于与它同名的用户组,

这个用户组在创建用户时同时创建。用户组的管理涉及用户组的添加、删除和修改。组的增加、删除和修改实际上就是对/etc/group文件的更新。

常用用户命令

useradd 添加用户

    man中的解释:
    Usage: useradd [options] LOGIN
    useradd -D
    useradd -D [options]

    Options:
    -b, --base-dir BASE_DIR       base directory for the home directory of the
                                    new account
    -c, --comment COMMENT         GECOS field of the new account
    -d, --home-dir HOME_DIR       home directory of the new account
    -D, --defaults                print or change default useradd configuration
    -e, --expiredate EXPIRE_DATE  expiration date of the new account
    -f, --inactive INACTIVE       password inactivity period of the new account
    -g, --gid GROUP               name or ID of the primary group of the new
                                    account
    -G, --groups GROUPS           list of supplementary groups of the new
                                    account
    -h, --help                    display this help message and exit
    -k, --skel SKEL_DIR           use this alternative skeleton directory
    -K, --key KEY=VALUE           override /etc/login.defs defaults
    -l, --no-log-init             do not add the user to the lastlog and
                                    faillog databases
    -m, --create-home             create the user's home directory
    -M, --no-create-home          do not create the user's home directory
    -N, --no-user-group           do not create a group with the same name as
                                    the user
    -o, --non-unique              allow to create users with duplicate
                                    (non-unique) UID
    -p, --password PASSWORD       encrypted password of the new account
    -r, --system                  create a system account
    -R, --root CHROOT_DIR         directory to chroot into
    -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files
    -s, --shell SHELL             login shell of the new account
    -u, --uid UID                 user ID of the new account
    -U, --user-group              create a group with the same name as the user
    -Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping

userdel 删除用户

    man中的解释:
    Usage: userdel [options] LOGIN

    Options:
    -f, --force                   force some actions that would fail otherwise
                                    e.g. removal of user still logged in
                                    or files, even if not owned by the user
    -h, --help                    display this help message and exit
    -r, --remove                  remove home directory and mail spool
    -R, --root CHROOT_DIR         directory to chroot into
    -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files
    -Z, --selinux-user            remove any SELinux user mapping for the user

    passwd 设置用户密码
    man中的解释:
    Usage: passwd [OPTION...] <accountName>
    -k, --keep-tokens       keep non-expired authentication tokens
    -d, --delete            delete the password for the named account (root only); also removes password lock if
                            any
    -l, --lock              lock the password for the named account (root only)
    -u, --unlock            unlock the password for the named account (root only)
    -e, --expire            expire the password for the named account (root only)
    -f, --force             force operation
    -x, --maximum=DAYS      maximum password lifetime (root only)
    -n, --minimum=DAYS      minimum password lifetime (root only)
    -w, --warning=DAYS      number of days warning users receives before password expiration (root only)
    -i, --inactive=DAYS     number of days after password expiration when an account becomes disabled (root only)
    -S, --status            report password status on the named account (root only)
        --stdin             read new tokens from stdin (root only)

    Help options:
    -?, --help              Show this help message
        --usage             Display brief usage message

usermod 修改用户信息

    man中的解释:
    Usage: usermod [options] LOGIN

    Options:
    -c, --comment COMMENT         new value of the GECOS field
    -d, --home HOME_DIR           new home directory for the user account
    -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
    -f, --inactive INACTIVE       set password inactive after expiration
                                    to INACTIVE
    -g, --gid GROUP               force use GROUP as new primary group
    -G, --groups GROUPS           new list of supplementary GROUPS
    -a, --append                  append the user to the supplemental GROUPS
                                    mentioned by the -G option without removing
                                    the user from other groups
    -h, --help                    display this help message and exit
    -l, --login NEW_LOGIN         new value of the login name
    -L, --lock                    lock the user account
    -m, --move-home               move contents of the home directory to the
                                    new location (use only with -d)
    -o, --non-unique              allow using duplicate (non-unique) UID
    -p, --password PASSWORD       use encrypted password for the new password
    -R, --root CHROOT_DIR         directory to chroot into
    -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files
    -s, --shell SHELL             new login shell for the user account
    -u, --uid UID                 new UID for the user account
    -U, --unlock                  unlock the user account
    -v, --add-subuids FIRST-LAST  add range of subordinate uids
    -V, --del-subuids FIRST-LAST  remove range of subordinate uids
    -w, --add-subgids FIRST-LAST  add range of subordinate gids
    -W, --del-subgids FIRST-LAST  remove range of subordinate gids
    -Z, --selinux-user SEUSER     new SELinux user mapping for the user account

groupadd 添加用户组

    man中的解释:
    Usage: groupadd [options] GROUP

    Options:
    -f, --force                   exit successfully if the group already exists,
                                    and cancel -g if the GID is already used
    -g, --gid GID                 use GID for the new group
    -h, --help                    display this help message and exit
    -K, --key KEY=VALUE           override /etc/login.defs defaults
    -o, --non-unique              allow to create groups with duplicate
                                    (non-unique) GID
    -p, --password PASSWORD       use this encrypted password for the new group
    -r, --system                  create a system account
    -R, --root CHROOT_DIR         directory to chroot into
    -P, --prefix PREFIX_DIR       directory prefix

    groupdel 删除用户组
    man中的解释:
    Usage: groupdel [options] GROUP

    Options:
    -h, --help                    display this help message and exit
    -R, --root CHROOT_DIR         directory to chroot into
    -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files
    -f, --force                   delete group even if it is the primary group of a user

用户的家目录: /home/用户名

以管理员身份运行

su 切换当前用户身份

    man中的解释:
    Usage:
    su [options] [-] [<user> [<argument>...]]

    Change the effective user ID and group ID to that of <user>.
    A mere - implies -l.  If <user> is not given, root is assumed.

    Options:
    -m, -p, --preserve-environment  do not reset environment variables
    -g, --group <group>             specify the primary group
    -G, --supp-group <group>        specify a supplemental group

    -, -l, --login                  make the shell a login shell
    -c, --command <command>         pass a single command to the shell with -c
    --session-command <command>     pass a single command to the shell with -c
                                    and do not create a new session
    -f, --fast                      pass -f to the shell (for csh or tcsh)
    -s, --shell <shell>             run <shell> if /etc/shells allows it
    -P, --pty                       create a new pseudo-terminal

    -h, --help                      display this help
    -V, --version                   display version

sudo 用root用户身份执行某条命令

    man中的解释:
    sudo - execute a command as another user

    usage: sudo -h | -K | -k | -V
    usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
    usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
    usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-T timeout] [-u user]
                [VAR=value] [-i|-s] [<command>]
    usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-T timeout] [-u user] file
                ...

    Options:
    -A, --askpass                 use a helper program for password prompting
    -b, --background              run command in the background
    -B, --bell                    ring bell when prompting
    -C, --close-from=num          close all file descriptors >= num
    -E, --preserve-env            preserve user environment when running command
        --preserve-env=list       preserve specific environment variables
    -e, --edit                    edit files instead of running a command
    -g, --group=group             run command as the specified group name or ID
    -H, --set-home                set HOME variable to target user's home dir
    -h, --help                    display help message and exit
    -h, --host=host               run command on host (if supported by plugin)
    -i, --login                   run login shell as the target user; a command may also be specified
    -K, --remove-timestamp        remove timestamp file completely
    -k, --reset-timestamp         invalidate timestamp file
    -l, --list                    list user's privileges or check a specific command; use twice for longer format
    -n, --non-interactive         non-interactive mode, no prompts are used
    -P, --preserve-groups         preserve group vector instead of setting to target's
    -p, --prompt=prompt           use the specified password prompt
    -r, --role=role               create SELinux security context with specified role
    -S, --stdin                   read password from standard input
    -s, --shell                   run shell as the target user; a command may also be specified
    -t, --type=type               create SELinux security context with specified type
    -T, --command-timeout=timeout terminate command after the specified time limit
    -U, --other-user=user         in list mode, display privileges for user
    -u, --user=user               run command (or edit file) as specified user name or ID
    -V, --version                 display version information and exit
    -v, --validate                update user's timestamp without running a command
    --                            stop processing command line arguments

visudo 修改sudo命令的配置文件

    man中的解释:
    visudo - safely edit the sudoers file

    usage: visudo [-chqsV] [[-f] sudoers ]

    Options:
    -c, --check              check-only mode
    -f, --file=sudoers       specify sudoers file location
    -h, --help               display help message and exit
    -q, --quiet              less verbose (quiet) syntax error messages
    -s, --strict             strict syntax checking
    -V, --version            display version information and exit

用户配置文件

    /etc/passwd 用户信息配置文件
    /etc/shadow 用户密码信息配置文件

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。