2.6 Relative and absolute paths 2.7 The cd command 2.8 Creating and deleting directories mkdir/rmdir 2.9 The rm command

Absolute and relative paths

An absolute path that begins with a directory

An absolute path that does not start with the root directory

[root@cham3 ~]# ls /etc/sysconfig/network-scripts/ifcfg-

ifcfg-ens33 ifcfg-lo

[root@cham3 ~]# ls /etc/sysconfig/network-scripts/ifcfg-

ifcfg-ens33 ifcfg-lo

[root@cham3 ~]# ls /etc/sysconfig/network-scripts/ifcfg-ens33

/etc/sysconfig/network-scripts/ifcfg-ens33

[root@cham3 ~]# ls /root/anaconda-ks.cfg

/root/anaconda-ks.cfg

[root@cham3 ~]# ls /etc/hostname

/etc/hostname

[root@cham3 ~]# cat /etc/hostname

cham3

[root@cham3 ~]# ls /root/.ssh/authorized_keys 绝对路径

/root/.ssh/authorized_keys

[root@cham3 ~]# pwd

/root

[root@cham3 ~]# ls .ssh/authorized_keys 相对路径

.ssh/authorized_keys

[root@cham3 ~]# cd /etc/sysconfig/

[root@cham3 sysconfig]# ls network-scripts/ifcfg-ens33

network-scripts/ifcfg-ens33 相对路径

 

cd command

[root@cham3 ~]# cd /etc/sysconfig/             cd进入 etc /sysconfig路径

[root@cham3 sysconfig]# cd - cd -               返回上一次的所在目录,有点类似电视的返看键

/root

[root@cham3 ~]# cd -                                  再cd - 又回到 etc/sysconfig路径

/etc/sysconfig

[root@cham3 sysconfig]# pwd

/etc/sysconfig

[root@cham3 sysconfig]# cd -

/root

[root@cham3 ~]# cd ~                               ~就是家目录,cd ~就是回到加目录

[root@cham3 ~]# cd ..                               cd .. 返回上一级目录

[root@cham3 /]# cd -                                cd- 返回到家目录

/root

[root@cham3 ~]# pwd                              查看所在目录位置


 

 

 

Create and delete directories mkdir/rmdir rm command

 

1. Command syntax

rm directory

2. Command description:

Abbreviation for rm (remove), this command can delete both directories and files.

3. Command parameters

-r Option to delete directories, you can delete non-empty directories. but will ask you if you want to delete, "y" or "n"
Enter image description

-f means force delete. It will not ask you to delete. If followed by a nonexistent file or directory, no error will be reported. When using the -f option, be sure to add the -r option, otherwise an error will be reported.

Note: Generally, the -rf command is used, which is more convenient to delete directories or files.

 

command history

1.History命令语法: #history [n]
#history [-c]
#history [-raw] histfiles

2. Command description: history (short for history) can list all the commands you used before

3. Parameters:
n: number, to list the latest n command list
-c: delete all history content in the current shell
-a: add the currently added history command to histfiles, if not added histfiles , the default is to write ~/
.bash_history -r : read the content of histfiles into the history memory of the current shell
-w : write the current history memory content to histfiles

Linux system When you enter and execute commands in the shell (console), the shell will automatically record your commands in the history list, which is generally saved in the .bash_history file in the user directory. By default, 1000 records are saved, but you can also change this value.

If you type history, history will show you the first 1000 history commands you've used, numbered them, and you'll see a numbered list scroll quickly across the screen. You probably don't need to look at all the items in the 1000 commands, of course you can add numbers to get a list of the most recent n commands.

The history command in linux not only allows us to query historical commands. We can also use related functions to help us execute commands.

 

History command in action

List all history records: # history
only lists the most recent 10 records: # history 10 (Note, there is a space between history and 10)
Enter image description
Use the command record number to execute the command, and execute the 99th command in the history list #!99 ( There is no space between ! and 99)
Repeat the previous command#!!

Execute the last command starting with rpm (!? ? represents a string, this String can be entered at will, the Shell will search forward from the last historical command, and the first matching command will be executed.) #!rpm

List all history records screen by screen: # history | more Use spaces to see the following command records.

Immediately clear the records of all current history commands in history #history -c

In addition to using the history command, at a shell or GUI terminal prompt, you can also use the up and down arrow keys to scroll through the command history (the down arrow will scroll forward) until you find the command you want. This allows us to easily edit a previous command without having to repeatedly enter similar commands.

 

 

Create and delete directories

1. Command format:
#mkdir [-mp] directory name

2. Command description:
The command mkdir (short for make directory) is used to create a directory.

3. Command parameters:
-m: The option is used to specify the permissions of the directory to be created. The
-p: option can create a large series of cascading directories, and when creating an existing directory, no error will be reported.
-pv: Add the v option to display the creation process

