Linux

Linux

cronsun 执行计划任务是报错 exec format error

Linux李魔佛 发表了文章 • 0 个评论 • 74 次浏览 • 2021-03-28 12:32 • 来自相关话题

把执行的python命令写到shell里面,也给了+x权限,还是报这个错误fork/exec /root/crontab_script/hello.sh: exec format error
单独执行shell的脚本是没有问题的。
 
经过试验测试,是因为shell脚本的开头没有没有添加:#!/bin/bash的标记。
 
在shell脚本的第一行添加上后就没有问题了。
 
附一个脚本批量处理: 自动在首行添加 #!/bin/bash
In [1]: folder='/root/crontab_script'

In [2]: import os

In [3]: filelist=os.listdir(folder)

In [6]: def change_file(filename):
...: with open(filename,'r') as fp:
...: content=fp.read()
...: content=content.strip()
...: concat='#!/bin/bash\n'
...: content=concat+content
...: with open(filename,'w') as fp:
...: fp.write(content)
...:

In [7]: for file in filelist:
...: if file.endswith('.sh'):
...: full_path = os.path.join(folder,file)
...: change_file(full_path) 查看全部
把执行的python命令写到shell里面,也给了+x权限,还是报这个错误
fork/exec /root/crontab_script/hello.sh: exec format error

单独执行shell的脚本是没有问题的。
 
经过试验测试,是因为shell脚本的开头没有没有添加:
#!/bin/bash
的标记。
 
在shell脚本的第一行添加上后就没有问题了。
 
附一个脚本批量处理: 自动在首行添加 #!/bin/bash
In [1]: folder='/root/crontab_script'

In [2]: import os

In [3]: filelist=os.listdir(folder)

In [6]: def change_file(filename):
...: with open(filename,'r') as fp:
...: content=fp.read()
...: content=content.strip()
...: concat='#!/bin/bash\n'
...: content=concat+content
...: with open(filename,'w') as fp:
...: fp.write(content)
...:

In [7]: for file in filelist:
...: if file.endswith('.sh'):
...: full_path = os.path.join(folder,file)
...: change_file(full_path)

cronsun 计划任务运行python脚本

Linux李魔佛 发表了文章 • 0 个评论 • 80 次浏览 • 2021-03-27 23:34 • 来自相关话题

在执行脚本那里,不能执行
cd xxxxx && python xxx.py这样的操作,这样貌似不会实际去执行
 
只能把上面的命令放到一个shell文件里面,比如worker.sh
然后把worker.sh 放到指定的位置,然后把这个shell的完整路径放入到 cronsun的计划任务的脚本里面。
 










 
 
  查看全部
在执行脚本那里,不能执行
 cd xxxxx && python xxx.py
这样的操作,这样貌似不会实际去执行
 
只能把上面的命令放到一个shell文件里面,比如worker.sh
然后把worker.sh 放到指定的位置,然后把这个shell的完整路径放入到 cronsun的计划任务的脚本里面。
 

PD19MdOZOi.png


chrome_IyOEpNaSm1.png

 
 
 

chrome secure shell插件无法上传下载文件

Linux李魔佛 发表了文章 • 0 个评论 • 184 次浏览 • 2021-02-22 19:28 • 来自相关话题

本来挺强大的一个插件,结果因为这个小功能导致鸡肋了,或者我不知道如何在下载文件??
 
后记:
只好用scp传输啦,还好windows平台的git客户端。
本来挺强大的一个插件,结果因为这个小功能导致鸡肋了,或者我不知道如何在下载文件??
 
后记:
只好用scp传输啦,还好windows平台的git客户端。

armdebian 修改大写键 为esc

Linux李魔佛 发表了文章 • 0 个评论 • 355 次浏览 • 2021-01-18 18:15 • 来自相关话题

一个几乎没什么用的按键,直接用软件把它映射为esc键。
 
armdebian上没有xmodmap 这个软件,但有一个xkeycaps的GUI的小应用,可以很方便地修改在图形界面上修改按键映射。
 
而且xkeycaps修改是持续有效的,如果想该回去,上面有个restore的功能,可以一键恢复默认值。
 
  查看全部
一个几乎没什么用的按键,直接用软件把它映射为esc键。
 
armdebian上没有xmodmap 这个软件,但有一个xkeycaps的GUI的小应用,可以很方便地修改在图形界面上修改按键映射。
 
而且xkeycaps修改是持续有效的,如果想该回去,上面有个restore的功能,可以一键恢复默认值。
 
 

bbdoc居然不支持代码搜索

Linux李魔佛 发表了文章 • 0 个评论 • 387 次浏览 • 2021-01-03 16:54 • 来自相关话题

那有什么用?辣鸡
什么python,cpp,java一个都不支持。
那有什么用?辣鸡
什么python,cpp,java一个都不支持。

win7安装sshd服务

闲聊李魔佛 发表了文章 • 0 个评论 • 488 次浏览 • 2020-12-29 08:52 • 来自相关话题

Installing SFTP/SSH Server on Windows using OpenSSH
Recently, Microsoft has released a port of OpenSSH for Windows. You can use the package to set up an SFTP/SSH server on Windows.Installing SFTP/SSH Server

On Windows 10 version 1803 and newer
On earlier versions of Windows

https://github.com/PowerShell/Win32-OpenSSH/releases 

Configuring SSH server
Setting up SSH public key authentication
Connecting to the server

Finding Host Key
Connecting

Further readingInstalling SFTP/SSH Server
On Windows 10 version 1803 and newerIn Settings app, go to Apps > Apps & features > Manage optional features.

Locate “OpenSSH server” feature, expand it, and select Install.Binaries are installed to %WINDIR%\System32\OpenSSH. 
Configuration file (sshd_config) and host keys are installed to %ProgramData%\ssh
 (only after the server is started for the first time).
 
You may still want to use the following manual installation, if you want to install a newer version of OpenSSH than the one built into Windows 10.

On earlier versions of WindowsDownload the latest OpenSSH for Windows binaries (package OpenSSH-Win64.zip or OpenSSH-Win32.zip)

As the Administrator, extract the package to C:\Program Files\OpenSSH
As the Administrator, install sshd and ssh-agent services:
 
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
 
Configuring SSH serverAllow incoming connections to SSH server in Windows Firewall:

When installed as an optional feature, the firewall rule “OpenSSH SSH Server (sshd)” should have been created automatically. If not, proceed to create and enable the rule as follows.
Either run the following PowerShell command as the Administrator:New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\System32\OpenSSH\sshd.exe"

Replace C:\System32\OpenSSH\sshd.exe with the actual path to the sshd.exe 
(C:\Program Files\OpenSSH\ssh.exe, 
 
had you followed the manual installation instructions above).or go to Control Panel > System and Security > Windows Firewall1 > Advanced Settings > Inbound Rules and add a new rule for port 22.

Start the service and/or configure automatic start:

Go to Control Panel > System and Security > Administrative Tools and open Services. Locate OpenSSH SSH Server service.

If you want the server to start automatically when your machine is started: Go to Action > Properties. In the Properties dialog, change Startup type to Automatic and confirm.

Start the OpenSSH SSH Server service by clicking the Start the service.These instructions are partially based on the official deployment instructions. 查看全部
Installing SFTP/SSH Server on Windows using OpenSSH
Recently, Microsoft has released a port of OpenSSH for Windows. You can use the package to set up an SFTP/SSH server on Windows.Installing SFTP/SSH Server

