HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
We know that the directory structure of Linux as a tree structure, the top of the root directory /.
You can mount other directories by adding them to the tree, you can remove them by unmounting.
Before starting this tutorial we need to know what is the absolute path and relative path.
Next we will look at several common command processing directory it:
You can use the man [command] to view the document using the individual commands, such as: man cp.
Among the Linux system, ls command is probably the most common being run.
grammar:
[root@www ~]# ls [-aAdfFhilnrRSt] 目录名称 [root@www ~]# ls [--color={never,auto,always}] 目录名称 [root@www ~]# ls [--full-time] 目录名称
Options and parameters:
All the files listed under the home directory (including hidden files and attributes)
[root@www ~]# ls -al ~
cd Change Directory is the abbreviation, which is the command used to transform the working directory.
grammar:
cd [相对路径或绝对路径]
#使用 mkdir 命令创建w3cschool.cc目录 [root@www ~]# mkdir w3cschool.cc #使用绝对路径切换到w3cschool.cc目录 [root@www ~]# cd /root/w3cschool.cc/ #使用相对路径切换到w3cschool.cc目录 [root@www ~]# cd ./w3cschool.cc/ # 表示回到自己的家目录,亦即是 /root 这个目录 [root@www w3cschool.cc]# cd ~ # 表示去到目前的上一级目录,亦即是 /root 的上一级目录的意思; [root@www ~]# cd /en
The next few times you should be able to operate more than a good understanding of the cd command.
Print Working Directory pwd is the abbreviation, which is the command to display the current directory is.
[root@www ~]# pwd [-P] 选项与参数: -P :显示出确实的路径,而非使用连结 (link) 路径。 范例:单纯显示出目前的工作目录: [root@www ~]# pwd /root <== 显示出目录啦~ 范例:显示出实际的工作目录,而非连结档本身的目录名而已 [root@www ~]# cd /var/mail <==注意,/var/mail是一个连结档 [root@www mail]# pwd /var/mail <==列出目前的工作目录 [root@www mail]# pwd -P /var/spool/mail <==怎么回事?有没有加 -P 差很多~ [root@www mail]# ls -ld /var/mail lrwxrwxrwx 1 root root 10 Sep 4 17:54 /var/mail -> spool/mail # 看到这里应该知道为啥了吧?因为 /var/mail 是连结档,连结到 /var/spool/mail # 所以,加上 pwd -P 的选项后,会不以连结档的数据显示,而是显示正确的完整路径啊!
If you want to create a new directory, then use the mkdir (make directory) it.
grammar:
mkdir [-mp] 目录名称
Options and parameters:
Example: Go to / tmp under several attempts to create a new directory to see:
[root@www ~]# cd /tmp [root@www tmp]# mkdir test <==创建一名为 test 的新目录 [root@www tmp]# mkdir test1/test2/test3/test4 mkdir: cannot create directory `test1/test2/test3/test4': No such file or directory <== 没办法直接创建此目录啊! [root@www tmp]# mkdir -p test1/test2/test3/test4
-p Add this option can help you create your own multi-directory!
Example: Creating permissions rwx - x - x directory
[root@www tmp]# mkdir -m 711 test2 [root@www tmp]# ls -l drwxr-xr-x 3 root root 4096 Jul 18 12:50 test drwxr-xr-x 3 root root 4096 Jul 18 12:53 test1 drwx--x--x 2 root root 4096 Jul 18 12:54 test2
Permissions section above, if you did not add -m to force configuration properties, the system uses the default attributes.
If we use -m, as in the example we give -m 711 to give a new directory drwx - x - x permissions.
grammar:
rmdir [-p] 目录名称
Options and parameters:
Remove w3cschool.cc directory
[root@www tmp]# rmdir w3cschool.cc/
Example: mkdir directory will be created in the example (/ tmp under) removed!
[root@www tmp]# ls -l <==看看有多少目录存在? drwxr-xr-x 3 root root 4096 Jul 18 12:50 test drwxr-xr-x 3 root root 4096 Jul 18 12:53 test1 drwx--x--x 2 root root 4096 Jul 18 12:54 test2 [root@www tmp]# rmdir test <==可直接删除掉,没问题 [root@www tmp]# rmdir test1 <==因为尚有内容,所以无法删除! rmdir: `test1': Directory not empty [root@www tmp]# rmdir -p test1/test2/test3/test4 [root@www tmp]# ls -l <==您看看,底下的输出中test与test1不见了! drwx--x--x 2 root root 4096 Jul 18 12:54 test2
Use the -p option, it can be immediately test1 / test2 / test3 / test4 delete.
Note, however, that this rmdir can only delete empty directories, you can use the rm command to remove a non-empty directory.
That cp copy files and directories.
grammar:
[root@www ~]# cp [-adfilprsu] 来源档(source) 目标档(destination) [root@www ~]# cp [options] source1 source2 source3 /en/en directory
Options and parameters:
As root, copy .bashrc under the home directory to / tmp, and renamed bashr
[root@www ~]# cp ~/.bashrc /tmp/bashrc [root@www ~]# cp -i ~/.bashrc /tmp/bashrc cp: overwrite `/tmp/bashrc'? n <==n不覆盖,y为覆盖
grammar:
rm [-fir] 文件或目录
Options and parameters:
The bashrc just created in the example of cp deleted!
[root@www tmp]# rm -i bashrc rm: remove regular file `bashrc'? y
If we add -i option will take the initiative to ask Oh, you avoid deleting the wrong file name!
grammar:
[root@www ~]# mv [-fiu] source destination [root@www ~]# mv [options] source1 source2 source3 /en/en directory
Options and parameters:
Copy a file, create a directory, move the file to a directory
[root@www ~]# cd /tmp [root@www tmp]# cp ~/.bashrc bashrc [root@www tmp]# mkdir mvtest [root@www tmp]# mv bashrc mvtest
Will move a file to a directory to go, it is to do so!
The directory name just renamed mvtest2
[root@www tmp]# mv mvtest mvtest2
Linux systems use the following command to view the contents of the file:
You can use the man [command] to view the document using the individual commands, such as: man cp.
From the first line displays the file contents
grammar:
cat [-AbEnTv]
Options and parameters:
See to / etc / issue the contents of this file:
[root@www ~]# cat /etc/issue CentOS release 6.4 (Final) Kernel \r on an \m
tac with the cat command the contrary, began to show the contents of the file from the last line, you can see the tac is cat written backwards! Such as:
[root@www ~]# tac /etc/issue Kernel \r on an \m CentOS release 6.4 (Final)
Show Line Numbers
grammar:
nl [-bnw] 文件
Options and parameters:
Example 1: The lists nl / etc / issue content
[root@www ~]# nl /etc/issue 1 CentOS release 6.4 (Final) 2 Kernel \r on an \m
Flip from page to page
[root@www ~]# more /etc/man.config # # Generated automatically from man.conf.in by the # configure script. # # man.conf from man-1.6d /en/en(中间省略)/en/en --More--(28%) <== 重点在这一行喔!你的光标也会在这里等待你的命令
In the process of running more this program, you have to press a few keys:
Flip from page to page, the content of the following examples /etc/man.config output file:
[root@www ~]# less /etc/man.config # # Generated automatically from man.conf.in by the # configure script. # # man.conf from man-1.6d /en/en(中间省略)/en/en : <== 这里可以等待你输入命令!
Command less run-time can be entered are:
Remove the front of the file lines
grammar:
head [-n number] 文件
Options and parameters:
[root@www ~]# head /etc/man.config
By default, the display 10 front row! To display the first 20 lines, you have to be like this:
[root@www ~]# head -n 20 /etc/man.config
Remove a few lines later in the file
grammar:
tail [-n number] 文件
Options and parameters:
[root@www ~]# tail /etc/man.config # 默认的情况中,显示最后的十行!若要显示最后的 20 行,就得要这样: [root@www ~]# tail -n 20 /etc/man.config