(1) Basic Linux commands

Tip: I am learning basic linux commands recently, and forgetting to learn is the norm. Write an article and learn it from time to time.

1. Linux basic shortcut keys

1. Move

Up, down, left, and right shortcut keys.
ctrl + p(previous) on
ctrl + n(next) under
ctrl + b(back) left
ctrl + f(forward) right

2. Delete

Up, down, left, and right shortcut keys.
ctrl + d Delete the character under the cursor
ctrl + h Left delete the character in front of the cursor, equivalent to backspace
ctrl + u Delete all characters in front of the cursor

3. Clear the screen

ctrl + l Clear screen

4. Turn pages

shift+pageup On the turn
shift+pagedown Flip down

Two.Linux directory structure

Linux files are usually installed automatically through the network and installed in a fixed directory, so you must know what each directory does.
The following lists only some of the more important Linux directories.

/bin Executable program that stores commands
/boot Store startup items
/dev Store equipment files
/ etc Configuration file
/ lib Dynamic library.so
/ media Auto mount directory
/ mnt Mount the directory manually
/ etc Store configuration files
/ opt Store third-party software
/ sbin Store administrator's command executable program
/ var / log Store log files
/ usr/src Store source code

Three.Linux basic commands

1.linux file type

user_name@machine_name: ~#
用户名@机器名:家目录 root权限

Different files have different colors under linux (environment ubantu)

white Normal file
blue table of Contents
green executable file
red Archive
Blue Link file
yellow Device file

2.ls

#显示所有文件包括隐藏文件
ls -a
#显示文件的所有信息
ls -l
ls -l
#example
d rwx rwx rwx 2 itcast itcast
#目录文件 所有者权限 同组权限 其他人权限 硬链接个数 文件所有者 文件所有组名

The meaning of the first character

- Normal file
d dir directory file
l link soft link file
b block device
c char device
s socket device
p pipe file

3.pwd

pwd displays the current path

4.mkdir

tip:cp rm 递归复制或者删除都是-r,mkdir是-p

#创建文件夹
mkdir hello
#递归创建文件夹
mkdir -p dir/dir1/dir2

5.rm

#删除
rm hello
#递归删除
rm -r dir/dir1/dir2

6.touch

#创建文件
touch hello.c

7.cp

#拷贝 源文件 目的目录
cp hello.c dir
#递归拷贝 源目录  目的目录
cp -r source_dir terminal_dir

8.cat

查看文件内容的命令类似的有cat more less head tail,有了vim之后都不太常用。

#查看hello.c文件的内容
cat hello.c

9.mv

#移动 源目录 目的目录
mv dir1 dir2

10.ln

软连接相当于快捷方式

#创建软连接 绝对路径 软连接文件名称
ln -s ~/dir/hello.c hello.soft

硬链接相当于备份。目录不可以创建硬链接

#创建硬链接 绝对路径 软连接文件名称
ln  ~/dir/hello.c hello.soft

11.df

#查看磁盘使用情况
df -h

12.which

#查看命令所在的路径
which ls

13.chmod

#修改文件权限 + - 覆盖
# u(user) g(group) o(other) a(all)
# r (read)w(write) x(execute)
chmod o+w file
chmod 777 file
chmod +001 file

14.chown

#修改文件所有者和所有组
#管理员权限 chmod new文件所有者:new文件所有组 文件名
sudo chown usrname:groupname filename

15.chgrp

#修改文件所有组
#chgrp new文件所有组 文件名
sudo chgrp groupname filename

16.文件查找

find(按照文件名,类型,大小查)
grep(按照文件内容查找)

find search_dir -name "filename"
find search_dir -type d/f/b/c/s/p
#查找文件<1k的
find search_dir -size -1k

#在指定目录下递归查找hello关键字
grep -r “hello” search_dir

17.程序安装

三种方式:1.在线安装 2.deb包安装 3.源码安装

#1.在线安装:install remove update clean
	sudo apt-get install soft_name
#2.deb包安装:
	#1.安装 -i
		sudo dpkg -i subline-amd64.deb
	#2.卸载 -r
		sudo dpkg -r subline
#3.源码安装(参看具体包的readme)
	#1.解压缩文件包
	#2.进入目录
	#3.执行./config
	#4.编译源代码 make
	#5.安装 sudo make install
	#6.卸载软件 sudo make distclean

18.U盘挂载

tip:不可以在当前目录卸载当前目录

#手动挂载 设备名 挂载目录
mount DeviceName /mnt
#手动卸载
umount /media/itcast/usb_name

19.压缩包

关键命令:gzip gunzip bzip2 bunzip2 tar rar zip unzip

#gzip每个文件单独压缩,且不会保留源文件
	gzip *.txt
	gunzip *.gz
#bzip每个文件单独压缩,但是可以保留源文件
	bzip2 *.txt
	bunzip *.bz2
#tar(常用)
	#压缩
		tar zcvf XXX.tar.gz dir/file
		tar jcvf XXX.tar.bz2 dir/file
	#解压缩到指定目录
		tar zxvf XXX.tar.gz -C dir
		tar jxvf XXX.tar.bz2 -C dir
#rar
	#压缩 自动生成后缀
		rar a file_name source_name
	#解压缩
		rar x rar_name terminal_dir
#zip 自动生成后缀
	zip file_name source_name
	unzip zip_name -d terminal_dir

20.进程管理

主要命令who ps kill env top

# who当前用户在线情况
	who
# ps aux 查看没有终端的应用程序
	ps aux|grep bash
# kill进程4986
	kill -9 4986
# 查看环境变量,管道查path关键字
	env|grep path
# top类似任务管理器
	top

21.用户管理

只用了adduser这种最简单的方式,其他方式自己找。

#创建用户
	sudo adduser luffy
#设置用户组
	sudo groupadd robin
#删除用户
	sudo deluser luffy
	sudo userdel -r luffy
#切换用户
	su luffy
#修改密码
	sudo passwd robin

22. 服务器搭建

ftp nfs 请见本人其他博客
nfs
ftp
ssh服务器搭建
1.安装openssh-server
2.远程ssh

四.vim的使用

神的编译器,太复杂,命令太多,只记忆一些简单常用的命令。

三种模式

命令模式 编辑模式 末行模式
一进入即为命令模式,命令模式可以进入编辑模式,和末行模式,编辑和末行模式只能退回到命令模式不可以相互转换。也就是状态转换必须要经过命令模式。

模式 进入 退出
编辑模式 命令模式下点击 i 编辑模式下点击esc,回到命令模式
末行模式 命令模式下点击 : 编辑模式下点击2次esc,回到命令模式

1.命令模式下的命令:

功能 命令
上下左右移动 就不说了
u(undo) 相当于windows中的ctrl+z
复制 yy
粘贴 p/P
删除 d
查找 /或者?
替换 r
高亮 #

2.编辑模式下的命令:

和记事本类似,不多说。

3.末行模式下的命令:

功能 命令
退出 q
强制退出 q!
保存退出 wq

总结

linux命令多而繁杂,只需要记忆一些常用的命令即可,常用的命令也是需要时常复习。本文只简述了常用的linux命令,大家共勉。

Guess you like

Origin blog.csdn.net/qq_23844501/article/details/112860703