linux 常见操作

移动/重命名文件  mv

 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.

mv 文件名 新文件名 or 新的路径

当要移动文件下所有文件时,遇到了-bash: /bin/mv: 参数列表过长这个问题。于是采用

find 源文件路径 -type f -name '*.jpg' -exec mv {} 目标路径 \;


合并文件  cat

cat --help

    Usage: cat [OPTION]... [FILE]...

    Concatenate FILE(s) to standard output.

cat 文件1 文件2 文件3 ... > 新文件

cat 文件1 >> 文件2  将文件1追加到文件2的尾部


统计数量  wc

wc --help

    Usage: wc [OPTION]... [FILE]...
      or:  wc [OPTION]... --files0-from=F

    Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified.  A word is a     non-zero-length sequence of characters delimited by white space.

wc -l 文件名  统计文件行数

wc -m 文件名  统计文件字数


拆分文件  split

split --help

    Usage: split [OPTION]... [FILE [PREFIX]]
    Output pieces of FILE to PREFIXaa, PREFIXab, ...;
    default size is 1000 lines, and default PREFIX is 'x'.

split -d -l 行数 文件名 新文件名  可选参数 -d 以数字命名新文件后缀  -l 以行数分割  -b 以字节分割


查找字符  grep

grep --help

    Usage: grep [OPTION]... PATTERN [FILE]...
    Search for PATTERN in each FILE or standard input.
    PATTERN is, by default, a basic regular expression (BRE).
    Example: grep -i 'hello world' menu.h main.c

grep ‘字符’文件名 


打包文件  tar

单个文件压缩打包 tar czvf my.tar file1

多个文件压缩打包 tar czvf my.tar file1 file2,...

单个目录压缩打包 tar czvf my.tar dir1

多个目录压缩打包 tar czvf my.tar dir1 dir2

解包至当前目录:tar xzvf my.tar


远程拷贝  scp

# 文件复制
$scp local_file remote_username@remote_ip:remote_folder
$scp local_file remote_username@remote_ip:remote_file
$scp local_file remote_ip:remote_folder
$scp local_file remote_ip:remote_file

# 目录复制
$scp -r local_folder remote_username@remote_ip:remote_folder
$scp -r local_folder remote_ip:remote_folder

从远程复制的话

 scp remote_username@remote_ip:remote_folder local_folder


猜你喜欢

转载自blog.csdn.net/cliviabao/article/details/79541138