Linux与Docker常见命令

52 阅读4分钟

Linx:

ls:

显示指定目录下的内容: ls [-al] [dir]
-a 显示所有文件及目录 (. 开头的隐藏文件也会列出)
-l 除文件名称外,同时将文件型态(d表示目录,-表示文件)、权限、拥有者、文件大小等信息详细列出
ls -al 查看当前目录的所有文件及目录详细信息
ls -al /etc 查看/etc目录下所有文件及目录详细信息
ll 查看当前目录文件及目录的详细信息

cd:

用于切换当前工作目录,即进入指定目录: cd [dirName]
cd .. 切换到当前目录的上级目录
cd ~ 切换到用户的home目录
cd /usr/local 切换到/usr/local目录

mkdir

创建目录: mkdir [-p] dirName
mkdir itcast 在当前目录下,建立一个名为itcast的子目录
mkdir -p itcast/test 在工作目录下的itcast目录中建立一个名为test的子目录,若itcast目录不存在,则建立一个

rm

删除文件或者目录: rm [-rf] name
rm -r itcast/ 删除名为itcast的目录和目录中所有文件,删除前需确认
rm -rf itcast/ 无需确认,直接删除名为itcast的目录和目录中所有文件
rm -f hello.txt 无需确认,直接删除hello.txt文件

cat

用于显示文件内容: cat [-n] fileName
cat /etc/profile 查看/etc目录下的profile文件内容

more

以分页的形式显示文件内容: more fileName
more /etc/profile 以分页方式显示/etc目录下的profile文件内容
回车键 向下滚动一行
空格键 向下滚动一屏
b 返回上一屏 q或者Ctrl+C 退出more

head

查看文件开头的内容: head [ -n ] fileName
head 1.log 默认显示1.log文件开头的10行内容
head -20 1.log 显示1.log文件开头的20行内容

tail

查看文件末尾的内容: tail [-f] fileName
tail /etc/profile 显示/etc目录下的profile文件末尾10行的内容
tail -20 /etc/profile 显示/etc目录下的profile文件末尾20行的内容
tail -f /itcast/my.log 动态读取/itcast目录下的my.log文件末尾内容并显示

cp

用于复制文件或目录: cp [-r] source dest
cp hello.txt itcast/ 将hello.txt复制到itcast目录中
cp hello.txt ./hi.txt 将hello.txt复制到当前目录,并改名为hi.txt
cp -r itcast/ ./itheima/ 将itcast目录和目录下所有文件复制到itheima目录下
cp -r itcast/* ./itheima/ 将itcast目录下所有文件复制到itheima目录下

mv

为文件或目录改名、或将文件或目录移动到其它位置: mv source dest
mv hello.txt hi.txt 将hello.txt改名为hi.txt
mv hi.txt itheima/ 将文件hi.txt移动到itheima目录中
mv hi.txt itheima/hello.txt 将hi.txt移动到itheima目录中,并改名为hello.txt
mv itcast/ itheima/ 如果itheima目录不存在,将itcast目录改名为itheima
mv itcast/ itheima/ 如果itheima目录存在,将itcast目录移动到itheima目录中

tar

对文件进行打包、解包、压缩、解压: tar [-zcxvf] fileName [files] (包文件后缀为.tar表示只是完成了打包,并没有压缩;包文件后缀为.tar.gz表示打包的同时还进行了压缩)
tar -cvf hello.tar ./* 将当前目录下所有文件打包,打包后的文件名为hello.tar
tar -zcvf hello.tar.gz ./* 将当前目录下所有文件打包并压缩,打包后的文件名为hello.tar.gz
tar -xvf hello.tar 将hello.tar文件进行解包,并将解包后的文件放在当前目录
tar -zxvf hello.tar.gz 将hello.tar.gz文件进行解压,并将解压后的文件放在当前目录
tar -zxvf hello.tar.gz -C /usr/local 将hello.tar.gz文件进行解压,并将解压后的文件放在/usr/local目录

find

在指定目录下查找文件: find dirName -option fileName
find . –name ".java" 在当前目录及其子目录下查找.java结尾文件
find /itcast -name "
.java" 在/itcast目录及其子目录下查找.java结尾的文件

grep

从指定文件中查找指定的文本内容: grep word fileName
grep Hello HelloWorld.java 查找HelloWorld.java文件中出现的Hello字符串的位置
grep hello *.java 查找当前目录中所有.java结尾的文件中包含hello字符串的位置

Docker

docker pull 拉取镜像
docker push 推送镜像到DockerRegistry
docker images 查看本地镜像
docker rmi 删除本地镜像
docker run 创建并运行容器(不能重复创建)
docker stop 停止指定容器
docker start 启动指定容器
docker restart 重新启动容器
docker rm 删除指定容器
docker ps 查看容器
docker logs 查看容器运行日志
docker exec 进入容器
docker save 保存镜像到本地压缩文件
docker load 加载本地压缩文件到镜像
docker inspect 查看容器详细信息
docker volume create 创建数据卷
docker volume ls 查看所有数据卷
docker volume rm 删除指定数据卷
docker volume inspect 查看某个数据卷的详情
docker volume prune 清除数据卷