一、虚拟机安装
- VMware 15安装
- centOS 7 安装
- 远程连接:SecureCRT
二、Linux命令使用
- 基础命令
- 文件查看相关
-
pwd:列出当前目录的路径
[root@localhost ~]# pwd /root
- ls:列出当前目录下的所有文件
[root@localhost ~]# ls anaconda-ks.cfg
-
ll(ls -l缩写):列出当前目录下的文件(带文件信息)
[root@localhost ~]# ll total 4 //“total”,是指该目录所用到的block块数(可以简单理解为文件大小) -rw-------. 1 root root 1243 Feb 19 21:40 anaconda-ks.cfg ============================================================================================================================== [root@localhost ~]# ls -l total 4 -rw-------. 1 root root 1243 Feb 19 21:40 anaconda-ks.cfg
-
ll -a:列出当前目录中所有文件信息,包括隐藏文件
[root@localhost ~]# ll -a total 28 dr-xr-x---. 2 root root 135 Feb 19 21:49 . dr-xr-xr-x. 17 root root 224 Feb 19 21:36 .. -rw-------. 1 root root 1243 Feb 19 21:40 anaconda-ks.cfg -rw-------. 1 root root 8 Feb 19 21:49 .bash_history -rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout -rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile -rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc -rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc -rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
-
ll --help:查看ls的用法,-help是一个帮助命令
-
创建、重命名文件/目录
-
touch newfilename:创建空文件
[root@localhost ~]# touch hello.txt [root@localhost ~]# ll total 4 -rw-------. 1 root root 1243 Feb 19 21:40 anaconda-ks.cfg -rw-r--r--. 1 root root 0 Feb 21 21:32 hello.txt
-
mkdir 目录名称:创建目录
[root@localhost ~]# mkdir kpstu [root@localhost ~]# ll total 4 -rw-------. 1 root root 1243 Feb 19 21:40 anaconda-ks.cfg -rw-r--r--. 1 root root 0 Feb 21 21:32 hello.txt drwxr-xr-x. 2 root root 6 Feb 21 21:35 kpstu
-
mkdir -p 目录名称:创建重名目录不报错
[root@localhost ~]# mkdir kpstu mkdir: cannot create directory ‘kpstu’: File exists ============================================================================================================================== [root@localhost ~]# mkdir -p kpstu [root@localhost ~]# ls anaconda-ks.cfg hello.txt kpstu
-
mv oldname newname:重命名文件/目录(newname不存在)
[root@localhost ~]# mv hello.txt helloworld.txt [root@localhost ~]# mv kpstu amber [root@localhost ~]# ls amber anaconda-ks.cfg helloworld.txt
-
-
链接文件
-
硬链接:相当于对原始文件的一个复制,不能对目录使用硬链接
- 命令:ln 文件 链接名
[root@localhost ~]# ls amber anaconda-ks.cfg helloworld.txt ============================================================================================================================== [root@localhost ~]# ln helloworld.txt hlink [root@localhost ~]# ls amber anaconda-ks.cfg helloworld.txt hlink
-
软链接:相当于快捷方式,主要用于节省磁盘空间
-
命令:ln -s 文件 链接名
[root@localhost ~]# ln -s helloworld.txt vlink [root@localhost ~]# ls amber anaconda-ks.cfg helloworld.txt hlink vlink
-
-
-
切换目录
-
cd .:当前目录(一个.代表当前目录)
[root@localhost ~]# pwd /root ============================================================================================================================== [root@localhost ~]# cd . [root@localhost ~]# pwd /root
-
cd …:去上级目录(两个.代表上级目录)
[root@localhost ~]# pwd /root ============================================================================================================================== [root@localhost ~]# cd .. [root@localhost /]# pwd /
-
cd /:去根目录
[root@localhost /]# cd / [root@localhost /]# pwd /
-
cd ~:去当前用户主目录
[root@localhost /]# cd ~ [root@localhost ~]# pwd /root
-
cd xxx/xxx:直接跳转到某目录
[root@localhost ~]# ls amber anaconda-ks.cfg helloworld.txt hlink link newlink vlink [root@localhost ~]# cd amber [root@localhost amber]# pwd /root/amber
-
-
删除文件/目录
rm命令可以删除文件或者目录,也可以将某个目录及其下属的所有文件及其子目录均删除掉。
对于链接文件,只是删除整个链接文件,而原有文件保持不变。
-
rm 文件名:删除文件(有确认提示)
[root@localhost ~]# ls amber anaconda-ks.cfg helloworld.txt hlink link newlink vlink [root@localhost ~]# rm newlink rm: remove symbolic link ‘newlink’? y [root@localhost ~]# ls amber anaconda-ks.cfg helloworld.txt hlink link vlink
-
rm -r 目录名:删除目录(有确认提示)
[root@localhost ~]# rm amber rm: cannot remove ‘amber’: Is a directory ====================================================================================================================== [root@localhost ~]# rm -r amber rm: remove directory ‘amber’? y [root@localhost ~]# ls anaconda-ks.cfg helloworld.txt hlink link vlink
-
rm -f 文件名:强制删除文件(没有提示)【慎用!!!】
[root@localhost ~]# ls anaconda-ks.cfg helloworld.txt hlink link vlink =================================================================================================
-
-