Linux Cloud Automation Operations Lesson II

Source: Internet
Author: User
Tags file copy parent directory

First, the Linux system structure

1.Linux is an inverted tree structure. Everything in Linux is a file. These files are in the top-level directory of the System "/", "/" is the root directory. The "/" directory below is a level two directory, which is automatically created when the system is installed.

2. The role of level two directories:

/bin # # #二进制可执行文件, which is the system command. Eg: delete date file in/bin, command line input date, display Bash:date:command not found ...

/sbin # # #系统管理命令存放位置

/Boot # # #启动分区, responsible for system startup. Eg: delete/boot/directory, command line input reboot reboot, system will not restart

/Dev # # #设备管理文件. Eg: Managing a USB flash drive

/etc # # #大多数系统管理文件

/Home # #普通用户的家目录

/lib # # #32位系统库文件存放位置

/LIB64 # # #64位系统库文件存放位置

/media # # #系统临时设备挂载点

/MNT # # #系统临时设备挂载点

/run # # #系统临时设备挂载点

/OPT # # #第三方软件安装位置

/proc # # #系统进程消息

/root # # #超级用户的家目录

/SRV # # #系统数据

/var # # #系统数据

/sys # # #系统管理, mainly about the kernel

/tmp # #系统临时文件存放位置

/usr # #系统用户相关信息数据及用户自定义软件存放位置

Ii. addressing the file

1. Absolute path: The file is in the real position of the system, the file name begins with "/".

Eg:[[email protected] desktop]$ ls/home/kiosk/lianxi/###/home/kiosk/lianxi/is a true path

File1 ML2 Music Test

2. Relative path: The file is abbreviated to a name in the current position, and the name does not begin with "/", and the name automatically adds the value displayed by the PWD.

Eg:[[email protected] lianxi]$ pwd # # #ml2是一个相对路径 (relative to current position/home/kiosk/lianxi)

/home/kiosk/lianxi

[[email protected] lianxi]$ ls ML2 # # #在这里, ls ML2 and ls/home/kiosk/lianxi/ml2/, the meaning of two commands is the same

Lianxi

[Email protected] lianxi]$ ls/home/kiosk/lianxi/ml2/

Lianxi

III. Management of documents

1.touch creating files or modifying file timestamps

1) Touch File # # #创建文件

2) Stat File # # #列出文件的详细信息

3) Cat File # # #查看文件

Eg:[[email protected] lianxi]$ Touch file1 # # #创建文件file1

[Email protected] lianxi]$ Stat file1 # # #列出文件file1的详细信息

File: "File1"

Size: 0 Block: 0 IO block: 4096 plain empty file

Device: 803h/2051d inode:1079315801 hard Link: 1

Permissions: (0664/-rw-rw-r--) Uid: (1000/kiosk) Gid: (1000/kiosk)

Last visited: 2017-03-17 14:18:02.113591317 +0800

Last modified: 2017-03-17 14:18:02.113591317 +0800

Last modified: 2017-03-17 14:18:02.113591317 +0800

Creation Time:-

[email protected] lianxi]$ Touch file1 # # #修改文件file1的时间戳

[Email protected] lianxi]$ Stat file1 # # #以下时间均发生变动

File: "File1"

Size: 0 Block: 0 IO block: 4096 plain empty file

Device: 803h/2051d inode:1079315801 hard Link: 1

Permissions: (0664/-rw-rw-r--) Uid: (1000/kiosk) Gid: (1000/kiosk)

Last visited: 2017-03-17 14:19:32.620878994 +0800

Last modified: 2017-03-17 14:19:32.620878994 +0800

Last modified: 2017-03-17 14:19:32.620878994 +0800

Creation Time:-

[email protected] lianxi]$ Cat File1 # # #查看文件file1

[Email protected] lianxi]$ Stat file1 # # #文件file1的最近访问时间改变.

File: "File1"

Size: 0 Block: 0 IO block: 4096 plain empty file

Device: 803h/2051d inode:1079315801 hard Link: 1

Permissions: (0664/-rw-rw-r--) Uid: (1000/kiosk) Gid: (1000/kiosk)

Last visited: 2017-03-17 14:19:52.347942105 +0800

Last modified: 2017-03-17 14:19:32.620878994 +0800

Last modified: 2017-03-17 14:19:32.620878994 +0800

Creation Time:-

2.mkdir Creating a Directory

1) mkdir Directory # # #创建目录

2) mkdir-p Directory # # #上级目录不存在时自动建立

Eg:[[email protected] lianxi]$ ls-a

.  .. File1

[Email protected] lianxi]$ mkdir ML1 # # #创建目录ml1

[Email protected] lianxi]$ ls-a

.  .. File1 ML1

[[email protected] lianxi]$ mkdir-p ml2/ml3/# # #上级目录ml2不存在, automatically established

[Email protected] lianxi]$ Ls-r

.:

File1 ML1 ML2

./ML1:

./ML2:

