安装
sudo apt-get install .. .
文件操作
1. Terminal
laplacekang@laplacekang- virtual- machine:~$
laplacekang(@前)
laplacekang-virtual-machine(@后)
~
现在的目录,这里为home目录,即/home/laplacekang $
2. cd 进入
cd bin/
cd . .
cd . . / . . /
cd -
去往 home (/home/laplacekang)
cd ~
cd / opt/ ros/ kinetic
3. ls 显示
laplacekang@laplacekang- virtual- machine:/ opt/ ros/ kinetic$ ls
bin include local_setup. sh setup. sh share
env. sh lib local_setup. zsh _setup_util. py
etc local_setup. bash setup. bash setup. zsh
ls -l
(long 的简写)
输出详细信息,打印出文件的权限 (-rw-rw-r--
), 用户名, 文件大小, 修改日期, 文件名
laplacekang@laplacekang- virtual- machine:/ opt/ ros/ kinetic$ ls - l
总用量 80
drwxr- xr- x 2 root root 4096 7月 29 12:44 bin
- rwxr- xr- x 1 root root 506 12月 14 2019 env. sh
drwxr- xr- x 4 root root 4096 7月 29 12:42 etc
drwxr- xr- x 102 root root 4096 7月 29 12:44 include
drwxr- xr- x 93 root root 12288 7月 29 12:44 lib
- rw- r-- r-- 1 root root 283 12月 14 2019 local_setup. bash
- rw- r-- r-- 1 root root 347 12月 14 2019 local_setup. sh
- rw- r-- r-- 1 root root 293 12月 14 2019 local_setup. zsh
- rw- r-- r-- 1 root root 260 12月 14 2019 setup. bash
- rw- r-- r-- 1 root root 2774 12月 14 2019 setup. sh
- rwxr- xr- x 1 root root 13331 12月 14 2019 _setup_util. py
- rw- r-- r-- 1 root root 270 12月 14 2019 setup. zsh
drwxr- xr- x 235 root root 12288 7月 29 12:44 share
ls -lh
(human)
直接 -l
不方便人看, 这个指令是为了方便给人观看的. 注意:这里的文件大小使用了 K, MB, GB 之类概括
laplacekang@laplacekang- virtual- machine:/ opt/ ros/ kinetic$ ls - lh
总用量 80K
drwxr- xr- x 2 root root 4. 0K 7月 29 12:44 bin
- rwxr- xr- x 1 root root 506 12月 14 2019 env. sh
drwxr- xr- x 4 root root 4. 0K 7月 29 12:42 etc
drwxr- xr- x 102 root root 4. 0K 7月 29 12:44 include
drwxr- xr- x 93 root root 12K 7月 29 12:44 lib
- rw- r-- r-- 1 root root 283 12月 14 2019 local_setup. bash
- rw- r-- r-- 1 root root 347 12月 14 2019 local_setup. sh
- rw- r-- r-- 1 root root 293 12月 14 2019 local_setup. zsh
- rw- r-- r-- 1 root root 260 12月 14 2019 setup. bash
- rw- r-- r-- 1 root root 2. 8K 12月 14 2019 setup. sh
- rwxr- xr- x 1 root root 14K 12月 14 2019 _setup_util. py
- rw- r-- r-- 1 root root 270 12月 14 2019 setup. zsh
drwxr- xr- x 235 root root 12K 7月 29 12:44 share
laplacekang@laplacekang- virtual- machine:/ opt/ ros/ kinetic$ ls - a
. . catkin include local_setup. sh setup. bash setup. zsh
. . env. sh lib local_setup. zsh setup. sh share
bin etc local_setup. bash . rosinstall _setup_util. py
laplacekang@laplacekang- virtual- machine:/ opt/ ros/ kinetic$ ls -- help
4. touch 新建文件
laplacekang@laplacekang- virtual- machine:~/ try $ touch file1
laplacekang@laplacekang- virtual- machine:~/ try $ touch file2 file3 file4
5. cp 复制
5.1 文件
将 file1
复制到 file1copy
不会判断file1copy
是否存在,若存在则会覆盖
laplacekang@laplacekang- virtual- machine:~/ try $ cp file1 file1copy
laplacekang@laplacekang- virtual- machine:~/ try $ cp file1 file1copy
-i
(interactive)
cp
后加上-i
,可以避免覆盖在问句后面打上 “Yes”, “Y”, 或者任何大小写形式的 “y” 和 “yes”, 它将进行覆盖操作. 直接回车或者打其他字母, 就会放弃复制这项操作.
laplacekang@laplacekang- virtual- machine:~/ try $ cp - i file1 file1copy
cp :是否覆盖'file1copy' ? y
laplacekang@laplacekang- virtual- machine:~/ try $ cp - i file1 file1copy
cp :是否覆盖'file1copy' ? n
5.2 文件夹
laplacekang@laplacekang- virtual- machine:~/ try $ cp file1 folder1/
laplacekang@laplacekang- virtual- machine:~/ try $ cp - R folder1/ folder2/
复制多个文件
复制名字部分相同的多个文件,file*
是说“找以file开头的文件”
laplacekang@laplacekang- virtual- machine:~/ try $ cp file* folder2/
单独选定几个文件, cp
会默认最后一个选项是要复制去的文件夹
laplacekang@laplacekang- virtual- machine:~/ try $ cp file1copy file2 folder1/
6. mv 移动
laplacekang@laplacekang- virtual- machine:~/ try $ mv file1 folder1/
重命名文件
移动文件到原始的地点, 但是以不同的文件名. 这种做法不就是在重命名嘛!
laplacekang@laplacekang- virtual- machine:~/ try $ mv file2 file2Rename
7. mkdir 创建文件夹
laplacekang@laplacekang- virtual- machine:~/ try $ mkdir folder3
laplacekang@laplacekang- virtual- machine:~/ try $ mkdir folder3/ f3
8. rmdir 移除空文件夹
laplacekang@laplacekang- virtual- machine:~/ try $ rmdir folder3
rmdir : 删除 'folder3' 失败: 目录非空
laplacekang@laplacekang- virtual- machine:~/ try $ cd folder3/
laplacekang@laplacekang- virtual- machine:~/ try / folder3$ rmdir f3
9. rm 移除文件
laplacekang@laplacekang- virtual- machine:~/ try $ rm file3
-i
或 -I
有提示地移除文件 (为了避免误删)
-i
会每个要移除的文件都进行提示-I
超过3个文件才进行提示
laplacekang@laplacekang- virtual- machine:~/ try / folder2$ rm - i file1copy
rm :是否删除普通空文件 'file1copy' ? y
laplacekang@laplacekang- virtual- machine:~/ try / folder2$ rm - I file1
laplacekang@laplacekang- virtual- machine:~/ try / folder2$ rm - I file1 file2 file3 file4
rm : remove 4 arguments? n
laplacekang@laplacekang- virtual- machine:~/ try / folder2$ rm - i file1 file2 file3 file4
rm :是否删除普通空文件 'file1' ? y
rm :是否删除普通空文件 'file2' ? n
rm :是否删除普通空文件 'file3' ? n
rm :是否删除普通空文件 'file4' ? y
-r
或 -R
(recursively) 用来删文件夹
和 rmdir
不同, rm -r
可以在文件夹中有文件的情况下删除这个文件夹
laplacekang@laplacekang- virtual- machine:~/ try / folder2$ cd . . /
laplacekang@laplacekang- virtual- machine:~/ try $ rmdir folder2
rmdir : 删除 'folder2' 失败: 目录非空
laplacekang@laplacekang- virtual- machine:~/ try $ rm folder2
rm : 无法删除'folder2' : 是一个目录
laplacekang@laplacekang- virtual- machine:~/ try $ rm - r folder2
权限管理
1. ls -l 查看权限
laplacekang@laplacekang- virtual- machine:~/ try $ ls - l
总用量 8
- rw- rw- r-- 1 laplacekang laplacekang 0 7月 29 16:47 file1copy
- rw- rw- r-- 1 laplacekang laplacekang 0 7月 29 16:28 file2Rename
- rw- rw- r-- 1 laplacekang laplacekang 0 7月 29 16:28 file4
drwxrwxr- x 2 laplacekang laplacekang 4096 7月 29 17:09 folder1
drwxrwxr- x 2 laplacekang laplacekang 4096 7月 29 17:45 folder3
Type
: 很多种 (最常见的是 -
为文件, d
为文件夹).User
: User 一般就是指你, 这个正在使用电脑的人
后面跟着的三个空是使用 User 的身份能对这个做什么处理 (r
能读; w
能写; x
能执行; -
不能完成某个操作). Group
: 一个 Group 里可能有一个或多个 user, 这些权限的样式和 User 一样.像一个企业部门的电脑, 都可以放在一个 Group 里, 分享了一些共享文件和权限Others
: 除了 User 和 Group 以外人的权限.
2. chmod 修改权限(change mode)
laplacekang@laplacekang- virtual- machine:~/ try $ chmod 777 *