有很多bash指南,包括增加线路,如HISTTIMEFORMAT='%d/%m/%y %T '或HISTTIMEFORMAT="%F %T "对~/.bashrc或/etc/bash.bashrc。
在最终报价之前总是有一个空格。例如,它永远不会HISTTIMEFORMAT='%d/%m/%y %T'。
为什么是这样?
我ext4在一个(磁性)硬盘驱动器上有一个 900GB 的分区,它没有缺陷也没有坏扇区。除了一个空lost+found目录外,该分区完全是空的。该分区使用默认参数进行格式化,但我将保留文件系统块的数量设置为 1%。
我xubuntu-15.04-desktop-amd64.iso使用wget. 下载完成后,发现文件被分成了四个片段:
filefrag -v /media/emma/red/xubuntu-15.04-desktop-amd64.iso
Filesystem type is: ef53
File size of /media/emma/red/xubuntu-15.04-desktop-amd64.iso is 1009778688 (246528 blocks of 4096 bytes)
ext: logical_offset: physical_offset: length: expected: flags:
0: 0.. 32767: 34816.. 67583: 32768:
1: 32768.. 63487: 67584.. 98303: 30720:
2: 63488.. 96255: 100352.. 133119: 32768: 98304:
3: 96256.. 126975: 133120.. 163839: 30720:
4: 126976.. 159743: 165888.. 198655: 32768: 163840:
5: 159744.. 190463: 198656.. 229375: 30720:
6: 190464.. 223231: 231424.. …Run Code Online (Sandbox Code Playgroud) 我想将大约 1000 个 mp3 文件从包含复杂嵌套目录结构的名为“music”的目录移动到名为“mp3s”的单个目录,以便我可以在车中收听它们。
我使用的命令是:
find music -name '*mp3' -exec mv -v -t mp3s {} +
Run Code Online (Sandbox Code Playgroud)
然而,当我执行命令时发生了一些奇怪的事情。命令完成后,我注意到省略了四个文件。这些文件是:
"music/Michael Hedges/Michael Hedges - Taproot/06 - Chava's Song.mp3"
'music/Michael Hedges/Michael Hedges - Aerial Boundaries/04 - Ragamuffin.mp3'
'music/Jonas Hellborg/1988 - Bass/07. Blues For LW.flac.mp3'
'music/Jonas Hellborg/1988 - Axis/03. Roman.flac.mp3'
Run Code Online (Sandbox Code Playgroud)
我再次执行了完全相同的命令,这一次先前省略的四个文件已按预期移动。
我无法想象为什么find会做出这样出乎意料的事情。为什么会发生这种情况?
在 Ubuntu 上的 bash shell 中执行。
我见过history | grep blah和history |grep blah; 并且history|grep blah也有效,尽管似乎从来没有人使用过它。
空格中是否有任何意义(例如,与不同命令之间的管道传输需要不同的空格使用),还是总是任意的?
我是否正确地假设当;在一行上加入两个命令时,Bash 总是等到第一个命令退出后再执行第二个命令?同样,在不同行包含两个不同命令的 shell 脚本中,Bash 总是等到第一行的命令退出后才执行第二行的命令?
如果是这种情况,有没有办法在一行或脚本中执行两个命令,以便第二个命令不会等到第一个命令完成?
此外,shell 脚本中的不同行是否等同于由;或连接的单独行&&?
根据此网页,将“/”添加到 rsync 目标的末尾与不添加会产生不同的结果。
我试图对此进行测试,但无法验证:
$ mkdir dir{1..3}
$ touch dir1/file
$ rsync -r dir1/ dir2
$ rsync -r dir1/ dir3/
$ ls dir*
dir1:
file
dir2:
file
dir3:
file
Run Code Online (Sandbox Code Playgroud)
有时将“/”附加到目的地实际上是否有用?
如果我有一个目录,其中包含一些名称有空格的文件,例如
$ ls -1 dir1
file 1
file 2
file 3
Run Code Online (Sandbox Code Playgroud)
我可以成功地将它们全部复制到另一个目录,如下所示:
$ find dir1 -mindepth 1 -exec cp -t dir2 {} +
Run Code Online (Sandbox Code Playgroud)
但是,输出find dir1 -mindepth 1包含未转义的空格:
$ find dir1 mindepth 1
dir1/file 1
dir1/file 3
dir1/file 3
Run Code Online (Sandbox Code Playgroud)
如果我使用print0而不是print,输出仍然包含未转义的空格:
$ find dir1 mindepth 1 -print0
dir1/file 1dir1/file 2dir1/file 3
Run Code Online (Sandbox Code Playgroud)
要使用 手动复制这些文件cp,我需要对空格进行转义;但是当cp的参数来自时,这似乎是不必要的find,无论我是否使用+或\;在命令末尾。
这是什么原因?
sort -o似乎是多余的。当我们可以使用的时候,使用它还有什么意义呢sort >?
有时无法使用 shell 重定向吗?
$ touch file{1..12}
$ echo *e{1..12}
file1 file2 file3 file4 file5 file6 file7 file8 file9 file10 file11 file12
$ echo *{1..12}
file1 file11 file12 file2 file3 file4 file5 file6 file7 file8 file9 file10 file11 file12
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会这样。请问有人可以解释一下吗?