Ml3

./ML2/ML3:

3.RM Deleting a directory or file

1) RM File # # #删除文件

1) rm-f File/dictory # # #强行删除不提示

2) rm-r Directory # # #删除目录

Eg:[[email protected] lianxi]$ rm file1 # # #删除文件file1

[Email protected] lianxi]$ ls-a

.  .. ML1 ML2

[Email protected] lianxi]$ rm-r ML1 # # #删除目录ml1

[Email protected] lianxi]$ Ls-r

.:

Ml2

./ML2:

Ml3

./ML2/ML3:

[Email protected] lianxi]$ rm-r ML2/ML3 # # #删除目录ml2/ML3

[Email protected] lianxi]$ Ls-r

.:

Ml2

./ML2:

4.cat|head|tail viewing the contents of a file

1) Cat File # # #查看文件内容

2) head File # # #显示文件前几行

3) Tail File # # #显示文件后几行

Eg:[[email protected] lianxi]$ vim file1

[email protected] lianxi]$ Cat File1 # # #查看文件file1

1

2

3

10

Hello

How are you doing

[Email protected] lianxi]$ head-n 2 file1 # # #显示文件file1前2行

1

2

[Email protected] lianxi]$ tail-n 2 file1 # # #显示文件file1后2行

Hello

How are you doing

Edit files in 5.vim text mode

Enter VIM filename in the command line to enter the command mode. The command mode cannot edit the file and the edit file needs to go into insert mode. Press "I" to enter insert mode. If you are finished editing, press "ESC" to exit Insert mode, enter ": Wq" to save exit and enter ":!q" to force exit without saving. Vim filename If the file name does not exist, it is automatically created in the current directory. Vim does not manipulate the object, will open directly, after editing the file to ": Wq filename" Save exit.

6.CD Switch Working directory

1) CD Directory # # #切换到指定工作目录

2) CD-# # #切换到之前所在工作目录

3) CD ~ # # #切换到自己的家目录

4) CD ~username # # #切换到指定用户的家目录

5) CD. # # #切换到当前目录的上级目录

Eg:[[email protected] lianxi]$ Cd/home/kiosk # # #切换到目录/home/kiosk

[[Email protected] ~]$ CD-# # #切换到之前目录/home/kiosk/lianxi

/home/kiosk/lianxi

[[Email protected] lianxi]$ CD ~ # # #切换到家目录

[[Email protected] ~]$ CD ~root # # #普通用户无法切换到超级用户家目录, not enough permissions

BASH:CD:/root: Insufficient Authority

[email protected] ~]$ Su-

Password:

Last login: 53 months 13:35:28 CST 2017 from FOUNDATION0.ILT.EXAMPLE.COMPTS/2

[Email protected] ~]# CD ~kiosk # # #切换到普通用户kiosk的家目录

[Email protected] kiosk]# pwd

/home/kiosk

[Email protected] kiosk]# CD. # # #切换到当前目录/home/kiosk's parent directory/home

[Email protected] home]#

7.ls listing directory or file information

1) LS # # #列出当前目录的目录内容

2) LS Directory|filename # # #列出指定的文件或目录内容

3) ls-d Directory # # #列出目录本身

4) ls-l Directory|filename # # #列出文件或目录里面内容的属性

5) ls-ld Directory # # #列出目录本身的属性

6) Ls-a # # #列出目录中所有内容, including "." Hidden files at the beginning

7) Ls-r # # #递归显示目录中所以内容

Eg:[[email protected] ~]$ ls # # #列出当前目录的内容

Desktop Downloads Music Public Videos

Documents Lianxi Pictures Templates

[[email protected] ~]$ Ls/home/kiosk/lianxi # # #列出/home/kiosk/lianxi content, here is the absolute path used

File1 ML2

[Email protected] ~]$ PWD # # #查看当前目录

/home/kiosk

[[email protected] ~]$ ls lianxi/# # #列出 The contents of the/home/kiosk/lianxi, the relative path is used here

File1 ML2

[Email protected] ~]$ ls-d lianxi/# # #列出目录本身

lianxi/

[Email protected] ~]$ ls-d

.

[Email protected] ~]$ ls-d/home/kiosk/lianxi/

/home/kiosk/lianxi/

[[email protected] ~]$ ls-l lianxi/# # # #列出/home/kiosk/lianxi inside content Properties

Total 4

-rw-rw-r--1 Kiosk Kiosk 14:48 File1

Drwxrwxr-x 2 Kiosk Kiosk 6 Mar 14:42 ML2

[[email protected] ~]$ ls-ld lianxi/# # #列出 The properties of the/home/kiosk/lianxi itself

Drwxrwxr-x 3 Kiosk Kiosk 14:48 lianxi/

[[email protected] lianxi]$ Ls-a # # #列出 All content in/home/kiosk/lianxi, including "." "..."

.  .. File1 ML2

[[email protected] lianxi]$ Ls-r # # #递归显示/home/kiosk/lianxi so content

