Lao Li share: "Linux shell Script Raiders" Essentials (iii)

Source: Internet
Author: User

1, 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/s 2, 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 the target True if the record is returned. [-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 generated 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 symbolic Link file method 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/bash

If [$#-ne 1];

Then

echo $ basepath;

Exit 1

Fi

Path=$1

Declare-a Statarray;

while read line;

Do

ftype=$ (file-b "$line")

Let statarray["$ftype"]++;

Done < < (find $path-type f-print)//In child process statistics file name

echo ===================file types and counts ===============

For ftype in "${!statarray[@]}"; Array table

Do

echo $ftype: ${statarray["$ftype"}

Done

6, real-time viewing of the growing file [[email protected] touch_more]# tail-f filestat.sh 7, directory switching [[email protected] program_test]# CD-
/home/yxx/program_test/touch_more

Lao Li share: "Linux shell Script Raiders" Essentials (iii)

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.