1.Linux命令行使用技巧 2.Linux下的文件管理(上)
1.Linux命令行使用技巧
什么是Linux?
Linux:Linux内核
内核:1 系统的核心程序 2 相当于人的大脑 3 负责系统程序和硬件分配及调度
shell打开方式
1 右键打开
2 Application-favorites-terminal
3 gnome-terminal
4 在shell中还需代开一个新的shell,按住shift+ctrl+n打开
5 设置快捷键进行 setting-devices-keyboard 添加指令gnome-terminal
注意:
[[email protected] Desktop]#
1 Desktop表明当前目录名称
2 root表明运行shell的用户
3 #为超级用户 $为普通用户
shell中的快捷键
1 ctrl+c 取消命令执行
2 ctrl+d 关闭shell
3 ctrl+shift+t 在一个terminal中开启多个窗口
4 ctrl+shift+n 重新打开一个terminal
shell中获得帮助命令
-
whatis rm 查看命令用途
-
su - root 切换为超级用户
-
mandb 更新命令
-
rm --help 查看帮助
-
man rm
q 退出
G 移动到man最后
g 移动到man最前
/关键字 搜索 n往下 N往上 -
history 查看历史
! 数字 or!字符 根据序号和字符调用历史命令
ctrl+r 可以搜索关键字调用历史 -
history -c 清空当前历史命令,永久清空历史需要清空文件 .bash_history
-
tab键自动补全命令
按一次自动补全如果不显示,按两次显示含有字符的全部命令
2.Linux下的文件管理(上)
文件管理命令
-
touch
touch file file1 file2 建立空文件
touch file 将文件同步到当前时间
touch -t YYMMDDHHmm file 将文件更改到当前时间
-
mkdir (make directory)
mkdir dir dir1 dir2 建立空目录
mkdir -p dir/westos/linux 建立多层目录 -
rm
rm file file1 file2 删除文件有提示
rm -f file 强制删除文件不提示
rm -r dir dir1 dir3 删除目录
rm -rf dir 强制删除目录 -
gedit
gedit file file1 编辑文件
其中gedit在使用时必须有图形,file file1可以不存在 -
vim
vim file 进入vim的浏览模式
vim -o file file1 上下模式打开文件 按 ctrl+w 后通过 上|下 键切换窗口
vim -p file file1 左右模式打开文件 按 :tabn 进入下一个窗口 按 :tabp 进入上一个窗口
按 i 进入插入模式
按Esc退出插入模式
按:wq保存更改
注意vim异常退出
按 D 键 -
cat
cat file 显示文件内容
cat -b file 显示文件内容并显示行号,不显示空行的行号
cat -n file 显示文件内容并显示行号,显示空行的行号
history > file 将history的内容放到file中 -
head
head file 默认查看文件前10行
head -n file 默认查看文件前n行 -
tail
tail file 默认查看文件后10行
tail -n file 默认查看文件后n行 -
less
less file 进入分页浏览(less)模式查看file
上、下 逐行查看文件内容
pgup、pgdn 逐页查看文件内容
/关键字 搜索关键字 n 往下 N 往上
按 v 进入vim模式 :wq 返回less
按 q 退出less模式 -
cp
cp 文件 目的地文件
cp 文件1 文件2 目的地目录
cp -r 目录1 目录2
复制原理:按照源文件建立新文件(抄作业) -
mv
mv file file1 dir 将文件移动到目录下
mv dir dir1 dir 将目录移动到目录下
mv file 不存在file 重命名 eg:mv file file1 将file重命名为file1
移动原理:相同设备分区的移动过程是重命名的过程,不同分区的文件移动是建立删除的过程
ls -i file 查看文件节点号(相当于文件身份证号)