软件测试从业者必备的Linux命令(完整篇)

观点:

关于Linux,测试从业者,看这篇文章就够了 。

具体,往下看 :

网上关于Linux资料太多、太杂,学习没有重点,特别是对于没有基础的从业者,期望通过那些文档,去自学掌握Linux,可能性太小(资料太多、时间有限、精力不够) 。

这次,老徐花了21天,重新梳理了,测试从业者,需要掌握的高频Linux命令,且通过实际工作场景的方式,布置任务,每天一个任务,第二天公布答案 。

通过这种方式,带领各位从业者,高效、有针对性的掌握一门技术 。

开始之前,先同步一个结论:

对于软件测试从业者,如果你至今为止,还不懂Linux,或者完全没有接触Linux ,这是一件很危险和恐怖的事 。

此刻、现在、果断,学习Linux命令 。

如果你工作中,完全接触不到Linux ,或者公司服务的环境,还是Windows,赶紧自学Linux,并果断干脆的跳槽 。
这件事,太危险 ,几年后,也许会出现,找不到工作的尴尬境遇 。

开始进入主题 。

如下的这些命令,都是老徐根据自己的从业十年经验,精心筛选,每个命令,点到为止,挑选了一些高频的工作场景 。

对于,满足初中级的的工作任务,足够 。

Linux系统的命令通常都是如下所示的格式:
命令名称 [命名参数] [命令对象]

命令 cd

  1. 如何进入上级目录
    cd ..

  2. 如何进入当前用户主目录
    cd ~

  3. 如何进入上两级目录
    cd ../..

  4. 进入当前目录命令
    cd .

  5. 如何进入目录 /usr/isTester
    cd /usr/isTester

命令 mv

mv 命令(move 的缩写),既可以在不同的目录之间移动文件或目录,也可以对文件和目录进行重命名。
[root@localhost ~]# mv 【选项】 源文件 目标文件
选项:
-f:强制覆盖,如果目标文件已经存在,则不询问,直接强制覆盖;
-i:交互移动,如果目标文件已经存在,则询问用户是否覆盖(默认选项);
-n:如果目标文件已经存在,则不会覆盖移动,而且不询问用户;
-v:显示文件或目录的移动过程;
-u:若目标文件已经存在,但两者相比,源文件更新,则会对目标文件进行升级;
需要注意的是,同 rm 命令类似,mv 命令也是一个具有破坏性的命令,如果使用不当,很可能给系统带来灾难性的后果。

  1. 移动一个文件夹(isTester文件夹,移动到/APP/www目录)
    mv ~/isTester/ /APP/www

  2. 移动一个文件(isTester.ini 移动到/APP/www目录)
    mv isTester.ini /APP/www

  3. 当前目录istester.tar.gz 移动到 /usr/ido 目录,并重命名为ido.tar.gz
    mv isTester.tar.gz /usr/ido/ido.tar.gz

  4. 移动文件到上级目录
    mv isTester.tar.gz ../

  5. 一条命令,移动两个文件 isTester.tar idoxu.tar 到目录 /APP/www
    mv isTester.tar idoxu.tar -t /APP/www
    参数:-t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY

没有加-t参数也能移动成功

[root@VM_0_12_centos /]# ls
1.txt  2.txt  bin  boot  data  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  temp  tmp  usr  var
[root@VM_0_12_centos /]# mv 1.txt 2.txt /temp/
[root@VM_0_12_centos /]# ls
bin  boot  data  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  temp  tmp  usr  var
[root@VM_0_12_centos /]# cd temp/
[root@VM_0_12_centos temp]# ls
1.txt  2.txt  test

mv语法:

[root@VM_0_12_centos temp]# mv --help
Usage: mv [OPTION]... [-T] SOURCE DEST
  or:  mv [OPTION]... SOURCE... DIRECTORY
  or:  mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

Mandatory arguments to long options are mandatory for short options too.
      --backup[=CONTROL]       make a backup of each existing destination file
  -b                           like --backup but does not accept an argument
  -f, --force                  do not prompt before overwriting
  -i, --interactive            prompt before overwrite
  -n, --no-clobber             do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect.
      --strip-trailing-slashes  remove any trailing slashes from each SOURCE
                                 argument
  -S, --suffix=SUFFIX          override the usual backup suffix
  -t, --target-directory=DIRECTORY  move all SOURCE arguments into DIRECTORY
  -T, --no-target-directory    treat DEST as a normal file
  -u, --update                 move only when the SOURCE file is newer
                                 than the destination file or when the
                                 destination file is missing
  -v, --verbose                explain what is being done
  -Z, --context                set SELinux security context of destination
                                 file to default type
      --help     display this help and exit
      --version  output version information and exit

The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable.  Here are the values:

  none, off       never make backups (even if --backup is given)
  numbered, t     make numbered backups
  existing, nil   numbered if numbered backups exist, simple otherwise
  simple, never   always make simple backups

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'mv invocation'

命令 cp

  1. 复制当前目录部署包isTester.tar.gz 到备份目录/APP/www/bak 目录
    cp isTester.tar.gz /APP/www/bak

  2. 复制文件夹 isTester 到部署目录 /APP/www
    cp -r isTester/ /APP/www
    参数:-r, --recursive copy directories recursively,递归cp

[root@VM_0_12_centos temp]# cp --help
Usage: cp [OPTION]... [-T] SOURCE DEST
  or:  cp [OPTION]... SOURCE... DIRECTORY
  or:  cp [OPTION]... -t DIRECTORY SOURCE...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

