本文作为学习Hua Hua “玩转Linux命令行”的笔记,视频地址:https://www.youtube.com/playlist?list=PLLuMmzMTgVK6LIon2E7rjM2XBInMzfmjQ
EP1:
echo:自言自语
pwd: print working directory,打印目前位置
cd: change directory, cd path, cd ~, cd ..
ls: list directory contents
ls
ls -l #list mode
ls -l -a = ls -la # list mode + all files
ls -lh # list mode + human readable size
man: 用户手册
man pwd
man -h
grep --help
cat: 打印文件内容,concatenate and print files
cat a.txt
cat a.txt b.txt # print a.txt then b.txt
cat < a.txt # read from stdin
head and tail
head a.txt #默认前十行
tail a.txt #默认后十行
tail -n 5 a.txt #-n+number,打印后number行
tail -f a.txt #-f用来观察变化,比如观察log
less: read-only version of vi
less a.txt
grep: 内容查找
cat a.txt | grep 8 #查找A中带8的内容
cat a txt | grep -n 8 #查找A中带8并且返回行号
wc:单词统计 word, line and byte count
man wc | wc #统计wc这个manual手册,返回A-行数 B-单词书 C-字节数
重定向:改变输入输出设备
标准输入stdin/标准输入stdout:控制台/键盘/屏幕
echo hello > hello.txt # redirect to a file
echo world >> hello.txt # append to a file
cat < hello.txt # use file as stdin, read from file
管道:将前一个命令的标准输出作为下一个程序的标准输入
man less | grep sim #在less manual中找有sim的内容
man less | grep -n sim | grep That > that.txt #multiple pipe 在less manual中找有sim内容以及其行,在其中找有That内容及其行数,重定向到that.txt文件
利用nano实现echo:
打开nano: 直接输入nano
写代码
ctrl+x退出并保存代码
g++编译