假设我有两条路径:<source_path>和<target_path>。我希望我的 shell (zsh) 自动找出是否有办法将<target_path>from表示<source_path>为相对路径。
例如让我们假设
<source_path> 是 /foo/bar/something<target_path> 是 /foo/hello/world结果是 ../../hello/world
我需要<source_path>尽可能<target_path>使用相对符号链接创建一个符号链接,否则当我从 Windows 访问网络上的这些文件时,我们的 samba 服务器无法正确显示文件(我不是系统管理员,并且不无法控制此设置)
假设<target_path>和<source_path>是绝对路径,下面创建一个指向绝对路径的符号链接。
ln -s <target_path> <source_path>
Run Code Online (Sandbox Code Playgroud)
所以它不适合我的需要。我需要为数百个文件执行此操作,因此我无法手动修复它。
任何 shell 内置程序可以解决这个问题?
我的.ssh/config文件中有以下条目
Host AAA
User BBB
HostName CCC
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
Run Code Online (Sandbox Code Playgroud)
以上允许我通过相同的 ssh 连接多路复用多个 ssh 会话,而无需每次需要新会话时都输入密码(只要主连接保持打开状态)。
但是,我注意到,一旦我拥有相对较高的多路连接数(~7),就无法向同一个多路连接添加更多会话,并且开始出现以下错误:
> ssh -X AAA
mux_client_request_session: session request failed: Session open refused by peer
Password:
Run Code Online (Sandbox Code Playgroud)
为什么我收到这个错误?我可以在同一连接中复用的 ssh 会话数量是否有限制?我可以更改该限制吗?那会是个坏主意吗?
考虑以下来自 的输出df。
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 23G 6.1G 16G 29% /
udev 10M 0 10M 0% /dev
tmpfs 397M 420K 397M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.8G 904K 1.8G 1% /run/shm
/dev/sda6 890G 324G 521G 39% /home
/dev/sdb1 459G 267G 169G 62% /home/user/mnt
none 4.0K 0 4.0K 0% /sys/fs/cgroup
Run Code Online (Sandbox Code Playgroud)
我怎样才能只显示"/dev"以标题开头并保留标题的行,而过滤掉其他所有内容。我还想不必诉诸于使用临时文件或变量?注意:标题取决于语言环境,因此您无法使用正则表达式捕获它。
我经常发现自己将包含 10K - 100K 文件的文件夹发送到远程机器(在校园内的同一网络内)。
我只是想知道是否有理由相信,
tar + rsync + untar
Run Code Online (Sandbox Code Playgroud)
或者干脆
tar (from src to dest) + untar
Run Code Online (Sandbox Code Playgroud)
在实践中可能比
rsync
Run Code Online (Sandbox Code Playgroud)
第一次传输文件时。
我对在两种情况下解决上述问题的答案感兴趣:使用压缩和不使用压缩。
我刚刚运行了一些移动 10,000 个小文件(总大小 = 50 MB)的实验,并且tar+rsync+untar始终比rsync直接运行(都没有压缩)快。
假设我有一个包含三个文件的文件夹:
foo1
foo2
bar
Run Code Online (Sandbox Code Playgroud)
1. 如果我跑
list_of_files=$(print foo*)
echo $list_of_files
Run Code Online (Sandbox Code Playgroud)
我得到: foo1 foo2
2.如果我跑
list_of_files=$(print bar*)
echo $list_of_files
Run Code Online (Sandbox Code Playgroud)
我得到: bar
3.但是,如果我跑
list_of_files=$(print other*)
echo $list_of_files
Run Code Online (Sandbox Code Playgroud)
我得到:(虽然zsh: no matches found: other*变量$list_of_files是空的)
有没有办法让 zsh 在无法匹配 glob 扩展时不抱怨?
我的目标是使用上述机制静默收集与给定 glob 模式匹配的文件列表。
我听说过关于zmvin 的好消息zsh,并且很想真正学会使用它。不过我对zsh还是比较缺乏经验,有一些基本的问题:
zmvin的手册页zsh(man zsh 输出“没有手动输入zmv”)zmv本地是否允许空运行?zmv?假设我有一个 shell 变量$string,其中包含一些带有多个换行符的文本,例如:
string="this
is
a test"
Run Code Online (Sandbox Code Playgroud)
我想将此字符串转换为一个新字符串new_string,其中所有换行符都转换为空格:
new_string="this is a test"
Run Code Online (Sandbox Code Playgroud)
我试过:
print $string | sed 's/\n/ /g'
Run Code Online (Sandbox Code Playgroud)
但它没有用
我也想知道是否有办法使用perl -0777 's/\n/ /g'或命令来做到这一点 tr?
是否有可能有一个shebang,而不是指定解释器的路径,而是具有解释器的名称,并让shell通过$PATH找到它?
如果没有,有什么原因吗?
我有如下一行:
find /foo/bar -name '*.mp4' -print0 | xargs -i {} -0 mv -t /some/path {}
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
xargs: argument line too long
Run Code Online (Sandbox Code Playgroud)
我很迷惑。不xargs应该使用' should'来精确地帮助解决这个问题吗?
注意:我知道我可以在技术上使用-execfind,但我想了解为什么上述失败,因为我的理解xargs是应该知道如何将输入拆分为可管理的大小以使其运行的参数。这不是真的吗?
这都是zsh。
我刚刚切换到 Macbook Air。我安装的zsh使用自制的,但是当我在使用一些代码,我(原本).zshrc,我得到一个错误说.dircolors was not found。
下面是有问题的代码:
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
eval "$(dircolors -b)"
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current …Run Code Online (Sandbox Code Playgroud)