Mandatory arguments to long options are mandatory for short options too.
  -a, --archive                same as -dR --preserve=all
      --attributes-only        don't copy the file data, just the attributes
      --backup[=CONTROL]       make a backup of each existing destination file
  -b                           like --backup but does not accept an argument
      --copy-contents          copy contents of special files when recursive
  -d                           same as --no-dereference --preserve=links
  -f, --force                  if an existing destination file cannot be
                                 opened, remove it and try again (this option
                                 is ignored when the -n option is also used)
  -i, --interactive            prompt before overwrite (overrides a previous -n
                                  option)
  -H                           follow command-line symbolic links in SOURCE
  -l, --link                   hard link files instead of copying
  -L, --dereference            always follow symbolic links in SOURCE
  -n, --no-clobber             do not overwrite an existing file (overrides
                                 a previous -i option)
  -P, --no-dereference         never follow symbolic links in SOURCE
  -p                           same as --preserve=mode,ownership,timestamps
      --preserve[=ATTR_LIST]   preserve the specified attributes (default:
                                 mode,ownership,timestamps), if possible
                                 additional attributes: context, links, xattr,
                                 all
  -c                           deprecated, same as --preserve=context
      --no-preserve=ATTR_LIST  don't preserve the specified attributes
      --parents                use full source file name under DIRECTORY
  -R, -r, --recursive          copy directories recursively
      --reflink[=WHEN]         control clone/CoW copies. See below
      --remove-destination     remove each existing destination file before
                                 attempting to open it (contrast with --force)
      --sparse=WHEN            control creation of sparse files. See below
      --strip-trailing-slashes  remove any trailing slashes from each SOURCE
                                 argument
  -s, --symbolic-link          make symbolic links instead of copying
  -S, --suffix=SUFFIX          override the usual backup suffix
  -t, --target-directory=DIRECTORY  copy all SOURCE arguments into DIRECTORY
  -T, --no-target-directory    treat DEST as a normal file
  -u, --update                 copy only when the SOURCE file is newer
                                 than the destination file or when the
                                 destination file is missing
  -v, --verbose                explain what is being done
  -x, --one-file-system        stay on this file system
  -Z                           set SELinux security context of destination
                                 file to default type
      --context[=CTX]          like -Z, or if CTX is specified then set the
                                 SELinux or SMACK security context to CTX
      --help     display this help and exit
      --version  output version information and exit

By default, sparse SOURCE files are detected by a crude heuristic and the
corresponding DEST file is made sparse as well.  That is the behavior
selected by --sparse=auto.  Specify --sparse=always to create a sparse DEST
file whenever the SOURCE file contains a long enough sequence of zero bytes.
Use --sparse=never to inhibit creation of sparse files.

When --reflink[=always] is specified, perform a lightweight copy, where the
data blocks are copied only when modified.  If this is not possible the copy
fails, or if --reflink=auto is specified, fall back to a standard copy.

The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable.  Here are the values:

  none, off       never make backups (even if --backup is given)
  numbered, t     make numbered backups
  existing, nil   numbered if numbered backups exist, simple otherwise
  simple, never   always make simple backups

As a special case, cp makes a backup of SOURCE when the force and backup
options are given and SOURCE and DEST are the same name for an existing,
regular file.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'cp invocation'

命令 mkdir

在目录/APP/www 下,
cd /APP/www

  1. 新建一个文件夹 isTester
    mkdir isTester

  2. 新建三个文件夹 isTester1 isTester2 isTester3
    mkdir isTester1 isTester2 isTester3

  3. 新建一个多层级文件夹 idoxu/20181230/01
    mkdir -p idoxu/20181230/01
    参数:-p, --parents no error if existing, make parent directories as needed

[root@VM_0_12_centos temp]# mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
  -p, --parents     no error if existing, make parent directories as needed
  -v, --verbose     print a message for each created directory
  -Z                   set SELinux security context of each created directory
                         to the default type
      --context[=CTX]  like -Z, or if CTX is specified then set the SELinux
                         or SMACK security context to CTX
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'mkdir invocation'

命令 history

  1. 查看历史命令执行记录
    history

  2. 查看命令mkdir 的历史执行记录
    history | grep mkdir

  3. 执行历史记录中,序号为178的命令
    !178

root@VM_0_12_centos temp]# history |grep mkdir
    5  2020-05-30 09:50:20 mkdir temp
   36  2020-05-30 11:16:45 mkdir java
   67  2020-05-30 11:53:32 mkdir jenkins
  125  2020-06-13 09:39:12 mkdir temp
  127  2020-06-13 09:39:59 mkdir test
  157  2020-06-13 09:54:14 mkdir test1
  160  2020-06-13 09:54:30 mkdir test2
  172  2020-06-13 10:00:15 mkdir te1 te2
  174  2020-06-13 10:00:46 mkdir te3/01/02
  175  2020-06-13 10:01:11 mkdir -p te3/01/02
  181  2020-06-13 10:02:31 mkdir --help
  183  2020-06-13 10:04:59 history |grep mkdir
[root@VM_0_12_centos temp]# !181
mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask
  -p, --parents     no error if existing, make parent directories as needed
  -v, --verbose     print a message for each created directory
  -Z                   set SELinux security context of each created directory
                         to the default type
      --context[=CTX]  like -Z, or if CTX is specified then set the SELinux
                         or SMACK security context to CTX
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'mkdir invocation'
[root@VM_0_12_centos temp]# 

命令 tail

  1. 实时刷新log
    tail -f isTester.log

  2. 实时刷新最新500条log
    tail -500f isTester.log

[root@VM_0_12_centos temp]# tail --help
Usage: tail [OPTION]... [FILE]...
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=K            output the last K bytes; or use -c +K to output
                             bytes starting with the Kth 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=K            output the last K lines, instead of the last 10;
                             or use -n +K to output starting with the Kth
      --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
      --help     display this help and exit
      --version  output version information and exit

If the first character of K (the number of bytes or lines) is a '+',
print beginning with the Kth item from the start of each file, otherwise,
print the last K items in the file.  K may have a multiplier suffix:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.

With --follow (-f), tail defaults to following the file descriptor, which
means that even if a tail'ed file is renamed, tail will continue to track
its end.  This default behavior is not desirable when you really want to
track the actual name of the file, not the file descriptor (e.g., log
rotation).  Use --follow=name in that case.  That causes tail to track the
named file in a way that accommodates renaming, removal and creation.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'tail invocation'

