十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
怎样通过命令行给linux传输文件,方法如下
成都创新互联公司专业为企业提供天等网站建设、天等做网站、天等网站设计、天等网站制作等企业网站建设、网页设计与制作、天等企业网站模板建站服务,10年天等做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
一、从服务器下载文件到本机
1、修改文件所属
由于只能下载文件所属为自己的文件,所以要做修改文件所属的操作。
chown hudelei /opt/logs/tomcat/app/tomcat_stk_nm/stk-time.log
2、下载到本机
scp hi@10.10.30.10:/opt/logs/tomcat/app/tomcat_stk_nm/stk-time.log /Users/hvvi/Desktop
3、输入密码
二、上传文件夹到服务器
1、scp -r /Users/hddvvi/Desktop/load hi@10.10.30.10:/opt/logs/tomcat/app/tomcat_stk_nm/
注意:加上 -r,否则会报错:not a regular file
2、输入密码3、文件移动上上层 mv filename.java 。。/
注:本文使用的是mac本机和linux服务器。
Linux服务器应该开放了ssh服务的,这样方便远程管理,可以利用ssh服务上传文件的,用ssh服务上传文件时的权限,和你用ssh远程登录的那个用户的权限是一样的,这样就不用考虑权限设置的问题。下面是上传文件的方法:如果你的本地电脑是Linux系统,可以打开终端,不需要登录Linux服务器,直接用scp命令上传文件。scp命令是scp协议的命令,scp协议就是利用ssh连接来传输文件的一个协议。使用scp命令时需要将登录的用户名作为它的参数(参数的一部分),接着scp命令会提示你输入登录密码,如果连接成功就会直接传输文件了。scp命令的具体用法可以自行百度一下,很简单的,就不介绍了。 如果你的本地电脑是Windows就更好办了,可以安装一个WinSCP,这个软件是免费的,打开WinSCP软件,要选择scp协议,然后输入ssh登录的用户名和密码,连接成功后,WinSCP软件界面的左边是本地文件,右边是Linux的目录,然后就能随便上传文件到Linux服务器了。
linux下可以直接运行命令下载或上传文件 1、检查并安装相应的包:yum install lrzsz 2、使用 sz 文件名 现在相应的文件到本地磁盘。 3、上传使用rz 选择相应文件即可。
你是你是要通过git命令上传东西,还是想上传git到服务器上面,你可以先通过yum安装git
# yum install git
已加载插件:fastestmirror, refresh-packagekit, security
设置安装进程
Loading mirror speeds linuxprobe.com from cached hostfile
base | 3.7 kB 00:00
epel | 4.3 kB 00:00
epel/primary_db | 5.9 MB 00:05
extras | 3.4 kB 00:00
hhvm | 2.9 kB 00:00
shells_fish_release_2 | 1.2 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 821 kB 00:01
upgrade | 1.9 kB 00:00
virtualbox/signature | 181 B 00:00
virtualbox/signature | 1.1 kB 00:00 ...
包 git-1.7.1-8.el6.x86_64 已安装并且是最新版本
无须任何处理
#git --help
usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
[--help] COMMAND [ARGS]
The most commonly used git commands are:
add Add file contents to the index
bisect Find by binary search the change that introduced a bug
branch List, create, or delete branches
checkout Checkout a branch or paths to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
fetch Download objects and refs from another repository
grep Print lines matching a pattern
init Create an empty git repository or reinitialize an existing one
log Show commit logs
merge Join two or more development histories together
mv Move or rename a file, a directory, or a symlink
pull Fetch from and merge with another repository or a local branch
push Update remote refs along with associated objects
rebase Forward-port local commits to the updated upstream head
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
show Show various types of objects
status Show the working tree status
tag Create, list, delete or verify a tag object signed with GPG
See 'git help COMMAND' for more information on a specific command.
下面我给介绍一种从本地上传到服务器的命令:
命令rz和sz命令,首先你需要安装lrzsz库
#rz --help
rz version 0.12.20
Usage: rz [options] [filename.if.xmodem]
Receive files with ZMODEM/YMODEM/XMODEM protocol
(X) = option applies to XMODEM only
(Y) = option applies to YMODEM only
(Z) = option applies to ZMODEM only
-+, --append append to existing files
-a, --ascii ASCII transfer (change CR/LF to LF)
-b, --binary binary transfer
-B, --bufsize N buffer N bytes (N==auto: buffer whole file)
-c, --with-crc Use 16 bit CRC (X)
-C, --allow-remote-commands allow execution of remote commands (Z)
-D, --null write all received data to /dev/null
--delay-startup N sleep N seconds before doing anything
-e, --escape Escape control characters (Z)
-E, --rename rename any files already existing
--errors N generate CRC error every N bytes (debugging)
-h, --help Help, print this usage message
-m, --min-bps N stop transmission if BPS below N
-M, --min-bps-time N for at least N seconds (default: 120)
-O, --disable-timeouts disable timeout code, wait forever for data
--o-sync open output file(s) in synchronous write mode
-p, --protect protect existing files
-q, --quiet quiet, no progress reports
-r, --resume try to resume interrupted file transfer (Z)
-R, --restricted restricted, more secure mode
-s, --stop-at {HH:MM|+N} stop transmission at HH:MM or in N seconds
-S, --timesync request remote time (twice: set local time)
--syslog[=off] turn syslog on or off, if possible
-t, --timeout N set timeout to N tenths of a second
-u, --keep-uppercase keep upper case filenames
-U, --unrestrict disable restricted mode (if allowed to)
-v, --verbose be verbose, provide debugging information
-w, --windowsize N Window is N bytes (Z)
-X --xmodem use XMODEM protocol
-y, --overwrite Yes, clobber existing file if any
--ymodem use YMODEM protocol
-Z, --zmodem use ZMODEM protocol
short options use the same arguments as the long ones
#sz --help
sz version 0.12.20
Usage: sz [options] file ...
or: sz [options] -{c|i} COMMAND
Send file(s) with ZMODEM/YMODEM/XMODEM protocol
(X) = option applies to XMODEM only
(Y) = option applies to YMODEM only
(Z) = option applies to ZMODEM only
-+, --append append to existing destination file (Z)
-2, --twostop use 2 stop bits
-4, --try-4k go up to 4K blocksize
--start-4k start with 4K blocksize (doesn't try 8)
-8, --try-8k go up to 8K blocksize
--start-8k start with 8K blocksize
-a, --ascii ASCII transfer (change CR/LF to LF)
-b, --binary binary transfer
-B, --bufsize N buffer N bytes (N==auto: buffer whole file)
-c, --command COMMAND execute remote command COMMAND (Z)
-C, --command-tries N try N times to execute a command (Z)
-d, --dot-to-slash change '.' to '/' in pathnames (Y/Z)
--delay-startup N sleep N seconds before doing anything
-e, --escape escape all control characters (Z)
-E, --rename force receiver to rename files it already has
-f, --full-path send full pathname (Y/Z)
-i, --immediate-command CMD send remote CMD, return immediately (Z)
-h, --help print this usage message
-k, --1k send 1024 byte packets (X)
-L, --packetlen N limit subpacket length to N bytes (Z)
-l, --framelen N limit frame length to N bytes (l=L) (Z)
-m, --min-bps N stop transmission if BPS below N
-M, --min-bps-time N for at least N seconds (default: 120)
-n, --newer send file if source newer (Z)
-N, --newer-or-longer send file if source newer or longer (Z)
-o, --16-bit-crc use 16 bit CRC instead of 32 bit CRC (Z)
-O, --disable-timeouts disable timeout code, wait forever
-p, --protect protect existing destination file (Z)
-r, --resume resume interrupted file transfer (Z)
-R, --restricted restricted, more secure mode
-q, --quiet quiet (no progress reports)
-s, --stop-at {HH:MM|+N} stop transmission at HH:MM or in N seconds
--tcp build a TCP connection to transmit files
--tcp-server open socket, wait for connection
-u, --unlink unlink file after transmission
-U, --unrestrict turn off restricted mode (if allowed to)
-v, --verbose be verbose, provide debugging information
-w, --windowsize N Window is N bytes (Z)
-X, --xmodem use XMODEM protocol
-y, --overwrite overwrite existing files
-Y, --overwrite-or-skip overwrite existing files, else skip
--ymodem use YMODEM protocol
-Z, --zmodem use ZMODEM protocol
short options use the same arguments as the long ones
More information can be used for reference linuxprobe.com。
linux的rz/ sz 指令是上传、下载文件指令。一般需要服务器先安装好响应的包才能用。
1、安装lrzsz的包:yum install lrzsz ;如果没有yum,可以到安装盘的pakage里找到lrzsz的包,放到服务器里进行安装。
2、安装好后,运行 rz 进行上传文件测试;sz 文件名 进行下载测试。
通过仿真器传输命令。
上传文件只需在shell终端仿真器中输入命令rz,即可从弹出的对话框中选择本地磁盘上的文件,利用Zmodem上传到服务器当前路径下。下载文件只需在shell终端仿真器中输入命令sz文件名,即可利用Zmodem将文件下载到本地某目录下。