English 中文(简体)
我如何通过每一篇档案来翻一番?
原标题:How do I traverse through every file in a folder?
  • 时间:2011-10-27 20:15:59
  •  标签:
  • bash
  • shell

我有一个称为考试的夹。 这组人有3个称为数学、物理学和english的夹。 所有这些人都有一些子夹和档案。 我想通过翻翻一番,在另一个称为档案的档案中印刷每翻一番的道路。 我这样做了:

#!/bin/bash

LOC="/home/school/exam/*"

{
  for f in $LOC 
  do
   echo $f
  done
 } > "files"

我的出走是:

/home/school/exam/math

/home/school/exam/phyics

/home/school/exam/english

我可以说明如何访问守则,对考试分数人也一样。 任何建议?

PS I m 仅是身穿便衣的开端人。

最佳回答
find /home/school/exam -print > files
问题回答

使用<代码>globstar 选项 bash,在使用两个相邻星时,将重印各子公司的所有档案名称。

使用:

shopt -s globstar
for i in /home/school/exam/**

The reference here is man bash:

globstar
                      If set, the pattern ** used in a pathname expansion context
                      will match all files and zero or more directories and
                      subdirectories.  If the pattern is followed by a /, only
                      directories and subdirectories match.

www.un.org/Depts/DGACM/index_spanish.htm

          *      Matches any string, including the null string.  When  the
                 globstar  shell  option  is  enabled,  and * is used in a
                 pathname expansion context, two adjacent  *s  used  as  a
                 single  pattern  will  match  all  files and zero or more
                 directories and subdirectories.  If followed by a /,  two
                 adjacent  *s  will match only directories and subdirecto‐
                 ries.

you can use find command, it could get all files, then you can do something on them, using exec or xargs for example.

您也可使用列入多数*六分送的<条码>。 (尽管乌兰巴托是一个显著的例外,但可以通过适当的植被安装)

LOC="/home/school/exam/"
tree -if $LOC > files

如何重新列出你们的所有档案。

for i in *; do ls -l $i ; done




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Bash usage of vi or emacs

From a programming standpoint, when you set the bash shell to use vi or emacs via set -o vi or set -o emacs What is actually going on here? I ve been reading a book where it claims the bash shell ...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Perform OR on two hash outputs of sha1sum

I want perform sha1sum file1 and sha1sum file2 and perform bitwise OR operation with them using bash. Output should be printable i.e 53a23bc2e24d039 ... (160 bit) How can I do this? I know echo $(( ...

Set screen-title from shellscript

Is it possible to set the Screen Title using a shell script? I thought about something like sending the key commands ctrl+A shift-A Name enter I searched for about an hour on how to emulate ...

热门标签