命令 tar

  1. 压缩一个文件 isTester.ini
    tar -cvf isTester.tar isTester.ini

  2. 压缩多个文件 isTester.ini readme.ini
    tar -cvf all.tar isTester.ini readme.ini

  3. 压缩文件夹 isTester/
    tar -cvf isTester.tar isTester/

  4. 将当前目录,所有jpg文件打包成isTesterjpg.tar
    tar -cvf isTesterjpg.tar *.jpg

  5. 将当前目录,所有jpg文件打包成isTesterjpg.tar.gz
    tar -zcvf isTesterjpg.tar.gz *.jpg

  6. 解压 isTesterjpg.tar
    tar -xvf isTesterjpg.tar

  7. 解压 isTesterjpg.tar.gz
    tar -zxvf isTesterjpg.tar.gz

常用参数:
-c, --create create a new archive
-z, --gzip, --gunzip, --ungzip filter the archive through gzip 通过gzip过滤存档
-v, --verbose verbosely list files processed 处理过程中输出相关信息
-f, --file=ARCHIVE use archive file or device ARCHIVE 使用存档文件或设备存档
-x, --extract, --get extract files from an archive 解压

[root@VM_0_12_centos temp]# tar --help
Usage: tar [OPTION...] [FILE]...
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.

 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
      --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
      --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')
      --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
      --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
  -p, --preserve-permissions, --same-permissions
                             extract information about file permissions
                             (default for superuser)
      --preserve             same as both -p and -s
      --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

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

      --add-file=FILE        add given FILE to the archive (useful if its name
                             starts with a dash)
      --backup[=CONTROL]     backup before removal, choose version CONTROL
  -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-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
  -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
      --no-null              disable the effect of the previous --null option
      --no-recursion         avoid descending automatically in directories
      --no-unquote           do not unquote filenames read with -T
      --null                 -T reads null-terminated names, disable -C
  -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
      --recursion            recurse into directories (default)
      --suffix=STRING        backup before removal, override usual suffix ('~'
                             unless overridden by environment variable
                             SIMPLE_BACKUP_SUFFIX)
  -T, --files-from=FILE      get names to extract or create from FILE
      --unquote              unquote filenames read with -T (default)
  -X, --exclude-from=FILE    exclude patterns listed in FILE

 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

 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)

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

Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.

The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control may be set with --backup or VERSION_CONTROL, values are:

  none, off       never make backups
  t, numbered     make numbered backups
  nil, existing   numbered if numbered backups exist, simple otherwise
  never, simple   always make simple backups

Valid arguments for the --quoting-style option are:

  literal
  shell
  shell-always
  c
  c-maybe
  escape
  locale
  clocale

*This* tar defaults to:
--format=gnu -f- -b20 --quoting-style=escape --rmt-command=/etc/rmt
--rsh-command=/usr/bin/ssh

Report bugs to <bug-tar@gnu.org>.
[root@VM_0_12_centos temp]# tar --help |grep -v
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
[root@VM_0_12_centos temp]# tar --help |grep "-v"
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.
[root@VM_0_12_centos temp]# tar --help |grep "-f"
grep: option requires an argument -- 'f'
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.

命令 ls

  1. 列出当前目录中所有的子目录和文件。
    ls

  2. 列出目录下的所有文件(包含隐**件)
    ls -a

  3. 列出文件的详细信息(包括权限、所有者、文件大小等)
    ls -l

  4. 列出当前目录中所有以“isTester”开头的详细内容
    ls -l isTester*

[root@VM_0_12_centos temp]# ls
1.tar  1.txt  2.tar  2.txt  3.tar  3.txt  4.tar.gz  te1  te2  te3  test  test1  test2
[root@VM_0_12_centos temp]# ls -l te*
te1:
total 0

te2:
total 0

te3:
total 4
drwxr-xr-x 3 root root 4096 Jun 13 10:01 01

test:
total 0

test1:
total 0

test2:
total 0

命令 ps

  1. 查看所有进程
    ps -A
[root@VM_0_12_centos /]# ps -a
  PID TTY          TIME CMD
15919 pts/0    00:00:00 ps
[root@VM_0_12_centos /]# ps -A
  PID TTY          TIME CMD
    1 ?        00:00:42 systemd
    2 ?        00:00:00 kthreadd
    3 ?        00:00:12 ksoftirqd/0
    5 ?        00:00:00 kworker/0:0H
    7 ?        00:00:00 migration/0
    8 ?        00:00:00 rcu_bh
    9 ?        00:00:41 rcu_sched
   10 ?        00:00:00 lru-add-drain
   11 ?        00:00:03 watchdog/0
   13 ?        00:00:00 kdevtmpfs
   14 ?        00:00:00 netns
   15 ?        00:00:00 khungtaskd
   16 ?        00:00:00 writeback
   17 ?        00:00:00 kintegrityd
   18 ?        00:00:00 bioset
   19 ?        00:00:00 kblockd
   20 ?        00:00:00 md
   21 ?        00:00:00 edac-poller
   27 ?        00:00:00 kswapd0
   28 ?        00:00:00 ksmd
   29 ?        00:00:01 khugepaged
   30 ?        00:00:00 crypto
   38 ?        00:00:00 kthrotld
   40 ?        00:00:00 kmpath_rdacd
   41 ?        00:00:00 kaluad
   42 ?        00:00:00 kpsmoused
   43 ?        00:00:00 ipv6_addrconf
   56 ?        00:00:00 deferwq
   95 ?        00:00:04 kauditd
  222 ?        00:00:00 ata_sff
  229 ?        00:00:00 scsi_eh_0
  230 ?        00:00:00 scsi_tmf_0
  231 ?        00:00:00 scsi_eh_1
  232 ?        00:00:00 scsi_tmf_1
  234 ?        00:00:00 ttm_swap
  235 ?        00:00:34 kworker/0:1H
  253 ?        00:01:05 jbd2/vda1-8
  254 ?        00:00:00 ext4-rsv-conver
  328 ?        00:02:01 systemd-journal
  359 ?        00:00:00 lvmetad
  360 ?        00:00:00 systemd-udevd
  494 ?        00:00:30 auditd
  516 ?        00:00:12 polkitd
  521 ?        00:00:01 lsmd
  523 ?        00:00:00 acpid
  524 ?        00:00:17 systemd-logind
  525 ?        00:00:50 dbus-daemon
  529 ?        00:00:01 ntpd
  542 ?        00:26:58 YDService
  602 ?        00:00:00 kworker/u2:1
  797 ?        00:00:00 dhclient
  864 ?        00:01:29 tuned
  941 ?        00:01:19 rsyslogd
  979 ?        00:00:04 crond
  980 ?        00:00:00 atd
 1274 ttyS0    00:00:00 agetty
 1275 tty1     00:00:00 agetty
 1316 ?        00:00:35 sshd
 1337 ?        00:00:05 sgagent
 1350 ?        00:00:10 barad_agent
 1355 ?        00:08:07 barad_agent
 1356 ?        00:40:28 barad_agent
 1382 ?        00:01:30 YDLive
 2660 ?        00:00:00 sshd
 2662 pts/0    00:00:00 bash
 4184 ?        00:12:33 java
