开发者学堂课程【Linux 操作系统实战:文件操作管理】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/699/detail/12286
文件操作管理
目录:
一、查看路径命令
二、切换路径命令
三、创建文件命令
四、创建目录命令
五、拷贝命令
六、远程拷贝命令
七、删除文件或目录命令
八、修改或移动文件(目录)命令
九、常用的命令
一、查看路径命令
pwd
操作如下:
[root@AliECS /]# pwd
[root@AliECS /]# cd
[root@AliECS ~]# pwdroot
[root@AliECS ~]# cl
二、切换路径命令
有以下五种命令。
cd
cd./
cd..
cd /
Cd
操作如下:
[root@AliECS ~]# cd
[root@AliECS ~]# cd ./
[root@AliECS ~]# cd
[root@AliECS /]# pwd
[root@AliECS /]# cd 1
[root@AliECS /]# pwd
[root@AliECS /]# cd
[root@AliECS ~]# pwd
/ root
三、创建文件命令
touch (更新现有文件时间列表)、vi 或 vim
操作如下:
[root@AliECS ~]# II
total 4
drwxr-xr-x 2 root root 6 May 28 22:34aa
-rw-r--r-- 1 root root 62 May 28 22:50 bb.txt
drwxr-xrwx 2 ken ken 6 May 28 17:38test
drwxrwxr-x 2 root root 6 May 28 21:51 test1
drwxr-xr-x 2 root root 6 May 28 21:52 test2
drwxr-xr-x 2 root root 6 May 28 22:02 test3
-rw-r--r-- 1 root root 0 May 28 22:32 test.txt
[root@AliECS ~]#touch bb.txt
[root@AliECS ~]#II
total 4
drwxr-xr-x 2 root root 6 May 28 22:34 aa
-rw-r--r-- 1 root root 62 May 28 23:12 bb.txt
drwxr-xrwx 2 ken ken 6 May 28 17:38 test
drwxrwxr-x 2 root root 6 May 28 21:51 test1
drwxr-xr-x 2 root root 6 May 28 21:52 test2
drwxr-xr-x 2 root root 6 May 28 22:02 test3
-rw-r--r-- 1 root root 0 May 28 22:32 test.txt
[root@AliECS ~]# touch cc.txt I
四、创建目录命令
mkidr,mkdir-pV
/home/A1/A2
操作如下:
[root@AliECS~]#mkdir cc[root@AliECS~]#II
[root@AliECS ~]# mkdir -pv / home/A1/A2/A3
mkdir: created directory ' / home/A1'
mkdir:created directory '/ home/A1/A2'
mkdir: created directory ' /home/A1/A2/A3'
[ root@AliECS ~]#cd / home/A1
[root@AliECS Al]#LL-bash:LL:command not found
[ root@AliECS A1]#II
五、拷贝命令
cp;cp -R
操作如下:
[root@AliECS ~]# cp cc /home
cp:-r not specified; omitting directory 'cc'
[root@AliECS ~]# cp -R cc /home
[root@AliECS ~]# cd /home
[root@AliECS home]# II
total 8
drwxr-xr-x 3 rootroot 16 May 28 23:13 A1
drwxr-xr-x 3 root root16 May 28 22:35 A3
drwxr-xr-x 2 root root 6 May 28 22:37aa
drwxr-xr-x 2 root root 6 May 28 23:14 cc
drwxr-xr-x 2 root root 6 May 28 22:20dd
---r--r-- 1 root root 2 May 28 22:40gg.txt
-rw-r--r-- 1 root root 13 May 28 11:42 hello.txt
drwx------ 2 ken ken 62 May 28 21:30 ken
[root@AliECS home]# cp qq.txtr~/
六、远程拷贝命令
本地文件拷贝到远程服务器:
scp local file remote_user@remote_ip:remote folder;
远程服务器文件拷贝回本地:
remote user@remote ip:remote folder local folder
七、删除文件或目录命令
rm
[ root@AliECS home]# rm my.cnf - bak
rm:remove regular file ' my.cnf -bak'?
[ root@AliECS home] # II
rm -rf
[root@AliECS home ] #rm-f gg.txt
[ root@AliECS home] #rm-Rf A1
[root@AliECS home]#II
rmdir
[ root@AliECS home]# rm my.cnf - bak
rm:remove regular file ' my.cnf -bak'?
[ root@Al iECS home] # l l
八、修改或移动文件(目录)命令
mv
[root@AliECS home]# mv hello.txt /homemv:‘hello.txt'and '/home/hello.txt' are thesamefile [root@AliECS home]# mv hello.txt /home/
A3/ aa/ cc/ hello.txt ken/
[root@AliECS home]# mv hello.txt /home/ken/
[root@AliECS home]# cd /home/ken
[root@AliECS ken]# II
total 4
-rW-r--r-- 1 root root 13 May 28 11:42 hello.txt
[root@AliECSken]# mv hello.txt nihao.txt
[root@AliECS kenl#11
九、常用的命令
1.查看文件命令
cat (全部显示)
less (分页显示,可上翻)
more (显示第一页)
head -n 文件几行;
tail -n 文件后几行
2.查看或编辑文件命令
vi 或 vim
3.统计文件信息命令
wc-l, wc-c 1 wc -w
[ root@Al iECS ~] # Wc -l bb. txt
28 bb. txt
[root@AliECS~]#WC-cbb.txt
62 bb. txt
[ root@AliECS ~] # WC -W bb. txt
25 bb. Txt
4.文件搜索
1.find 、
2. whereis
root@Al iECS ~] # find / -name bb. txt
/ root/bb. txt
/usr/bb. txt
[ root@AliECS ~]# whereis top
top: /usr/bin/ top /usr/ share/ man/man1/top.1.gz
[ root@AliECS ~] #