我创建了以下端口转发:
ssh -vL localhost:4433:example.com:443 remote-linux-host
Run Code Online (Sandbox Code Playgroud)
注意:我在4433本地使用而不是443避免使用sudo.
但是,当我转到https://localhost:4433/,忽略证书检查后,出现以下错误(在 Chrome 和 Firefox 上):
404 - 未找到
使用时相同curl:
$ curl -s https://localhost:4433/ | html2text
<?xml version="1.0" encoding="iso-8859-1"?>
****** 404 - Not Found ******
Run Code Online (Sandbox Code Playgroud)
如何为 HTTPS 进行端口转发?
我的目标是https://example.com/通过远程服务器在我的本地(端口 4433)上打开(通过 HTTPS 正常工作)。
我意识到这可能是一个非常简单的问题,但我对命令行仍然很陌生,并且只掌握了基本命令。
我已经从我的大学下载了一些讲座演示文稿(大约 25 个左右),但是这样做时它们被命名为……
L2%20Development%20of%20immune%20system.pptx
L4%20Molecular%20Recognition.pdf
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,他们下载的是 URL 编码%20而不是空格。
我的问题是如何批量重命名所有这些文件,以便%20删除并替换为空格?
输入:
line1 with the PATTERN that contains ( )
line2 with the PATTERN that contains ( )
lineN with the PATTERN that contains ( )
Run Code Online (Sandbox Code Playgroud)
输出:
line1 with the PATTERN that contains ( ) ;
line2 with the PATTERN that contains ( ) ;
...
lineN with the PATTERN that contains ( ) ;
Run Code Online (Sandbox Code Playgroud)
我试过这个:
find . -name "test.txt" -print | xargs sed -i "/PATTERN/ s/$)/); /g"
Run Code Online (Sandbox Code Playgroud)
但它没有用。
在perlre的扩展模式页面上,我们可以阅读\K:
保留 的左侧的内容
\K,不要将其包含在 $& 中
这是使用 GNU 的实际示例grep(实际上保留了 的内容\K):
$ echo "foo bar buzz" | grep -Po "foo \Kbar buzz"
bar buzz
Run Code Online (Sandbox Code Playgroud)
有相反的顺序\K吗?
例如打印 just bar,如:
$ echo "foo bar buzz" | grep -Po "foo \Kbar\X buzz"
bar
Run Code Online (Sandbox Code Playgroud) 我想使用install命令来创建一个新的可执行文件,其中包含预先填充的内容(例如,其中包含单个pwd命令)。
所以我扩展了这个例子,它创建了一个新的空可执行文件:
install -b -m 755 /dev/null newfile
Run Code Online (Sandbox Code Playgroud)
进入这个:
install -m755 <(echo pwd) newfile
Run Code Online (Sandbox Code Playgroud)
或者:
echo pwd | install -m755 /dev/stdin newfile
Run Code Online (Sandbox Code Playgroud)
我希望创建一个新的newfile可执行文件,其中包含内容pwd。
它适用于 Linux,但在 OS X 上它失败并出现以下错误:
BSD install( /usr/bin/install)
安装::
/dev/fd/63不合适的文件类型或格式
GNU install( /usr/local/opt/coreutils/libexec/gnubin/install)
安装:跳过文件
/dev/fd/63,因为它在复制时被替换
为什么这在 Unix 上不起作用,但在 Linux 上有效?我错过了什么?有没有办法通过使用不同的语法来绕过上述警告(无需在单独的命令中创建文件并chmod在此之后使用)?
在两种环境(Linux 和 OS X)上,我都有相同版本的install:
$ install --version
install (GNU coreutils) 8.23
Run Code Online (Sandbox Code Playgroud) 我想从字符串变量中去除所有数字字符,例如:
VARIABLE=qwe123rty567
Run Code Online (Sandbox Code Playgroud)
到:
echo $VARIABLE
> qwerty
Run Code Online (Sandbox Code Playgroud)
我搜索了很多帖子,但他们要么使用 sed 输出到文件/文件名,要么输出到 echo。由于空白,我无法使用它:
VARIABLE=$VARIABLE | sed 's/[0-9]*//g'
Run Code Online (Sandbox Code Playgroud) 我有以下foo.txt文件:
This is the first line.
This is the middle line.
This is the last line.
Run Code Online (Sandbox Code Playgroud)
而且我正在尝试仅通过单词 grep 中间行middle并返回周围环境(例如),因此我可以突出显示整个句子(这在与上下文选项一起使用时特别有用)。
它确实可以在没有颜色的情况下工作:
$ grep -o --color=none '.\+ middle .\+' foo.txt
This is the middle line.
Run Code Online (Sandbox Code Playgroud)
但相同的命令不适用于颜色:
$ grep -o --color=auto '.\+ middle .\+' foo.txt
(empty line)
Run Code Online (Sandbox Code Playgroud)
注意:没有-o它没有任何区别。
虽然它仅在过滤行的前半部分时有效:
$ grep -o --color=auto '.\+ middle' foo.txt
This is the middle
Run Code Online (Sandbox Code Playgroud)
但不是下半场 ( 'middle .\+')。
为什么这不能按预期工作,我该如何解决?这是一个错误还是由于某种原因我不能同时使用两个正则表达式?
在 OS X 上测试:
$ grep --version …Run Code Online (Sandbox Code Playgroud) 我的驱动器被格式化为 hfs+ 并且不干净。
例如,当我尝试通过 挂载驱动器时mount -f -o rw,dmesg显示错误:
hfs: Filesystem was not cleanly unmounted, running fsck.hfsplus is recommended.
mounting read-only.
Run Code Online (Sandbox Code Playgroud)
所以当我试图通过fsck.hfsplus(部分hfsprogs)修复它时,它说:
$ fsck -dyf /media/sdd2
** /dev/sdd2
Using cacheBlockSize=32K cacheTotalBlock=1024 cacheSize=32768K.
** Checking HFS Plus volume.
** Detected a case-sensitive catalog.
** Checking Extents Overflow file.
** Checking Catalog file.
Invalid map node linkage
(4, 0)
** Volume check failed.
volume check failed with error 7
volume type is pure HFS+
primary …Run Code Online (Sandbox Code Playgroud) sudo ps o gpid,comm报告类似3029 bash但命令有参数--arbitrary -other -searchword有没有办法显示这些参数?
我编写了一个简单的 bash 脚本,将 ssh 连接到 3 个主机(2 个远程,1 个我自己的用于测试)并运行一个长时间运行的 gui 程序,该程序将文本输出到我想记录的终端。
#!/bin/bash
ssh -f -X user@remote1 '(python -u long_running_program.py &> ~/log1.txt)'
ssh -f -X user@remote2 '(python -u long_running_program.py &> ~/log2.txt)'
ssh -f -X user@localhost '(python -u long_running_program.py &> ~/log3.txt)'
multitail -s 3 ~/log*
Run Code Online (Sandbox Code Playgroud)
由上可知,ssh 是通过 f 参数调用的,以在后台运行并允许脚本继续执行。在远程服务器上,使用无缓冲开关调用 python 程序并将输出重定向到日志文件(请注意,远程和本地计算机的主目录都在网络安装驱动器上,因此使用 ~ 在所有其中)。
上述技术上可行,但是来自远程机器的 2 个日志 (log1,log2) 更新速度非常慢。文件更新可能需要 20 秒以上(无论您是否使用 multitail、vi 等查看文件),而本地日志文件 (log3) 更新是即时的。
为了确认这不应该发生,我可以手动 ssh 进入遥控器并运行程序,而无需将输出重定向到文件。正如预期的那样,输出会无延迟地连续流式传输。我还尝试了各种方法,例如尝试关闭缓冲和使用脚本/tee/etc 都无济于事。
有谁知道是什么原因造成的和/或如何解决它?
shell ×4
osx ×3
bash ×2
command-line ×2
grep ×2
ssh ×2
bsd ×1
executable ×1
files ×1
fsck ×1
hfs+ ×1
https ×1
line-editor ×1
perl ×1
ps ×1
rename ×1
sed ×1
shell-script ×1
stdout ×1
string ×1