Linux Shell Script Raiders notes Chapter III: File Operations

Source: Internet
Author: User

Linux Shell Script Raiders notes Chapter III: File Operations1, the production of any size file [[email protected] dd_test]#
[[email protected] dd_test]# dd If=/dev/zero of=junk.data bs=1k count=10
10+0 Records in
10+0 Records out
10240 bytes (Ten kB) copied, 0.00137023 S, 7.5 mb/s2, file system related test [-f $file _var]: The given variable contains a normal file path or file name, returns True [-D $var]: The given variable is a directory , the return is true. [-e $var]: Returns True if the given variable contains a file that exists. [[-Z $STR 1]]: Returns True if Str1 contains an empty string. [[-N $str 1]]: Returns True if STR1 contains a non-empty string. -GT: Greater than-lt: less than-ge: greater than or equal to.-le: less than or equal to.
3. file permissions [[email protected] program_test]# chmod 777 cnts.sh
4. Batch generate files of any size [[email protected] touch_more]# cat create_morefile.sh
#!/bin/bash
For name in {1..100}.txt
Do
Touch $name
DD If=/dev/zero of= $name bs=1k count=1
Done

5. Generate Symbolic link file [[email protected] touch_more]# ln-s 100.txt 100_symbol.txt
[Email protected] touch_more]# Ll-al 100*
lrwxrwxrwx. 1 root root 7 Jan 2 00:24 100_symbol.txt-100.txt
-rw-r--r--. 1 root root 2 00:22 100.txt
Find file methods for symbolic Links One: [[email protected] touch_more]# Ls-al | grep ' ^l ' | awk ' {print $9} '//feature tag, starting with L.
100_symbol.txt method Two: [[email protected] touch_more]# find./-type L
./100_symbol.txt
Print symbolic link to file name: [[email protected] touch_more]# Ls-al 100_symbol.txt | awk ' {print $11} '
100.txt
6, Traversal files, classification type statistics file
[email protected] touch_more]# cat Filestat.sh#!/bin/bashif [$#-ne 1];then        echo $ basepath;        Exit 1fipath=$1declare-a Statarray;while Read Line;do        ftype=$ (file-b "$line") Let        statarray["$ftype"]++;d One < < (find $path-type f-print)  //With child process statistics file name echo ===================file types and counts ===============for Ftyp E in "${!statarray[@]}"; Array table do        echo $ftype: ${statarray["$ftype"]}done



6. Watch the growing files in real time [[email protected] touch_more]# tail-f filestat.sh
7. Directory switch [[email protected] program_test]# CD-
/home/yxx/program_test/touch_more

Ming Yi World

Reprint please indicate source, original address: http://blog.csdn.net/laoyang360/article/details/42364783

If you feel this article is helpful, please click on the ' top ' support, your support is I insist on writing the most power, thank you!


Linux Shell Script Raiders notes Chapter III: File Operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.