Bird Brother Linux private kitchens notes Chapter VI

Directory path

Relative path and absolute path

I mentioned in the previous chapter simple absolute and relative paths

Absolute path: the wording of the path must be from the root directory (/) to write plays, for example: / home / user directory
relative path: writing path is not starting from the root directory (/) write, for example: my current directory / home / user, I want to switch to the next / home / user2 directory. It is written cd ../user2, in fact, refers to the relative path means: relative to the current directory path.


Directory related operations

Special directory:

.   //代表当前目录
..  //代表上一次目录
-   //代表前一个工作目录(其实就是上一个操作的目录)
~   //代表当前用户的家目录,例如当前用户是user,那么user的家目录就是在/home/user下
~username   //代表用户名为username的用户的家目录。


Instructions deal with common directory

cd     //切换目录
pwd    //显示当前目录
mkdir  //创建目录
rmdir  //删除空目录,注意是空目录!不空的目录后面再讲

Usage is as follows simple instructions

cd /home/user //使用绝对路径切换目录
pwd           //显示当前所在目录,只会显示绝对路径
mkdir dir     //创建一个名为dir的目录(可以理解为文件夹)
rmdir dir     //删除一个名为dir的空目录


Execute the file path variable: $ PATH

ls command to consult the file attributes, from the corresponding complete file named: / bin / ls (This is an absolute path), then why do we enter ls executes / bin / ls command does this? This is because due to the PATH environment variable. Equivalent environment variable path in our Window.

echo $PATH   //打印PATH变量,$号后面接的是变量。
/home/vagrant/bin:/home/vagrant/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Each directory can see the middle colon (:) to separate, each directory will have a sequence of points. The reason why we can execute ls command, it is because the presence of the ls command / bin directory, we can see that there are $ PATH / bin directory, the ls command so you can directly execute it.
For example, it is used in two ways to add environment variables, you need to / home / vagrant added to the environment variables:
1. only for the current user:
modify the .bashrc file in the home directory, and then added to the bottom of the file:

export PATH=/home/vagrant:$PATH
///保存后执行
source ~/.bashrc

2. Modify the / etc / environment file directly using the vim command to add it later.

cat /etc/environment //查看该文件
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"


File and directory management

File and directory management, in fact, is the main attribute display, copy, delete, move, and so on.
Options:

View files and directories: ls

lsArguably the most commonly used commands, while the lscommand of some commonly used options are as follows:
-a: lists all files, including hidden files (files that start with)
-d: directory lists only itself, not listed in the directory the data file
-l: file or directory listed a per line, and display the file's properties, permissions, and so data.
Used as follows:

ls -[options]


Copy, delete and move: cp, rm, mv

cp (copy a file or directory)
cp command is also very important because we often copy the file, it will also often use this command. If you go to copy someone else's file, we must have read (read) permission. After the general copy someone else's file, the owner of the file will become their friends.
Common options:
-i: If the file already exists, ask if you want to overwrite files.
-p: Copy the past with the attributes of the file (permissions, users, time).
-r: recursive copy, such as copying a non-empty directory, you need to use this command it.

Used as follows:

cp [-options] 源文件 目标文件
cp -i /usr/bin /tmp/bin //例子



rm (remove files and directories)
options:
-f: ignore the file does not exist, no warning message
-i: asks if you really want to delete the implementation deletion
-r: recursive delete, delete directories in common the use of this command again to confirm ah. Danger!

Used as follows:

rm [-options] 文件或目录



Music Videos (move / rename a file or directory)
is similar to the window and under shear rename operations.
Options:
-f: If the file already exists, but just do not ask direct coverage.
-i: If the file already exists, it will ask if you want to cover.
-u: If the file already exists, and the copied file is newer than the existing files will be overwritten.

mv -[options] 源文件 目标文件
mv /home/vagrant /tmp/vg  //此命令就会把home下vagrant目录移动到tmp目录下,并且改名为vg啦。

Expansion: In fact, there is a command changed its name, called rename. Requires a detailed understanding of man rename, then you can take a look.

Guess you like

Origin www.cnblogs.com/Johnson-lin/p/10935051.html