1. Command format:
#rmdir directory name

2. Command function: The
command rmdir (short for remove directory) is used to delete an empty directory, followed by a directory or multiple directories (separated by spaces). This command can only delete directories, not files.

 

command touch

1. Command format:
touch [options] [file]

2. Command description:
If there is this file, the access time of the file will be changed, if there is no such file, the file will be created.
Enter image description

3. Command parameters:
-a or --time=atime or --time=access or --time=use only changes the access time.
-c or --no-create do not create any documentation.
-d Use the specified datetime instead of the current time.
-f This parameter will be ignored and not processed, and it is only responsible for solving the compatibility problem of the touch command of the BSD version.
-m or --time=mtime or --time=modify only change the change time.
-r Set the date and time of the specified document or directory to be the same as the date and time of the referenced document or directory.
-t Use the specified datetime instead of the current time.

 

command tree

1. Command syntax: tree [-aACdDfFgilnNpqstux][-I <template style>][-P <template style>][directory...]

2. Command description: List the contents of the directory in a tree diagram.
Supplementary note: Execute the tree command, it will list all files in the specified directory, including files in subdirectories.

3. Command parameters:
  -a Displays all files and directories.
  -d Display directory names instead of contents.
  -D List file or directory change times.
  -f Display the full relative path name before each file or directory.
  -i Do not list file or directory names in a ladder.
  -N List file and directory names directly, including control characters.
  -p List permission flags.
  -s List file or directory size.
  -t Sort by change time of files and directories.

Here is the command line:                                           

 make directory

Last login: Thu Oct 19 18:23:24 2017 from 192.168.230.1                   我们先登陆
[root@cham2 ~]# mkdir /tmp/chamlinux                                       在tmp下新建一个chamlinux目录
[root@cham2 ~]# ls -ld /tmp/chamlinux                                      用ls -ld 查看目录
drwxr-xr-x 2 root root 6 10月 23 21:18 /tmp/chamlinux
[root@cham2 ~]# date                                                            时间
2017年 10月 23日 星期一 21:19:01 CST
[root@cham2 ~]# mkdir /tmp/chamlinux/1/2/                       会提示没有文件或目录
mkdir: 无法创建目录"/tmp/chamlinux/1/2/": 没有那个文件或目录
[root@cham2 ~]# ls -l /tmp/chamlinux                                看一下   是空的
总用量 0
[root@cham2 ~]# mkdir -p /tmp/chamlinux/1/2/                 用-p 级联创建   
[root@cham2 ~]# ls -l /tmp/chamlinux/
总用量 0
drwxr-xr-x 3 root root 15 10月 23 21:20 1
[root@cham2 ~]# ls -l /tmp/chamlinux/1
总用量 0
drwxr-xr-x 2 root root 6 10月 23 21:20 2
[root@cham2 ~]# mkdir -p /tmp/chamlinux/2/3/4
[root@cham2 ~]# mkdir -pv /tmp/chamlinux/2/3/4                           -v可视化过程      

[root@cham2 ~]# mkdir -pv /tmp/chamlinux/2/3/4
mkdir: 已创建目录 "/tmp/chamlinux/2/3"
mkdir: 已创建目录 "/tmp/chamlinux/2/3/4"

[root@cham2 ~]# rmdir /tmp/chamlinux/2
rmdir: 删除 "/tmp/chamlinux/2" 失败: 目录非空
[root@cham2 ~]# rmdir /tmp/chamlinux/2/3/4/
[root@cham2 ~]# touch /tmp/chamlinux/2/3/1.txt
[root@cham2 ~]# ls /tmp/chamlinux/2/3/
1.txt

[root@cham2 ~]# tree /tmp/chamlinux/
/tmp/chamlinux/
├── 1
│   └── 2
└── 2
    └── 3
        └── 1.txt

4 directories, 1 file
[root@cham2 ~]# rmdir /tmp/chamlinux/2/3
rmdir: 删除 "/tmp/chamlinux/2/3" 失败: 目录非空
[root@cham2 ~]# rmdir /tmp/chamlinux/1/2/
[root@cham2 ~]# mk
mkdict            mkfifo            mkfs.ext2         mkfs.xfs          mknod
mkdir             mkfs              mkfs.ext3         mkhomedir_helper  mkswap
mkdumprd          mkfs.btrfs        mkfs.ext4         mkinitrd          mktemp
mke2fs            mkfs.cramfs       mkfs.minix        mklost+found      
[root@cham2 ~]# mkdir /tmp/chamlinux/1/2
[root@cham2 ~]# rmdir -p /tmp/chamlinux/1/2/                    这种方法很少用    一样可以级联删除
rmdir: 删除目录 "/tmp/chamlinux" 失败: 目录非空
[root@cham2 ~]# tree /tmp/chamlinux/                                实际上是已经删除了1/2已经删除了      
/tmp/chamlinux/
└── 2
    └── 3
        └── 1.txt

