练习 4:Bash:处理文件,pwd,ls,cp,mv,rm,touch
在 Linux 中,一切都是文件。但是什么是文件?现在完全可以说,它是一个包含一些信息的对象。它通常定义如下:
但这个定义太笼统了,所以让我们更具体一些。 struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size,in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B blocks allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last status change */
};
不要害怕,只要记住以下属性:
现在你将学习如何打印当前目录,目录中的文件,复制和移动文件。 这样做1: pwd
2: ls
3: ls -a
4: ls -al
5: ls -altr
6:cp -v .bash_history{,1}7: cp -v .bash_history1 .bash_history2
8: mv -v .bash_history1 .bash_history2
9: rm -v .bash_history2
10: touch .bashrc
11: ls -al
12: ls .*
你应该看到什么Hello,user1! user1@vm1:~$ pwd /home/user1 user1@vm1:~$ ls user1@vm1:~$ ls -a . .. .bash_history .bash_history1 .bash_logout .bashrc .lesshst .profile .profile.bak .profile.bak1 user1@vm1:~$ ls -al total 40 drwxr-xr-x 2 user1 user1 4096 Jun 7 13:30 . drwxr-xr-x 3 root root 4096 Jun 6 21:49 .. -rw------- 1 user1 user1 853 Jun 7 15:03 .bash_history -rw------- 1 user1 user1 308 Jun 7 13:14 .bash_history1 -rw-r--r-- 1 user1 user1 220 Jun 6 21:48 .bash_logout -rw-r--r-- 1 user1 user1 3184 Jun 6 21:48 .bashrc -rw------- 1 user1 user1 45 Jun 7 13:31 .lesshst -rw-r--r-- 1 user1 user1 697 Jun 7 12:25 .profile -rw-r--r-- 1 user1 user1 741 Jun 7 12:19 .profile.bak -rw-r--r-- 1 user1 user1 741 Jun 7 13:12 .profile.bak1 user1@vm1:~$ ls -altr total 40 -rw-r--r-- 1 user1 user1 3184 Jun 6 21:48 .bashrc -rw-r--r-- 1 user1 user1 220 Jun 6 21:48 .bash_logout drwxr-xr-x 3 root root 4096 Jun 6 21:49 .. -rw-r--r-- 1 user1 user1 741 Jun 7 12:19 .profile.bak -rw-r--r-- 1 user1 user1 697 Jun 7 12:25 .profile -rw-r--r-- 1 user1 user1 741 Jun 7 13:12 .profile.bak1 -rw------- 1 user1 user1 308 Jun 7 13:14 .bash_history1 drwxr-xr-x 2 user1 user1 4096 Jun 7 13:30 . -rw------- 1 user1 user1 45 Jun 7 13:31 .lesshst -rw------- 1 user1 user1 853 Jun 7 15:03 .bash_history user1@vm1:~$ cp -v .bash_history{,1} `.bash_history' -> `.bash_history1' user1@vm1:~$ cp -v .bash_history1 .bash_history2 `.bash_history1' -> `.bash_history2' user1@vm1:~$ mv -v .bash_history1 .bash_history2 `.bash_history1' -> `.bash_history2' user1@vm1:~$ rm -v .bash_history2 removed `.bash_history2' user1@vm1:~$ touch .bashrc user1@vm1:~$ ls -al total 36 drwxr-xr-x 2 user1 user1 4096 Jun 14 12:23 . drwxr-xr-x 3 root root 4096 Jun 6 21:49 .. -rw------- 1 user1 user1 853 Jun 7 15:03 .bash_history -rw-r--r-- 1 user1 user1 220 Jun 6 21:48 .bash_logout -rw-r--r-- 1 user1 user1 3184 Jun 14 12:24 .bashrc -rw------- 1 user1 user1 45 Jun 7 13:31 .lesshst -rw-r--r-- 1 user1 user1 697 Jun 7 12:25 .profile -rw-r--r-- 1 user1 user1 741 Jun 7 12:19 .profile.bak -rw-r--r-- 1 user1 user1 741 Jun 7 13:12 .profile.bak1 user1@vm1:~$ user1@vm1:~$ ls .* .bash_history .bash_logout .bashrc .lesshst .profile .profile.bak .profile.bak1 .: ls.out ..: user1 解释
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |