如何在没有扩展名且没有路径的情况下获取文件名?
以下给我没有扩展,但我仍然附加路径:
source_file_filename_no_ext=${source_file%.*}
Run Code Online (Sandbox Code Playgroud) 据我所知,&在命令之后使用是为了在后台运行它.
&用法示例:tar -czf file.tar.gz dirname &
但是怎么样&&?(看看这个例子:https://serverfault.com/questions/215179/centos-100-disk-full-how-to-remove-log-files-history-etc#answer-215188)
我有一个大约有一百万行的文件.我需要转到第320123行来检查数据.我怎么做?
使用Linux shell,如何从当前工作目录启动具有不同工作目录的程序?
例如,我有一个二进制文件helloworld,hello-world.txt在当前目录中创建该文件.该文件位于目录中/a.目前我在目录中/b.我想启动我的程序运行../a/helloworld并hello-world.txt在第三个目录中的某个位置/c.
我很难理解shell_exec()和exec()... 之间的区别
我一直习惯于exec()执行服务器端命令,我shell_exec()什么时候使用?
是否shell_exec()只是一个速记exec()?参数较少似乎是一样的.
例如,有时当我尝试启动Firefox时,它表示Firefox进程已在运行.所以我必须这样做:
jeremy@jeremy-desktop:~$ ps aux | grep firefox
jeremy 7451 25.0 27.4 170536 65680 ? Sl 22:39 1:18 /usr/lib/firefox-3.0.1/firefox
jeremy 7578 0.0 0.3 3004 768 pts/0 S+ 22:44 0:00 grep firefox
jeremy@jeremy-desktop:~$ kill 7451
Run Code Online (Sandbox Code Playgroud)
我想要的是一个可以为我做这一切的命令.它将在进程列表中为它(或其他)获取输入字符串和grep,并将终止输出中的所有进程:
jeremy@jeremy-desktop:~$ killbyname firefox
Run Code Online (Sandbox Code Playgroud)
我尝试在PHP中执行它但exec('ps aux')似乎只显示在PHP脚本本身中使用exec()执行的进程(因此它显示的唯一进程本身.)
在bash脚本的标题中,这两个语句之间的区别是什么?
#!/usr/bin/env bash
#!/usr/bin/bash
当我试图看到env手册页时,我得到了这个定义:
env - run a program in a modified environment
Run Code Online (Sandbox Code Playgroud)
这是什么意思?
假设我想复制目录的内容,不包括名称中包含"音乐"一词的文件和文件夹.
cp [exclude-matches] *Music* /target_directory
Run Code Online (Sandbox Code Playgroud)
什么应该代替[exclude-matches]来实现这个目标?
我正在尝试编写一个shell脚本,在远程服务器上创建一些目录,然后使用scp将文件从本地计算机复制到远程服务器上.这是我到目前为止所拥有的:
ssh -t user@server<<EOT
DEP_ROOT='/home/matthewr/releases'
datestamp=$(date +%Y%m%d%H%M%S)
REL_DIR=$DEP_ROOT"/"$datestamp
if [ ! -d "$DEP_ROOT" ]; then
echo "creating the root directory"
mkdir $DEP_ROOT
fi
mkdir $REL_DIR
exit
EOT
scp ./dir1 user@server:$REL_DIR
scp ./dir2 user@server:$REL_DIR
Run Code Online (Sandbox Code Playgroud)
每当我运行它时,我收到此消息:
Pseudo-terminal will not be allocated because stdin is not a terminal.
Run Code Online (Sandbox Code Playgroud)
脚本永远挂起.
我的公钥在服务器上是可信的,我可以在脚本之外运行所有命令.有任何想法吗?
命令的目的是什么,什么都不做,只是一个评论领导者,但实际上是一个内置的shell?
它比在每个调用中将注释插入脚本大约40%要慢,这可能会根据注释的大小而有很大差异.我能看到的唯一可能的原因是:
# poor man's delay function
for ((x=0;x<100000;++x)) ; do : ; done
# inserting comments into string of commands
command ; command ; : we need a comment in here for some reason ; command
# an alias for `true' (lazy programming)
while : ; do command ; done
Run Code Online (Sandbox Code Playgroud)
我想我真正想要的是它可能具有的历史应用.