2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
It is enough to have one bosom friend in life, and we should treat each other with the same feeling in this world. ——Lu Xun
grammar: ls [options] [target or file]
Function: For a directory, this command lists all subdirectories and files under the directory. For a file, the file name and other information will be listed.
ls -l:列出文件的详细信息
ls -la:(all)列出文件所有的信息,包括 . 开头的隐含文件
ls -l / :能够展现更目录下的文件
ls -l /root:展现root下的文件
ls -ld /:只差看目录本身的属性
ls *:其中的*在这里意味着当前目录下的所有文件,当然*加在别的地方的意思就是这个地方的中间可以是任意的,但是别的地方一定是必须要符合条件的。(*:表示一个通配符,匹配任意文件名)
When we execute these two commands, we will find some differences, including hidden files.
In Linux, files starting with . are called hidden files.
Under any directory, there are two default hidden files, . and . . A dot indicates the current directory, and two dots indicate the parent directory.
The role of two pointsThis is to facilitate returning to the parent directory.
We should know that if we want to execute a program, we need to load the program into the memory first. Therefore, because we need to find a file first to access it, a point can find the location under the current path.
The role of a pointThis is usually done while executing the current program.
Of course, Windows also includes hidden files.
grammar: pwd
Function: Display the directory where the current user is located
grammar: cd directory name
Function: Change working directory. Change the current working directory to the specified directory.
cd .. : 返回上级目录
cd /home/litao/linux/ : 绝对路径
cd ../day02/ : 相对路径
cd ~:进入用户家目录()
cd -:返回最近一次所属的路径之下(方便路径切换,两个路径之间快速跳转)
The operation of returning to the parent directory cannot return to the parent node until the result of /, which is the Linux root directory.
Specified users under Linux also have their own home directories
For the root account: the default home directory is /root-super administrator account
grammar: mkdir [options] dirname
Function: Create a directory named "dirname" in the current directory
mkdir –p test/test1 : 递归建立多个目录
There must be a "folder" between the two paths, and the end of the path must be an ordinary file or folder.
/: is the path separator in Linux
: is the path separator in Windows
Why is the role of paths needed in the system?
First, a path identifies a specific file at a system level. Second, the role of a path is to make the file have the necessary path uniqueness.
Why find the target file?
Because only after finding the target file can it be accessed. So how to find the file? That is because there is a path. And because the path is unique.
So every time I create a file directly, there is no content in it, but we can create it through other means.
mkdir -p a/b/c/d
This will create a recursive directory.
How do we check? We can check step by step by CD.
Of course there is also a simpler way
tree a
tree: Displays the directory structure in tree form. But sometimes you need to install the tree command.
yum -y install tree
After installation, you can see
# which tree
/usr/bin/tree
Through which, you can also find that you can now see the executable file of tree in bin.
So what does the yum -y install command mean? Please see the introduction below.
grammar: whoami
Function: Displays the current user's name
Use adduser to add a user in /home. Just like creating multiple users on Windows, different Windows users will see different desktop folders.
Instructions are essentially programs - instructions, programs, and executable programs are all the same thing. The principle is the same.
Where are these programs usually located? In /usr/bin/… You can find them yourself.
So what does installation and uninstallation mean? It means copying or deleting the executable program to the system path.
Programs are also files, and files are also content + permissions.
grammar: which [command name]
Function: The name of the command which means to tell me where the executable program is located at the system level.
But when we carry out
which ls//这个时候出现了有点不一样的东西
alias ls='ls --color=auto'
/usr/bin/ls 会出现这种情况
But when I can find the executable program file, we can directly /usr/bin/ls, find ls through the absolute path, and execute ls, but different results appear at this time.
One is colored and the other is colorless. Why is that?
Please see the introduction of the alias command below.
Alias is also a Linux command that gives other commands an alias.
alias zhangsan='ls -la'
which zhangsan
alias zhangsan='ls -la'
/usr/bin/ls
Then you can also use zhangsan directly to achieve the effect of ls -la. At this time, zhangsan is an alias of ls -la.It's like you give your friends nicknames, even the nicknames are the same person (same effect of the command)
It can be explained that,llthat isls -lSo it has the same effect.
The difference in color is the effect of the following - -color=auto.
This way we have two commands with the same result.
grammar: touch [options] file
Function: The touch command parameters can change the date and time of a file or directory, including the access time and modification time, or create a new file that does not exist.
touch can only create ordinary files!
Replenish: If you want to know more information about a file, you need to usestat [filename]
Access, Modify and Change have different meanings.
Referred to as the ACM time of a file.
Access is the time of the last entry, but Modify and Change are somewhat similar. Translated into Chinese, they both mean change. So what do they mean?
Modify means the time when the file content was last modified.
Change means the last time the file attributes were modified.
Generally speaking, the attributes of a file contain a lot of things, and sometimes along with the change of Modify, most of them will change the Change time.
As shown in the figure, rmdir can delete the dir folder with no content, but it cannot delete the folder containing content.
Then we can use the rm command
rm [文件名]:删除,但是过程中会询问是否要删除,系统要小心的询问一下(通常在root的情况下才会询问)
rm -f [文件名]:强制删除,不会弹出对话框询问是否需要删除文件
//默认是文件夹的情况下rm都要加上 -r 通过递归的方式来删除文件夹。当然此时的-f,强制删除的命令也是能够使用的。
[root@VM-16-12-centos ~]# rm empty
rm: cannot remove ‘empty’: Is a directory
[root@VM-16-12-centos ~]# rm -r empty
rm: remove directory ‘empty’? y
//话说回来!千万别用这个代码
rm -rf /
//删除的话,”会有好果子吃“
//会将一切有可能的都解决掉
In the Linux system, rm means delete, and delete means delete. For a novice, it is almost impossible to recover.
Once there are uncertain directories or files, it is better to back them up rather than delete them.
Linux commands have many parameters and it is impossible to remember them all. We can get help by checking the online manual.
The command to access the Linux manual is
man syntax: man [options] command
Press Q to exit. Press the up and down keys to turn pages.
When we man man
It's not just about checking instructions.
There are three more important points about the main uses of man.
The first is executable program search.
The second point is to find the system call
The third is C library function lookup.
grammar: cp [options] source file or directory target file or directory
Function: Copying a file or directory
cp src dst :其中dst可以是目录(直接拷贝到目录中),可以是带路径的文件名(拷贝到指定目录,顺便进行重命名)
src或者是dst都可以携带绝对路径或者相对路径进行拷贝
cp [源文件] ../ :直接拷贝到上一级的目录中
cp [源文件] ../hello.txt:将文件拷贝到上一级并且修改名字为hello.txt
cp -rf a ../ ://拷贝递归文件夹的时候需要带上-r
The mv command is the abbreviation of move, which can be used to move files or rename files (move (rename) files). It is a commonly used command in Linux systems and is often used to back up files or directories.
grammar: mv [options] source file or directory target file or directory
Function: Can rename, cut or rename and cut together
mv src dst
mv test.txt log.txt//将test.txt的名字改为log.txt
mv log.txt ..(/):将log.txt剪切