On Windows 10 version 1803 and newer
On earlier versions of Windows

https://github.com/PowerShell/Win32-OpenSSH/releases 

Configuring SSH server
Setting up SSH public key authentication
Connecting to the server

Finding Host Key
Connecting

Further readingInstalling SFTP/SSH Server
On Windows 10 version 1803 and newerIn Settings app, go to Apps > Apps & features > Manage optional features.

Locate “OpenSSH server” feature, expand it, and select Install.Binaries are installed to %WINDIR%\System32\OpenSSH. 
Configuration file (sshd_config) and host keys are installed to %ProgramData%\ssh
 (only after the server is started for the first time).
 
You may still want to use the following manual installation, if you want to install a newer version of OpenSSH than the one built into Windows 10.

On earlier versions of WindowsDownload the latest OpenSSH for Windows binaries (package OpenSSH-Win64.zip or OpenSSH-Win32.zip)

As the Administrator, extract the package to C:\Program Files\OpenSSH
As the Administrator, install sshd and ssh-agent services:
 
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
 
Configuring SSH serverAllow incoming connections to SSH server in Windows Firewall:

When installed as an optional feature, the firewall rule “OpenSSH SSH Server (sshd)” should have been created automatically. If not, proceed to create and enable the rule as follows.
Either run the following PowerShell command as the Administrator:New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\System32\OpenSSH\sshd.exe"

Replace C:\System32\OpenSSH\sshd.exe with the actual path to the sshd.exe 
(C:\Program Files\OpenSSH\ssh.exe, 
 
had you followed the manual installation instructions above).or go to Control Panel > System and Security > Windows Firewall1 > Advanced Settings > Inbound Rules and add a new rule for port 22.

Start the service and/or configure automatic start:

Go to Control Panel > System and Security > Administrative Tools and open Services. Locate OpenSSH SSH Server service.

If you want the server to start automatically when your machine is started: Go to Action > Properties. In the Properties dialog, change Startup type to Automatic and confirm.

Start the OpenSSH SSH Server service by clicking the Start the service.These instructions are partially based on the official deployment instructions.

网易云音乐居然还有linux版本,网易还是一个良心企业

Linux李魔佛 发表了文章 • 0 个评论 • 655 次浏览 • 2020-12-18 11:31 • 来自相关话题

 
啥时候有道云笔记也搞一个linux版本的呀.
 
如果要在ubuntu16.04上安装,就不要去官网下载,gclib库不兼容,要升级到18.04, 会会很折腾.
直接下载:
$ wget http://s1.music.126.net/downlo ... 4.deb --默认下载到Desktop
 
然后sudo dpkg -i xxxxx.deb 就可以啦

良心的还要搜狗,linux下的输入法好用.
 
更新:
安装上面方法安装后,可以打开,可以播放mv,不过就是无法播放声音.
需要解决依赖问题.
网上找到了好的方法: 亲测有效
 
更改源为阿里云的源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiversean然后运行 apt -f install 修复依赖关系就可以了.
  查看全部
Workspace_1_0091.png

 
啥时候有道云笔记也搞一个linux版本的呀.
 
如果要在ubuntu16.04上安装,就不要去官网下载,gclib库不兼容,要升级到18.04, 会会很折腾.
直接下载:
$ wget http://s1.music.126.net/downlo ... 4.deb --默认下载到Desktop
 
然后sudo dpkg -i xxxxx.deb 就可以啦

良心的还要搜狗,linux下的输入法好用.
 
更新:
安装上面方法安装后,可以打开,可以播放mv,不过就是无法播放声音.
需要解决依赖问题.
网上找到了好的方法: 亲测有效
 
更改源为阿里云的源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiversean
然后运行 apt -f install 修复依赖关系就可以了.
 

vimium 配合chrome 真的好用,尤其用惯vim的用户

Linux李魔佛 发表了文章 • 0 个评论 • 394 次浏览 • 2020-11-22 01:59 • 来自相关话题

chrome最好用的插件,没有之一哈。





 
上面是vimium的快捷键用法
 
chrome最好用的插件,没有之一哈。

clipboard.png

 
上面是vimium的快捷键用法
 

windows下的分区挂载到linux下面,然后docker在上面挂载-无法识别

Linux李魔佛 发表了文章 • 0 个评论 • 429 次浏览 • 2020-11-11 02:40 • 来自相关话题

坑:
windows下的分区挂载到linux下面,然后docker在上面挂载-无法识别。
情况是这样的:
双系统的环境,一个ubuntu,一个windows。 ubuntu上的有个docker,但是ubuntu的分区比较小,需要挂载windows的ntfs分区来扩展空间。
其他程序用起来没什么问题,可是,在用docker 挂在windows分区下的文件夹,总是报错,用的 -v xxxx:xxxx 方式。
同样的docker启动命令,在ubuntu下的目录就没有问题,所以就开始怀疑是权限问题。
但是经过一系列的mount操作,chmod也给足了了权限,可是还没无法启动docker。
后来没办法,只好把windows分区缩小容量,把多余的容量格式化为ext分区格式,然后重新用docker mount -v, 后面docker就可以正常启动了。 查看全部

坑:
windows下的分区挂载到linux下面,然后docker在上面挂载-无法识别。
情况是这样的:
双系统的环境,一个ubuntu,一个windows。 ubuntu上的有个docker,但是ubuntu的分区比较小,需要挂载windows的ntfs分区来扩展空间。
其他程序用起来没什么问题,可是,在用docker 挂在windows分区下的文件夹,总是报错,用的 -v xxxx:xxxx 方式。
同样的docker启动命令,在ubuntu下的目录就没有问题,所以就开始怀疑是权限问题。
但是经过一系列的mount操作,chmod也给足了了权限,可是还没无法启动docker。
后来没办法,只好把windows分区缩小容量,把多余的容量格式化为ext分区格式,然后重新用docker mount -v, 后面docker就可以正常启动了。

斐讯N1 armlinux 长时间运行会导致文件系统只读 readonly

Linux李魔佛 发表了文章 • 0 个评论 • 558 次浏览 • 2020-10-25 00:24 • 来自相关话题

斐讯N1 刷的armlinux 长时间运行会导致文件系统只读 readonly。
比如放着几个晚上不关机,然后文件系统变成了只读,无法写入文件,提示只读系统。
 
原因是系统分区有坏道。 可能由于关机使用拔电源的方式导致的。
所以要养成好的习惯,正常关机,使用命令 shutdown -h 或者点击关机按钮就好了。
 
那么如果出现了上述问题,怎么办?
 
可以使用用U盘启动,运行一次e2fsck /dev/mmcblk1p2
然后选择Y,修复坏道就可以了。
 
U盘启动就是之前刷Armlinux时的那个U盘。
接上U盘,然后上电启动即可。 然后进入系统运行上述的命令:
e2fsck /dev/mmcblk1p2
 
  查看全部
斐讯N1 刷的armlinux 长时间运行会导致文件系统只读 readonly。
比如放着几个晚上不关机,然后文件系统变成了只读,无法写入文件,提示只读系统。
 
原因是系统分区有坏道。 可能由于关机使用拔电源的方式导致的。
所以要养成好的习惯,正常关机,使用命令 shutdown -h 或者点击关机按钮就好了。
 
那么如果出现了上述问题,怎么办?
 
可以使用用U盘启动,运行一次e2fsck /dev/mmcblk1p2
然后选择Y,修复坏道就可以了。
 
