编写一个shell程序stdout

时间:2014-01-29 23:38:49

标签: shell glob ls

编写一个遵循以下算法的shell程序,以获得一个     列出名称以3个字符扩展名结尾的所有目录的长列表,     并且其权限是用户(所有者)的rwx。

ALGORITHM:
1. Do the same ls command you used in question 2 above, except REDIRECT 
   the ls command's stdout to go into a file named tempFile (instead of 
   the monitor).
2. Use grep to filter the lines of tempFile so that a line is kept ONLY 
   if it corresponds to a DIRECTORY that has rwx permissions for its 
   user (owner).
3. delete (remove) tempFile
到目前为止,我被困在1 i上了:

ls -ld *。??? > TEMPFILE

1 个答案:

答案 0 :(得分:0)

这对我有用:

#! /bin/bash

ls -ld * > tmp   # get a list of the permissions of all directorys in this folder and write it to the tmp file
grep "^drwx" tmp # filter the tmp files for lines beginning with drwx
rm tmp           # remove the file tmp