一、目录相关命令
1.Pwd:查看当前所在的目录位置
[root@localhost ~]#pwd
/root
2.cd:切换目录
- cd ~:回到用户的家目录(工作目录)
- cd dir:切换到dir目录
- cd .. :返回上一级目录
[root@localhost ~]# cd dir
[root@localhost dir]# cd ~
[root@localhost ~]# cd ..
[root@localhost /]#
3.ls:列出当前目录下的文件或者目录
- ls -a:列出所有文件(包括隐藏文件)
- ls -A:列出所有文件(包括隐藏文件,不包括.和..)
- ls -l :列出文件的详细信息(包括文件拥有者、所属组、大小、创建时间、文件名)
[root@localhost ~]# ls -a
. anaconda-ks.cfg .bash_logout .bashrc csdn1 .cshrc index.html .pki www
.. .bash_history .bash_profile csdn csdn2 dir nginxtest.tar .tcshrc
[root@localhost ~]# ls -A
anaconda-ks.cfg .bash_logout .bashrc csdn1 .cshrc index.html .pki www
.bash_history .bash_profile csdn csdn2 dir nginxtest.tar .tcshrc
[root@localhost ~]# ls -l
total 140688
-rw-------. 1 root root 1260 Apr 24 11:30 anaconda-ks.cfg
drwxr-xr-x. 3 root root 18 May 11 21:41 csdn
-rw-r--r--. 1 root root 100 May 11 21:21 csdn1
-rw-r--r--. 1 root root 100 May 11 21:21 csdn2
drwxr-xr-x. 2 root root 6 May 11 20:39 dir
-rw-r--r--. 1 root root 76 Apr 29 03:29 index.html
-rw-------. 1 root root 144044544 Apr 28 21:15 nginxtest.tar
drwxr-xr-x. 3 root root 70 May 11 21:35 www
[root@localhost ~]#
4.cat:查看文件
- cat -n:对所有行标注行号显示
[root@localhost ~]# cat csdn1
欢迎使用CSDN,下面我们进行操作!!!!!!!!!!!!
懂了吗?
[root@localhost ~]# cat -ncsdn1
cat: invalid option -- 'c'
Try 'cat --help' for more information.
[root@localhost ~]# cat -n csdn1
1 欢迎使用CSDN,下面我们进行操作!!!!!!!!!!!!
2
3
4
5
6
7
8
9 懂了吗?
[root@localhost ~]#
二、操作目录类命令
1.mkdir:创建目录
1)mkdir -p csdn/nice:如果csdn目录不存在,会连级创建,同时创建csdn和nice目录
例如:创建一个名为csdn的目录,并用ls查看
[root@localhost ~]# mkdir csdn
[root@localhost ~]# ls
anaconda-ks.cfg csdn dir index.html nginxtest.tar www
[root@localhost ~]#
在csdn下创建一个nice目录,如果csdn目录不存在,使用-p参数,进行连级创建
[root@localhost ~]# ls
anaconda-ks.cfg dir index.html nginxtest.tar www
[root@localhost ~]# mkdir -p csdn/nice
[root@localhost ~]# ls csdn/
nice
[root@localhost ~]#
2.rmdir:删除空目录
1)rmdir -p csdn/nice:删除csdn目录,如果nice目录下没有其他文件或目录,同时删除nice目录
例如:删除一个名为csdn的目录,并用ls查看
[root@localhost ~]# ls
anaconda-ks.cfg csdn dir index.html nginxtest.tar www
[root@localhost ~]# rmdir csdn
[root@localhost ~]# ls
anaconda-ks.cfg dir index.html nginxtest.tar www
[root@localhost ~]#
在删除csdn及该目录下的子目录nice
[root@localhost ~]# ls csdn/
nice
[root@localhost ~]# ls csdn/nice/
[root@localhost ~]# rmdir -p csdn/nice
[root@localhost ~]# ls
anaconda-ks.cfg dir index.html nginxtest.tar www
[root@localhost ~]#
3.cp:复制文件的命令
- cp -a:将文件状态、权限等属性照原状予以复制
- cp -f:如果目标文件或目录存在,先删除他们在进行复制(即覆盖),并且不提示用户
- cp -i:如果目标文件或目录存在,提示是否覆盖已有的文件。
- cp -R:递归复制目录,即包含目录下的各级子目录
例如:将csdn1文件复制且新文件名为csdn2
[root@localhost csdn]# ll
total 8
-rw-r--r--. 1 root root 159 May 12 00:09 csdn1
-rw-r--r--. 1 root root 159 May 12 00:09 csdn2
drwxr-xr-x. 2 root root 6 May 12 00:08 nice
[root@localhost csdn]#
将csdn目录下的各级子目录复制到www的目录下
[root@localhost csdn]# ls /root/www/
nginx nice
[root@localhost csdn]# cd ~
[root@localhost ~]# cp -r csdn/* /root/www/
[root@localhost ~]# ls /root/www
csdn1 csdn2 nginx nice
[root@localhost ~]#
4.mv:移动文件或更改文件名
例如:mv csdn1 csdn3(将文件(目录)csdn1改名为csdn3)
[root@localhost csdn]# ls
csdn1 csdn2 nice
[root@localhost csdn]# mv csdn1 csdn3
[root@localhost csdn]# ls
csdn2 csdn3 nice
[root@localhost csdn]#
mv csdn3 /root/www/ (将文件(目录)csdn3移动到根目录下的www目录下)
[root@localhost csdn]# mv csdn3 /root/www/
[root@localhost csdn]# ls /root/www/
csdn1 csdn2 csdn3 nginx nice
[root@localhost csdn]#
5.touch:创建文件
touch csdn.txt(表示创建一个文件csdn.txt)
[root@localhost csdn]# touch csdn.txt
[root@localhost csdn]# ls
csdn2 csdn.txt nice
[root@localhost csdn]#
6.rm:删除文件
- rm -i:删除文件或目录时提示用户
- rm -f:删除文件或目录时不提示用户
- rm -R:递归删除目录,即包含目录下的文件和各级子目录
- 例如:rm -rf csdn*(表示删除所有名字以csdn开头的目录或者是文件,递归删除且不询问)
[root@localhost csdn]# ls
csdn2 csdn.txt nice
[root@localhost csdn]# rm -rf csdn*
[root@localhost csdn]# ls
nice
[root@localhost csdn]#