首页
关于
Search
1
网站回归
20 阅读
2
以色列施行了种族灭绝吗?——数字来说明
15 阅读
3
当我指出 ChatGPT 的错误,它竟然改过来了
14 阅读
4
为什么要给日本单方面免签?
13 阅读
5
人类文明的瑰宝:苏联笑话
12 阅读
默认分类
科技
财经
军事
社会
历史
编程
随笔
登录
Search
标签搜索
苏联
以色列
巴勒斯坦
ChatGPT
JavaScript
AI
笑话
银行
华侨银行
终端
Mac Os
Linux
外国人
俄罗斯
女孩
滴滴
就业
手机
华为
广告
Bread
累计撰写
13
篇文章
累计收到
0
条评论
首页
栏目
默认分类
科技
财经
军事
社会
历史
编程
随笔
页面
关于
搜索到
3
篇与
的结果
2024-12-15
Linux 用户和用户组管理
创建和删除用户组groupadd 和 groupdel 命令可以创建和删除用户组groupadd test groupdel testuseradd 可以创建用户 -g 指定用户组,不指定则创建同名组 -d 指定 home 目录,不指定则为 /home/usernamegroupadd testg mkdir /home/testu useradd testu -g testg -d /home/testuuserdel 可以删除用户-r 同时删除 home 目录userdel testu -rid 命令可以查看用户所属的组id caddy uid=999(caddy) gid=997(caddy) groups=997(caddy)将用户添加到组可以用 usermod -aGgroupadd g1 groupadd g2 useradd u1 -g g1 usermod -aG u1 g2 usermod: group 'u1' does not exist usermod -aG g2 u1 id u1 uid=1000(u1) gid=1001(g1) groups=1001(g1),1002(g2)getent passwd 查看有哪些用户显示:用户名:密码(x代替):用户id:组id:描述信息:home目录:执行终端getent passwd sshd:x:101:65534::/run/sshd:/usr/sbin/nologin caddy:x:999:997:Caddy web server:/var/lib/caddy:/usr/sbin/nologin u1:x:1000:1001::/home/u1:/bin/shgetent group 可以查看组getent group _ssh:x:108: caddy:x:997: g1:x:1001: g2:x:1002:u1添加用户到 sudoerusermod -aG sudo username
2024年12月15日
10 阅读
0 评论
0 点赞
2024-12-14
Mac Os 在终端下复制粘贴字符串的时候,偶然多了一对 00~ 01~ 字符
Mac Os 的终端有一个鲜为人知很少使用的功:是括号粘贴模式(bracketed paste mode)。当您处于括号粘贴模式并粘贴到终端时,内容将由序列 \e[200~ 和 \e[201~ 包裹。例如,假设我从网站复制了字符串 echo 'hello'\n。当我粘贴到终端时,它会向正在运行的任何程序发送 \e[200~echo 'hello'\n\e[201~。这个功能可以让程序可以区分您手动输入的内容和您粘贴的内容。为什么需要这个功能呢?例如,许多终端应用程序专门处理某些字符:特别是当您按下回车键时,它会发送一个换行符。大多数 shell 会在此时执行输入缓冲区的内容。这通常是您想要的,但也可能不是。同时,这意味着如果您粘贴到终端中的任何内容中有换行符,它们也会运行输入缓冲区的内容。有时发现突然终端打开了括号粘贴模式,为什么终端会打开括号粘贴模式呢?其实大部分情况都不是我们主动开启的,是由个别软件在无意中将括号粘贴模式开启的。当开启了括号粘贴模式粘贴的字符串收尾会多了一对字符:00~ xxx 01~,一般情况下我们把括号粘贴模式关闭就可以了。解决方案只需在终端关闭括号粘贴模式即可:printf "\e[?2004l"那如果想主动开启括号粘贴模式该如何操作呢?也只需在终端开启括号粘贴模式即可:printf "\e[?2004h"
2024年12月14日
12 阅读
0 评论
0 点赞
2024-11-30
当我指出 ChatGPT 的错误,它竟然改过来了
ChatGPT 的回答一般挺不错的,比搜索引擎好很多。经常问它一些问题,大部分时候有满意的答案。当然不是 100% 满意,有时答案是错的,甚至明显是错的,然后我就会忽略错误答案,或者它的回答不完全对,但我也能补充出正确答案,然后就结束对话了。但今天我尝试指出它的错误,它竟然修复了。起因:我想写一段 JavaScript 使用 sftp 传文件夹的代码,首先安装依赖npm install ssh2-sftp-clientChatGPT 给的答案是:const Client = require('ssh2-sftp-client'); const path = require('path'); const fs = require('fs'); const sftp = new Client(); const config = { host: 'your.server.com', port: 22, username: 'your-username', password: 'your-password', // Alternatively, use SSH keys // privateKey: require('fs').readFileSync('/path/to/your/private-key') }; const localDir = '/path/to/local/folder'; // Local directory to upload const remoteDir = '/path/to/remote/folder'; // Remote destination directory // Function to recursively upload files and directories async function uploadDir(localPath, remotePath) { try { // Connect to the SFTP server await sftp.connect(config); // Ensure the remote directory exists await sftp.mkdir(remotePath, true); // 'true' means recursive mkdir // Read the contents of the local directory const files = await fs.promises.readdir(localPath); // Iterate through each file/subdirectory in the local directory for (let file of files) { const localFile = path.join(localPath, file); const remoteFile = path.join(remotePath, file); // Check if it's a file or directory const stats = await fs.promises.stat(localFile); if (stats.isDirectory()) { // If it's a directory, recursively upload it await uploadDir(localFile, remoteFile); } else { // If it's a file, upload it await sftp.put(localFile, remoteFile); console.log(`Uploaded file: ${localFile} -> ${remoteFile}`); } } console.log('Directory upload complete!'); } catch (err) { console.error('Error uploading directory:', err); } finally { // Close the SFTP connection sftp.end(); } } // Start uploading the directory uploadDir(localDir, remoteDir);这里有个问题,文件夹可能会有子文件夹,会递归调用 uploadDir 方法,在递归调用时会重复连接 sftp ,会报错:Error: connect: An existing SFTP connection is already defined at SftpClient.fmtError (/Users/wjf/wjf/repo/js-scp/node_modules/ssh2-sftp-client/src/index.js:94:22) at SftpClient.connect (/Users/wjf/wjf/repo/js-scp/node_modules/ssh2-sftp-client/src/index.js:188:20) at uploadDir (/Users/wjf/wjf/repo/js-scp/test2.js:32:20) at uploadDir (/Users/wjf/wjf/repo/js-scp/test2.js:50:23) { code: 'ERR_NOT_CONNECTED', custom: true }于是向 ChatGPT 指出错误:This code do not work. Because in the recursion, you connect sftp multiple times于是 ChatGPT 重新写了代码,把连接 sftp 放在递归函数的外面,给出了可运行的代码。const Client = require('ssh2-sftp-client'); const path = require('path'); const fs = require('fs'); const sftp = new Client(); const config = { host: 'your.server.com', port: 22, username: 'your-username', password: 'your-password', // Alternatively, use SSH keys // privateKey: require('fs').readFileSync('/path/to/your/private-key') }; const localDir = '/path/to/local/folder'; // Local directory to upload const remoteDir = '/path/to/remote/folder'; // Remote destination directory // Function to recursively upload files and directories async function uploadDir(localPath, remotePath) { try { // Read the contents of the local directory const files = await fs.promises.readdir(localPath); // Iterate through each file/subdirectory in the local directory for (let file of files) { const localFile = path.join(localPath, file); const remoteFile = path.join(remotePath, file); // Check if it's a file or directory const stats = await fs.promises.stat(localFile); if (stats.isDirectory()) { // If it's a directory, create it on the remote server await sftp.mkdir(remoteFile, true); // 'true' means recursive mkdir console.log(`Created directory: ${remoteFile}`); // Recursively upload the directory's contents await uploadDir(localFile, remoteFile); } else { // If it's a file, upload it await sftp.put(localFile, remoteFile); console.log(`Uploaded file: ${localFile} -> ${remoteFile}`); } } console.log('Directory upload complete!'); } catch (err) { console.error('Error uploading directory:', err); } } // Start the upload process async function startUpload() { try { // Connect to the SFTP server once await sftp.connect(config); // Upload the entire directory await uploadDir(localDir, remoteDir); } catch (err) { console.error('Error during connection or upload:', err); } finally { // Always end the SFTP connection when done sftp.end(); } } // Start the process startUpload();没想到人工智能还可以这样操作!
2024年11月30日
14 阅读
0 评论
0 点赞