2 directories, 1 file
[root@cham2 ~]# rm /tmp/chamlinux/2/3/1.txt                        使用rm 命令删除
rm:是否删除普通空文件 "/tmp/chamlinux/2/3/1.txt"?y                   
[root@cham2 ~]# tree /tmp/chamlinux/                                        看一下
/tmp/chamlinux/
└── 2
    └── 3

2 directories, 0 files
[root@cham2 ~]# toch /tmp/chamlinux/2/3/1.txt                新建文件
-bash: toch: 未找到命令
[root@cham2 ~]# touch /tmp/chamlinux/2/3/1.txt               新建文件

[root@cham2 ~]# touch /tmp/chamlinux/2/3/2.txt          
[root@cham2 ~]# rm /tmp/chamlinux/2/3/                        使用了TAB命令
1.txt  2.txt  
[root@cham2 ~]# rm /tmp/chamlinux/2/3/
1.txt  2.txt  
[root@cham2 ~]# rm /tmp/chamlinux/2/3/*.txt                           用*表示通配
rm:是否删除普通空文件 "/tmp/chamlinux/2/3/1.txt"?n
rm:是否删除普通空文件 "/tmp/chamlinux/2/3/2.txt"?n
[root@cham2 ~]# rm -f /tmp/chamlinux/2/3/*.txt                加-f   不询问   强制的
[root@cham2 ~]# !tree                                                       小知识,上一次最近的tree开头的命令
tree /tmp/chamlinux/
/tmp/chamlinux/
└── 2
    └── 3

2 directories, 0 files
[root@cham2 ~]# rm /tmp/chamlinux/2/3/                      删除目录rm不行
rm: 无法删除"/tmp/chamlinux/2/3/": 是一个目录           
[root@cham2 ~]# rm -rv /tmp/chamlinux/2/3/                 加-r  就是删除级联的目录
rm:是否进入目录"/tmp/chamlinux/2/3/"? y
rm:是否删除普通空文件 "/tmp/chamlinux/2/3/2.txt"?y
已删除"/tmp/chamlinux/2/3/2.txt"
rm:是否删除目录 "/tmp/chamlinux/2/3/"?y
已删除目录:"/tmp/chamlinux/2/3/"
[root@cham2 ~]# 

[root@cham2 ~]# rm -r /tmp/chamlinux/2/3/
rm: 无法删除"/tmp/chamlinux/2/3/": 没有那个文件或目录
[root@cham2 ~]# tree /tmp/chamlinux/
/tmp/chamlinux/
└── 2

1 directory, 0 files
[root@cham2 ~]# rm -rf /tmp/chamlinux/2/                     加-f  就是不提示,强制删除
[root@cham2 ~]# !tree
tree /tmp/chamlinux/
/tmp/chamlinux/                                                            这时候已经没有任何文件和目录了

0 directories, 0 files

[root@cham2 ~]# !tree
tree /tmp/chamlinux/2
/tmp/chamlinux/2 [error opening dir]

0 directories, 0 files
[root@cham2 ~]# mkdir -pv /tmp/chamlinux/2/3/      在创建一下
mkdir: 已创建目录 "/tmp/chamlinux/2"
mkdir: 已创建目录 "/tmp/chamlinux/2/3/"

[root@cham2 ~]# touch /tmp/chamlinux/2/3/1.txt        在新建一个文件
[root@cham2 ~]# touch /tmp/chamlinux/2/2.txt             在新建一个文件

[root@cham2 ~]# tree /tmp/chamlinux/                       看一下
/tmp/chamlinux/
└── 2
    ├── 2.txt
    └── 3
        └── 1.txt

2 directories, 2 files
[root@cham2 ~]# rm -rfv /tmp/chamlinux/2/3/                加-v删除,,是可视化。
已删除"/tmp/chamlinux/2/3/1.txt"                                     先删除文件或者下面的子目录
已删除目录:"/tmp/chamlinux/2/3/"                                  然后再删除
[root@cham2 ~]# tree /tmp/chamlinux/
/tmp/chamlinux/
└── 2
    └── 2.txt

1 directory, 1 file
[root@cham2 ~]# rm -rfv /tmp/chamlinux/2/3/              知识点删除一个不存在的目录,再去删,什么                                                                                          都不提示   -f  起的作用
[root@cham2 ~]# rm -rv /tmp/chamlinux/2/3/              取消-f
rm: 无法删除"/tmp/chamlinux/2/3/": 没有那个文件或目录

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325906932&siteId=291194637