我想补充:
function ps_mem {
python /home/vagrant/ps_mem/ps_mem.py -p $@
}
Run Code Online (Sandbox Code Playgroud)
~/.bashrc从命令行结束。我试过使用:
printf "function ps_mem {\n python /home/vagrant/ps_mem/ps_mem.py -p $@ \n}" >> ~/.bashrc
Run Code Online (Sandbox Code Playgroud)
虽然它几乎起作用了,但输入字段$@被忽略了,使得:
function ps_mem {
python /home/vagrant/ps_mem/ps_mem.py -p
}
Run Code Online (Sandbox Code Playgroud)
而是添加到~/.bashrc.
我有文件,file1.txt其内容如下:
Date List
-----------
Quarter Date
Year Date
Month Date
Run Code Online (Sandbox Code Playgroud)
现在我想从文件的每一行读取非空格元素并写入一个变量。例如,第 2 行变量应Quarter Year仅在删除空格后才包含。
我试过:
tail -1 file1.txt > variable1
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
我想弄清楚如何计算file.txt至少有一个数字或数字的行数。
到目前为止,我认为将计算行数:
wc -l filename.txt
Run Code Online (Sandbox Code Playgroud)
然后我想这个grep命令将显示file.txt包含至少一位数字的所有行:
grep -E '[0-9]+' list.txt
Run Code Online (Sandbox Code Playgroud)
我如何将它们结合起来找到我的问题的答案?
我想要这样的输出:name size 和hash:
myfile.txt 222M 24f4ce42e0bc39ddf7b7e879a
mynewfile.txt 353M a274613df45a94c3c67fe646
Run Code Online (Sandbox Code Playgroud)
因为name而且size只有我有
ll -h | awk '{print $9,$10,$11,$12,$5}'
Run Code Online (Sandbox Code Playgroud)
但是我怎样才能得到hash每个文件?我试过:
ll -h | awk '{print $9,$10,$11,$12,$5}' | md5sum
但我只得到一个哈希值。
我的文件内容为:
this line 1 no un1x
this lines 22 0
butbutbut this 33 22 has unix
but not 1
THIS is not
butbutbut ffff
second line
Run Code Online (Sandbox Code Playgroud)
awk 'NR==2 && NR==3 {f=$0;next} NR ==5 &&f{print;print f}' awk.write
Run Code Online (Sandbox Code Playgroud)
这里的问题是,f我只能保存nr==3我想在第 5 行之后移动第 2 行和第 3 行的值。
按照下面的脚本我有一个保留所有变量的唯一变量,我需要将每个变量与$VALUES:
#!/bin/bash
shell=""
groups=""
user=""
home=""
exec 3>&1
VALUES=$(dialog --ok-label "Submit" \
--backtitle "Linux User Managment" \
--title "Useradd" \
--form "Create a new user" \
15 50 0 \
"Username:" 1 1 "$user" 1 10 10 0 \
"Shell:" 2 1 "$shell" 2 10 15 0 \
"Group:" 3 1 "$groups" 3 10 8 0 \
"HOME:" 4 1 "$home" 4 10 40 0 \
2>&1 1>&3)
exec 3>&-
echo "$VALUES"
Run Code Online (Sandbox Code Playgroud) 我知道这是一个非常简单的问题,但我正在努力寻找解决方案。
我需要在/etc/aliases文件中自动查找和替换以下部分:
# Person who should get root's mail
#root: marc
Run Code Online (Sandbox Code Playgroud)
它需要看起来像:
# Person who should get root's mail
root: someone@something.tld
Run Code Online (Sandbox Code Playgroud)
我一直无法找到解决方案。大家能不能给点建议?没必要sed。
我正在使用一个工具来计算 javascript 文件的 cylomatic 复杂性。
例子:
jsc --minimal test.js
Run Code Online (Sandbox Code Playgroud)
此命令将提供以下输出。
????????????????????????????????????????????????????????????????
? File ? LOC ? Cyclomatic ? Halstead difficulty ?
????????????????????????????????????????????????????????????????
? /home/shray/test.js ? 23 ? 4 ? 10 ?
????????????????????????????????????????????????????????????????
Cyclomatic: min 4 mean 4.0 max 4
Halstead: min 10 mean 10.0 max 10
Run Code Online (Sandbox Code Playgroud)
现在我用
jsc --minimal test.js | grep "Cyclomatic:"
Run Code Online (Sandbox Code Playgroud)
这给了我输出
Cyclomatic: min 4 mean 4.0 max 4
Run Code Online (Sandbox Code Playgroud)
现在我有一个正则表达式,Cyclomatic:[\s]*min[\s]+([0-9]+)但我无法使用它来提取显示最小 Cylomatic 值的数字。
有什么帮助我如何在终端输出上输出 Min 或 Max Cyclomatic 复杂度值的值?
sample_dir2
`-- sample_dir
|-- cambridge
| `-- security
| |-- annex
| `-- parking
|-- history.exe
|-- markham
| |-- annex
| |-- building1
| `-- parking
`-- stenton
|-- admin
| `-- accounting
| `-- payroll
|-- gen_ed
| `-- Holidays
`-- lib_arts
`-- english.txt
Run Code Online (Sandbox Code Playgroud)
您当前的目录是stenton。删除会计目录:
您输入了:rm -r /admin/accounting
请重试。
您当前的目录是stenton。删除会计目录:
不应该rm -rf /admin/accounting工作吗?
我通过 SSH 连接到我的新 Linux 机器(没有物理访问权限)并且我有 root 凭据。但是,我无法运行 sudo 命令,因为之前以 root 身份登录的其他人在 sudoers 文件中出现了一些错误。
我曾经visudo将我的用户名添加到列表中,当前文件权限为:
-r--r----- 1 root root 3419 May 29 11:57 /etc/sudoers
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
>>> /etc/sudoers: syntax error near line 82 <<<
sudo: parse error in /etc/sudoers near line 82
sudo: no valid sudoers sources found, quitting
Run Code Online (Sandbox Code Playgroud)
请看一看,让我知道你们认为是什么问题。
我的 sudoers 文件的内容是:
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
##
## Examples are provided at the bottom …Run Code Online (Sandbox Code Playgroud)