U盘启动就是之前刷Armlinux时的那个U盘。
接上U盘,然后上电启动即可。 然后进入系统运行上述的命令:
e2fsck /dev/mmcblk1p2
 
 

Started update UTMP about system Runlevel during booting ubuntu/armlinux

Linux李魔佛 发表了文章 • 0 个评论 • 1186 次浏览 • 2020-10-20 13:33 • 来自相关话题

I hit this issue on my ARMLinux (Same arch as Ubuntu), i can't login system with graphic. It always stuck on the line 
 
Started update UTMP about system Runlevel
 
Finally, i try to enter into secure mode and check logs.
it was caused by system disk is out of space.
So i try to delete some unless file to release some space, then reboot system, then everything is ok now.
 
http://30daydo.com/article/617
  查看全部
I hit this issue on my ARMLinux (Same arch as Ubuntu), i can't login system with graphic. It always stuck on the line 
 
Started update UTMP about system Runlevel
 
Finally, i try to enter into secure mode and check logs.
it was caused by system disk is out of space.
So i try to delete some unless file to release some space, then reboot system, then everything is ok now.
 
http://30daydo.com/article/617
 

zsh历史记录文件损坏: zsh: corrupt history file /home/admin/.zsh_history

Linux李魔佛 发表了文章 • 0 个评论 • 995 次浏览 • 2020-10-09 18:12 • 来自相关话题

由于不正确关机,或者突然重启造成的文件属性损坏。可以使用以下方式修复。cd ~
mv .zsh_history .zsh_history_bad
strings .zsh_history_bad > .zsh_history
fc -R .zsh_history
如果最后一步提示出错 fc的参数不对,可以进入zsh,然后再执行 fc -R .zsh_histroy
原创文章,转载请注明出处:
http://30daydo.com/article/612
  查看全部
由于不正确关机,或者突然重启造成的文件属性损坏。可以使用以下方式修复。
cd ~
mv .zsh_history .zsh_history_bad
strings .zsh_history_bad > .zsh_history
fc -R .zsh_history

如果最后一步提示出错 fc的参数不对,可以进入zsh,然后再执行 fc -R .zsh_histroy
原创文章,转载请注明出处:
http://30daydo.com/article/612
 

crontab定时运行图形程序

Linux李魔佛 发表了文章 • 0 个评论 • 1249 次浏览 • 2019-08-26 15:56 • 来自相关话题

默认情况不会显示任何图形的界面,需要在程序前添加 
export DISPLAY=:0;* * * * * export DISPLAY=:0; gedit 
附一个linux下桌面提醒GUI程序,定时提醒你休息哈:
 
import pyautogui as pag
import datetime

def neck_rest():
f = open('neck_record.txt', 'a')
ret = pag.prompt("Rest! Protect your neck !")
if ret == 'rest':
f.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
f.write('\t')
f.write('Rest')
f.write('\n')
else:
f.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
f.write('\t')
f.write('Failed to rest')
f.write('\n')
f.close()

neck_rest()
程序保存为task.py
然后设定crontab任务:

* * * * * export DISPLAY=:0; python task.py 
即可

  查看全部
默认情况不会显示任何图形的界面,需要在程序前添加 
export DISPLAY=:0;
* * * * * export DISPLAY=:0; gedit
 
附一个linux下桌面提醒GUI程序,定时提醒你休息哈:
 
import pyautogui as pag
import datetime

def neck_rest():
f = open('neck_record.txt', 'a')
ret = pag.prompt("Rest! Protect your neck !")
if ret == 'rest':
f.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
f.write('\t')
f.write('Rest')
f.write('\n')
else:
f.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
f.write('\t')
f.write('Failed to rest')
f.write('\n')
f.close()

neck_rest()

程序保存为task.py
然后设定crontab任务:

* * * * * export DISPLAY=:0; python task.py 
即可

 

alias别名 等号后面不用

Linux李魔佛 发表了文章 • 0 个评论 • 1174 次浏览 • 2019-08-12 14:17 • 来自相关话题

alias sync="git commit -m 'update' -a && git push origin master"
alias fetch="git fetch origin"
alias dj="python manage.py runserver 0.0.0.0"
alias py2="python2"
alias py3="python3"
alias ggg="cd ~/git" 查看全部
alias sync="git commit -m 'update' -a && git push origin master"
alias fetch="git fetch origin"
alias dj="python manage.py runserver 0.0.0.0"
alias py2="python2"
alias py3="python3"
alias ggg="cd ~/git"

ubuntu/linux shell根据进程名杀死进程 一句搞定

Linux李魔佛 发表了文章 • 0 个评论 • 2194 次浏览 • 2019-04-19 23:15 • 来自相关话题

ps -ef | grep "进程名" | grep -v grep | cut -c 10-16 | xargs kill -9 
比如我要杀死python的进程,就使用
 

ps -ef | grep "python" | grep -v grep | cut -c 10-16 | xargs kill -9
 
来使用。
 
grep -v grep 因为 ps 会把grep python这个进程也打印出来,所以-v 是反转的意思,不匹配的才打印出来,然后cut 是找出10到16位的字符,这里需要大家根据自己的用户名来调整。
一般ps -ef输出是 前面 用户名,然后空格, 接着是进程号。 如果你的用户名很长,可以调整10-16的位置来适应。
 
后面就是把进程号传递给kill作为参数,-9 是强制杀死。
 
  查看全部
ps -ef | grep "进程名" | grep -v grep | cut -c 10-16 | xargs kill -9
 
比如我要杀死python的进程,就使用
 

ps -ef | grep "python" | grep -v grep | cut -c 10-16 | xargs kill -9
 
来使用。
 
grep -v grep 因为 ps 会把grep python这个进程也打印出来,所以-v 是反转的意思,不匹配的才打印出来,然后cut 是找出10到16位的字符,这里需要大家根据自己的用户名来调整。
一般ps -ef输出是 前面 用户名,然后空格, 接着是进程号。 如果你的用户名很长,可以调整10-16的位置来适应。
 
后面就是把进程号传递给kill作为参数,-9 是强制杀死。
 
 

linux目录跳转利器 z.sh

Linux李魔佛 发表了文章 • 0 个评论 • 3953 次浏览 • 2016-06-17 17:32 • 来自相关话题

使用linux的朋友,经常要在命令下面运行命令,并且频繁地在不同的目录切换, 不断的cd ..,cd ../../../../../../bin,或者cd ../../../../../../../../../, 或者cd ~/Download/bin/
 
浪费时间且效率低下。
 
推荐大家使用一个小脚本,可以快速切换目录,不需要经常cd了。
 
拷贝下面的代码,保存为z.sh,放在用户目录下,/home/xxxx, xxx为用户名, 然后 给予 777权限, chmod 777 z.sh
 
然后 修改 .bashrc 文件, vim ~/.bashrc
 
在文件的最后添加一句 source ~/z.sh
 
然后保存.bashrc
 
然后运行 source ~./bashrc , 然后就马上生效了。
 
然后你进入到某一个目录,比如 /home/user/build/data/bin/hello/, 运行 z
 
系统会纪录你的hello目录一次,
 
下一次在其他目录比如在/etc/apt/,如果要跳转到 /home/user/build/data/bin/hello/,
直接运行 z hello 就可以了。# Copyright (c) 2009 rupa deadwyler under the WTFPL license

