linux-->文件及其目录的管理

练习1(passwd使用)

 

1. 修改root用户密码为redhat

[root@localhost ~]# passwd redhat

Changing password for user redhat.

New password:

BAD PASSWORD: The password is shorter than 8characters

Retype new password:

passwd: all authentication tokens updated successfully.

2. 设置root用户密码的警告期为5天, 最短有效期为10天;

[root@localhost ~]# passwd -w 5 -n 10 root

Adjusting aging data for user root.

passwd: Success

3. 删除student用户的密码;

[root@localhost ~]# passwd -d student

Removing password for user student.

passwd: Success

4. 分别查看root用户和student用户的密码状态;

        [root@localhost~]# passwd -S redhat

redhat NP 2018-02-02 0 99999 7 -1 (Empty password.)

[root@localhost ~]# passwd -S root

root PS 1969-12-31 10 99999 5 -1 (Password set, SHA512crypt.)

 

 

练习2(cat, head, tail, gedit的使用):

1. 在桌面上用gedit编辑文件westos, 任意编辑20行内容;

[root@westos Desktop]# gedit westos

2. 查看westos文件的前3行;

[root@westos Desktop]# head -n 3 westos

    public voidcharacters(char[] ch, int start, int length)

            throwsSAXException {

        //获取标签的文本内容

3. 查看westos文件的后10;

[root@westos Desktop]# tail -n 10 westos

            con.setPhone(Content);

        }

        if("address".equals(cruTag)){

            con.setAddress(Content);

        }

    }

     * 结束标签

    @Override

    public voidendElement(String uri, String localName, String qName)

4. vim编辑,在westos文件最后一行添加hello java;

(1) 先获取该文件:vim westos,

(2) i→进入编辑模式

(3) 在最后一行添加hellojava字样

(4) 按住shift + :→wq保存并退出

      publicvoid characters(char[] ch, int start, int length)

                       throws SAXException {

               //获取标签的文本内容

                String Content=newString(ch,start,length);

               if("name".equals(cruTag)){

                       con.setName(Content);

               }

               if("sex".equals(cruTag)){

                       con.setSex(Content);

                }

               if("phone".equals(cruTag)){

                       con.setPhone(Content);

               }

               if("address".equals(cruTag)){

                       con.setAddress(Content);

               }

        }

         * 结束标签

       @Override

        publicvoid endElement(String uri, String localName, String qName)

hello,java

 

~                                                                              

"westos" 22L, 510C                                            21,1          All

 

 

 

练习3(路径管理):

    1. 在当前系统的桌面打开一个shell终端;

    2. 打印当前所在工作目录位置;

    [root@westosDesktop]# pwd

  /root/Desktop

    3. 切换工作目录到当前用户的家目录,并编辑文件westos,文件内容自行发挥;

    [root@westosDesktop]# cd ~

  [root@westos ~]# vim /root/Desktop/westos

5. 切换工作目录到student用户的家目录;

[root@westos ~]# su -l student

Last login: Sat Feb 3 09:53:55 GMT 2018 on pts/0

[student@westos ~]$

    6. 切换工作目录到当前用户的上一级目录;

[student@westos ~]$ cd ..

[student@westos home]$

 

 

                                                             

普通文件    touch           rm -f           vim,gedit              cat,head,tail,less,more

目录        mkdir(-p)       rm -fr          (增删file or dir)      ls

 

 

拓展: 删除所有内容   ------  rm -fr *

 

 

            复制                       移动

file        cpfile... 目录名          mv file... 目录名

dir         cp -rdir... 目录名        mv -r dir... 目录名

 

 

 

练习4

1. /mnt目录创建文件music1music10 music{1..10}

[root@westos ~]# touch /mnt/music{1..10}

[root@westos ~]# ls /mnt/

music1 music10  music2  music3 music4  music5  music6 music7  music8  music9

[root@westos ~]#

2. /mnt目录创建目录pic1~pic20;

[root@westos ~]# mkdir /mnt/pic{1..20}

[root@westos ~]# ls /mnt/

music1  music3  music6  music9 pic11  pic14  pic17 pic2   pic4  pic7

music10 music4  music7  pic1   pic12  pic15  pic18 pic20  pic5  pic8

music2  music5  music8  pic10  pic13  pic16  pic19 pic3   pic6  pic9

[root@westos ~]#

3. root用户的桌面上创建MyPic目录,并将/mnt里面的pic1~pic20复制过去;

[root@westos ~]# cp -r /mnt/pic* /root/Desktop/MyPic/

4. root用户的桌面上创建MyMusic目录,并将/mnt里面的music1~music10移动过去;、

[root@westos ~]# mkdir /root/Desktop/MyMusic

[root@westos ~]# mv /mnt/music* /root/Desktop/MyMusic/

[root@westos ~]# ls /root/Desktop/MyMusic/

music1 music10  music2  music3 music4  music5  music6 music7  music8  music9

5. 删除创建的所有文件和目录;

[root@westos ~]# rm -fr /root/Desktop/MyPic

[root@westos ~]# rm -fr /root/Desktop/MyMusic

[root@westos ~]# rm -f /root/Desktop/westos 

猜你喜欢

转载自blog.csdn.net/fath_kevin/article/details/79253154