【编程学习】大数据平台基础课程要点总结——Linux基础操作

在此附上老师教学课件地址:

Linux简单操作

basic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
ssh username@ip # 登录Linux服务器
whoami # 当前登陆用户名
pwd # 当前工作目录

ls # 当前目录下文件
ls /home # /home目录下文件
ls -lstah # 当前目录下文件详细信息

~ # 当前用户根目录,等价于/home/username
. # 当前目录
.. # 上一目录

cd /home # 更换目录到/home

mkdir a # 创建文件夹a
rmdir a # 删除文件夹a
touch a.txt # 创建文件a.txt
cp a.txt b.txt # 复制文件a.txt为b.txt
mv a.txt /a/a.txt # 把a.txt移动到a目录下
mv a.txt b.txt # 把a.txt改名为b.txt
rm a.txt # 删除文件a.txt

rsync localfile remotedir # 在本地运行,将文件上传至远程服务器
scp localfile remotedir # 在本地运行,将文件上传至远程服务器

cat a.txt # 在命令行输出a.txt内容
head -n 5 a.txt # 在命令行输出a.txt内容前五行
tail -n 5 a.txt # 在命令行输出a.txt内容后五行

Vim

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
vim a.txt # 编辑文件
# :q! - discard all changes, since the last save, and exit
# :w - save file but don't exit
# :wq - again, save and exit

# Arrow keys - move the cursor around
# j, k, h, l - move the cursor down, up, left and right (similar to the arrow keys)
# ^ (caret) - move cursor to beginning of current line
# $ - move cursor to end of the current line
# nG - move to the nth line (eg 5G moves to 5th line)
# G - move to the last line
# w - move to the beginning of the next word
# nw - move forward n word (eg 2w moves two words forwards)
# b - move to the beginning of the previous word
# nb - move back n word
# { - move backward one paragraph
# } - move forward one paragraph

# x - delete a single character
# nx - delete n characters (eg 5x deletes five characters)
# dd - delete the current line
# dn - d followed by a movement command. Delete to where the movement # # command would have taken you. (eg d5w means delete 5 words)

# u - Undo the last action (you may keep pressing u to keep undoing)
# U (Note: capital) - Undo all changes to the current line

正则

1
2
3
4
5
6
# * - represents zero or more characters
# ? - represents a single character
# [] - represents a range of characters

ls B* # 当前目录下所有B开头的文件
ls */*.png # 当前目录的下一层目录的所有png文件

pipline

1
2
3
4
5
6
7
ls > output # 把ls的运行结果写入output文件(覆盖)
ls >> output # 把ls的运行结果追加至output文件
mysql -u root -p -h test < test.sql # 把test.sql文件中数据导入到test变量

ls | head -3
# `command 1 | command 2`:send the output of `command 1` to `command 2`.
# 本案例输出当前目录前三个文件

space

1
2
3
top # shows you the processes running on your machine, ordered by resource consumption.
free # displays a simple readout of how much memory is used and available on your system.
du # short for disk usage. It's is extremely useful for estimating the size of directories.