scp

scp scp 可以在两个 linux 主机间复制文件; # 复制目录 -r scp -r local_folder remote_username@remote_ip:remote_folder ash: /usr/libexec/sftp-server: not found This is a consequence(结果/后果) of your client machine using a very recent OpenSSH release (9.0 - check https://www.openssh.com/txt/release-9.0 62 for more info), which changes the scp program to use the SFTP protocol under the hood, which vanilla OpenWrt/dropbear installations do not support. To work around the problem on the client side, use the new -O (that is an uppercase letter “o”) switch when invoking scp, which will cause it to fall back to the legacy behavior. ...

2023-01-08 · 1 min · 205 words · -

shell 进制转换

shell 进制转换 16进制转换成10进制 printf %d 0xF echo $((16#F)) 10进制转换成16进制 printf %x 15 echo "obase=16;15"|bc 三、10进制转换成8进制 printf %o 9 11 四、8进制转换成10进制 echo $((8#11)) 9 五、同理二进制转换成10进制 echo $((2#111)) 7 六、10进制转换成二进制 echo “obase=2;15”|bc 1111 https://blog.csdn.net/rheostat/article/details/8057405

2020-03-24 · 1 min · 32 words · -

shell下批量替换文件名中的空格

shell下批量替换文件名中的空格 http://blog.csdn.net/dliyuedong/article/details/14229121 rename 's/ /_/g' * rename 's/\(/_/g' *

2017-09-22 · 1 min · 9 words · -

bash

bash # -n 选项代表只检查语法,不执行脚本。 bash -n foo.sh # -n 或 --noexec 选项告诉 Bash:只读取并检查脚本的语法是否正确,但不会实际执行脚本中的任何命令。 bash -c 用法: bash -c "cmd string" 通常使用shell去运行脚本,两种方法 bash xxx.sh,另外一种就是bash -c “cmd string” 对于bash xxx.sh, 首先bash 会在当前目录去寻找xxx.sh,如果找到,就直接运行,找不到则按照环境变量$PATH的指定路径,按顺序去找,如果找到,则执行,找不到则报错。 shell 脚本的参数 $0 就是要执行的 shell 脚本 xxx.sh, $1 就是后面紧跟 xxx.sh 的参数,$2 $3依次类推 而对于bash -c “cmd string” 首先我们看看官方的说明解释 -c If the -c option is present, then commands are read from the first non-option argument command_string. If there are arguments after the command_string, they are assigned to the positional parameters, starting with $0. ...

2015-01-06 · 1 min · 174 words · -

执行 Shell 脚本, fork, exec, source, shell 执行

执行 Shell 脚本, fork, exec, source, shell 执行 cx ./xxx.sh sh xxx.sh 用户可以用任何编辑程序来编写Shell程序。因为Shell程序是解释执行的,所以不需要编译成目的程序。按照Shell编程的惯例,以bash 为例,程序的第一行一般为"#!/bin/bash",其中 # 表示该行是注释,叹号 ! 告诉Shell运行叹号之后的命令并用文档的其余部分作为输入,也就是运行/bin/bash并让/bin/bash去执行Shell程序的内容。 执行Shell程序的方法有3种。 sh Shell 程序文件名 这种方法的命令格式为: sh <foo.sh> 这实际上是调用一个新的bash命令解释程序,而把Shell程序文件名作为参数传递给它。新启动的Shell将去读指定的文件,可执行文件中列出的命令,当所有的命令都执行完后结束。该方法的优点是可以利用Shell调试功能。 bash < foo.sh 格式为: bash< Shell程序名 这种方式就是利用输入重定向,使Shell命令解释程序的输入取自指定的程序文件。 用 chmod 命令使 Shell 程序成为可执行的,"./Shell文件名" 一个文件能否运行取决于该文档的内容本身可执行且该文件具有执行权。对于Shell程序,当用编辑器生成一个文件时,系统赋予的许可权都是644(rw-r-r-),用"chomd 755 Shell文件名"命令将其改为可执行的,因此,当用户需要运行这个文件时,"./Shell文件名"来执行就是行了。 在这3种运行Shell程序的方法中,最好按下面的方式选择: 当刚创建一个Shell程序,对它的正确性还没有把握时,应当使用第一种方式进行调试。当一个Shell程序已经调试好时,应使用第三种方式把它固定下来,以后只要键入相应的文件名即可,并可被另一个程序所调用。 source (.) 使用 source 命令和点号(.)是等价的, 类似于 C/C++ 中的 #include 预处理指令,都是将指定的脚本内容拷贝至当前的脚本中,由同一个 Shell 进程来执行。 source (source /directory/script.sh) 与fork的区别是不新开一个 sub-shell 来执行被调用的脚本,而是在同一个 shell 中执行。所以被调用的脚本中声明的变量和环境变量。 都可以在主脚本中得到和使用。 使用 source 执行命令时, 脚本文件可以没有执行权限, source 命令是 bash 的内置命令,不需要 (也没有) 绝对路径. source 命令也称为"点命令",也就是一个点符号 “. “。 source 命令通常用于重新执行刚修改的初始化文件,使之立即生效,而不必注销并重新登录。 ...

2011-12-26 · 2 min · 241 words · -

Linux命令之exit – 退出当前shell

Linux命令之exit – 退出当前shell 本文链接: http://codingstandards.iteye.com/blog/836625 (转载请注明出处) 用途说明 exit命令用于退出当前shell,在shell脚本中可以终止当前脚本执行。 常用参数 格式: exit n 退出。设置退出码为n。 (Cause the shell to exit with a status of n.) 格式: exit 退出。退出码不变,即为最后一个命令的退出码。 (If n is omitted, the exit status is that of the last command executed. ) 格式: $? 上一个命令的退出码。 格式: trap “commands” EXIT 退出时执行commands指定的命令。 ( A trap on EXIT is executed before the shell terminates.) 退出码 (exit status,或exit code) 的约定: 0表示成功 (Zero - Success) 非0表示失败 (Non-Zero - Failure) ...

2011-12-26 · 2 min · 359 words · -

gorun, golang, shell

gorun, golang, shell 用 golang 语言编写脚本 install gorun go get github.com/erning/gorun 能用 “./” 执行的 golang代码 /// 2>/dev/null ; gorun "$0" "$@" ; exit $? package main import ( "os/exec" "fmt" "os" ) func main() { println("Hello world!") var whoami []byte var err error var cmd *exec.Cmd cmd = exec.Command("whoami") if whoami, err = cmd.Output(); err != nil { fmt.Println(err) os.Exit(1) } // 默认输出有一个换行 fmt.Println(string(whoami)) } ./hello.go golang shell, 在 golang 中调用 shell func shellExec(command string) string { log.Printf("exec: %s\n", command) cmd := exec.Command("/bin/sh", "-c", command) var out bytes.Buffer cmd.Stdout = &out err := cmd.Run() if err != nil { log.Printf("failed to exec: %s, err: %v", command, err) return "" } ourStr := out.String() log.Printf("exec response: \n%s", ourStr) return ourStr } func shellExecFmt(format string, params ...interface{}) string { return shellExec(fmt.Sprintf(format, params...)) } go 调用 shell https://blog.csdn.net/qq_36874881/article/details/78234005 ...

2011-09-18 · 2 min · 352 words · -

shell 彩色 echo

shell 彩色 echo #黑底红字 echo -e 'E[31;40mThis prints in red.'; tput sgr0 #!/bin/bash echo -e 'E[COLOR1;COLOR2mSome text goes here.' COLOR1: Foreground Color COLOR2: Background Color #!/bin/bash echo -e 'E[32;40mThis prints in green.'; tput sgr0 echo -e:enable interpretation of backslash escapes -e "允许 反斜杠 (对字符)的转义" e[32;1m: 控制字体和背景颜色的转义字符,3037是字体颜色、4047是背景颜色 “m"终止该转义序列, 然后文本以结束的转义指定的属性显示. tput sgr0: 把终端设置恢复为原样. 如果省略这一句会使后续在该终端的输出仍为xx色. 色彩 前景色 背景色 黑 30 40 红 31 41 ...

2011-07-28 · 1 min · 83 words · -