13453 ?        00:00:00 kworker/0:0
14451 ?        00:00:00 kworker/0:2
14668 ?        00:00:30 kworker/u2:0
15467 ?        00:00:00 kworker/0:1
16018 ?        00:00:00 sshd
16019 ?        00:00:00 sshd
16021 pts/0    00:00:00 ps
  1. 查看java进程
    ps -ef|grep java
[root@VM_0_12_centos /]# ps -ef |grep jenkins
root      4184     1  0 May30 ?        00:12:33 java -jar jenkins.war --httpPort=8080
root     16292  2662  0 10:42 pts/0    00:00:00 grep --color=auto jenkins
  1. 显示所有进程信息,连同命令行
    ps -ef
ps [-aAcdefHjlmNVwy][acefghLnrsSTuvxX][-C <指令名称>][-g <群组名称>]

[-G <群组识别码>][-p <进程识别码>][p <进程识别码>][-s <阶段作业>]

[-t <终端机编号>][t <终端机编号>][-u <用户识别码>][-U <用户识别码>]

[U <用户名称>][-<进程识别码>][--cols <每列字符数>]

[--columns <每列字符数>][--cumulative][--deselect][--forest]

[--headers][--help][-- info][--lines <显示列数>][--no-headers]

[--group <群组名称>][-Group <群组识别码>][--pid <进程识别码>]

[--rows <显示列数>][--sid <阶段作业>][--tty <终端机编号>]

[--user <用户名称>][--User <用户识别码>][--version]

[--width <每列字符数>]

参数说明:

  -a  显示所有终端机下执行的进程,除了阶段作业领导者之外。
   a  显示现行终端机下的所有进程,包括其他用户的进程。
  -A  显示所有进程。
  -c  显示CLS和PRI栏位。
   c  列出进程时,显示每个进程真正的指令名称,而不包含路径,参数或常驻服务的标示。
  -C<指令名称>  指定执行指令的名称,并列出该指令的进程的状况。
  -d  显示所有进程,但不包括阶段作业领导者的进程。
  -e  此参数的效果和指定"A"参数相同。
   e  列出进程时,显示每个进程所使用的环境变量。
  -f  显示UID,PPIP,C与STIME栏位。
   f  用ASCII字符显示树状结构,表达进程间的相互关系。
  -g<群组名称>  此参数的效果和指定"-G"参数相同,当亦能使用阶段作业领导者的名称来指定。
   g  显示现行终端机下的所有进程,包括群组领导者的进程。
  -G<群组识别码>  列出属于该群组的进程的状况,也可使用群组名称来指定。
   h  不显示标题列。
  -H  显示树状结构,表示进程间的相互关系。
  -j或j  采用工作控制的格式显示进程状况。
  -l或l  采用详细的格式来显示进程状况。
   L  列出栏位的相关信息。
  -m或m  显示所有的执行绪。
   n  以数字来表示USER和WCHAN栏位。
  -N  显示所有的进程,除了执行ps指令终端机下的进程之外。
  -p<进程识别码>  指定进程识别码,并列出该进程的状况。
   p<进程识别码>  此参数的效果和指定"-p"参数相同,只在列表格式方面稍有差异。
   r  只列出现行终端机正在执行中的进程。
  -s<阶段作业>  指定阶段作业的进程识别码,并列出隶属该阶段作业的进程的状况。
   s  采用进程信号的格式显示进程状况。
   S  列出进程时,包括已中断的子进程资料。
  -t<终端机编号>  指定终端机编号,并列出属于该终端机的进程的状况。
   t<终端机编号>  此参数的效果和指定"-t"参数相同,只在列表格式方面稍有差异。
  -T  显示现行终端机下的所有进程。
  -u<用户识别码>  此参数的效果和指定"-U"参数相同。
   u  以用户为主的格式来显示进程状况。
  -U<用户识别码>  列出属于该用户的进程的状况,也可使用用户名称来指定。
   U<用户名称>  列出属于该用户的进程的状况。
   v  采用虚拟内存的格式显示进程状况。
  -V或V  显示版本信息。
  -w或w  采用宽阔的格式来显示进程状况。 
   x  显示所有进程,不以终端机来区分。
   X  采用旧式的Linux i386登陆格式显示进程状况。
   -y 配合参数"-l"使用时,不显示F(flag)栏位,并以RSS栏位取代ADDR栏位
  -<进程识别码>  此参数的效果和指定"p"参数相同。
  --cols<每列字符数>  设置每列的最大字符数。
  --columns<每列字符数>  此参数的效果和指定"--cols"参数相同。
  --cumulative  此参数的效果和指定"S"参数相同。
  --deselect  此参数的效果和指定"-N"参数相同。
  --forest  此参数的效果和指定"f"参数相同。
  --headers  重复显示标题列。
  --help  在线帮助。
  --info  显示排错信息。
  --lines<显示列数> 设置显示画面的列数。
  --no-headers  此参数的效果和指定"h"参数相同,只在列表格式方面稍有差异。
  --group<群组名称>  此参数的效果和指定"-G"参数相同。
  --Group<群组识别码>  此参数的效果和指定"-G"参数相同。
  --pid<进程识别码>  此参数的效果和指定"-p"参数相同。
  --rows<显示列数>  此参数的效果和指定"--lines"参数相同。
  --sid<阶段作业>  此参数的效果和指定"-s"参数相同。
  --tty<终端机编号>  此参数的效果和指定"-t"参数相同。
  --user<用户名称>  此参数的效果和指定"-U"参数相同。
  --User<用户识别码>  此参数的效果和指定"-U"参数相同。
  --version  此参数的效果和指定"-V"参数相同。
  --widty<每列字符数>  此参数的效果和指定"-cols"参数相同。 

