[Bash] pipe intro

Zhentiw發表於2024-05-22

Compse commands with pipe

# List all folders and files in current dir
% ls -l
total 56
-rw-r--r--  1 zwt  staff   51 May 16 22:35 data.txt
-rwxr-xr-x  1 zwt  staff  159 May 19 10:52 example.sh
-rw-r--r--  1 zwt  staff  123 May 16 22:25 example.txt
-rwxr-xr-x  1 zwt  staff  251 May 19 11:00 example2.sh
-rw-r--r--  1 zwt  staff   38 May 21 21:31 hello.txt
-rwxr-xr-x  1 zwt  staff  105 May 19 11:12 if.sh
-rwxr-xr-x  1 zwt  staff  162 May 19 11:19 list_regular_files.sh
drwxr-xr-x  4 zwt  staff  128 May 16 22:20 test_directory
-rwxr--r--  1 zwt  staff    0 May 19 10:35 testfile

# count how many folder and files in current dir
% ls -l | wc -l 
      10
% ls -l *.txt
-rw-r--r--  1 zwt  staff   51 May 16 22:35 data.txt
-rw-r--r--  1 zwt  staff  123 May 16 22:25 example.txt
-rw-r--r--  1 zwt  staff   38 May 21 21:31 hello.txt

# only count txt files
% ls -l *.txt | wc -l
    3

相關文章