学会如何使用终端对于学习如何使用Ubuntu来说,似乎是一个先决条件。所以我正在努力找出最好的学习方法。是否有在线的Quizlet闪卡集?或者还有其他更好的方法吗?
~/.bashrc
文件的末尾添加以下行(命令):echo "Did you know that:"; whatis $(ls /bin | shuf -n 1)
sudo apt-get install cowsay
~/.bashrc
文件的末尾添加以下行:cowsay -f $(ls /usr/share/cowsay/cows | shuf -n 1 | cut -d. -f1) $(whatis $(ls /bin) 2>/dev/null | shuf -n 1)
~/.bash_aliases
中。我已经添加了:alias ?='cowsay -f $(ls /usr/share/cowsay/cows | shuf -n 1 | cut -d. -f1) $(whatis $(ls /bin) 2>/dev/null | shuf -n 1)'
?
(然后按下Enter键)。这就像是自己玩骰子一样。
Did you know that: mkdir: nothing appropriate.
(译者注:你知道吗:mkdir:没有合适的内容。)虽然我不总是看到mkdir
,但我总是看到nothing appropriate
。如果我将你的代码放在~/.bashrc
的顶部,whatis
就能正常工作,但放在末尾就不行。不确定是什么导致了这个问题,但我猜其他人也会遇到同样的问题。 - snim2/bin
,因为那里是最常用的命令。但你可以使用 echo "你知道吗:";whatis $(ls /usr/share/man/man1 | shuf -n 1 | cut -d. -f1)
从所有 man 页面中选择一个随机页面。 - Radu Rădeanumkdir: nothing appropriate
的问题,那可能是你的man页面出了问题。不过,为了绕过这个问题,你可以使用以下命令:echo "Did you know that:"; whatis $(ls /bin) 2>/dev/null | shuf -n 1
。另外,如果你的~/.bashrc
文件有问题,那么你猜测的可能性不大。 - Radu Rădeanu/bin
目录中有文件名包含空格或换行符的话,那么你面临的问题比糟糕的脚本编写习惯更大。 - evilsoup/bin
目录中,带有空格、换行符等的文件名比其他任何地方更成问题。 - heinrich5991ls
添加了 -F
或其他影响输出的标志。将 ls /bin
更改为 /bin/ls /bin
。 - Gilles 'SO- stop being evil'whatis
。它不完全是一个游戏,但却是一个相对容易学习的方式。whatis sudo apt-get update
,它会返回:
whatis
命令。我会了解我要做的事情,然后有信心地执行该命令。whatis
提供的信息不多或者对我来说不清楚,我会去阅读man
。man sudo
。whatis something
和man something
。特别是对于一些(大多数!)命令,比如dd
等等... 例如,man也会解释你自己提供的示例中的"update"参数... 在你的示例中,whatis显示了"apt-get"是什么,然后尝试找到"update"命令的定义,但实际上它不存在(但可能存在并且是完全无关的东西)。 - Olivier Dulac我不知道任何游戏,但有一些有用的命令行实用程序可以帮助。
一个命令做什么?
whatis command
# example:
$ whatis cut
cut (1) - remove sections from each line of files
man -k keyword
# example:
$ man -k "remove empty"
rmdir (1) - remove empty directories
或者:
apropos keyword
# defaults to printing every result with at least one of the keywords supplied
# use --and to only print results matching multiple keywords.
$ apropos zip --and extract
funzip (1) - filter for extracting from a ZIP archive in a pipe
unzip (1) - list, test and extract compressed files in a ZIP archive
unzipsfx (1) - self-extracting stub for prepending to ZIP archives
uz (1) - gunzips and extracts a gzip'd tar'd archive
man command
# example:
man tar
# use '?' key to search, and 'q' to quit.
$ umount --help
Usage: umount -h | -V
umount -a [-d] [-f] [-r] [-n] [-v] [-t vfstypes] [-O opts]
umount [-d] [-f] [-r] [-n] [-v] special | node...
command -h
,command --help
,command -?
的形式出现。info command
# example:
$ info cat
# shows an information page
<
和 >
,因为需要使用 man
命令的人可能不了解重定向的危险性。例如:command <something> somethingelse
会在当前目录下创建一个空的 somethingelse
文件(或截断已存在的文件!),这是个不好的习惯。只需使用 man command
就足够清楚明了了。或者使用 man __some__command__
或其他安全的方式。 - Olivier Dulac<something>
不是一个已存在的文件,那么是安全的,因为否则,shell会抱怨它不存在(显然在创建输出文件之前就这样做)...但是,这仍然是个坏习惯。 - Olivier Dulachttp://www.nongnu.org/lpi-manuals/manual/ Linux专业协会(LPI)学习手册
GNU Bash参考手册
高级Bash脚本指南(http://linux.die.net/),作者Mendel CooperMemrise工具有一个Unix和Linux命令行部分。这是一个学习任何东西的绝佳工具,以打孔卡的方式进行。
rm -- '-rf ~/*'
。如果想要面对真正的挑战,试试删除一个文件,其名称完全由不可打印的控制字符组成。如果仅仅打印文件名就搞乱了你的终端,那就额外加分。 - Ilmari Karonen