命令 top

  1. 显示进程信息
    top

  2. 监控每个逻辑CPU的状况
    top ,按 1

  3. 高亮显示当前运行进程
    top ,按 b

  4. 显示完整命令
    top ,按 c

  5. 退出top程序
    按 q

  • ps与top命令的区别:
    ps是静态的
    top是可交互的

命令wget

Linux系统中的wget是一个下载文件的工具,对于Linux用户是必不可少的工具。我们经常要下载一些软件或从远程服务器恢复备份到本地服务器。

wget支持HTTP,HTTPS和FTP协议,可以使用HTTP代理。所谓的自动下载是指,wget可以在用户退出系统的之后在后台执行。这意味这你可以登录系统,启动一个wget下载任务,然后退出系统,wget将在后台执行直到任务完成

wget 可以跟踪HTML页面上的链接依次下载来创建远程服务器的本地版本,完全重建原始站点的目录结构。这又常被称作”递归下载”。

wget 非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性.如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕。如果是服务器打断下载过程,它会再次联到服务器上从停止的地方继续下载。这对从那些限定了链接时间的服务器上下载大文件非常有用。

文件地址
http://51.istester.com/isTester.png

  1. 下载isTester.jpg文件
    wget http://51.istester.com/isTester.png

  2. 下载isTester.jpg文件,并存储名为isTester_Logo.jpg
    wget -o isTester_Logo.jpg
    http://51.istester.com/isTester.png

  3. 下载isTester.jpg文件,后台形式下载
    wget -b http://51.istester.com/isTester.png

GNU Wget 1.12,非交互式的网络文件下载工具。
用法: wget [选项]... [URL]...
 
长选项所必须的参数在使用短选项时也是必须的。
 
开始:
  -V,  --version           显示 Wget 的版本信息并退出。
  -h,  --help              打印此帮助。
  -b,  --background        启动后转入后台。
  -e,  --execute=COMMAND   运行一个‘.wgetrc’风格的命令。
 
登入并输入文件:
  -o,  --output-file=FILE    将信息写入 FILE。
  -a,  --append-output=FILE  将信息添加至 FILE。
  -d,  --debug               打印大量调试信息。
  -q,  --quiet               安静模式(无信息输出)。
  -v,  --verbose             详尽的输出(此为默认值)。
  -nv, --no-verbose          关闭详尽输出,但不进入安静模式。
  -i,  --input-file=FILE     下载本地或外部 FILE 中的 URLs。
  -F,  --force-html          把输入文件当成 HTML 文件。
  -B,  --base=URL            解析与 URL 相关的
                             HTML 输入文件(由 -i -F 选项指定)。
 
下载:
  -t,  --tries=NUMBER           设置重试次数为 NUMBER (0 代表无限制)。
        --retry-connrefused       即使拒绝连接也是重试。
  -O,  --output-document=FILE    将文档写入 FILE。
  -nc, --no-clobber              不要重复下载已存在的文件。
                                 
  -c,  --continue                继续下载部分下载的文件。
       --progress=TYPE           选择进度条类型。
  -N,  --timestamping            只获取比本地文件新的文件。
                                  
  -S,  --server-response         打印服务器响应。
       --spider                   不下载任何文件。
  -T,  --timeout=SECONDS         将所有超时设为 SECONDS 秒。
       --dns-timeout=SECS        设置 DNS 查寻超时为 SECS 秒。
       --connect-timeout=SECS    设置连接超时为 SECS 秒。
       --read-timeout=SECS       设置读取超时为 SECS 秒。
  -w,  --wait=SECONDS            等待间隔为 SECONDS 秒。
       --waitretry=SECONDS       在取回文件的重试期间等待 1..SECONDS 秒。
       --random-wait             取回时等待 0...2*WAIT 秒。
       --no-proxy                关闭代理。
  -Q,  --quota=NUMBER            设置取回配额为 NUMBER 字节。
       --bind-address=ADDRESS    绑定至本地主机上的 ADDRESS (主机名或是 IP)。
       --limit-rate=RATE         限制下载速率为 RATE。
       --no-dns-cache            关闭 DNS 查寻缓存。
       --restrict-file-names=OS  限定文件名中的字符为 OS 允许的字符。
       --ignore-case             匹配文件/目录时忽略大小写。
  -4,  --inet4-only              仅连接至 IPv4 地址。
  -6,  --inet6-only              仅连接至 IPv6 地址。
       --prefer-family=FAMILY    首先连接至指定协议的地址
                                 FAMILY 为 IPv6,IPv4 或是 none。
       --user=USER               将 ftp 和 http 的用户名均设置为 USER。
       --password=PASS           将 ftp 和 http 的密码均设置为 PASS。
       --ask-password           提示输入密码。
       --no-iri                关闭 IRI 支持。
       --local-encoding=ENC      IRI 使用 ENC 作为本地编码。
       --remote-encoding=ENC     使用 ENC 作为默认远程编码。
 
目录:
  -nd, --no-directories           不创建目录。
  -x,  --force-directories        强制创建目录。
  -nH, --no-host-directories      不要创建主目录。
       --protocol-directories     在目录中使用协议名称。
  -P,  --directory-prefix=PREFIX  以 PREFIX/... 保存文件
       --cut-dirs=NUMBER          忽略 NUMBER 个远程目录路径。
 
