codecademy 命令行手册(中英文)

codecademy 命令行手册

BACKGROUND
The command line is a text interface for your computer. It’s a program that takes in commands, which it passes on to the computer’s operating system to run.
命令行是计算机上的文字用户交互界面,是一个接受命令并交给计算机操作系统执行的程序。

From the command line, you can navigate through files and folders on your computer, just as you would with Windows Explorer on Windows or Finder on Mac OS. The difference is that the command line is fully text-based.
从命令行,你可以浏览计算机上的文件和文件夹,就像window上的文件资源管理器或MacOS上的finder。不同的是命令行是完全基于文字(相对于图形界面)。

Here’s an appendix of commonly used commands.
下面的附录是一些常用的命令。


COMMANDS
>

$ cat oceans.txt > continents.txt

> takes the standard output of the command on the left, and redirects it to the file on the right.
接收左边命令的标准输出,转发到右边的文件。


>>

$ cat glaciers.txt >> rivers.txt

>>takes the standard output of the command on the left and appends (adds) it to the file on the right.
接收左边命令的标准输出,添加(追加)到右边的文件。


<

$ cat < lakes.txt

< takes the standard input from the file on the right and inputs it into the program on the left.
接收右边命令的标准输出,输出到左边的程序。


|

$ cat volcanoes.txt | wc

| is a “pipe”. The | takes the standard output of the command on the left, and pipes it as standard input to the command on the right. You can think of this as “command to command” redirection.
是一个“管道”。|接收左边命令的标准输出,作为右边命令的标准输入,你可以认为这是“命令到命令”的重定向。


~/.BASH_PROFILE

$ nano ~/.bash_profile

~/.bash_profile is the name of file used to store environment settings. It is commonly called the “bash profile”. When a session starts, it will load the contents of the bash profile before executing commands.
是保存环境设置的文件。通常被叫做“bash profile”。当一个会话启动,将在执行命令之前加载bash profile中的内容。


ALIAS

alias pd="pwd"

The alias command allows you to create keyboard shortcuts, or aliases, for commonly used commands.
alias命令允许你对于经常使用的命令创建键盘快捷键,或者说缩写。


CD

cd Desktop/

cd takes a directory name as an argument, and switches into that directory.
cd接受一个文件夹名作为参数,切换到该文件夹。

$ cd jan/memory

To navigate directly to a directory, use cd with the directory’s path as an argument. Here, cd jan/memory/ command navigates directly to the jan/memory directory.
如果想直接导航到某文件夹,在cd命令后接一个文件路径作为参数。在这个例子中cd jan/memory/ command导航到jan/memory文件夹。

CD ..

$ cd ..

To move up one directory, use cd ... Here, cd .. navigates up from jan/memory/ to jan/.
使用cd ..移动到上一级文件夹,cd ..jan/memory/ 导航到 jan/
CP

$ cp ada_lovelace.txt historical/

cp copies files or directories. Here, we copy the file ada_lovelace.txt and place it in the historical/ directory
cp命令用来复制文件或文件夹。在例子中我们复制了ada_lovelace.txt并把它放在historical/文件夹下


WILDCARDS (*)

$ cp * satire/

The wildcard * selects all of the files in the current directory. The above example will copy all of the files in the current directory to the directory called satire. There are other types of wildcards, too, which are beyond the scope of this glossary.
通配符*能匹配当前文件夹下的所有文件。上面的例子会把当前文件夹下所有文件复制到叫做satire的文件夹下。也有一些其他类型的通配符,但已经超出了本术语表的讨论范围。

$ cp m*.txt scifi/

Here, m*.txt selects all files in the working directory starting with “m” and ending with “.txt”, and copies them to scifi/.
在这里,m*.txt匹配当前文件夹下所有以“m”开头,以“.txt”结尾的文件,并复制到scifi/文件夹下。


ENV

env

The env command stands for “environment”, and returns a list of the environment variables for the current user.
env命令表示“environment”,并返回一个当前用户的环境变量列表。

ENV | GREP VARIABLE

env | grep PATH

env | grep PATH is a command that displays the value of a single environment variable.
该命令显示单个环境变量的值。

EXPORT

export USER="Jane Doe"

export makes the variable to be available to all child sessions initiated from the session you are in. This is a way to make the variable persist across programs.
export使得该变量对所有从当前会话中启动的子会话可用。这是一种使变量跨进程保持的方法。


GREP

$ grep "Mount" mountains.txt

grep stands for “global regular expression print”. It searches files for lines that match a pattern and returns the results. It is case sensitive.
grep 代表”global regular expression print”(全局正则表达式打印)。它在文件中搜索匹配模式的行并返回结果。是大小写敏感。

GREP -I

$ grep -i "Mount" mountains.txt

grep -i enables the command to be case insensitive.
grep -i使该命令大小写不敏感。

GREP -R

$ grep -R Arctic /home/ccuser/workspace/geography

grep -R searches all files in a directory and outputs filenames and lines containing matched results. -R stands for “recursive”.
grep -R检索一个文件夹下的所有文件,输出匹配模式的文件和行,-R表示“recursive”(递归)。

GREP -RL

$ grep -Rl Arctic /home/ccuser/workspace/geography

grep -Rl searches all files in a directory and outputs only filenames with matched results. -R stands for “recursive” and l stands for “files with matches”.
grep -Rl检索文件夹下的所有文件,只输出文件名和匹配结果,-R表示“recursive”(递归),l表示“files with matches”(带有匹配的文件)。


