随笔 - 55  文章 - 0  评论 - 0  阅读 - 1047

01_常用命令

1. 查看当前目录下所有东西
# ls => list: 列表展示

# 查看当前目录都有什么 . 表示当前,  ./ 也表示当前,可以简写为 ls
ls
ls .
ls ./

# 查看 aaa 目录下都有什么
ls aaa/

# 查看上层目录
ls ../

# 查看上上层目录
ls ../../

# 加参数 -l, 查看更详细的文件信息
# Oct 文件创建的日期
# ls --help  不会的时候,查看帮助文档
root@bk:~/ckh# ls -l
total 8
-rw-r--r-- 1 root root 4 Oct  6 15:17 1.txt
-rw-r--r-- 1 root root 4 Oct  6 15:23 2.txt
2. 切换目录
# cd => change directory

# /     根目录
# /root 家目录

# 去根目录 绝对路径
cd /

# 去家目录
cd /root
cd ~

# 去 /root/test 绝对路径
cd /root/test

# 去当前目录下的test目录 相对路径
cd test

# 切换上层目录
cd ../

# 切换上上层目录
cd ../../
3. 查看当前路径、位置
pwd
4. 创建文件夹
# mkdir => make directory

root@bk:~/ckh# mkdir dir1
root@bk:~/ckh# mkdir dir2
root@bk:~/ckh# ls -l
total 16
-rw-r--r-- 1 root root    4 Oct  6 15:17 1.txt
-rw-r--r-- 1 root root    4 Oct  6 15:23 2.txt
drwxr-xr-x 2 root root 4096 Oct  6 15:25 dir1
drwxr-xr-x 2 root root 4096 Oct  6 15:25 dir2

# 递归创建文件夹 此种情况,前面的目录要提前存在
root@bk:~/ckh# mkdir test1/test2/test3

# 递归创建文件夹
root@bk:~/ckh# mkdir -p test1/test2/test3

# 绝对路径创建文件夹
mkdir /root/ckh/test1/test2/test3/test4
5. 创建文件
# 方法1 创建的是空文件
root@bk:~/ckh# touch 1.txt
root@bk:~/ckh# touch 2.txt
root@bk:~/ckh# ls -l
total 0
-rw-r--r-- 1 root root 0 Oct  6 15:33 1.txt
-rw-r--r-- 1 root root 0 Oct  6 15:33 2.txt

# 方法2 创建文件并写入内容 覆盖
root@bk:~/ckh# echo "abc" >3.txt
root@bk:~/ckh# cat 3.txt
abc
root@bk:~/ckh# echo "aaa" >3.txt
root@bk:~/ckh# cat 3.txt
aaa
root@bk:~/ckh# echo "bbb" >>3.txt
root@bk:~/ckh# cat 3.txt
aaa
bbb

# 方法3 用vim命令
vim 4.txt => i 输入 => esc => shift + : => wq

6. 删除文件或文件夹
root@bk:~/ckh# ls -l
total 12
-rw-r--r-- 1 root root    0 Oct  6 15:33 1.txt
-rw-r--r-- 1 root root    0 Oct  6 15:33 2.txt
-rw-r--r-- 1 root root    8 Oct  6 15:42 3.txt
-rw-r--r-- 1 root root   66 Oct  6 15:44 4.txt
drwxr-xr-x 2 root root 4096 Oct  6 15:38 aaa
root@bk:~/ckh# rm -rf 1.txt
root@bk:~/ckh# rm -rf aaa/
root@bk:~/ckh# ls
2.txt  3.txt  4.txt
root@bk:~/ckh# rm -rf *.txt
root@bk:~/ckh# ls
7. 复制文件或文件夹
# cp => copy 复制

# 复制文件
root@bk:~/ckh# echo 111 > 1.txt
root@bk:~/ckh# ls
1.txt
root@bk:~/ckh# cat 1.txt
111
root@bk:~/ckh# cp 1.txt 2.txt
root@bk:~/ckh# ls
1.txt  2.txt
root@bk:~/ckh# cat 2.txt
111

# 复制文件夹(多层) -r 不论何时,复制目录都要添加
root@bk:~/ckh# mkdir -p test1/test2
root@bk:~/ckh# ls
1.txt  2.txt  test1
root@bk:~/ckh# cp test1/ test7
cp: -r not specified; omitting directory 'test1/'
root@bk:~/ckh# cp -r test1/ test7
root@bk:~/ckh# ls
1.txt  2.txt  test1  test7
root@bk:~/ckh# ls test7/
test2

8. 移动并重命名
# mv => move 移动

# 重命名
root@bk:~/ckh# ls
1.txt
root@bk:~/ckh# mv 1.txt 2.txt
root@bk:~/ckh# ls
2.txt

# 移动/剪切
root@bk:~/ckh# ls
2.txt
root@bk:~/ckh# mkdir test1
root@bk:~/ckh# ls
2.txt  test1
root@bk:~/ckh# mv 2.txt test1/
root@bk:~/ckh# ls
test1
root@bk:~/ckh# ls test1/
2.txt

# 剪切并重命名
root@bk:~/ckh# ls
test1
root@bk:~/ckh# ls test1/
2.txt
root@bk:~/ckh# mkdir test2
root@bk:~/ckh# mv test1/2.txt test2/3.txt
root@bk:~/ckh# ls
test1  test2
root@bk:~/ckh# ls test1/
root@bk:~/ckh# ls test2/
3.txt

# 重命名文件夹
root@bk:~/ckh# ls
test1  test2
root@bk:~/ckh# mv test1/ test3
root@bk:~/ckh# ls
test2  test3

9. 查看文件内容
# cat 查看文件内容 cat 本意是 猫
root@bk:~/ckh# ls
main.sh
root@bk:~/ckh# cat main.sh
#!/bin/bash
echo "hello,world"
10. vim 内部命令
# i 之后,insert 出现的时候,叫编辑模式
# esc 之后,普通模式
# :末行模式


删除1行:  i(进入编辑模式) + 退格
删除1行: 普通模式  dd
删除4行: 普通模式  4dd
删除所有行: 普通模式 光标移动到第一行 9999dd
还原:普通模式 u
快速移动到顶部:普通模式 gg
快速移动到底部:普通模式 GG

末行模式:set nu 显示行数
posted on   鸟叔书  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
< 2025年3月 >
23 24 25 26 27 28 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 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示