HTTP 选项:
       --http-user=USER        设置 http 用户名为 USER。
       --http-password=PASS    设置 http 密码为 PASS。
       --no-cache              不在服务器上缓存数据。
       --default-page=NAME     改变默认页
                               (默认页通常是“index.html”)。
  -E,  --adjust-extension      以合适的扩展名保存 HTML/CSS 文档。
       --ignore-length         忽略头部的‘Content-Length’区域。
       --header=STRING         在头部插入 STRING。
       --max-redirect          每页所允许的最大重定向。
       --proxy-user=USER       使用 USER 作为代理用户名。
       --proxy-password=PASS   使用 PASS 作为代理密码。
       --referer=URL           在 HTTP 请求头包含‘Referer: URL’。
       --save-headers          将 HTTP 头保存至文件。
  -U,  --user-agent=AGENT      标识为 AGENT 而不是 Wget/VERSION。
       --no-http-keep-alive    禁用 HTTP keep-alive(永久连接)。
       --no-cookies            不使用 cookies。
       --load-cookies=FILE     会话开始前从 FILE 中载入 cookies。
       --save-cookies=FILE     会话结束后保存 cookies 至 FILE。
       --keep-session-cookies  载入并保存会话(非永久) cookies。
       --post-data=STRING      使用 POST 方式;把 STRING 作为数据发送。
       --post-file=FILE        使用 POST 方式;发送 FILE 内容。
       --content-disposition   当选中本地文件名时
                               允许 Content-Disposition 头部(尚在实验)。
       --auth-no-challenge     send Basic HTTP authentication information
                               without first waiting for the server's
                               challenge.
 
HTTPS (SSL/TLS) 选项:
       --secure-protocol=PR     选择安全协议,可以是 auto、SSLv2、
                                SSLv3 或是 TLSv1 中的一个。
       --no-check-certificate   不要验证服务器的证书。
       --certificate=FILE       客户端证书文件。
       --certificate-type=TYPE  客户端证书类型, PEM 或 DER。
       --private-key=FILE       私钥文件。
       --private-key-type=TYPE  私钥文件类型, PEM 或 DER。
       --ca-certificate=FILE    带有一组 CA 认证的文件。
       --ca-directory=DIR       保存 CA 认证的哈希列表的目录。
       --random-file=FILE       带有生成 SSL PRNG 的随机数据的文件。
       --egd-file=FILE          用于命名带有随机数据的 EGD 套接字的文件。
 
FTP 选项:
       --ftp-user=USER         设置 ftp 用户名为 USER。
       --ftp-password=PASS     设置 ftp 密码为 PASS。
       --no-remove-listing     不要删除‘.listing’文件。
       --no-glob               不在 FTP 文件名中使用通配符展开。
       --no-passive-ftp        禁用“passive”传输模式。
       --retr-symlinks         递归目录时,获取链接的文件(而非目录)。
 
递归下载:
  -r,  --recursive          指定递归下载。
  -l,  --level=NUMBER       最大递归深度( inf 或 0 代表无限制,即全部下载)。
       --delete-after       下载完成后删除本地文件。
  -k,  --convert-links      让下载得到的 HTML 或 CSS 中的链接指向本地文件。
  -K,  --backup-converted   在转换文件 X 前先将它备份为 X.orig。
  -m,  --mirror             -N -r -l inf --no-remove-listing 的缩写形式。
  -p,  --page-requisites    下载所有用于显示 HTML 页面的图片之类的元素。
       --strict-comments    开启 HTML 注释的精确处理(SGML)。
 
递归接受/拒绝:
  -A,  --accept=LIST               逗号分隔的可接受的扩展名列表。
  -R,  --reject=LIST               逗号分隔的要拒绝的扩展名列表。
  -D,  --domains=LIST              逗号分隔的可接受的域列表。
       --exclude-domains=LIST      逗号分隔的要拒绝的域列表。
       --follow-ftp                跟踪 HTML 文档中的 FTP 链接。
       --follow-tags=LIST          逗号分隔的跟踪的 HTML 标识列表。
       --ignore-tags=LIST          逗号分隔的忽略的 HTML 标识列表。
  -H,  --span-hosts                递归时转向外部主机。
  -L,  --relative                  只跟踪有关系的链接。
  -I,  --include-directories=LIST  允许目录的列表。
  -X,  --exclude-directories=LIST  排除目录的列表。
  -np, --no-parent                 不追溯至父目录。

命令 find

Linux find 命令用来在指定目录下查找文件。任何位于参数之前的字符串都将被视为欲查找的目录名。如果使用该命令时,不设置任何参数,则 find 命令将在当前目录下查找子目录与文件。并且将查找到的子目录和文件全部进行显示。

语法
find path -option [ -print ] [ -exec -ok command ] {} \;

参数说明 :
find 根据下列规则判断 path 和 expression,在命令列上第一个 - ( ) , ! 之前的部份为 path,之后的是 expression。如果 path 是空字串则使用目前路径,如果 expression 是空字串则使用 -print 为预设 expression。

expression 中可使用的选项有二三十个之多,在此只介绍最常用的部份。

-mount, -xdev : 只检查和指定目录在同一个文件系统下的文件,避免列出其它文件系统中的文件

-amin n : 在过去 n 分钟内被读取过

-anewer file : 比文件 file 更晚被读取过的文件

-atime n : 在过去n天内被读取过的文件

-cmin n : 在过去 n 分钟内被修改过

-cnewer file :比文件 file 更新的文件

-ctime n : 在过去n天内被修改过的文件

-empty : 空的文件-gid n or -group name : gid 是 n 或是 group 名称是 name

-ipath p, -path p : 路径名称符合 p 的文件,ipath 会忽略大小写

-name name, -iname name : 文件名称符合 name 的文件。iname 会忽略大小写

-size n : 文件大小 是 n 单位,b 代表 512 位元组的区块,c 表示字元数,k 表示 kilo bytes,w 是二个位元组。

-type c : 文件类型是 c 的文件。

d: 目录

c: 字型装置文件

b: 区块装置文件

p: 具名贮列

f: 一般文件

l: 符号连结

s: socket

-pid n : process id 是 n 的文件