# maintains a jump-list of the directories you actually use
#
# INSTALL:
# * put something like this in your .bashrc/.zshrc:
# . /path/to/z.sh
# * cd around for a while to build up the db
# * PROFIT!!
# * optionally:
# set $_Z_CMD in .bashrc/.zshrc to change the command (default z).
# set $_Z_DATA in .bashrc/.zshrc to change the datafile (default ~/.z).
# set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
# set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself.
# set $_Z_EXCLUDE_DIRS to an array of directories to exclude.
# set $_Z_OWNER to your username if you want use z while sudo with $HOME kept
#
# USE:
# * z foo # cd to most frecent dir matching foo
# * z foo bar # cd to most frecent dir matching foo and bar
# * z -r foo # cd to highest ranked dir matching foo
# * z -t foo # cd to most recently accessed dir matching foo
# * z -l foo # list matches instead of cd
# * z -c foo # restrict matches to subdirs of $PWD

[ -d "${_Z_DATA:-$HOME/.z}" ] && {
echo "ERROR: z.sh's datafile (${_Z_DATA:-$HOME/.z}) is a directory."
}

_z() {

local datafile="${_Z_DATA:-$HOME/.z}"

# bail if we don't own ~/.z and $_Z_OWNER not set
[ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return

# add entries
if [ "$1" = "--add" ]; then
shift

# $HOME isn't worth matching
[ "$*" = "$HOME" ] && return

# don't track excluded directory trees
local exclude
for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do
case "$*" in "$exclude*") return;; esac
done

# maintain the data file
local tempfile="$datafile.$RANDOM"
while read line; do
# only count directories
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v path="$*" -v now="$(date +%s)" -F"|" '
BEGIN {
rank[path] = 1
time[path] = now
}
$2 >= 1 {
# drop ranks below 1
if( $1 == path ) {
rank[$1] = $2 + 1
time[$1] = now
} else {
rank[$1] = $2
time[$1] = $3
}
count += $2
}
END {
if( count > 9000 ) {
# aging
for( x in rank ) print x "|" 0.99*rank[x] "|" time[x]
} else for( x in rank ) print x "|" rank[x] "|" time[x]
}
' 2>/dev/null >| "$tempfile"
# do our best to avoid clobbering the datafile in a race condition
if [ $? -ne 0 -a -f "$datafile" ]; then
env rm -f "$tempfile"
else
[ "$_Z_OWNER" ] && chown $_Z_OWNER:$(id -ng $_Z_OWNER) "$tempfile"
env mv -f "$tempfile" "$datafile" || env rm -f "$tempfile"
fi

# tab completion
elif [ "$1" = "--complete" -a -s "$datafile" ]; then
while read line; do
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v q="$2" -F"|" '
BEGIN {
if( q == tolower(q) ) imatch = 1
q = substr(q, 3)
gsub(" ", ".*", q)
}
{
if( imatch ) {
if( tolower($1) ~ tolower(q) ) print $1
} else if( $1 ~ q ) print $1
}
' 2>/dev/null

else
# list/go
while [ "$1" ]; do case "$1" in
--) while [ "$1" ]; do shift; local fnd="$fnd${fnd:+ }$1";done;;
-*) local opt=${1:1}; while [ "$opt" ]; do case ${opt:0:1} in
c) local fnd="^$PWD $fnd";;
h) echo "${_Z_CMD:-z} [-chlrtx] args" >&2; return;;
x) sed -i -e "\:^${PWD}|.*:d" "$datafile";;
l) local list=1;;
r) local typ="rank";;
t) local typ="recent";;
esac; opt=${opt:1}; done;;
*) local fnd="$fnd${fnd:+ }$1";;
esac; local last=$1; [ "$#" -gt 0 ] && shift; done
[ "$fnd" -a "$fnd" != "^$PWD " ] || local list=1

