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 .*
-
pwd: Prints out current working directory.
-
ls: Prints out files(excepts hidden files like .bashrc. Hidden files are ones which names start with a dot.) in current directory.
-
ls -a: Prints out all files in current directory, -a tells ls to show all files including hidden ones.
-
ls -al: Prints out all files in current directory in long format.
-
ls -altr: -t tells ls to sort by time, and -r tells ls to reverse the sort.
-
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).
-
cp -v .bash_history1 .bash_history2
Copies recently created .bash_history1 to .bash_history2.
-
mv -v .bash_history1 .bash_history2
Moves .bash_history1 to .bash_history2. Notice that it overwrites the destination file without asking.
-
rm -v .bash_history2: Removes .bash_history2 without warning.
-
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.
-
ls -al: Prints out all files in current directory in long format.
-
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

浙公网安备 33010602011771号