**
linux commonly used commands (1)
**
Notes organized by yourself. If
you have any questions, please leave a message or chat privately, thank you
**
1. Start the network command
**
ip addr view network card information
service network start 启动网卡
service network stop 关闭网卡
service network restart 重启网络
**
2.pwd command
**
pwd command, view the path of the current directory
All absolute paths under linux start from the root directory "/"
/root:是linux下root用户的根目录
/home:是linux下其他用户的默认根目录 (例如:在linux上创建了一个bow用户,那么就会在/home下面生成一个bow目录作为bow用户的根目录)
/etc:是linux下系统配置文件目录
/tmp:临时文件目录,所有用户都可以用
2.ls command
ls [parameter] directory path
ls means to view files in the directory
ls #表示查看当前目录下的文件
ls -l #表示查看当前目录下的详细信息
ls -a #表示查看当前目录下的所有文件(包含隐藏文件)
ls -la #表示查看当前目录下的所有文件(包含隐藏文件)的详细信息
ls -lh #h是以适当的单位来显示文件的大小 ls -lh表示查看当前目录下的文件的详细信息,并以合适单位显示文件大小
ls -l / #表示查看根目录"/"下文件的详细信息
ls /etc #表示查看目录/etc下的文件
ls --help #查看命令的帮助文档
--help参数:所有linux上的命令都有,但写法上有如下几种:
(1)--help
(2)--h
(3)-help
(4)-h
ll命令:它和ls -l命令功能相同,但是不是所有的linux上都默认安装
**
3.cd command
**
cd directory path#Enter a directory, the directory path can be absolute path (paths starting with / are absolute paths), or relative path.
Relative path: path starting with other than /.
Note: "." means current The directory
"..." means the upper-level directory of the current directory, and it can be used together.
"~" means the root directory of the current user. For example: when root user, ~ means /root directory and bow user, ~ means /home/bow directory
cd / #表示进入系统根目录
cd usr/ #表示进入当前目录下的usr目录
cd local/ #表示进入当前目录下的local目录
cd ./bin #表示进入当前目录下的bin目录
cd .. #表示进入当前目录的上一级目录
cd ../.. #表示进入当前目录的上级目录的上一级目录
cd /usr/local/bin #进入/usr/local/bin目录
cd ../etc #表示进入和当前目录同级的etc目录 #..表示当前目录的上一级目录 ../etc表示当前目录上级目录下的etc目录(和当前目录同级)
cd ~ #表示进入当前用户的根目录(cd ~ 和直接执行cd后不加目录的效果相同)
#例如:root用户进入/root目录,bow用户进入/home/bow目录
cd ~/data #表示进入当前用户根目录下的data目录 例如:root用户则进入了/root/data目录
**
4.mkdir command
**
mkdir directory path#Create a directory, the directory path can be an absolute path or a relative path
mkdir data #在当前目录下创建一个data目录
mkdir ./dir #在当前目录下创建一个dir目录
mkdir /root/tmp #在/root目录下创建一个tmp目录
When mkdir creates a directory, it will only be created if the parent directory of the directory exists
mkdir -p directory#When creating a directory, if there is no parent directory, the parent directory will be created, and the directory will be created recursively
mkdir -pa/b/c #Create a three-level directory in the current directory
**
5.rmdir command
**
rmdir [参数] 目录路径 #删除目录命令,rmdir默认只能删除空目录
rmdir ./dir #删除当前目录下的dir目录
rmdir -p 目录路径 #表示删除目录和它的父目录(目录要是一个空目录)
rmdir -p a/b/c #删除当前目录下的a/b/c目录
**6.touch command
**
touch command#Create file command
touch file path
touch 1.txt #在当前目录下创建一个1.txt文件
touch /root/2.txt #在/root目录下创建一个2.txt文件
**
7.rm command
**
rm [parameter] path#delete command
rm 1.txt #Delete the 1.txt file in the current directory. When deleting, it will prompt whether to delete. If you enter y to delete, enter n to not delete
rm -f /root/2.txt #-f means to delete forcibly, without prompting, forcibly delete 2.txt in the /root directory
rm -r a/ #递归的删除当前目录下a目录下的所有内容
[root@bow ~]# rm -r a/
rm:是否进入目录"a/"? y
rm:是否进入目录"a/b"? y
rm:是否进入目录"a/b/c"? y
rm:是否删除普通空文件 "a/b/c/3.txt"?y
rm:是否删除目录 "a/b/c"?y
rm:是否删除普通空文件 "a/b/2.txt"?y
rm:是否删除目录 "a/b"?y
rm:是否删除普通空文件 "a/1.txt"?y
rm:是否删除目录 "a/"?y
rm -rf a/ #强制删除当前目录下a目录及a目录下的所有内容
rm -rf * #删除当前目录下的所有内容
rm -rf a/* #删除当前目录下a目录下的所有内容
rm -rf *.txt #删除当前目录下的所有txt文件
rm -rf *s* #删除当前目录下所有名字中包含s的文件或文件夹
**
8.echo command
**
echo #output command, you can input variables, string values
echo Hello World #打印Hello World
echo $PATH #打印环境变量PATH的值,其中$是取变量值的符号,用法:$变量名 或者 ${变量名}
echo -n #打印内容但不换行
echo -n Hello World
**
9.> and >> commands
**
And >>: output symbols, output the content to the file,> means overwrite (the original file content will be deleted) >> means append
echo Hello World > 1.txt #将Hello World输出到当前目录下的1.txt文件
#如果当前目录下没有1.txt文件会创建一个新文件,
#如果当前目录下有1.txt,则会删除原文件内容,写入Hello World
echo 1234 >> 1.txt #将1234追加到当前目录下的1.txt中,如果文件不存在会创建新文件
Files can be created by both >> and >>
10. File view command
cat file path#View all contents of the file
cat 1.txt #查看当前目录下1.txt的内容
cat /root/1.txt #查看/root目录下的1.txt文件内容
more file path#View file content by page
more linux commonly used commands.txt #page to view the contents of the linux commonly used commands.txt file in the current directory
#Press space or enter, the file content will continue to be loaded, press q to exit the view
#When loading to the end of the file, it will automatically exit the view
less file path#View the file content by page
less common linux commands.txt #View the file content by page, press the space to continue loading the file, press q to exit the view, it will not automatically exit the view
head [parameter] file path#View file from file
head linux常用命令.txt #查看文件的前10行内容
head -n 文件路径 # n是一个正整数,表示查看文件的前n行数据
head -20 linux常用命令.txt #查看文件的前20行内容
tail [parameter] file path#View the file content from the end of the file
tail linux commonly used commands.txt #View the last 10 lines of the file
tail -n 文件路径 # n是一个正整数,表示查看文件的后n行数据
tail -15 linux常用命令.txt #查看文件后15行内容
tail -f 文件路径 #动态的查看文件的最后几行内容(查看文件时,等待文件更新,如果文件更新了,会显示出新的内容)
tail -f 1.txt #View the latest content of file 1.txt, tail -f is generally used to view log files and press CTRL+C or CTRL+Z to exit the view
CTRL+C:表示暂停进程
CTRL+Z: 表示停止进程