常用操作
指令 | 功能 |
---|
man | manual,查看指令用法 |
clear | 清空终端 |
history | 输出历史命令 |
!cmd | 运行之前的命令,cmd由history运行后的cmd标号 |
文件操作——file operation
指令 | 功能 |
---|
ls | list the direction and files |
ls -a | list all includes hidden directory and files,将所有文件(包括隐藏文件)一起显示 |
ls -l | format list,将文件信息一起输出 |
ll -a | format list (ls -l的缩写) |
cd | change directory to the /home/user |
cd ~ | ~mean the /home/user directory |
cd / | 回到根目录 |
cd dir_path | change to the dir_path directory,回到用户目录 |
cd … | 返回上一级,‘.’代表着当前目录 ,‘…’代表着上级目录 |
pwd | present working directory,打印当前目录 |
mkdir dir | create a directoy |
touch file | create a file |
vi file | gvim editor |
gvim file | 返回上一级 |
chmod 777 dir | change r/w/x property |
文件类型和权限
注意:chmod 777 中的777指的是rwxrwxrwx,750设置的比较多指的是rwxr-x—
查看文件内容
指令 | 功能 |
---|
cat file | look at the file context on terminal |
more file | view the file ,按回车键能继续看 |
less file | view the file like gvim or vi,按“q”可推出 |
wc file | count lines words and characters,打印字数和行数 |
wc -w file | count word of file, 打印字数 |
wc -l file | count line ,打印行数 |
wc -c file | count characters ,打印字符数 |
拷贝文件
指令 | 功能 |
---|
cp (-f) file1 file2 | copy file1 to file2,拷贝文件, -f 强制拷贝 |
cp -r dir1 dir2 | copy directory recursively,递归拷贝 |
文件的移动和重命名
指令 | 功能 |
---|
mv file1 dir|file2 | move file1 to dir, or rename file1 to file2 |
-i | 如果存在同名,先询问是否覆盖 |
-f | 强制移动,不提示直接覆盖已有文件 |
-v | 显示删除速度 |
文件删除
指令 | 功能 |
---|
rm file | remove file |
rm -r dir | remove dir* recursively |
rm -f file | enforce to remove file(force),强制删除 |
rm -rf dir | enforce to remove dir* recursively |
rm [选项] file | 文件删除 |
-r | 递归删除,删除文件夹 |
-i | 删除前询问确认 |
-f | 强制删除 |
-v | 显示删除速度 |
模式匹配
指令 | 功能 |
---|
grep pattern file | search pattern matched in file |
grep error sim.log | 在sim.log中查找有error的行 |
grep -r pattern dir | search pattern incursively in directory,在路径dir下递归匹配 |
文件查找
指令 | 功能 |
---|
find / -name file_name | search the file form /directory,'/‘根目录 ,’.'当前目录 |
fine /etc -name ‘*con*’ | 在/etc路径下查找 |
find / -size +100M | 查找大于100M的文件 |
文件打包和压缩
指令 | 功能 |
---|
tar -cvf file.tar files | create a tar file,打包文件 |
tar -xvf file.tar | extract a tar file,解绑文件 |
tar -czvf file.tar.gz files | create a gzip file,压缩文件 |
tar -xzvf file.tar.fz | 解压文件 |
tar -cjvf file.tar.bz2 files | create a bzip2 file |
tar -xjvf file.tar.bz2 | |
gzip file | create a file.gz file |
gzip -d file.gz | 解压 |
注:常用解压命令 tar -xzpf file.tar.gz ,不显示操作详细信息,或者是tar -xvzpf file.tar.gz,显示操作详细信息。
文件的比较
指令 | 功能 |
---|
diff [选项] file1 file2 | 比较两个文件是否一样 |
diff -r dir1 dir2 | 比较两个目录是否一致 |
-b | 忽略空格造成的不同 |
-q | 只报告什么地方不同,不报告具体的不同信息 |
-i | 忽略大小写的变化 |
-r | 在比较目录时比较所有的子目录 |
-s | 两个文件相同时才报告 |
-v | 在表尊输出上输出版本信息并退出 |
安装rpm包——install rpm package
指令 | 功能 |
---|
rpm -qa | query all install rpm packages,输出所有rpm包 |
rpm -ivh rpm.rpm | install rpm package |
重定向和管道
重定向
指令 | 功能 |
---|
grep error cmp.log > error.log | 将cmp.log中含有error的行输出到error.log中 |
grep error cmp.log >> error.log | 追加输出到error.log中 |
cat > file | sample the standard input and put them into the file,将键盘输入放入file中,^c退出 |
管道
指令 | 功能 |
---|
rpm -qa |grep vim | 将rpm -qa的输出作为grep vim的输入,即rpm -qa得到所有的rpm包,再通过grep vim匹配vim的rpm包 |
grep error sim.log | tee -a error.log | tee也是将文件输出到error.log中,-a指的是追加 |
man ls | col -b > ls_man.txt | col -b 是将回车键给去掉 |
进程管理——process manage
指令 | 功能 |
---|
ps | display the current active process |
top | display all process of the OS,包括root,其他user的进程 |
kill pid | stop the pid process |
killall proc | stop all of the proc process |
bg | list the suspended job in background |
fg | resum the last suspended job in foreground,将后台的进程调到前台 |
打印系统信息——system info
指令 | 功能 |
---|
date | 打印时间 |
data +%Y%m%d | 年月日打印时间 |
cal | 打印日历 |
which cmd | 打印cmd的路径 |
whoami | print effective userid,打印当前使用的账号名 |
who | 查看当前有哪些用户登录到系统中 |
w | display who logon and what are doing, 打印系统谁登录了并且干了什么 |
su root | usr |
exit | 退出root |
echo $PATH | show the variable,打印变量 |
cat /proc/cpuinfo | show CPU information,打印cpu信息 |
cat /proc/meminfo | show memory information,打印内存信息 |
df | report file system disk space information |
du -b|k|m file|dir | estimate file space usage |
du -s file |dir | summary |
du -sm file|file | |
网络信息——network info
指令 | 功能 |
---|
ping host | IP |
hostname | display system host name |
ifconfig -a | configure the network |
快捷键——hot key
指令 | 功能 |
---|
ctrl + c | 终端指令 |
ctrl + z | 将指令放在后台 |
VNC常用指令
指令 | 功能 |
---|
vncserver | 开vncserver |
vncserver -kill :# | 关闭vncserver,#代表端口号 |
vncpasswd | 更改vnc密码 |
vncserver -geometry 1200x800 | 设置分辨率 |
vncserver -geometry 1200x800 :69 | 申请指定的端口 |
vncconfig -nowin & | window通过vnc和linux进行复制,-nowin可不要,&指的是后台运行 |