File Command

File Command

Stat

Size

Time of last access, which is updated when you view a file.

Time of last modification, which is updated when you change a file.

File operations

 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 .*
  1. pwd: Prints out current working directory.

  2. ls: Prints out files(excepts hidden files like .bashrc. Hidden files are ones which names start with a dot.) in current directory.

  3. ls -a: Prints out all files in current directory, -a tells ls to show all files including hidden ones.

  4. ls -al: Prints out all files in current directory in long format.

  5. ls -altr: -t tells ls to sort by time, and -r tells ls to reverse the sort.

  6. cp -v .bash_history{,1}

    Copies .bash_history to .bash_history1. The form like .bash_history{,1} is a feature called [brace expansion](#brace expansion).

  7. cp -v .bash_history1 .bash_history2

    Copies recently created .bash_history1 to .bash_history2.

  8. mv -v .bash_history1 .bash_history2

    Moves .bash_history1 to .bash_history2. Notice that it overwrites the destination file without asking.

  9. rm -v .bash_history2: Removes .bash_history2 without warning.

  10. touch .bashrc: Updates .bashrc timestamp to current date and time. This means that all .bashrc time attributes, st_atime, st_mtime and st_ctime are set to current date and time. You may become sure of this by typing in stat .bashrc.

  11. ls -al: Prints out all files in current directory in long format.

  12. ls .*: Prints out files in you home directory in short format.

brace expansion

In our case .bash_history{,1} expands into two arguments, namely .bash_history and .bash_history1. Bash just takes a parameter before the brace, .bash_history in our case, and adds everything which is in braces, separated by commas, to this parameter consequentially. First addition becomes just .bash_history because first argument in braces is void, there is no first argument. Next, Bash adds 1 because that's the second argument. Resulting arguments, which are passed to cp after expansion are -v .bash_history .bash_history1.

Exercise 4. Bash: working with files, pwd, ls, cp, mv, rm, touch

posted @ 2021-03-12 10:31  上官凉皮  阅读(39)  评论(0)    收藏  举报