.:

File1 ML2

./ML2:

8.CP file copy

1) CP is the process of creating a new file

2) CP file Directory # # #把file复制到directory中

3) CP File Test # # # #建立test文件, with file as template

4) Cp-r Directory Directory1 # # #复制目录

Eg:[[email protected] ~]$ ls

Desktop Downloads Music Public Videos

Documents Lianxi Pictures Templates

[email protected] ~]$ CP lianxi/file1. # # #将当前目录lianxi中文件file1复制到当前目录

[[email protected] ~]$ ls

Desktop Downloads Lianxi Pictures Templates

Documents file1 Music Public Videos

[[email protected] ~]$ CP lianxi/file1 Test # # # #建立test文件, in the current directory Lianxi file file1 as a template

[[email protected] ~]$ ls

Desktop Downloads lianxi Pictures Templates Videos

Documents file1 Music Public test

[[email protected] ~]$ cp lianxi/file1 lianxi/test # # #在当前目录lianxi中建立test文件, in the current directory Lianxi file file1 as a template

[[email protected] ~]$ ls lianxi/

File1 ML2 Test

[[email protected] ~]$ CP music/lianxi/-R # # #把Music/directory copy under lianxi/directory

[[email protected] ~]$ ls lianxi/

File1 ML2 Music Test

[[email protected] ~]$ CP lianxi/ml2/music/-R # # #把lanxi中的ml2目录复制到Music/directory

[[email protected] ~]$ ls music/

Ml2

9.MV Move or rename

1) The MV of the same disk is renamed, the MV of different disks is the copy delete process

2) MV File file1 Directory # # #将file, file1 move to Directory

3) MV exists file does not exist file # # #重命名文件

4) MV Westos/linux. # # #把westos中的linux移动到当前目录

Eg:[[email protected] ~]$ mv file1 lianxi/ml2/# # #将文件file1移动到目录/HOME/KIOSK/LIANXI/ML2

[[email protected] ~]$ ls lianxi/ml2/###/home/kiosk/lianxi/ml2 has files file1

File1 Lianxi

[[email protected] ~]$ ls

Desktop Downloads Music Public test

Documents Lianxi Pictures Templates Videos

[Email protected] ~]$ mv Test Test1 # # #将文件test冲命名为test1

[[email protected] ~]$ ls

Desktop Downloads Music Public test1

Documents Lianxi Pictures Templates Videos

[Email protected] ~]$ mv Lianxi/ml2/file1. # # # #将 files in/home/kiosk/lianxi/ml2 file1 move to current directory

[[email protected] ~]$ ls

Desktop Downloads lianxi Pictures Templates Videos

Documents file1 Music Public test1

<<< Second unit exercise >>>

1. Create a file with commands and regular expressions as required
*) Create 12 files with one command Westos_classx_linuxy (the value range of x is 1-2,y 1-6)
*) These files are included in the study directory of the root user's desktop
[[email protected] Desktop] #mkdir./study
[[email protected] Desktop] #cd./study/
[[Email protected] study] #touch westos_class{1..2}_linmkdirux{1..6}
*) Create 8 files with one command Redhat_versionx (the range of x is 1-8)
*) Redhat_virsionx These files are included in version in the/MNT directory
[[Email protected] study] #mkdir/mnt/version
[[Email protected] study] #cd/mnt/version/
[[email protected] VERSION] #touch redhat_version{1..8}

2. Management of the documents just established by the letter is as follows
*) Copy the odd files in the Redhat_versionx to the single in the desktop with one command
[[email protected] VERSION] #mkdir/root/desktop/single
[[email protected] VERSION] #cp/mnt/version/redhat_version[:1.3.5.7:]/root/desktop/single
*) copy files with even numbers in Redhat_versionx to/double with a single command
[[email protected] VERSION] #mkdir/double
[[email protected] VERSION] #cp/mnt/version/redhat_version[:2.4.6.8:]/double
*) move Class1 files in Westos_classx_linuxy to CLASS1 in the current user's desktop with a single command
[[email protected] VERSION] #cd/root/desktop/
[[email protected] Desktop] #mkdir CLASS1
[[email protected] Desktop] #mv./study/westos_class[:1:]*./class1
*) move class2 files in Westos_classx_linuxy to CLASS2 in the current user's desktop with a single command
[[email protected] Desktop] #mkdir CLASS2
[[email protected] Desktop] #mv./study/westos_class[:2:]*./class2

3. Back up all the files in the/etc directory with the names with numbers and end with. conf to the Confdir on the desktop
[[email protected] Desktop] #mkdir confdir
[[email protected] Desktop] #cp/etc/*[:0-9:]*.conf./confdir

4. Delete all files you have just created or backed up
[[email protected] Desktop] #rm-rf/mnt/version/redhat_version{1..8}
[[email protected] Desktop] #rm-RF */

Linux Cloud Automation Operations Lesson II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.