HOME

$ echo $HOME

The HOME variable is an environment variable that displays the path of the home directory.
HOME变量是一个展示home文件夹的路径的环境变量。


LS

$ ls
2014  2015  hardware.txt

ls lists all files and directories in the working directory
ls -a列出当前文件夹下全部文件和文件夹

ls -a

ls -a
.  ..  .preferences  action  drama comedy  genres.xt

ls -a lists all contents in the working directory, including hidden files and directories
ls -a列出当前文件夹下所有的内容,包括隐藏文件和文件夹

ls -l

ls -l
drwxr-xr-x 5  cc  eng  4096 Jun 24 16:51  action
drwxr-xr-x 4  cc  eng  4096 Jun 24 16:51  comedy
drwxr-xr-x 6  cc  eng  4096 Jun 24 16:51  drama
-rw-r--r-- 1  cc  eng     0 Jun 24 16:51  genres.txt

ls -l lists all contents of a directory in long format. Here’s what each column means.
ls -l以长格式列出当前文件夹下所有内容,这里是每一列代表的意思

ls -t
ls -t orders files and directories by the time they were last modified.
ls -t根据文件的最后修改时间排序文件。


MKDIR

$ mkdir media

mkdir takes in a directory name as an argument, and then creates a new directory in the current working directory. Here we used mkdir to create a new directory named media/.
mkdir接收一个文件夹名作为参数,然后在当前目录下创建一个新文件夹。这里我们使用mkdir创建一个名为media/的文件夹。


MV

$ mv superman.txt superhero/

To move a file into a directory, use mv with the source file as the first argument and the destination directory as the second argument. Here we move superman.txt into superhero/.
把一个文件移动到文件夹中,使用mv并且把源文件作为第一个参数,目标文件夹作为第二个参数。这里我们把superman.txt移动到superhero/


NANO

$ nano hello.txt

nano is a command line text editor. It works just like a desktop text editor like TextEdit or Notepad, except that it is accessible from the the command line and only accepts keyboard input.
nano是一个命令行文本编辑器。它就像一个桌面编辑器(例如TextEdit或者Notepad)那样工作,除了它可以从命令行打开并且只接受键盘输入。


PATH

$ echo $PATH

/home/ccuser/.gem/ruby/2.0.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin

PATH is an environment variable that stores a list of directories separated by a colon. Each directory contains scripts for the command line to execute. PATH lists which directories contain scripts.
PATH是一个保存一组文件夹的环境变量,用逗号分隔,每个文件夹包括一个命令行可以执行的脚本文件。


PWD

$ pwd
/home/ccuser/workspace/blog

pwd prints the name of the working directory
pwd打印出当前文件夹


RM

$ rm waterboy.txt

rm deletes files. Here we remove the file waterboy.txt from the file system.
rm删除文件。这里我们从文件系统中删除waterboy.txt这个文件。

RM -R

$ rm -r comedy

rm -r deletes a directory and all of its child directories.
rm -r删除一个文件夹及其所有子文件夹。


SED

$ sed 's/snow/rain/' forests.txt

sed stands for “stream editor”. It accepts standard input and modifies it based on an expression, before displaying it as output data.
sed表示”stream editor”,它接收一个标准输入,根据一个表达式修改它,然后作为输出数据展示。

In the expression 's/snow/rain/':
在表达式's/snow/rain/'中:
- s: stands for “substitution”. 表示替换
- snow: the search string, the text to find. 搜索字符串,需要找到的文字
- rain: the replacement string, the text to add in place. 替换的字符串,添加到找到的地方


SORT

$ sort lakes.txt

sort takes a filename or standard input and orders each line alphabetically, printing it to standard output.
sort 命令接收一个文件名或标准输出并按照字母对每一行进行排序,然后打印到标准输出。


STANDARD ERROR
standard error, abbreviated as stderr, is an error message outputted by a failed process.
标准错误,缩写为stderr,是一个运行失败的进程输出的错误信息。


SOURCE

source ~/.bash_profile

source activates the changes in ~/.bash_profile for the current session. Instead of closing the terminal and needing to start a new session, source makes the changes available right away in the session we are in.
source命令行可以为当前命令行会话激活~/.bash_profile,而无需关掉终端启动新的会话,source命令使得改变在当前所在的会话立即生效。


STANDARD INPUT
standard input, abbreviated as stdin, is information inputted into the terminal through the keyboard or input device.
标准输入,缩写为stdin,是通过键盘或输入设备输入到终端的信息。

STANDARD OUTPUT
standard output, abbreviated as stdout, is the information outputted after a process is run.
标准输出,缩写为stdout,是一个进程运行后的输出信息。


TOUCH

$ touch data.txt

touch creates a new file inside the working directory. It takes in a file name as an argument, and then creates a new empty file in the current working directory. Here we used touch to create a new file named keyboard.txt inside the 2014/dec/directory.
touch命令在当前文件夹下创建一个新文件。接收一个文件名作为参数,然后在当前文件夹下创建一个新的空文件。这里(教程中)我们用touch来在2014/dec/文件夹下创建名为keyboard.txt的新文件。

If the file exists, touch is used to update the modification time of the file
如果这个文件存在,touch可以用来更新文件的修改时间。


UNIQ

$ uniq lakes.txt

uniq, short for “unique”, takes a filename or standard input and prints out every line, removing any exact duplicates.
uniq是“unique”的缩写,接收一个文件名或标准输入作为参数,显示每一行并移除确切的重复(的行)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值