Experiment two Linux systems simple file manipulation commands

project content
This work belongs courses Spring 2020 Linux Systems and Applications (Nanchang Aeronautical University - School of Information Engineering)
Where this requirement in the job Operation links, click here it!
Student ID - Name 17041517- UrushiKyo
Job learning objectives 1, learning in the command line in Linux operating system terminal

2, to master the common command line operation and through the command-line operations to solve simple problems

ubuntu18.04 terminal command line version linux systems and common command line


1, (open ubuntu18.04 terminal) to view the current directory


pwd #显示当前目录

Q: prompt difference between the $ and #?

Answer: $ Base Shell ordinary user default prompt;

# Is the root user (super user) of Base Shell default prompt.

Specifically, as shown:


pwd
su root #进入root用户

2, in the user's home directory (home directory) to create a directory named own student number below and see whether creating success


pwd
mkdir 17041517 #创建以17041517为文件名的目录
ls             #显示当前目录下文件

Q: (1) how to list all the current directory the following files? (Screenshot)


(2) how to list the contents of the current directory as a list? (Screenshot)


ls -l     #以列表形式列出当前目录下内容

(3) . And .. what they represent?

A: represents the current directory;.

.. represents the current directory of the parent directory.

3, enter the number in their own school named catalog, view the current directory, and then create their own full name directory named


pwd
ls
mkdir qi jing1 jing2    #创建文件名为qi jing1 jing2 的目录
ls

Q: The difference between (1) the relative and absolute paths?

A: The absolute path is the path to the file on the hard drive really exist;

Relative paths are relative to your target file location.

(2) how to return the user's home directory (home directory) from the current directory? (Screenshot)


cd  17041517/
pwd
cd /home/crystal    #更改当前目录或文件进入/home/crystal
pwd

(3) How do I delete a directory? (Screenshot) (you can create a temporary directory and then delete)

1) When the directory is an empty directory:


mkdir b1 b2
ls
rmdir b1  #删除b1文件(空目录文件)
ls

2) non-empty directory when the directory:


cd b2
pwd
touch b.txt
cd /home/crystal
ls
rmdir b2
rm -rf b2     #删除b2文件(非空目录文件)
ls

4, first create a file in a subdirectory of the current directory and name a.txt

(Note: the contents of the current directory are listed from left to right we were labeled as the first sub-directory, subdirectory second, third subdirectories)


cd jing1
ls
pwd
touch a.txt    #在目录下创建文件并命名为a.txt
ls

Q: What is the role of touch command if the file already exists will produce?

A: The existing file time stamp is updated to the current system time


5,进入当前目录的第一个子目录,然后显示当前目录,并列出当前目录的内容,并向文件a.txt写入一个字符串Hello World


pwd 
ls
echo "Hello World" > a.txt   #向文件a.txt中写入字符串"Hello World"
cat a.txt

问:图中符号 > 表示什么?

答:> 为输出重定向(覆盖原来内容);

​ 与其相关的为 >> ,其为追加(追加到原内容尾部) 。

ls
echo "Hello World" > a.txt
cat a.txt
echo "CRYSTAL" > a.txt
cat a.txt
echo "Hello World" >> a.txt
cat a.txt

6,返回自己学号命名的目录,查看tree命令是否可以使用,不能使用的话,安装tree,安装成功后使用该命令


sudo apt install tree #Ubuntu系统终端安装tree的命令
pwd
cd ..
pwd
tree                  #以树形结构显示文件夹目录结构

7,把当前目录的第一个子目录中文件a.txt复制到第二个子目录中,然后再次把第一个子目录中的a.txt复制到第三个子目录并命名为b.txt,最后把第一个子目录中文件a.txt重命名为c.txt。通过tree命令查看当前目录情况。


ls
cp jing1/a,txt jing2/  #将jing1 目录下的文件a.txt拷贝到jing2目录下
tree

ls
cp jing1/a.txt qi/b.txt    #将jing1目录下的文件a.txt拷贝到qi目录下并改名为b.txt
tree

ls
mv jing1/a.txt jing1/c.txt   #将jing1目录下的文件a.txt重命名为c.txt
tree

问:分别说明cp和mv的用法?(并配以截图描述)

答:cp指令:拷贝,拷贝文件到指定目录;mv指令:移动文件或将文件重命名。

cp拷贝用法参见7.1,7.2图片;mv指令文件重命名参见图片7.3

mv移动文件:

mv qi/b.txt jing1/   #将qi目录下的b.txt移动到jing1目录下

8,把/etc目录下面的文件passwd复制到自己学号命名的文件夹下。


pwd
ls
cp /etc/passwd ./    #将/etc/passwd复制到17041517文件夹下
ls
tree

9,用head查看passwd文件的前5行内容,用tail查看passwd文件的后5行内容


head -5 passwd   #用head指令查看passwd文件的前五行内容

tail -5 passwd  #用tail指令查看passwd文件的后五行内容

问:文件查看的命令还有哪些?并简要说明使用方法

答:more,less,cal等等

​ more指令:按页显示查看文本文件内容(以全屏方式);

   more file   #按页查看

​ less指令:分屏查看文件内容(大型文件效率高);

less   file    #分屏查看

​ cal指令:显示指定月份的日历。

 cal  (月份)  年份 #显示某年(某月)日历       

10,删除学号命名的文件下passwd文件,以及删除当前目录下第三个子文件夹


pwd
ls
rm passwd   #删除17041517文件名下的passwd文件
ls

问:

(1),删除文件夹还可以用什么命令?如果使用该命令应如何操作?(截图)


rm -r qi

rm -rf jing1

rm -r jing2

(2), 请简要说明rm命令的使用方法?(截图)

答:rm -r file    #递归删除整个文件夹(能删除非空目录及文件)
   rm -f file    #强制删除目录或文件夹,不提示
   rm -rf file   #删除目录或文件夹
   截图如题10(1)

Guess you like

Origin www.cnblogs.com/crystalqj/p/12442540.html