https://www.codecademy.com/en/courses/learn-the-command-line

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.

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.

alias

alias pd="pwd"

The alias command allows you to create keyboard shortcuts, or aliases, for commonly used commands.

cd

cd Desktop/

cd takes a directory name as an argument, and switches into that directory.

$ 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 ..

To move up one directory, use cd ... Here, cd .. navigates up from jan/memory/ to jan/.

cp

$ cp frida.txt historical/

cp copies files or directories. Here, we copy the file lincoln.txt and place it in the historical/ directory

Wildcards

$ cp * satire/

The wildcard * selects in the working directory, so here we use cp to copy all files into the satire/ directory.

$ 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/.

env

env

The env command stands for "environment", and returns a list of the environment variables for the current user.

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.

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 -i

$ grep -i Mount mountains.txt

grep -i enables the command to be case insensitive.

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 -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".

HOME

$ echo $HOME

The HOME variable is an environment variable that displays the path of the home directory.

ls

  $ ls
2014 2015 hardware.txt

ls lists all files and directories in the working directory

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 -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 -t

ls -t orders files and directories by the time they were last modified.

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/.

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/.

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.

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.

pwd

$ pwd
/home/ccuser/workspace/blog

pwd prints the name of the working directory

rm

$ rm waterboy.txt

rm deletes files. Here we remove the file waterboy.txt from the file system.

rm -r

$ rm -r comedy

rm -r deletes a directory and all of its child directories.

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.

In the expression '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 the standard input and orders it alphabetically for the standard output.

standard error

standard error, abbreviated as stderr, is an error message outputted by a failed process.

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.

standard input

standard input, abbreviated as stdin, is information inputted into the terminal through the keyboard or input device.

standard output

standard output, abbreviated as stdout, is the information outputted after a process is run.

touch

$ touch data.tx

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.

If the file exists, touch is used to update the modification time of the file

uniq

$ sort lakes.txt

sort takes the standard input and orders it alphabetically for the standard output.

Linux Command Line learning的更多相关文章

  1. 10 Interesting Linux Command Line Tricks and Tips Worth Knowing

    I passionately enjoy working with commands as they offer more control over a Linux system than GUIs( ...

  2. 《The Linux Command Line》 读书笔记04 Linux用户以及权限相关命令

    Linux用户以及权限相关命令 查看身份 id:Display user identity. 这个命令的输出会显示uid,gid和用户所属的组. uid即user ID,这是账户创建时被赋予的. gi ...

  3. 《The Linux Command Line》 读书笔记02 关于命令的命令

    <The Linux Command Line> 读书笔记02 关于命令的命令 命令的四种类型 type type—Indicate how a command name is inter ...

  4. 《The Linux Command Line》 读书笔记01 基本命令介绍

    <The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...

  5. Linux Command Line Basics

    Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...

  6. Linux Command Line 解析

    Linux Command Line 解析 0 处理模型 Linux kernel的启动包括很多组件的初始化和相关配置,这些配置参数一般是通过command line进行配置的.在进行后续分析之前,先 ...

  7. 15 Examples To Master Linux Command Line History

    When you are using Linux command line frequently, using the history effectively can be a major produ ...

  8. Reso | The Linux Command Line 的中文版

    http://book.haoduoshipin.com/tlcl/book/zh/ 本书是 The Linux Command Line 的中文版, 为大家提供了多种不同的阅读方式. 中英文双语版- ...

  9. [笔记]The Linux command line

    Notes on The Linux Command Line (by W. E. Shotts Jr.) edited by Gopher 感觉博客园是不是搞了什么CSS在里头--在博客园显示效果挺 ...

随机推荐

  1. Spring+SpringMVC+MyBatis集成学习笔记【一】

    一,首先要清楚,SpringMVC其实就是Spring的一个组件       例如我们知道Spring中有类似于,AOP TX等等类似的组件,所以SpringMVC其实就是Spring的一个组件,是S ...

  2. Linux日志分析ELK环境搭建

    场景:ELK作为一个日志收集和检索系统,感觉功能还是相当的强大的. ELK是啥, 其实是是三个组件的缩写, 分别是elasticsearch, logstash, kibana. ELK平台可以用于实 ...

  3. 聪明的燕姿[JLOI2014]

    题目描述 阴天傍晚车窗外 未来有一个人在等待 向左向右向前看 爱要拐几个弯才来 我遇见谁会有怎样的对白 我等的人他在多远的未来 我听见风来自地铁和人海 我排着队拿着爱的号码牌 城市中人们总是拿着号码牌 ...

  4. NYOJ--水池数目

    //NYOJ--水池数目 #include<iostream> #include<cstring> }; using namespace std; void dfs(int,i ...

  5. C#上位机串口控制12864显示

    实现的效果 上面是用Proteus仿真的,,对了如果自己想用proteus仿真需要安装下面这个软件 再看一下实物显示效果 先做上位机部分........... 为了程序一启动就把电脑上能用的串口号显示 ...

  6. Centos 7.3 安装mysql5.7.19 各种调试就不多说了

    mysql 5.7.19linux-glibc2.12 (x86_64) 安装 1.在安装目录进行解压2.mv解压目录为mysql3.创建mysql的用户 useradd -s /sbin/nolon ...

  7. 地铁间谍 洛谷 p2583

    题目描述 特工玛利亚被送到S市执行一个特别危险的任务.她需要利用地铁完成他的任务,S市的地铁只有一条线路运行,所以并不复杂. 玛利亚有一个任务,现在的时间为0,她要从第一个站出发,并在最后一站的间谍碰 ...

  8. 17个新手常见Python运行时错误

    当初学 Python 时,想要弄懂 Python 的错误信息的含义可能有点复杂.这里列出了常见的的一些让你程序 crash 的运行时错误. 1)忘记在 if , elif , else , for , ...

  9. RMAN备份-未使用catalog-控制文件丢失

    情况描述 客户报告数据库故障,新来的系统管理员误操作.删掉了一些文件.具体情况是:删掉了所有重要数据文件.所有控制文件.数据库原来是归档模式,用rman备份数据,而rman 使用控制文件. 幸运的是, ...

  10. RabbitMQ --- Publish/Subscribe(发布/订阅)

    目录 RabbitMQ --- Hello Mr.Tua RabbitMQ --- Work Queues(工作队列) 前言 在第二篇文章中介绍了 Work Queues(工作队列),它适用于把一个消 ...