Tag: shell

Shell脚本:通过ssh脚本运行函数

有没有什么聪明的方法通过ssh在远程主机上运行本地Bash函数? 例如: #!/bin/bash #Definition of the function f () { ls -l; } #I want to use the function locally f #Execution of the function on the remote machine. ssh user@host f #Reuse of the same function on another machine. ssh user@host2 f 是的,我知道这是行不通的,但有没有办法做到这一点?

如何find两个date之间的差异?

A = “2002-20-10” B = “2003-22-11” 如何find两个date之间的差异?

如何在Java中获取本地应用程序数据文件夹?

可能重复: 什么是获取本地应用程序数据目录的path的跨平台方式? 我正在寻找一种方法来获取本地应用程序数据文件夹,这是一个特殊的Windows文件夹,在Java中的位置。 不幸的是,以下仅适用于英文版的Windows XP,默认设置为: System.getProperty("user.home") + "\\Local Settings\\Application Data" 我想在.NET中有这样的东西: System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) 有没有办法做到这一点,而不必调用Windows Shell API的SHGetSpecialFolderLocation ?

如何按照Windows资源pipe理器的相同方式按文件名进行sorting?

这是着名的问题“ASCIIbetical”顺序与“自然”顺序适用于PowerShell。 为了能够像浏览器一样在PowerShell中进行sorting,可以在StrCmpLogicalW API上使用这个包装器 ,它实际上执行Windows资源pipe理器的自然sorting。 这将需要一些pipe道。 但是, 这篇文章build议在python中有三种types的实现。 人们会希望Get-ChildItem cmdlet或至less文件系统提供程序可以有内置的自然sorting选项。 不幸的是,他们没有。 那么这里是一个问题,Powershell中这个最简单的实现是什么? 简单来说,我的意思是写最less量的代码,并且可能没有第三方/外部脚本/组件。 理想情况下,我想要一个短的 Powershell函数,可以为我sorting。

权限被拒绝在hdfs

我是hadoop分布式文件系统的新手,我已经在我的机器上完成了hadoop单节点的完整安装,但之后当我要将数据上传到hdfs时,它给出了一个错误消息Permission Denied 。 来自terminal的消息与命令: hduser@ubuntu:/usr/local/hadoop$ hadoop fs -put /usr/local/input-data/ /input put: /usr/local/input-data (Permission denied) hduser@ubuntu:/usr/local/hadoop$ 使用sudo并添加hduser到sudouser之后: hduser@ubuntu:/usr/local/hadoop$ sudo bin/hadoop fs -put /usr/local/input-data/ /inwe put: org.apache.hadoop.security.AccessControlException: Permission denied: user=root, access=WRITE, inode="":hduser:supergroup:rwxr-xr-x hduser@ubuntu:/usr/local/hadoop$

如何判断一个string在Unix shell脚本中是否包含另一个string?

我想编写一个Unix shell脚本,如果在另一个string中有一个string,它将执行各种逻辑。 例如,如果我在某个文件夹中,则closures。 有人可以告诉我如何做到这一点? 如果可能的话,我想使这不是特定的(即不bash),但如果没有其他的办法,我可以做到这一点。 #!/usr/bin/env sh if [ "$PWD" contains "String1" ] then echo "String1 present" elif [ "$PWD" contains "String2" ] then echo "String2 present" else echo "Else" fi

如何在Makefile目标中使用Bash语法?

我经常发现Bash语法非常有用,例如像diff <(sort file1) <(sort file2)这样的进程replace。 是否有可能在Makefile中使用这样的Bash命令? 我在想这样的事情: file-differences: diff <(sort file1) <(sort file2) > $@ 在我的GNU Make 3.80中,由于它使用shell而不是bash来执行命令,所以会出现错误。

在Linux中,如何在文件或目录更改时运行shell脚本

我想在特定文件或目录更改时运行一个shell脚本。 我怎么能轻松地做到这一点?

使用sed来批量重命名文件

目的 更改这些文件名: F00001-0708 RG-biasliuyda F00001-0708-CS-akgdlaul F00001-0708-VF-hioulgigl 到这些文件名: F0001-0708-RG-biasliuyda F0001-0708-CS-akgdlaul F0001-0708-VF-hioulgigl shell代码 去testing: ls F00001-0708-*|sed 's/\(.\).\(.*\)/mv & \1\2/' 去表演: ls F00001-0708-*|sed 's/\(.\).\(.*\)/mv & \1\2/' | sh 我的问题 我不明白sed代码。 我明白什么是替代命令 $ sed 's/something/mv' 手段。 我有一些正则expression式。 但我不明白这里发生了什么事情: \(.\).\(.*\) 或在这里: & \1\2/ 前者对我来说就是:“一个单一的字符,后面跟着一个单一的字符,然后是任何单个字符的长度序列” – 但是当然,除此之外还有更多。 就后者而言: & \1\2/ 我不知道。 我真的想了解这个代码。 请帮帮我,伙计们

在文件前加上一个内胆shell?

这可能是一个复杂的解决scheme 。 我正在寻找一个像“>>”这样简单的操作符,但是用于预先考虑。 恐怕它不存在。 我将不得不做类似的事情 mv myfile tmp cat myheader tmp> myfile 什么更聪明? (我不喜欢tmp文件)