我使用“
git bash
”(包含在 Windows 版 Git 下载包中)作为命令 shell,用于与 git
交互以及将文件传输到目标计算机或从目标计算机传输文件。
我使用
scp
将文件从一台目标计算机复制到另一台目标计算机,而不将它们复制到本地计算机:
MINGW64 [wfredk@Phoenix]pty0:/c/signoff/notes
7032/632 $ scp pi@H2:/home/pi/*.py pi@SB1:/home/pi
pi@sb1's password:
pi@h2's password:
config_mp_channel.py 100% 5452 36.3KB/s 00:00
decoder.py 100% 893 6.7KB/s 00:00
macp4to6.py 100% 687 5.2KB/s 00:00
macplusone.py 100% 399 2.7KB/s 00:00
meshchek.py 100% 1174 8.4KB/s 00:00
vispost.py 100% 4683 32.4KB/s 00:00
2023-10-16 20:04:06 Mon 8:04:06 pm
上述命令在以下摘录的 7032
输出中显示为条目
history
:
7020 Oct 16 19:26:44 grep "scp *pi@* *pi@*" *.notes.txt
7021 Oct 16 19:27:11 grep "scp*pi@*pi@*" *.notes.txt
7022 Oct 16 19:27:24 grep "scp*pi\@*pi\@*" *.notes.txt
7029 Oct 16 19:46:09 history|grep "scp pi@.?+[[digit]]\:/home* pi@.?+[[digit]]\:/home*"
7030 Oct 16 19:46:23 history|grep -e "scp pi@.?+[[digit]]\:/home* pi@.?+[[digit]]\:/home*"
7031 Oct 16 20:00:33 history|grep -e "scp pi@..?\d:\/home\/pi\/.* pi@..?\d:\/home\/pi"
7032 Oct 16 20:03:51 scp pi@H2:/home/pi/*.py pi@SB1:/home/pi
7033 Oct 16 20:04:13 history|grep -e "scp pi@..?\d:\/home\/pi\/.* pi@..?\d:\/home\/pi"
7034 Oct 16 20:11:04 history|grep -e "*: scp pi@..?\d:\/home\/pi\/.* pi@..?\d:\/home\/pi"
但是,上面
history
列表中显示的其他命令行都找不到与我刚刚使用的类似或包含该条目的
history
条目,或者在我记录了此类命令的文件中。
我还尝试了最后一个命令,其中路径分隔符未转义:
MINGW64 [wfredk@Phoenix]pty0:~/For_Hire/Client/install (the-demo-base)
7051/721 $ history|grep -e "scp pi@..?\d:/home\/pi/.* pi@..?\d:/home/pi"
2023-10-17 02:00:00 Tue 2:00:00 am
这些尝试都没有产生任何有用的输出。因此,我的问题是:
如何找到我从其中复制文件的
条目 使用history
将远程主机连接到另一个主机,而无需先将它们复制到 本地计算机,如上面的scp
条目history
所示?7032
。
仅供参考,我更喜欢我的历史显示和命令提示符包含大量信息,以用于文档目的。我使用的
~/.bashrc
文件包含以下命令:
set_ps1_prompt()
{
# prompt when no color support (?) terminated with a newline
PS1="\[\033]0;$TITLEPREFIX:$PWD\007\]\n"
# date and time as "2022-12-27 13:28:56 Tue 1:28:56 pm" on its own line, followed by a blank line
PS1="${PS1}\D{%F %T %a %l:%M:%S %P}\n\n"
# O/S name (purple), username@hostname (green) in uncolored "[ ]", terminal device basename, ":", path (yellow), git branch (light cyan)
PS1="${PS1}\[\033[35m\]$MSYSTEM\[\033[0m\] [\[\033[32m\]\u@\h\[\033[0m\]]\l:\[\033[01;33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n"
# history number, "/", command number, " ", prompt character (all in light blue), " "
PS1="${PS1}\[\033[01;34m\]\!/\# $\[\033[0m\] "
}
export HISTTIMEFORMAT="%h %d %H:%M:%S "
export HISTSIZE=10000
export HISTFILESIZE=10000
export HISTCONTROL=ignorespace
shopt -s histappend
shopt -s cmdhist
# append current session history to the history file
export PROMPT_COMMAND='history -a;set_ps1_prompt'
您正在尝试将全局模式提供给
grep
,它需要正则表达式。 *
的正则表达式等效项是 .*
。所有这些 grep 都污染了您的历史记录,因此使用控制 R 或 !
历史扩展来回忆第一次会很烦人,但您可以按 ctrl-R 以及您试图回忆的命令的任何子字符串(例如,我使用 sudo pacman -S --needed --no-confirm -uwy
进行系统更新检查,并且 uw
序列在我的命令历史记录中很少见,因此 ctrl-R u w return 是我的整个可用更新检查序列,然后当我看到足够的内容以实际执行更新我只是回忆它并删除最后两个字符。不需要 grep。