命令未在 GNOME 终端中找到。

huangapple go评论77阅读模式
英文:

for: Command not found on gnome terminal?

问题

Here is the translation of your provided content:

长话短说:我有一个文件夹里面装满了1583个.tar文件。每个.tar文件只包含一个文件夹,我希望有一个只包含这些文件夹的文件夹。我尝试使用控制台命令来实现这个目标,因为我不知道如何让Python来完成这个任务。通过在网上查找信息,我得到了以下命令:

for file in ls *.tar do; do tar -xzf $file -C /path/to/destination/folder done

出现了错误:

for: command not found

对于这个问题我不太确定该怎么办。我到处查找关于如何在Linux终端中使用for循环的信息,但每个地方都只说:“写for x; do y”,没有提供如何实际让这些东西工作的建议。

我听说很多关于Linux Bash和脚本等的东西...我不太理解这些东西。我需要执行某种仪式来让Bash工作吗?显然ls、cd等命令也是Bash的一部分?这些命令对我来说运行得很好,但for循环不行...

如果这些问题太基础的话,我真的对计算机不太懂。

感谢任何帮助!!


好的,它要求我写2个部分,我已经写了上面的部分之后,我想到了以下内容:

如上所述,我得到了以下命令:

for file in ls *.tar do; do tar -xzf $file -C /path/to/destination/folder done

手动使用tar -xzf命令可以正常工作,甚至可以将文件放在正确的文件夹中。但我不想手动执行这个操作(因为有1500多个文件),而tar命令不接受*.tar作为输入 - 我查找了如何解决这个问题的方法,然后得到了我尝试使用的命令。

再次感谢!

Jude S

英文:

Long and short of it: I have a folder full of 1583 .tar files. Each .tar file contains only one folder, and i want a folder full of only those folders. Trying to do this using console commands because i cant figure out how to get python to do it for me. By reading around online i've come up with the command

for file in ls *.tar do; do tar -xzf $file -C /path/to/destination/folder done

Error comes up:

for: command not found

Unsure what to do about this. Everywhere i look about how to get for loops to work in linux terminals and everywhere is just saying "
>write for x; do y

with no advice on how to actually get that stuff to work...

I'm hearing a lot about linux bash and scripting and stuff... I dont really understand what all these things are. Do i need to perform some ritual to get bash to work? Apparently ls and cd and stuff are part of bash too? Those are working fine for me, but for loops are not...

Sorry if this is really basic guys, i'm kind of computer illiterate.

Thanks for any help!!

--

ok it asked me to write 2 sections and i came up with the following after i had already written the above:


as stated before, I've come up with the command

for file in ls *.tar do; do tar -xzf $file -C /path/to/destination/folder done

Using tar -xzf manually works just fine, even puts it in the right folder. But i dont want to just do that manually (because of the 1500+ files thing) and the tar command wont take *.tar as an input - I looked up how to solve this problem and was fed the command I tried to use as a fix.

Thanks again!!

Jude S

答案1

得分: 2

命令中存在一些语法错误。但是bash应该能够理解for。您确定您正在使用的是bash而不是cshtcsh吗?

为了确保(进行测试),您可以只需键入

bash

这将为您启动一个bash shell。

至于语法错误,命令可能应该是:

for file in *.tar ; do tar xzf "$file" -C /path/to/destination/folder ; done

另一方面,如果您想继续使用您的(t)csh,可以这样做:

foreach file ( *.tar )
tar xzf $file -C /path/to/destination/folder
end
英文:

There are some syntax-errors in the command. But bash should understand for. Are you sure you are using bash and not a csh or tcsh?

To be sure (for test purposes) you can just type

bash

and that will start a bash-shell for you.

As for the syntax-errors: the command should probably be:

for file in *.tar ; do tar xzf "$file" -C /path/to/destination/folder ; done

On the other hand, if you want keep using your (t)csh, it would be something like:

foreach file ( *.tar )
tar xzf $file -C /path/to/destination/folder
end

huangapple
  • 本文由 发表于 2023年2月24日 14:58:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75553434.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定