bash 命令汇总

服务器的连接与文件传输

notes
- 注意scp指定端口号时是大写的P ref
- 断点续传可以用rsync

ssh -p portnumber username@ip
# download: remote -> local
scp -P portnumber user@remote_host:remote_file local_file 
# upload: local -> remote
scp -P portnumber local_file user@remote_host:remote_file
# 断点续传
rsync -P -e ssh  local_file  ssh_host_name:/remote_file
# ssh_host_name的配置参见下面的【ssh免秘钥,免ip登录】

ssh免秘钥,免ip登录

scp 单次传输多个文件 参考

scp -T username@ip.of.server.copyfrom:“file1.txt file2.txt” “~/yourpathtocopy”

# 只需输一次密码
scp username@ip.of.server.copyfrom:"file1.txt file2.txt" "~/yourpathtocopy"

Linux压缩与解压文件参考

# compress file or directory
tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
# Compress Multiple Directories or Files at Once
tar -czvf archive.tar.gz /home/ubuntu/Downloads /usr/local/stuff /home/ubuntu/Documents/notes.txt
# Exclude Directories and Files
tar -czvf archive.tar.gz /home/ubuntu --exclude=/home/ubuntu/Downloads --exclude=/home/ubuntu/.cache
tar -czvf archive.tar.gz /home/ubuntu --exclude=*.mp4
# using bzip2
tar -cjvf archive.tar.bz2 stuff
# Extract an Archive
tar -xzvf archive.tar.gz
  • -c: Create an archive.
  • -z: Compress the archive with gzip.
  • -j: Compress the archive with bzip2.
  • -v: Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it’s helpful.
  • -f: Allows you to specify the filename of the archive.

While gzip compression is most frequently used to create .tar.gz or .tgz files, tar also supports bzip2 compression. This allows you to create bzip2-compressed files, often named .tar.bz2, .tar.bz, or .tbz files. To do so, just replace the -z for gzip in the commands here with a -j for bzip2.

Gzip is faster, but it generally compresses a bit less, so you get a somewhat larger file.
Bzip2 is slower, but it compresses a bit more, so you get a somewhat smaller file. Gzip is also more common, with some stripped-down Linux systems including gzip support by default, but not bzip2 support. In general, though, gzip and bzip2 are practically the same thing and both will work similarly.

NameSpeedsizesuffixcmd
Gzipfasterlarger.tar.gz,.tar.bz-z
Bzip2slowersmaller.tar.bz2, .tar.bz-j

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值