Questions tagged «bash»

Bash(Bourne-Again SHell)是默认情况下在Ubuntu命令行界面中使用的shell。



5
从bash历史记录中选择命令
按下向上按钮很乏味,我可能会错过寻找的命令。因此,history在终端上键入内容时,会给我我之前输入的所有命令,并已索引成一个数字。有什么办法我可以拨打与该命令关联的数字吗?
20 bash  history 

8
如何计算文件中文本的出现次数?
我有一个按IP地址排序的日志文件,我想查找每个唯一IP地址的出现次数。我如何用bash做到这一点?可能列出IP旁边的出现次数,例如: 5.135.134.16 count: 5 13.57.220.172: count 30 18.206.226 count:2 等等。 这是日志示例: 5.135.134.16 - - [23/Mar/2019:08:42:54 -0400] "GET /wp-login.php HTTP/1.1" 200 2988 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0" 5.135.134.16 - - [23/Mar/2019:08:42:55 -0400] "GET /wp-login.php HTTP/1.1" 200 2988 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0" 5.135.134.16 …
19 command-line  bash  sort  uniq 


9
如何编写Shell脚本以将字母等级分配给数字范围?
我想制作一个脚本,提示您输入0-100之间的数字,然后根据该数字给您评分。 我想要它。 PS3='Please enter your choice: ' (Something here) do case $ "0-59") echo "F" ;; "60-69") echo "D" ;; "70-79") echo "C" ;; "Quit") break ;; *) echo invalid option;; esac done
19 bash  scripts 

2
如何在屏幕锁定/解锁时运行命令或脚本?
我正在寻找一种存储锁定/解锁屏幕时间的方法。 A=$(date) echo $A >> $HOME/time_xprofile 我尝试了什么: $HOME/.bashrc $HOME/.bash_logout $HOME/.bash_prompt $HOME/.xprofile 然后,我锁定了屏幕,并检查文件是否出现,并且每次都失败。我该如何检查时间?

2
在第一行中有#!/ usr / bin / env python`时,脚本可能无法找到python?
试图让casperjs在Ubuntu 12.04上运行。在我运行时安装它后,我得到: 09:20 $ ll /usr/local/bin/casperjs lrwxrwxrwx 1 root root 26 Nov 6 16:49 /usr/local/bin/casperjs -> /opt/casperjs/bin/casperjs 09:20 $ /usr/bin/env python --version Python 2.7.3 09:20 $ cat /opt/casperjs/bin/casperjs | head -4 #!/usr/bin/env python import os import sys 09:20 $ casperjs : No such file or directory 09: 22 $ python …
19 bash  python  scripts 

1
在Windows中使用Xubuntu和xrdp进行Bash auto_completion
我正在使用Xubuntu并通过Windows 7通过RemoteDesktop连接。 一切正常,但bash中的auto_completion无效。我检查了主目录中的.bashrc文件以及/etc/bash.bashrc。 我不建议在本地bashrc配置以及bash.bashrc中的以下行,但是什么都没有改变。 if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi

4
如何获得不同选项卡之间的共享历史记录
我在/unix//a/1292/41729中使用了答案,以在各个bash终端之间启用实时共享历史记录。如以上答案中所述,这是通过添加以下内容来实现的: # avoid duplicates.. export HISTCONTROL=ignoredups:erasedups # append history entries.. shopt -s histappend # After each command, save and reload history export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND" 如果bash外壳是分开的(例如,使用打开bash终端),则此方法效果很好CTRL+ALT+T。但是,如果我使用tabs(从打开的终端“ CTRL + SHIFT + T”)而不是新窗口使用,则无法正常工作。是否可以在各个选项卡之间共享Bash历史记录? 更新:我注意到一种不寻常的行为:如果CTRL+C键入,则正确显示了在其他任何终端(无论是否为制表符)中键入的最后一个命令。就像CTRL + C强制刷新历史记录以便正确共享历史记录一样。 作为示例输出(T1表示端子1,T2表示端子2): T1: ls -lah <enter> # the list of files and directory …
19 bash  bashrc  history 



3
bash不保留历史
我运行Ubuntu 12.04,由于某种原因,bash无法保留我的命令历史记录。该~/.bash_history文件仅包含我几个月前键入的3条命令。 我怎样才能解决这个问题? 编辑: 这是我的相关内容.bashrc: # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything [ -z "$PS1" ] && return # don't put duplicate lines or lines starting with space in the history. …
19 bash  history 


3
如何删除外壳程序中的“您的意思是……”功能?
当我无法正确键入命令时,例如: luca@mostro:~$ sido No command 'sido' found, did you mean: Command 'sudo' from package 'sudo' (main) Command 'sudo' from package 'sudo-ldap' (universe) Command 'sid' from package 'tendra' (universe) sido: command not found 命令解释器尝试猜测我要运行的程序。这对我来说很烦人(我将其与Google行为相关联)。 是否可以删除此功能?如何? 我以为是在我的本地设置的~/.bashrc,但是快速检查失败了……
19 bash 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.