你可以使用 ( ) 将运算式分隔,并使用下列运算。

exp1 -and exp2

! expr

-not expr

exp1 -or exp2

exp1, exp2

find命令,非常强大,也非常实用,分两次完成,今日第一次 。
给大家布置的作业,是比较实用的几个场景 。

  1. 在/root/isTester 目录及其子目录下面查找名字为isTester.ini的文件
    find /root/isTester/ -name isTester.ini

  2. 在当前目录及其子目录中查找任何扩展名为“ini”的文件
    find . -name "*.ini"
    注意:没有引号与有引号是有区别的哦

[root@VM_0_12_centos /]# find /temp/ -name 1.txt
/temp/1.txt
[root@VM_0_12_centos /]# find /temp/ -name *.txt
/temp/3.txt
[root@VM_0_12_centos /]# find /temp/ -name '*.txt'
/temp/3.txt
/temp/2.txt
/temp/1.txt

3.在/root/isTester目录下查找更改时间在5日以前的文件
find /root/isTester/ -mtime +5

  1. 在/root/isTester目录下查找更改时间在3日以内的文件
    find /root/isTester/ -mtime -3

  2. 在/root/isTester目录下查找所有的目录
    find . -type d

  3. 在/root/isTester目录下查找所有的文件
    find /root/isTester/ -type f

命令 继续find(进阶)
find命令,非常强大,也非常实用,分两次完成,今日第一次 。
给大家布置的作业,是比较实用的几个场景 。

  1. 在当前目录,所有的普通文件中搜索istester这个词
    find ./ -type f |xargs grep "istester"

  2. 在当前目录,删除1天以内的所有东西
    find ./ -mtime -1 -print | xargs rm -rf

  3. 在当前目录,删除10天以前的所有东西(实操的时候,需谨慎,确保在自己建的目录内,别把系统目录删了…)
    find ./ -mtime +10 -print | xargs rm -rf

  4. 删除文件大小为零的文件
    find ./ -size 0 | xargs rm -rf

[root@VM_0_12_centos temp]# find --help
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions:

operators (decreasing precedence; -and is implicit where no others are given):
      ( EXPR )   ! EXPR   -not EXPR   EXPR1 -a EXPR2   EXPR1 -and EXPR2
      EXPR1 -o EXPR2   EXPR1 -or EXPR2   EXPR1 , EXPR2

positional options (always true): -daystart -follow -regextype

normal options (always true, specified before other expressions):
      -depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
      --version -xautofs -xdev -ignore_readdir_race -noignore_readdir_race

tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N
      -cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
      -ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
      -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
      -nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN
      -readable -writable -executable
      -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
      -used N -user NAME -xtype [bcdpfls]
      -context CONTEXT


actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print 
      -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
      -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
      -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;

Report (and track progress on fixing) bugs via the findutils bug-reporting
page at http://savannah.gnu.org/ or, if you have no web access, by sending
email to <bug-findutils@gnu.org>.

命令 rm

