假设此命令从 MacOS 终端命令行调用一个应用程序:
/Applications/Matlab_R2020a.app/bin/matlab
然后终端不再能够接受命令,MATLAB 是依赖的(即如果终端控制台关闭,MATLAB 将终止)。这种依赖关系叫什么?如何启动应用程序才能使其“独立”?也就是说,关闭终端不会关闭应用程序?
假设此命令从 MacOS 终端命令行调用一个应用程序:
/Applications/Matlab_R2020a.app/bin/matlab
然后终端不再能够接受命令,MATLAB 是依赖的(即如果终端控制台关闭,MATLAB 将终止)。这种依赖关系叫什么?如何启动应用程序才能使其“独立”?也就是说,关闭终端不会关闭应用程序?
上下文:macOS Catalina (zsh)
此脚本用于处理所有 JPEG 文件。此脚本不处理 .JPG 文件,但它确实处理 .jpg 文件。
top=/Users/user/Desktop/
for file in $top/**/*.jp*g(NDn.); do #selects filetypes: .jpg .jpeg
mogrify -auto-orient \
-gravity northWest \
-font "Arial-Bold-Italic" \
-pointsize 175 \
-fill red \
-annotate +30+30 $n \
-- $file &&
echo $file "was watermarked with" $n | tee -a forLooplog.txt
(( n++ ))
done
如何将第二行修改为不区分大小写并捕获 .JPG .JPEG 文件?
上下文:zsh Catalina MacOS:
可执行脚本BatesStamp 使用imagemagick 将数字标记到 jpg 文件中:
# BatesStamp: OVERWRITES and stamps ONE file with COUNTER (upper left corner)
# usage ./BatesStamp COUNTER PATH_FILE
# to be used with find & -exec: https://unix.stackexchange.com/a/96239/182280
COUNTER=$1 # 1st argument = number to be stamped upon .jpg file
PATH_FILE=$2 # 2nd argument = /path_to_file/Filename.jpg
convert $PATH_FILE -auto-orient -gravity northWest -font "Arial-Bold-Italic" -pointsize 175 \
-fill red -annotate +30+30 "$COUNTER" $PATH_FILE;
((COUNTER++)) #https://stackoverflow.com/a/21035146/4953146
echo "watermarked i= $COUNTER $PATH_FILE"
目标是用唯一编号标记目录树中的所有 .jpg 文件。我相信每次调用 $COUNTER 时都必须增加它:这确保每个文件都带有唯一的编号。该策略是遍历所有子目录find
以识别 .jpg 文件,并使用 $COUNTER++ 对每个 .jpg 文件进行 BatesStamp。
此脚本goBatesStamp.sh
遍历子目录以执行每个要由BatesStamp处理的 .jpg 文件
# goBastesStamp.sh
cd /Users/user/Desktop/AITH_USB_Hope_Submitted_MyCloud/PhotoGraphs_Work/A_Building_NoBulkhead. # navigate to top level directory
COUNTER=100 # initialize COUNTER
find /Users/user/Desktop/AITH_USB_Hope_Submitted_MyCloud/PhotoGraphs_Work/A_Building_NoBulkhead -iname "*.jpg" -exec ./BatesStamp $((COUNTER+=1)) {} \;
问题在于以命令开头的行find
。具体来说, COUNTER 不会增加。
测试表明 .jpg 文件标有数字 100 它表明 $((COUNTER++)) 是问题所在。将 COUNTER 递增 1 并将递增的 COUNTER 输入 ./BatesStamp 的正确语法是什么?
Ubuntu 16.04:使用以下命令创建了 64GB SD 卡映像:
date; sudo sh -c 'pv /dev/mmcblk0 >rpi4_Ubuntu18.1_64GB.image'; date
rasbperry pi SD 卡配备 Ubuntu 18.1
Ubuntu 16.04 笔记本电脑可以:
我知道可以将图像文件恢复到 SD 卡并使用zerofree处理卡并再次捕捉图像。如果能够在不将它们恢复到 SD 卡的情况下处理多个 .image 文件,那就太好了。
映像成功挂载到 /dev/loop9p2:
$ sudo losetup -P /dev/loop9 rpi4_Ubuntu18.1_64GB.image
$ ls -l /dev/loop9*
brw-rw---- 1 root disk 7, 9 Feb 2 19:12 /dev/loop9
brw-rw---- 1 root disk 259, 0 Feb 2 19:12 /dev/loop9p1
brw-rw---- 1 root disk 259, 1 Feb 2 19:12 /dev/loop9p2
零故障:
$ zerofree -v /dev/loop9p2
zerofree: failed to open filesystem /dev/loop9p2
需要零零sudo
:
$ sudo zerofree -v /dev/loop9p2
14346339/14348998/15073019
奖励:使用脚本pishrink减小图像大小
如果要复制 SD 卡的命令:
date; sudo sh -c 'pv /dev/mmcblk0 >pv sdcard.image'; date
将全新安装的 Raspbian 安装在 128GB SD 卡上,然后 sdcard.image 文件将是 128GB。假设全新安装 Raspbian 需要 10 GB 空间。大多数图像将不包含数据(“空白空间”)。如果生成的图像:
minimal SD-Card
(16GB SD 卡或更大)容量是可以接受全新安装 Raspbian的minimal SD-card
最小 SD 卡:因为没有 10GB 的 SD 卡,所以下一个更大的尺寸(16GB)被定义为最小的 SD 卡。
解决方案首选项是为了简单和标准的 Unix 命令(必要时使用脚本)。
2个目标如何实现?一个明智的策略是确定 SD 卡上的数据量(10GB)并将磁盘参数更改为略大于 10GB 的磁盘大小:在这种情况下为 16GB?
参考:
NOW=$(date +%Y_%m_%d.%H:%M:%S)
echo "NOW: $NOW"
目标是用空格替换and.
之间的字符。这是如何执行的?用空格字符替换会产生错误。d
%
.
设置了“侦听器”控制台:
mosquitto_sub -h test.mosquitto.org -t "myTopic" -v
mosquitto_pub
返回错误:
pi@raspberrypi:~ $ mosquitto_pub -h test.mosquitto.org -t 'myTopic' -m 'hello world'
**Error: The connection was lost.**
可以从命令行采取哪些步骤来诊断是否存在语法问题?
更新:
将 MQTT 服务器替换为iot.eclipse.org
不会出现错误并按预期返回有效负载。
侦听器控制台设置:
mosquitto_sub -h iot.eclipse.org -t "myTopic" -v
发送有效载荷:
mosquitto_pub -h iot.eclipse.org -t 'myTopic' -m 'hello world'
mosquitto_pub
返回:
pi@raspberrypi:~ $ mosquitto_sub -h iot.eclipse.org -t "myTopic" -v
myTopic hello world
发布有效载荷:
pi@raspberrypi:~ $ mosquitto_pub -h test.mosquitto.org -t 'myTopic' -m 'hello world'
更改 MQTT 代理表明没有语法错误,但是问题仍然是为什么在原始测试中返回错误
可以收集哪些信息以采取纠正措施以启用对示例 MQTT 主题的订阅?
目标是按照 说明的第 3 步重现测试(订阅和发布) :安装了 MQTT 服务器,但尝试使用 MQTT 客户端订阅失败:
pi@raspberrypi:~ $ mosquitto_sub –d –t armtronix_mqtt
**Error: Unknown option '–d'.**
Use 'mosquitto_sub --help' to see usage.
帮助页面:
pi@raspberrypi:~ $ mosquitto_sub --help
mosquitto_sub is a simple mqtt client that will subscribe to a single topic and print all messages it receives.
mosquitto_sub version 1.4.10 running on libmosquitto 1.4.10.
Usage: mosquitto_sub [-c] [-h host] [-k keepalive] [-p port] [-q qos] [-R] -t topic ...
[-C msg_count] [-T filter_out]
[-A bind_address] [-S]
[-i id] [-I id_prefix]
[-d] [-N] [--quiet] [-v]
[-u username [-P password]]
[--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]
[{--cafile file | --capath dir} [--cert file] [--key file]
[--ciphers ciphers] [--insecure]]
[--psk hex-key --psk-identity identity [--ciphers ciphers]]
[--proxy socks-url]
mosquitto_sub --help
-A : bind the outgoing socket to this host/ip address. Use to control which interface
the client communicates over.
-c : disable 'clean session' (store subscription and pending messages when client disconnects).
-C : disconnect and exit after receiving the 'msg_count' messages.
-d : enable debug messages.
-h : mqtt host to connect to. Defaults to localhost.
-i : id to use for this client. Defaults to mosquitto_sub_ appended with the process id.
-I : define the client id as id_prefix appended with the process id. Useful for when the
broker is using the clientid_prefixes option.
-k : keep alive in seconds for this client. Defaults to 60.
-N : do not add an end of line character when printing the payload.
-p : network port to connect to. Defaults to 1883.
-P : provide a password (requires MQTT 3.1 broker)
-q : quality of service level to use for the subscription. Defaults to 0.
-R : do not print stale messages (those with retain set).
-S : use SRV lookups to determine which host to connect to.
-t : mqtt topic to subscribe to. May be repeated multiple times.
-T : topic string to filter out of results. May be repeated.
-u : provide a username (requires MQTT 3.1 broker)
-v : print published messages verbosely.
-V : specify the version of the MQTT protocol to use when connecting.
Can be mqttv31 or mqttv311. Defaults to mqttv31.
--help : display this message.
--quiet : don't print error messages.
--will-payload : payload for the client Will, which is sent by the broker in case of
unexpected disconnection. If not given and will-topic is set, a zero
length message will be sent.
--will-qos : QoS level for the client Will.
--will-retain : if given, make the client Will retained.
--will-topic : the topic on which to publish the client Will.
--cafile : path to a file containing trusted CA certificates to enable encrypted
certificate based communication.
--capath : path to a directory containing trusted CA certificates to enable encrypted
communication.
--cert : client certificate for authentication, if required by server.
--key : client private key for authentication, if required by server.
--ciphers : openssl compatible list of TLS ciphers to support.
--tls-version : TLS protocol version, can be one of tlsv1.2 tlsv1.1 or tlsv1.
Defaults to tlsv1.2 if available.
--insecure : do not check that the server certificate hostname matches the remote
hostname. Using this option means that you cannot be sure that the
remote host is the server you wish to connect to and so is insecure.
Do not use this option in a production environment.
--psk : pre-shared-key in hexadecimal (no leading 0x) to enable TLS-PSK mode.
--psk-identity : client identity string for TLS-PSK mode.
--proxy : SOCKS5 proxy URL of the form:
socks5h://[username[:password]@]hostname[:port]
Only "none" and "username" authentication is supported.
MQTT 客户端安装日志:
pi@raspberrypi:~ $ sudo apt-get install mosquitto-clients
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
coinor-libipopt1v5 libmumps-seq-4.10.0 libraw15
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libmosquitto1
The following NEW packages will be installed:
libmosquitto1 mosquitto-clients
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 99.5 kB of archives.
After this operation, 222 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://raspbian.raspberrypi.org/raspbian stretch/main armhf libmosquitto1 armhf 1.4.10-3+deb9u4 [47.2 kB]
Get:2 http://raspbian.raspberrypi.org/raspbian stretch/main armhf mosquitto-clients armhf 1.4.10-3+deb9u4 [52.3 kB]
Fetched 99.5 kB in 1s (86.7 kB/s)
Selecting previously unselected package libmosquitto1:armhf.
(Reading database ... 141867 files and directories currently installed.)
Preparing to unpack .../libmosquitto1_1.4.10-3+deb9u4_armhf.deb ...
Unpacking libmosquitto1:armhf (1.4.10-3+deb9u4) ...
Selecting previously unselected package mosquitto-clients.
Preparing to unpack .../mosquitto-clients_1.4.10-3+deb9u4_armhf.deb ...
Unpacking mosquitto-clients (1.4.10-3+deb9u4) ...
Processing triggers for libc-bin (2.24-11+deb9u4) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up libmosquitto1:armhf (1.4.10-3+deb9u4) ...
Setting up mosquitto-clients (1.4.10-3+deb9u4) ...
Processing triggers for libc-bin (2.24-11+deb9u4) ...
.list
Raspbian buster 的文件安装:
pi@raspberrypi:~ $ cd /etc/apt/sources.list.d/
pi@raspberrypi:/etc/apt/sources.list.d $ sudo wget http://repo.mosquitto.org/debian/mosquitto-buster.list
--2019-08-01 00:01:16-- http://repo.mosquitto.org/debian/mosquitto-buster.list
Resolving repo.mosquitto.org (repo.mosquitto.org)... 85.119.83.194, 2001:ba8:1f1:f271::2
Connecting to repo.mosquitto.org (repo.mosquitto.org)|85.119.83.194|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 50 [application/octet-stream]
Saving to: ‘mosquitto-buster.list’
mosquitto-buster.list 100%[===================================================================>] 50 --.-KB/s in 0s
2019-08-01 00:01:17 (1.14 MB/s) - ‘mosquitto-buster.list’ saved [50/50]
pi@raspberrypi:/etc/apt/sources.list.d $ mosquitto_sub –t armtronix_mqtt
Error: Unknown option '–t'.
Use 'mosquitto_sub --help' to see usage.
pi@raspberrypi:/etc/apt/sources.list.d $ sudo apt-get install mosquitto-clients
Reading package lists... Done
Building dependency tree
Reading state information... Done
mosquitto-clients is already the newest version (1.4.10-3+deb9u4).
The following packages were automatically installed and are no longer required:
coinor-libipopt1v5 libmumps-seq-4.10.0 libraw15
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
pi@raspberrypi:/etc/apt/sources.list.d $ mosquitto_sub –t armtronix_mqtt
Error: Unknown option '–t'.
Use 'mosquitto_sub --help' to see usage.
pi@raspberrypi:/etc/apt/sources.list.d $ mosquitto_sub -d –t armtronix_mqtt
Error: Unknown option '–t'.
Use 'mosquitto_sub --help' to see usage.
已为 Raspberry pi 配置了 SD 卡。目标是完全复制 SD 卡(操作系统、应用程序、数据),以便副本在 rPi 中的功能与原始\主 SD 卡完全相同。
更新:假设:
哪些 UNIX 克隆选项适用于带有 SD 卡插槽和 USB SD 卡读卡器/写卡器的 Ubuntu HP 笔记本电脑。
USB SD卡RW是读卡器还是写卡器有区别吗?
一个目标(约束)是避免购买额外的硬件。
date; sudo sh -c 'cat sdcard.image >/dev/mmcblk0'; date
2019 年 6 月 3 日星期一 17:53:18 EDT [sudo] 用户密码:2019 年 6 月 3 日星期一 23:42:17 EDT
date; sudo sh -c 'pv sdcard.image >/dev/mmcblk0'; date
2019 年 6 月 4 日星期二 00:33:50 EDT [sudo] 用户密码:119GiB 6:06:12 [5.56MiB/s] [=================== ============>] 100%
2019 年 6 月 4 日星期二 06:43:05 EDT
对闪存 SD 卡的 gParted 分析显示相同的分区:
diskutil list
写入时请务必卸载 SD 卡:
sudo diskutil unmount /dev/disk#
其中 # 是 1,2,3...
我想设置一个 cron 作业来定期记录测量值。USB记忆棒安装在路由器中:
user@router:/tmp/home/root# uname -a
Linux 路由器 2.6.36.4brcmarm #2 SMP PREEMPT Sun Mar 20 16:06:18 EDT 2016 armv7l GNU/Linux
user@router:/tmp/home/root# curl http://THERMOSTAT/tstat/humidity >> /tmp/mnt/USBstick/CT80_data/C14HumidityData.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 18 0 18 0 0 80 0 --:--:-- --:--:-- --:--:-- 83
为什么将输出附加(>>)到文件会产生上表?
不附加时不生成该表:
curl http://THERMOSTAT/tstat/humidity
{"humidity":51.00}
是否有抑制表响应的命令选项?
我正在测试 MATLAB 以确保我正确地应用了它的功能。 来自数据源的示例包括:
我假设以上是正确的,并试图在 MATLAB 中重现结果:
dt = 日期时间(1160967053,'ConvertFrom','posixtime')
返回:
dt = 16-Oct-2006 02:50:53
这个结果是 +4 小时:我期待 +5 小时。纽约时间是UTC -5。有1小时的差异:夏令时?
将时区添加到函数时,结果与参考示例匹配:
T = datetime(1160967053,'ConvertFrom','posixtime','TimeZone','America/New_York')
T = 15-Oct-2006 22:50:53
命令:
grep -rl "KORD" ./
搜索目录并返回文件内容(不是标题)中包含“KORD”的文件列表。
Users-MacBook-Air:myPhotorec user$ grep -rl "KORD" ./
.//output_apikey.txt
.//recup_dir.17/f13470392.txt
.//recup_dir.49/f45361992.txt
.//recup_dir.49/f45362424.txt
.//recup_dir.53/f48768408.txt
.//recup_dir.53/f49295480.txt
是否有一个首选命令(xargs?)可以扩充 grep 命令以将输出文件列表打印到控制台并将每个文件复制到 a 目录: ./ORD ?
我怀疑“给猫剥皮”的方法不止一种:我期待看到不止一种解决方案
重复标签阻止将此修改后的帖子作为答案发布:
尝试:
grep -rl --null --include '*.txt' KORD . | xargs -0r cp -t /path/to/dest
因为此命令使用 NUL 分隔,所以它对于所有文件名都是安全的,包括那些包含空格、制表符甚至换行符的难命名的文件名。
以上需要 GNU cp
。对于 BSD/OSX,请尝试:
grep -rl --null --include '*.txt' KORD . | xargs -0 sh -c 'cp "$@" /path/to/dest' sh
这个怎么运作:
grep
选项和参数
-r
告诉 grep 递归搜索目录结构。(在 FreeBSD 上,-r
将跟随符号链接进入目录。对于 OS/X 或最新版本的 GNU 都不是这样grep
。)
--include '*.txt'
告诉 grep 仅返回名称与 glob 匹配的文件*.txt
(包括隐藏的文件,如.foo.txt
or .txt
)。
-l
告诉 grep 只返回匹配文件的名称,而不是匹配项本身。
--null
告诉 grep 使用 NUL 字符来分隔文件名。
LINUX/UNIX
告诉 grep 只查找内容包含正则表达式的文件LINUX/UNIX
.
在当前目录中搜索。您可以在最新版本的 GNU 中省略它grep
,但是您需要传递一个--
选项终止符来cp
防止以 . 开头的文件名-
。
xargs
选项和参数
-0
告诉 xargs 期待 NUL 分隔的输入。
-r
告诉 xargs 除非找到至少一个文件,否则不要运行该命令。(此选项在 BSD 或 OSX 上都不需要,并且与 OSX 的xargs
.)不兼容。)
cp -t /path/to/dest
将目录复制到目标目录。(-t
需要 GNU cp
。)
目标:将 UNIX NAS ( WD myCloud ) 安装到 UNIX 路由器。
已经做了什么(不要假设它是正确的):
ps | grep nfsd
19243 用户名 1376 R grep nfsd
检查 NAS 正在从 macbook 运行 NFS 服务器:
rpcinfo -T udp 192.168.X.XXX | grep nfs
100003 2 tcp 0.0.0.0.8.1 nfs unknown
100003 3 tcp 0.0.0.0.8.1 nfs unknown
100003 2 udp 0.0.0.0.8.1 nfs unknown
100003 3 udp 0.0.0.0.8.1 nfs unknown
尝试挂载 NAS 目录使用语法:
mount -t nfs server_IP_addr:/share_name /local_mount_point
mount -t NFS 192.168.X.XXX:/shares/Public/Data /mnt/nas
错误响应:
mount:在 /mnt/nas 上安装 192.168.X.XXX:/shares/Public/Data/ 失败: 没有这样的设备
我有兴趣了解如何诊断“没有这样的设备”的原因。是否有系统地解决问题的程序(一系列命令行测试)?
未找到 nfs 服务器模块且无法加载:
root@WDMyCloud root # service nfs status
-sh: service: not found
root@WDMyCloud root # systemctl status nfs-server
-sh: systemctl: not found
root@WDMyCloud root # lsmod | grep nfs
root@WDMyCloud root # modprobe nfs
modprobe: chdir(/lib/modules): No such file or directory
root@WDMyCloud root # ipkg
-sh: ipkg: **not found**
ps
命令:
root@WDMyCloud root # ps | grep -i nfs
375 root 0 SW< [nfsiod]
2813 root 0 SW [nfsd]
2814 root 0 SW [nfsd]
2815 root 0 SW [nfsd]
2816 root 0 SW [nfsd]
2817 root 0 SW [nfsd]
2818 root 0 SW [nfsd]
2819 root 0 SW [nfsd]
2820 root 0 SW [nfsd]
11491 root 2592 S grep -i nfs
showmount -e 192.168.X.X
返回一个空的导出列表