【问题标题】:Writing a shell program stdout编写一个 shell 程序标准输出
【发布时间】:2014-02-22 01:57:09
【问题描述】:

编写一个遵循以下算法的 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 *.??? > 临时文件

【问题讨论】:

  • 为什么你所拥有的东西不起作用?
  • 另外,FIE 关于提出第 2 步的人。
  • 它有效,但我知道我必须为第 2 步做什么

标签: shell glob ls


【解决方案1】:

这对我有用:

#! /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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 2017-04-08
    • 2016-07-30
    • 2017-07-24
    • 2011-11-15
    • 1970-01-01
    相关资源
    最近更新 更多