# if we hit enter on a completion just go there
case "$last" in
# completions will always start with /
/*) [ -z "$list" -a -d "$last" ] && cd "$last" && return;;
esac

# no file yet
[ -f "$datafile" ] || return

local cd
cd="$(while read line; do
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" '
function frecent(rank, time) {
# relate frequency and time
dx = t - time
if( dx < 3600 ) return rank * 4
if( dx < 86400 ) return rank * 2
if( dx < 604800 ) return rank / 2
return rank / 4
}
function output(files, out, common) {
# list or return the desired directory
if( list ) {
cmd = "sort -n >&2"
for( x in files ) {
if( files[x] ) printf "%-10s %s\n", files[x], x | cmd
}
if( common ) {
printf "%-10s %s\n", "common:", common > "/dev/stderr"
}
} else {
if( common ) out = common
print out
}
}
function common(matches) {
# find the common root of a list of matches, if it exists
for( x in matches ) {
if( matches[x] && (!short || length(x) < length(short)) ) {
short = x
}
}
if( short == "/" ) return
# use a copy to escape special characters, as we want to return
# the original. yeah, this escaping is awful.
clean_short = short
gsub(/\[\(\)\[\]\|\]/, "\\\\&", clean_short)
for( x in matches ) if( matches[x] && x !~ clean_short ) return
return short
}
BEGIN {
gsub(" ", ".*", q)
hi_rank = ihi_rank = -9999999999
}
{
if( typ == "rank" ) {
rank = $2
} else if( typ == "recent" ) {
rank = $3 - t
} else rank = frecent($2, $3)
if( $1 ~ q ) {
matches[$1] = rank
} else if( tolower($1) ~ tolower(q) ) imatches[$1] = rank
if( matches[$1] && matches[$1] > hi_rank ) {
best_match = $1
hi_rank = matches[$1]
} else if( imatches[$1] && imatches[$1] > ihi_rank ) {
ibest_match = $1
ihi_rank = imatches[$1]
}
}
END {
# prefer case sensitive
if( best_match ) {
output(matches, best_match, common(matches))
} else if( ibest_match ) {
output(imatches, ibest_match, common(imatches))
}
}
')"
[ $? -gt 0 ] && return
[ "$cd" ] && cd "$cd"
fi
}

alias ${_Z_CMD:-z}='_z 2>&1'

[ "$_Z_NO_RESOLVE_SYMLINKS" ] || _Z_RESOLVE_SYMLINKS="-P"

if type compctl >/dev/null 2>&1; then
# zsh
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# populate directory list, avoid clobbering any other precmds.
if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then
_z_precmd() {
_z --add "${PWD:a}"
}
else
_z_precmd() {
_z --add "${PWD:A}"
}
fi
[[ -n "${precmd_functions[(r)_z_precmd]}" ]] || {
precmd_functions[$(($#precmd_functions+1))]=_z_precmd
}
}
_z_zsh_tab_completion() {
# tab completion
local compl
read -l compl
reply=(${(f)"$(_z --complete "$compl")"})
}
compctl -U -K _z_zsh_tab_completion _z
elif type complete >/dev/null 2>&1; then
# bash
# tab completion
complete -o filenames -C '_z --complete "$COMP_LINE"' ${_Z_CMD:-z}
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# populate directory list. avoid clobbering other PROMPT_COMMANDs.
grep "_z --add" <<< "$PROMPT_COMMAND" >/dev/null || {
PROMPT_COMMAND="$PROMPT_COMMAND"$'\n''_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;'
}
}
fi 查看全部
使用linux的朋友,经常要在命令下面运行命令,并且频繁地在不同的目录切换, 不断的cd ..,cd ../../../../../../bin,或者cd ../../../../../../../../../, 或者cd ~/Download/bin/
 
浪费时间且效率低下。
 
推荐大家使用一个小脚本,可以快速切换目录,不需要经常cd了。
 
拷贝下面的代码,保存为z.sh,放在用户目录下,/home/xxxx, xxx为用户名, 然后 给予 777权限, chmod 777 z.sh
 
然后 修改 .bashrc 文件, vim ~/.bashrc
 
在文件的最后添加一句 source ~/z.sh
 
然后保存.bashrc
 
然后运行 source ~./bashrc , 然后就马上生效了。
 
然后你进入到某一个目录,比如 /home/user/build/data/bin/hello/, 运行 z
 
系统会纪录你的hello目录一次,
 
下一次在其他目录比如在/etc/apt/,如果要跳转到 /home/user/build/data/bin/hello/,
直接运行 z hello 就可以了。
# Copyright (c) 2009 rupa deadwyler under the WTFPL license

# maintains a jump-list of the directories you actually use
#
# INSTALL:
# * put something like this in your .bashrc/.zshrc:
# . /path/to/z.sh
# * cd around for a while to build up the db
# * PROFIT!!
# * optionally:
# set $_Z_CMD in .bashrc/.zshrc to change the command (default z).
# set $_Z_DATA in .bashrc/.zshrc to change the datafile (default ~/.z).
# set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
# set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself.
# set $_Z_EXCLUDE_DIRS to an array of directories to exclude.
# set $_Z_OWNER to your username if you want use z while sudo with $HOME kept
#
# USE:
# * z foo # cd to most frecent dir matching foo
# * z foo bar # cd to most frecent dir matching foo and bar
# * z -r foo # cd to highest ranked dir matching foo
# * z -t foo # cd to most recently accessed dir matching foo
# * z -l foo # list matches instead of cd
# * z -c foo # restrict matches to subdirs of $PWD

[ -d "${_Z_DATA:-$HOME/.z}" ] && {
echo "ERROR: z.sh's datafile (${_Z_DATA:-$HOME/.z}) is a directory."
}

_z() {

local datafile="${_Z_DATA:-$HOME/.z}"

# bail if we don't own ~/.z and $_Z_OWNER not set
[ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return

# add entries
if [ "$1" = "--add" ]; then
shift

# $HOME isn't worth matching
[ "$*" = "$HOME" ] && return

# don't track excluded directory trees
local exclude
for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do
case "$*" in "$exclude*") return;; esac
done

# maintain the data file
local tempfile="$datafile.$RANDOM"
while read line; do
# only count directories
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v path="$*" -v now="$(date +%s)" -F"|" '
BEGIN {
rank[path] = 1
time[path] = now
}
$2 >= 1 {
# drop ranks below 1
if( $1 == path ) {
rank[$1] = $2 + 1
time[$1] = now
} else {
rank[$1] = $2
time[$1] = $3
}
count += $2
}
END {
if( count > 9000 ) {
# aging
for( x in rank ) print x "|" 0.99*rank[x] "|" time[x]
} else for( x in rank ) print x "|" rank[x] "|" time[x]
}
' 2>/dev/null >| "$tempfile"
# do our best to avoid clobbering the datafile in a race condition
if [ $? -ne 0 -a -f "$datafile" ]; then
env rm -f "$tempfile"
else
[ "$_Z_OWNER" ] && chown $_Z_OWNER:$(id -ng $_Z_OWNER) "$tempfile"
env mv -f "$tempfile" "$datafile" || env rm -f "$tempfile"
fi

# tab completion
elif [ "$1" = "--complete" -a -s "$datafile" ]; then
while read line; do
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v q="$2" -F"|" '
BEGIN {
if( q == tolower(q) ) imatch = 1
q = substr(q, 3)
gsub(" ", ".*", q)
}
{
if( imatch ) {
if( tolower($1) ~ tolower(q) ) print $1
} else if( $1 ~ q ) print $1
}
' 2>/dev/null

else
# list/go
while [ "$1" ]; do case "$1" in
--) while [ "$1" ]; do shift; local fnd="$fnd${fnd:+ }$1";done;;
-*) local opt=${1:1}; while [ "$opt" ]; do case ${opt:0:1} in
c) local fnd="^$PWD $fnd";;
h) echo "${_Z_CMD:-z} [-chlrtx] args" >&2; return;;
x) sed -i -e "\:^${PWD}|.*:d" "$datafile";;
l) local list=1;;
r) local typ="rank";;
t) local typ="recent";;
esac; opt=${opt:1}; done;;
*) local fnd="$fnd${fnd:+ }$1";;
esac; local last=$1; [ "$#" -gt 0 ] && shift; done
[ "$fnd" -a "$fnd" != "^$PWD " ] || local list=1

# if we hit enter on a completion just go there
case "$last" in
# completions will always start with /
/*) [ -z "$list" -a -d "$last" ] && cd "$last" && return;;
esac

# no file yet
[ -f "$datafile" ] || return

local cd
cd="$(while read line; do
[ -d "${line%%\|*}" ] && echo $line
done < "$datafile" | awk -v t="$(date +%s)" -v list="$list" -v typ="$typ" -v q="$fnd" -F"|" '
function frecent(rank, time) {
# relate frequency and time
dx = t - time
if( dx < 3600 ) return rank * 4
if( dx < 86400 ) return rank * 2
if( dx < 604800 ) return rank / 2
return rank / 4
}
function output(files, out, common) {
# list or return the desired directory
if( list ) {
cmd = "sort -n >&2"
for( x in files ) {
if( files[x] ) printf "%-10s %s\n", files[x], x | cmd
}
if( common ) {
printf "%-10s %s\n", "common:", common > "/dev/stderr"
}
} else {
if( common ) out = common
print out
}
}
function common(matches) {
# find the common root of a list of matches, if it exists
for( x in matches ) {
if( matches[x] && (!short || length(x) < length(short)) ) {
short = x
}
}
if( short == "/" ) return
# use a copy to escape special characters, as we want to return
# the original. yeah, this escaping is awful.
clean_short = short
gsub(/\[\(\)\[\]\|\]/, "\\\\&", clean_short)
for( x in matches ) if( matches[x] && x !~ clean_short ) return
return short
}
BEGIN {
gsub(" ", ".*", q)
hi_rank = ihi_rank = -9999999999
}
{
if( typ == "rank" ) {
rank = $2
} else if( typ == "recent" ) {
rank = $3 - t
} else rank = frecent($2, $3)
if( $1 ~ q ) {
matches[$1] = rank
} else if( tolower($1) ~ tolower(q) ) imatches[$1] = rank
if( matches[$1] && matches[$1] > hi_rank ) {
best_match = $1
hi_rank = matches[$1]
} else if( imatches[$1] && imatches[$1] > ihi_rank ) {
ibest_match = $1
ihi_rank = imatches[$1]
}
}
END {
# prefer case sensitive
if( best_match ) {
output(matches, best_match, common(matches))
} else if( ibest_match ) {
output(imatches, ibest_match, common(imatches))
}
}
')"
[ $? -gt 0 ] && return
[ "$cd" ] && cd "$cd"
fi
}

alias ${_Z_CMD:-z}='_z 2>&1'

[ "$_Z_NO_RESOLVE_SYMLINKS" ] || _Z_RESOLVE_SYMLINKS="-P"

if type compctl >/dev/null 2>&1; then
# zsh
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# populate directory list, avoid clobbering any other precmds.
if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then
_z_precmd() {
_z --add "${PWD:a}"
}
else
_z_precmd() {
_z --add "${PWD:A}"
}
fi
[[ -n "${precmd_functions[(r)_z_precmd]}" ]] || {
precmd_functions[$(($#precmd_functions+1))]=_z_precmd
}
}
_z_zsh_tab_completion() {
# tab completion
local compl
read -l compl
reply=(${(f)"$(_z --complete "$compl")"})
}
compctl -U -K _z_zsh_tab_completion _z
elif type complete >/dev/null 2>&1; then
# bash
# tab completion
complete -o filenames -C '_z --complete "$COMP_LINE"' ${_Z_CMD:-z}
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# populate directory list. avoid clobbering other PROMPT_COMMANDs.
grep "_z --add" <<< "$PROMPT_COMMAND" >/dev/null || {
PROMPT_COMMAND="$PROMPT_COMMAND"$'\n''_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;'
}
}
fi

ubuntu命令行的路径太长 如何缩短显示?

回复

Linux李魔佛 回复了问题 • 1 人关注 • 1 个回复 • 3623 次浏览 • 2016-07-10 17:38 • 来自相关话题

树莓派搭建ftp服务器 vsftpd 无法上传文件?

回复

网络安全低调的哥哥 回复了问题 • 2 人关注 • 1 个回复 • 4743 次浏览 • 2016-05-13 16:34 • 来自相关话题

Linux下如何解压tbz2后缀的压缩文件

回复

默认分类低调的哥哥 回复了问题 • 0 人关注 • 1 个回复 • 9464 次浏览 • 2016-05-11 18:33 • 来自相关话题

cronsun 执行计划任务是报错 exec format error

Linux李魔佛 发表了文章 • 0 个评论 • 74 次浏览 • 2021-03-28 12:32 • 来自相关话题

把执行的python命令写到shell里面,也给了+x权限,还是报这个错误fork/exec /root/crontab_script/hello.sh: exec format error
单独执行shell的脚本是没有问题的。
 
经过试验测试,是因为shell脚本的开头没有没有添加:#!/bin/bash的标记。
 
在shell脚本的第一行添加上后就没有问题了。
 
附一个脚本批量处理: 自动在首行添加 #!/bin/bash
In [1]: folder='/root/crontab_script'

In [2]: import os

In [3]: filelist=os.listdir(folder)

In [6]: def change_file(filename):
...: with open(filename,'r') as fp:
...: content=fp.read()
...: content=content.strip()
...: concat='#!/bin/bash\n'
...: content=concat+content
...: with open(filename,'w') as fp:
...: fp.write(content)
...:

In [7]: for file in filelist:
...: if file.endswith('.sh'):
...: full_path = os.path.join(folder,file)
...: change_file(full_path) 查看全部
把执行的python命令写到shell里面,也给了+x权限,还是报这个错误
fork/exec /root/crontab_script/hello.sh: exec format error

单独执行shell的脚本是没有问题的。
 
经过试验测试,是因为shell脚本的开头没有没有添加:
#!/bin/bash
的标记。
 
在shell脚本的第一行添加上后就没有问题了。
 
附一个脚本批量处理: 自动在首行添加 #!/bin/bash
In [1]: folder='/root/crontab_script'

In [2]: import os

In [3]: filelist=os.listdir(folder)

In [6]: def change_file(filename):
...: with open(filename,'r') as fp:
...: content=fp.read()
...: content=content.strip()
...: concat='#!/bin/bash\n'
...: content=concat+content
...: with open(filename,'w') as fp:
...: fp.write(content)
...:

In [7]: for file in filelist:
...: if file.endswith('.sh'):
...: full_path = os.path.join(folder,file)
...: change_file(full_path)

cronsun 计划任务运行python脚本

Linux李魔佛 发表了文章 • 0 个评论 • 80 次浏览 • 2021-03-27 23:34 • 来自相关话题

在执行脚本那里,不能执行
cd xxxxx && python xxx.py这样的操作,这样貌似不会实际去执行
 
只能把上面的命令放到一个shell文件里面,比如worker.sh
然后把worker.sh 放到指定的位置,然后把这个shell的完整路径放入到 cronsun的计划任务的脚本里面。
 










 
 
  查看全部
在执行脚本那里,不能执行
 cd xxxxx && python xxx.py
这样的操作,这样貌似不会实际去执行
 
只能把上面的命令放到一个shell文件里面,比如worker.sh
然后把worker.sh 放到指定的位置,然后把这个shell的完整路径放入到 cronsun的计划任务的脚本里面。
 

PD19MdOZOi.png


chrome_IyOEpNaSm1.png

 
 
 

chrome secure shell插件无法上传下载文件

Linux李魔佛 发表了文章 • 0 个评论 • 184 次浏览 • 2021-02-22 19:28 • 来自相关话题

本来挺强大的一个插件,结果因为这个小功能导致鸡肋了,或者我不知道如何在下载文件??
 
后记:
只好用scp传输啦,还好windows平台的git客户端。
本来挺强大的一个插件,结果因为这个小功能导致鸡肋了,或者我不知道如何在下载文件??
 
后记:
只好用scp传输啦,还好windows平台的git客户端。

armdebian 修改大写键 为esc

Linux李魔佛 发表了文章 • 0 个评论 • 355 次浏览 • 2021-01-18 18:15 • 来自相关话题

一个几乎没什么用的按键,直接用软件把它映射为esc键。
 
armdebian上没有xmodmap 这个软件,但有一个xkeycaps的GUI的小应用,可以很方便地修改在图形界面上修改按键映射。
 
而且xkeycaps修改是持续有效的,如果想该回去,上面有个restore的功能,可以一键恢复默认值。
 
  查看全部
一个几乎没什么用的按键,直接用软件把它映射为esc键。
 
armdebian上没有xmodmap 这个软件,但有一个xkeycaps的GUI的小应用,可以很方便地修改在图形界面上修改按键映射。
 
而且xkeycaps修改是持续有效的,如果想该回去,上面有个restore的功能,可以一键恢复默认值。
 
 

bbdoc居然不支持代码搜索

Linux李魔佛 发表了文章 • 0 个评论 • 387 次浏览 • 2021-01-03 16:54 • 来自相关话题

那有什么用?辣鸡
什么python,cpp,java一个都不支持。
那有什么用?辣鸡
什么python,cpp,java一个都不支持。

win7安装sshd服务

闲聊李魔佛 发表了文章 • 0 个评论 • 488 次浏览 • 2020-12-29 08:52 • 来自相关话题

Installing SFTP/SSH Server on Windows using OpenSSH
Recently, Microsoft has released a port of OpenSSH for Windows. You can use the package to set up an SFTP/SSH server on Windows.Installing SFTP/SSH Server

On Windows 10 version 1803 and newer
On earlier versions of Windows

https://github.com/PowerShell/Win32-OpenSSH/releases 

Configuring SSH server
Setting up SSH public key authentication
Connecting to the server

Finding Host Key
Connecting

Further readingInstalling SFTP/SSH Server
On Windows 10 version 1803 and newerIn Settings app, go to Apps > Apps & features > Manage optional features.

Locate “OpenSSH server” feature, expand it, and select Install.Binaries are installed to %WINDIR%\System32\OpenSSH. 
Configuration file (sshd_config) and host keys are installed to %ProgramData%\ssh
 (only after the server is started for the first time).
 
You may still want to use the following manual installation, if you want to install a newer version of OpenSSH than the one built into Windows 10.

On earlier versions of WindowsDownload the latest OpenSSH for Windows binaries (package OpenSSH-Win64.zip or OpenSSH-Win32.zip)

As the Administrator, extract the package to C:\Program Files\OpenSSH
As the Administrator, install sshd and ssh-agent services:
 
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
 
Configuring SSH serverAllow incoming connections to SSH server in Windows Firewall:

When installed as an optional feature, the firewall rule “OpenSSH SSH Server (sshd)” should have been created automatically. If not, proceed to create and enable the rule as follows.
Either run the following PowerShell command as the Administrator:New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\System32\OpenSSH\sshd.exe"

Replace C:\System32\OpenSSH\sshd.exe with the actual path to the sshd.exe 
(C:\Program Files\OpenSSH\ssh.exe, 
 
had you followed the manual installation instructions above).or go to Control Panel > System and Security > Windows Firewall1 > Advanced Settings > Inbound Rules and add a new rule for port 22.

Start the service and/or configure automatic start:

Go to Control Panel > System and Security > Administrative Tools and open Services. Locate OpenSSH SSH Server service.

If you want the server to start automatically when your machine is started: Go to Action > Properties. In the Properties dialog, change Startup type to Automatic and confirm.

Start the OpenSSH SSH Server service by clicking the Start the service.These instructions are partially based on the official deployment instructions. 查看全部
Installing SFTP/SSH Server on Windows using OpenSSH
Recently, Microsoft has released a port of OpenSSH for Windows. You can use the package to set up an SFTP/SSH server on Windows.Installing SFTP/SSH Server

On Windows 10 version 1803 and newer
On earlier versions of Windows

https://github.com/PowerShell/Win32-OpenSSH/releases 

Configuring SSH server
Setting up SSH public key authentication
Connecting to the server

Finding Host Key
Connecting

Further readingInstalling SFTP/SSH Server
On Windows 10 version 1803 and newerIn Settings app, go to Apps > Apps & features > Manage optional features.

Locate “OpenSSH server” feature, expand it, and select Install.Binaries are installed to %WINDIR%\System32\OpenSSH. 
Configuration file (sshd_config) and host keys are installed to %ProgramData%\ssh
 (only after the server is started for the first time).
 
You may still want to use the following manual installation, if you want to install a newer version of OpenSSH than the one built into Windows 10.

On earlier versions of WindowsDownload the latest OpenSSH for Windows binaries (package OpenSSH-Win64.zip or OpenSSH-Win32.zip)

As the Administrator, extract the package to C:\Program Files\OpenSSH
As the Administrator, install sshd and ssh-agent services:
 
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
 
Configuring SSH serverAllow incoming connections to SSH server in Windows Firewall:

When installed as an optional feature, the firewall rule “OpenSSH SSH Server (sshd)” should have been created automatically. If not, proceed to create and enable the rule as follows.
Either run the following PowerShell command as the Administrator:New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\System32\OpenSSH\sshd.exe"

Replace C:\System32\OpenSSH\sshd.exe with the actual path to the sshd.exe 
(C:\Program Files\OpenSSH\ssh.exe, 
 
had you followed the manual installation instructions above).or go to Control Panel > System and Security > Windows Firewall1 > Advanced Settings > Inbound Rules and add a new rule for port 22.

Start the service and/or configure automatic start:

Go to Control Panel > System and Security > Administrative Tools and open Services. Locate OpenSSH SSH Server service.

If you want the server to start automatically when your machine is started: Go to Action > Properties. In the Properties dialog, change Startup type to Automatic and confirm.

Start the OpenSSH SSH Server service by clicking the Start the service.These instructions are partially based on the official deployment instructions.

网易云音乐居然还有linux版本,网易还是一个良心企业

Linux李魔佛 发表了文章 • 0 个评论 • 655 次浏览 • 2020-12-18 11:31 • 来自相关话题

 
啥时候有道云笔记也搞一个linux版本的呀.
 
如果要在ubuntu16.04上安装,就不要去官网下载,gclib库不兼容,要升级到18.04, 会会很折腾.
直接下载:
$ wget http://s1.music.126.net/downlo ... 4.deb --默认下载到Desktop
 
然后sudo dpkg -i xxxxx.deb 就可以啦

良心的还要搜狗,linux下的输入法好用.
 
更新:
安装上面方法安装后,可以打开,可以播放mv,不过就是无法播放声音.
需要解决依赖问题.
网上找到了好的方法: 亲测有效
 
更改源为阿里云的源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiversean然后运行 apt -f install 修复依赖关系就可以了.
  查看全部
Workspace_1_0091.png

 
啥时候有道云笔记也搞一个linux版本的呀.
 
如果要在ubuntu16.04上安装,就不要去官网下载,gclib库不兼容,要升级到18.04, 会会很折腾.
直接下载:
$ wget http://s1.music.126.net/downlo ... 4.deb --默认下载到Desktop
 
然后sudo dpkg -i xxxxx.deb 就可以啦

良心的还要搜狗,linux下的输入法好用.
 
更新:
安装上面方法安装后,可以打开,可以播放mv,不过就是无法播放声音.
需要解决依赖问题.
网上找到了好的方法: 亲测有效
 
更改源为阿里云的源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiversean
然后运行 apt -f install 修复依赖关系就可以了.
 

vimium 配合chrome 真的好用,尤其用惯vim的用户

Linux李魔佛 发表了文章 • 0 个评论 • 394 次浏览 • 2020-11-22 01:59 • 来自相关话题

chrome最好用的插件,没有之一哈。





 
上面是vimium的快捷键用法
 
chrome最好用的插件,没有之一哈。

clipboard.png

 
上面是vimium的快捷键用法
 

windows下的分区挂载到linux下面,然后docker在上面挂载-无法识别

Linux李魔佛 发表了文章 • 0 个评论 • 429 次浏览 • 2020-11-11 02:40 • 来自相关话题

坑:
windows下的分区挂载到linux下面,然后docker在上面挂载-无法识别。
情况是这样的:
双系统的环境,一个ubuntu,一个windows。 ubuntu上的有个docker,但是ubuntu的分区比较小,需要挂载windows的ntfs分区来扩展空间。
其他程序用起来没什么问题,可是,在用docker 挂在windows分区下的文件夹,总是报错,用的 -v xxxx:xxxx 方式。
同样的docker启动命令,在ubuntu下的目录就没有问题,所以就开始怀疑是权限问题。
但是经过一系列的mount操作,chmod也给足了了权限,可是还没无法启动docker。
后来没办法,只好把windows分区缩小容量,把多余的容量格式化为ext分区格式,然后重新用docker mount -v, 后面docker就可以正常启动了。 查看全部

坑:
windows下的分区挂载到linux下面,然后docker在上面挂载-无法识别。
情况是这样的:
双系统的环境,一个ubuntu,一个windows。 ubuntu上的有个docker,但是ubuntu的分区比较小,需要挂载windows的ntfs分区来扩展空间。
其他程序用起来没什么问题,可是,在用docker 挂在windows分区下的文件夹,总是报错,用的 -v xxxx:xxxx 方式。
同样的docker启动命令,在ubuntu下的目录就没有问题,所以就开始怀疑是权限问题。
但是经过一系列的mount操作,chmod也给足了了权限,可是还没无法启动docker。
后来没办法,只好把windows分区缩小容量,把多余的容量格式化为ext分区格式,然后重新用docker mount -v, 后面docker就可以正常启动了。

斐讯N1 armlinux 长时间运行会导致文件系统只读 readonly

Linux李魔佛 发表了文章 • 0 个评论 • 558 次浏览 • 2020-10-25 00:24 • 来自相关话题

斐讯N1 刷的armlinux 长时间运行会导致文件系统只读 readonly。
比如放着几个晚上不关机,然后文件系统变成了只读,无法写入文件,提示只读系统。
 
原因是系统分区有坏道。 可能由于关机使用拔电源的方式导致的。
所以要养成好的习惯,正常关机,使用命令 shutdown -h 或者点击关机按钮就好了。
 
那么如果出现了上述问题,怎么办?
 
可以使用用U盘启动,运行一次e2fsck /dev/mmcblk1p2
然后选择Y,修复坏道就可以了。
 
U盘启动就是之前刷Armlinux时的那个U盘。
接上U盘,然后上电启动即可。 然后进入系统运行上述的命令:
e2fsck /dev/mmcblk1p2
 
  查看全部
斐讯N1 刷的armlinux 长时间运行会导致文件系统只读 readonly。
比如放着几个晚上不关机,然后文件系统变成了只读,无法写入文件,提示只读系统。
 
原因是系统分区有坏道。 可能由于关机使用拔电源的方式导致的。
所以要养成好的习惯,正常关机,使用命令 shutdown -h 或者点击关机按钮就好了。
 
那么如果出现了上述问题,怎么办?
 
可以使用用U盘启动,运行一次e2fsck /dev/mmcblk1p2
然后选择Y,修复坏道就可以了。
 
U盘启动就是之前刷Armlinux时的那个U盘。
接上U盘,然后上电启动即可。 然后进入系统运行上述的命令:
e2fsck /dev/mmcblk1p2
 
 

Started update UTMP about system Runlevel during booting ubuntu/armlinux

Linux李魔佛 发表了文章 • 0 个评论 • 1186 次浏览 • 2020-10-20 13:33 • 来自相关话题

I hit this issue on my ARMLinux (Same arch as Ubuntu), i can't login system with graphic. It always stuck on the line 
 
Started update UTMP about system Runlevel
 
Finally, i try to enter into secure mode and check logs.
it was caused by system disk is out of space.
So i try to delete some unless file to release some space, then reboot system, then everything is ok now.
 
http://30daydo.com/article/617
  查看全部
I hit this issue on my ARMLinux (Same arch as Ubuntu), i can't login system with graphic. It always stuck on the line 
 
Started update UTMP about system Runlevel
 
Finally, i try to enter into secure mode and check logs.
it was caused by system disk is out of space.
So i try to delete some unless file to release some space, then reboot system, then everything is ok now.
 
http://30daydo.com/article/617
 

zsh历史记录文件损坏: zsh: corrupt history file /home/admin/.zsh_history

Linux李魔佛 发表了文章 • 0 个评论 • 995 次浏览 • 2020-10-09 18:12 • 来自相关话题

由于不正确关机,或者突然重启造成的文件属性损坏。可以使用以下方式修复。cd ~
mv .zsh_history .zsh_history_bad
strings .zsh_history_bad > .zsh_history
fc -R .zsh_history
如果最后一步提示出错 fc的参数不对,可以进入zsh,然后再执行 fc -R .zsh_histroy
原创文章,转载请注明出处:
http://30daydo.com/article/612
  查看全部
由于不正确关机,或者突然重启造成的文件属性损坏。可以使用以下方式修复。
cd ~
mv .zsh_history .zsh_history_bad
strings .zsh_history_bad > .zsh_history
fc -R .zsh_history

如果最后一步提示出错 fc的参数不对,可以进入zsh,然后再执行 fc -R .zsh_histroy
原创文章,转载请注明出处:
http://30daydo.com/article/612
 

crontab定时运行图形程序

Linux李魔佛 发表了文章 • 0 个评论 • 1249 次浏览 • 2019-08-26 15:56 • 来自相关话题

默认情况不会显示任何图形的界面,需要在程序前添加 
export DISPLAY=:0;* * * * * export DISPLAY=:0; gedit 
附一个linux下桌面提醒GUI程序,定时提醒你休息哈:
 
import pyautogui as pag
import datetime

def neck_rest():
f = open('neck_record.txt', 'a')
ret = pag.prompt("Rest! Protect your neck !")
if ret == 'rest':
f.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
f.write('\t')
f.write('Rest')
f.write('\n')
else:
f.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
f.write('\t')
f.write('Failed to rest')
f.write('\n')
f.close()

neck_rest()
程序保存为task.py
然后设定crontab任务:

* * * * * export DISPLAY=:0; python task.py 
即可

  查看全部
默认情况不会显示任何图形的界面,需要在程序前添加 
export DISPLAY=:0;
* * * * * export DISPLAY=:0; gedit
 
附一个linux下桌面提醒GUI程序,定时提醒你休息哈:
 
import pyautogui as pag
import datetime

def neck_rest():
f = open('neck_record.txt', 'a')
ret = pag.prompt("Rest! Protect your neck !")
if ret == 'rest':
f.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
f.write('\t')
f.write('Rest')
f.write('\n')
else:
f.write(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
f.write('\t')
f.write('Failed to rest')
f.write('\n')
f.close()

neck_rest()

程序保存为task.py
然后设定crontab任务:

* * * * * export DISPLAY=:0; python task.py 
即可

 

alias别名 等号后面不用

Linux李魔佛 发表了文章 • 0 个评论 • 1174 次浏览 • 2019-08-12 14:17 • 来自相关话题

alias sync="git commit -m 'update' -a && git push origin master"
alias fetch="git fetch origin"
alias dj="python manage.py runserver 0.0.0.0"
alias py2="python2"
alias py3="python3"
alias ggg="cd ~/git" 查看全部
alias sync="git commit -m 'update' -a && git push origin master"
alias fetch="git fetch origin"
alias dj="python manage.py runserver 0.0.0.0"
alias py2="python2"
alias py3="python3"
alias ggg="cd ~/git"

ubuntu/linux shell根据进程名杀死进程 一句搞定

Linux李魔佛 发表了文章 • 0 个评论 • 2194 次浏览 • 2019-04-19 23:15 • 来自相关话题

ps -ef | grep "进程名" | grep -v grep | cut -c 10-16 | xargs kill -9 
比如我要杀死python的进程,就使用
 

ps -ef | grep "python" | grep -v grep | cut -c 10-16 | xargs kill -9
 
来使用。
 
grep -v grep 因为 ps 会把grep python这个进程也打印出来,所以-v 是反转的意思,不匹配的才打印出来,然后cut 是找出10到16位的字符,这里需要大家根据自己的用户名来调整。
一般ps -ef输出是 前面 用户名,然后空格, 接着是进程号。 如果你的用户名很长,可以调整10-16的位置来适应。
 
后面就是把进程号传递给kill作为参数,-9 是强制杀死。
 
  查看全部
ps -ef | grep "进程名" | grep -v grep | cut -c 10-16 | xargs kill -9
 
比如我要杀死python的进程,就使用
 

ps -ef | grep "python" | grep -v grep | cut -c 10-16 | xargs kill -9
 
来使用。
 
grep -v grep 因为 ps 会把grep python这个进程也打印出来,所以-v 是反转的意思,不匹配的才打印出来,然后cut 是找出10到16位的字符,这里需要大家根据自己的用户名来调整。
一般ps -ef输出是 前面 用户名,然后空格, 接着是进程号。 如果你的用户名很长,可以调整10-16的位置来适应。
 
后面就是把进程号传递给kill作为参数,-9 是强制杀死。