1. How to use echo to output a string STR = "-n". Because-N is a parameter of ECHO, the General echo "$ Str" method cannot be output.
The solution can be:
Echo x $ STR | SED's/^ x //'
Echo-ne "$ STR \ n"
Echo-e "$ STR \ n \ c"
Printf"% S \ n" $ STR (this can also be done)
Printf format output
The % s format character indicates that the output string is followed by a character array or character pointer.
2. How does Shell define the data structure of a directory? (Find.-type D-maxdepth 1)
Q: What should I do if I want to collect the basic information of each file in a directory, such as the file name, file directory, and size, and generate a file in a unified manner?
A: Use awk to process the results from LS-LH.
1) The last field (usually 9th) in each row is the file name.
2) Does the file directory refer to the directory where the file is located, or is it a directory to determine whether a file is located? If it is the former, use the PWD command to obtain it. (The following code is based on this situation) if it is the latter, the first character of each line is determined based on the LS-lH result. If it is D, it is represented as directory ).
3) obtain the file size based on 5th fields. The shell script is roughly as follows :#! /Bin/shls-lH "$1" | awk 'begin {printf ("FILENAME \ tdirectory \ tsize \ n ")} NR> 1 {printf ("% s \ t % s \ n", $ NF, '\ "$1 \"', $5 )} '> the file.txt exit 0 script is saved as statistic. sh run the following command: Sh statistic. sh [directory name for Statistics]
The results are stored in the file.txt file in the current directory.
Q: The file directory refers to the directory where the file is located. How should I continue to collect statistics on files in sub-directories?
A: There are subdirectories under the directory, and there are subdirectories under the subdirectory. This is endless. Run the "ls-LHR> file.txt" command to list files including subdirectories. Or: Tree-HD> file.txt generates the file directory of the tree structure, including the size of each file (directory) and the last modification time.