rm是常用的命令,该命令的功能为删除目录/文件(可同时删除,多个文件 / 多个目录)
当然,这也是一个非常危险的命令,建议少用(比如经常出现的误操作 rm * -rf 此命令慎用).

  1. 删除/root/isTester/目录下的文件isTester.ini (系统会询问是否删除)
    rm /root/isTester/isTester.ini

  2. 强行删除/root/isTester/目录下的文件isTester.ini(直接删除,系统不会提示)
    rm -f /root/isTester/isTester.ini

  3. 删除/root/isTester/目录下的所有.log文件
    rm -f /root/isTester/*.log

  4. 删除/root/isTester/目录下的 ido/文件夹
    rm -r /root/isTester/ido/

  5. 强行删除/root/isTester/目录下的 ido/文件夹
    rm -rf /root/isTester/ido/

  6. 删除/root/isTester/目录下的所有内容
    rm -rf /root/isTester/*

[root@VM_0_12_centos /]# rm --help
Usage: rm [OPTION]... FILE...
Remove (unlink) the FILE(s).

  -f, --force           ignore nonexistent files and arguments, never prompt
  -i                    prompt before every removal
  -I                    prompt once before removing more than three files, or
                          when removing recursively; less intrusive than -i,
                          while still giving protection against most mistakes
      --interactive[=WHEN]  prompt according to WHEN: never, once (-I), or
                          always (-i); without WHEN, prompt always
      --one-file-system  when removing a hierarchy recursively, skip any
                          directory that is on a file system different from
                          that of the corresponding command line argument
      --no-preserve-root  do not treat '/' specially
      --preserve-root   do not remove '/' (default)
  -r, -R, --recursive   remove directories and their contents recursively
  -d, --dir             remove empty directories
  -v, --verbose         explain what is being done
      --help     display this help and exit
      --version  output version information and exit

By default, rm does not remove directories.  Use the --recursive (-r or -R)
option to remove each listed directory, too, along with all of its contents.

To remove a file whose name starts with a '-', for example '-foo',
use one of these commands:
  rm -- -foo

  rm ./-foo

Note that if you use rm to remove a file, it might be possible to recover
some of its contents, given sufficient expertise and/or time.  For greater
assurance that the contents are truly unrecoverable, consider using shred.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'rm invocation'

文件操作系列 命令

  1. 创建文件,你知道有哪几个命令 ?(写出至少两种方式)
  1. touch isTester.ini
  2. vi isTester.md
  3. echo ‘only test’ > isTester.com
  4. cp isTester.ini isTester666.ini
  5. ls > fileList.txt
  1. 同时创建文件 isTester6.ini idoxu.ini
    touch isTester6.ini idoxu.ini

  2. 同时创建2000个文件 isTester0001.ini - isTester2000.ini
    touch istester{0001..2000}.ini

  3. 更改文件 isTester.ini时间为当前时间
    touch isTester.ini

  • touch
[root@VM_0_12_centos temp]# touch --help
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.

A FILE argument that does not exist is created empty, unless -c or -h
is supplied.

A FILE argument string of - is handled specially and causes touch to
change the times of the file associated with standard output.

Mandatory arguments to long options are mandatory for short options too.
  -a                     change only the access time
  -c, --no-create        do not create any files
  -d, --date=STRING      parse STRING and use it instead of current time
  -f                     (ignored)
  -h, --no-dereference   affect each symbolic link instead of any referenced
                         file (useful only on systems that can change the
                         timestamps of a symlink)
  -m                     change only the modification time
  -r, --reference=FILE   use this file's times instead of current time
  -t STAMP               use [[CC]YY]MMDDhhmm[.ss] instead of current time
      --time=WORD        change the specified time:
                           WORD is access, atime, or use: equivalent to -a
                           WORD is modify or mtime: equivalent to -m
      --help     display this help and exit
      --version  output version information and exit

Note that the -d and -t options accept different time-date formats.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'touch invocation'
  • 待补充

查看文件系列命令

  • cat 由第一行开始显示档案内容
  • tac 从最后一行开始显示,可以看出 tac 是 cat 的倒着写!
  • more 一页一页的显示档案内容
  • less 与 more 类似,但是比 more 更好的是,他可以往前翻页!
  • head 只看头几行
  • tail 只看尾巴几行
  • nl 显示的时候,顺道输出行号!
  1. 查看文件 isTester.ini的内容
    cat isTester.ini

  2. 看文件 isTester.ini前20行内容
    head -n 20 isTester.ini

  3. 看文件 isTester.ini最后30行内容
    tail -n 30 isTester.ini

  4. 显示文件isTester.ini 的第10至20行的内容
    head -n 20 isTester.ini | tail -n 10 # 首先过滤出前20行,再在前20行里过滤出后10行

  5. 倒序显示文件isTester.ini 前10行的内容
    tac isTester.ini | head -n 10

  6. 显示文件isTester.ini 前10行的内容,并显示行号
    nl isTester.ini | head -n 10

  • 待补充知识:通道

命令 yum & scp

假设当前服务器ip 192.168.1.23

  1. 从Linux服务器192.168.1.22 拷贝文件isTester.ini 到服务器192.168.1.23
    scp root@192.168.1.22:/root/idoxu/isTester.ini /root/idoxu

  2. 从Linux服务器192.168.1.22 拷贝目录 isTester/ 到服务器192.168.1.23
    scp -r root@192.168.1.22:/root/idoxu/isTester/ /root/idoxu

  3. Linux下安装scp命令(假设是centos服务器,命令用yum)
    yum install openssh-clients

yum命令

yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软体包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。
yum的命令形式一般是如下:yum [options] [command] [package ...]
[options]是可选的,选项包括-h(帮助),-y(当安装过程提示选择全部为"yes"),-q(不显示安装的过程)等等
[command]为所要进行的操作
[package ...]是操作的对象

概括了部分常用的命令包括:
自动搜索最快镜像插件: yum install yum-fastestmirror
安装yum图形窗口插件: yum install yumex
查看可能批量安装的列表: yum grouplist

scp命令

scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令, scp传输是加密的,可能会稍微影响一下速度。另外,scp还非常不占资源,不会提高多少系统负荷,在这一点上,rsync就远远不及它了。虽然 rsync比scp会快一点,但当小文件众多的情况下,rsync会导致硬盘I/O非常高,而scp基本不影响系统正常使用。

  • 常见命令参数
usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2
 
-q:  quiet
-r:   recuersive
-p:   properity
-v:   verbose
-i:   identity_file      【从指定文件中读取传输时使用的密钥文件,此参数直接传递给ssh】 
-P:  port

常用命令

  • clear
  • df
  • du
  • ifconfig
  1. 查看当前服务器ip
    ifconfig

  2. 查看当前服务器硬盘空间
    df -h

  3. 查看目录isTester/ 所占有的空间
    du -sh isTester

  4. 清空当前终端屏幕
    clear

命令 vi + chmod

  • vi 创建文件 + 编辑文件 。
  • chmod命令用于改变linux系统文件或目录的访问权限 。
  1. 创建文件 isTester.ini
    vi isTester.ini

  2. 更新文件内容为“21 day Linux Learn ,I'm Idolaoxu,in shenzhen .”
    输入 i ,进入编辑模式,输入内容,esc进入命令模式 :wq 保存 。

  3. 将文件 isTester.ini 设为所有人皆可读取
    chmod +r isTester.ini

  4. 将 isTester.ini 设定为只有该文件拥有者可以执行
    chmod u+x isTester.ini

  5. 给文件 isTester.ini 设置所有权限
    chmod 777 isTester.ini (或者 chmod a=rwx isTester.ini)

注:chmod还有很多命令用法,如上几种,满足日常需求 。

End ,命令,这些差不多够用了 。
如果遇到一些非高频的命令,自行百度/Google搞定即可 。

入了门,对Linux有感觉了,甚至是有兴趣了,其他命令,都没啥问题 ,看下帮助文档即可。

比如,想了解 top命令咋用 ?
终端输入 top --help 即可

最后,关于Linux学习的几个建议。

  1. 每个命令,多敲几次,每天掌握此文的一个命令即可,勿贪多。
  2. 掌握了前面的一个命令,再继续下一个命令。否则,欠的技术债会越来越多,最后放弃学习。
  3. 学Linux,没诀窍,多敲命令。
  4. 此文的命令,一个循环,预计你需要21天完成 。总共三个循环 ,2个月,大功告成。

所谓的三循环理论:
第一遍,花21天时间,把每个命令,敲一遍。
第二遍,花21天时间,把每个命令,再熟悉一遍。
第三遍,花21天时间,巩固,延伸更多命令组合玩法,熟记于心。

如果你能看到这段文字,且是第三遍以上看到,恭喜你,Linux这块的知识点,差不多了。

你,可以开始下一个环节 Jenkins / 接口自动化 / 数据库 / 性能测试 / 测试管理 等等 的 专项学习。

事情很多,别急,慢慢来。

原创:IDO老徐 公众号:软件测试isTester

posted @ 2020-06-10 22:45  捷后愚生  阅读(540)  评论(0编辑  收藏  举报