I want to write a shell program which will go through all folders whose names match a pattern like this:  sudo sh  shell.sh   pub    When run, the script will look for all folders whose name contains pub and print its modification date. I wish to have code which will print results like in this image:  I have this code but it is not giving me the result I expect.  echo  'the folder '$1' was modified at ';  find  -type d -name 'kam*'  -exec stat -c '%y %n' '{}' \;   I must go through every folder and output text echo 'the file '$1' was modified at '; and print the date like in the image.  I would like a result like this:  netcom@hotspot:~$ bash script.sh testRegex Pub the folder testRegex was modified on may 15 01:19  the folder Public was modified on may 19 01:19    the folder Pubos was modified on may 19 01:19
59969
I can easily find files with given string in name:  me@comp:/usr/local/hydra/hydra-7.4.2$ find -D stat -name "*hack*" ./hack881663129.txt ./hack881663129_7.txt ./hack881663129_5.txt ./hack881663129_4.txt ./hack881663129_4_7.txt ./hack881663129_6.txt ./hack881663129_1_6.txt ./hack881663129_8.txt   How can I also print file details, like size, date of creation etc.?
59964
I can't for the life of me figure out how find with the test -name works.  I run find / -name *in and returns a bunch of results:  /sbin /sbin/sulogin /dev/stdin   to name a few.  It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it. Also because I don't have any files in the current directory that match *in. Plus, single quoting *in yields the same results, which further supports that this can't be filename expansion.  The documentation leads me to believe that find with -name uses regular expressions, but the regex pattern *in doesn't match the results I showed above.  Can someone enlighten me?
87437
I'm trying to beat my head against the syntax of this. I'm getting problems with whitespaces and I can't see if there's a better way to do this.  vardir=/home/user cd $vardir for i in $(ls "$vardir") ; do timestamp="$(stat -c %Y $i)" echo "$i" echo "$timestamp"  done   Result is similar no matter where I quote and I'm not sure what I'm doing wrong:  stat: cannot stat ‘Temporary’: No such file or directory Temporary  stat: cannot stat ‘Items’: No such file or directory Items   My goal is I want to grab the timestamps off of backup directories and touch the current ones to restore the original modified dates.
96219
I was playing around in a shell and typed ./. I go the following output:  bash: ./: Is a directory   It looks like "./" checks if a directory with the given name exist. I was trying to find documentation on this to see if my understanding was right, but can't find anything online. Can anyone explain this one to me?
50121
The man page for GNU find states:    -exec command ;     [...] The  string `{}'  is  replaced  by the current      file name being processed everywhere it occurs in the      arguments to the command, not just in arguments where      it is alone, as in some  versions  of  find.     Both  of  these  constructions might need to be escaped      (with a `\') or quoted to protect them from expansion      by the shell.     That's from the man to find (GNU findutils) 4.4.2.   Now I tested this with bash and dash, and both don't need to have the {} being masked. Here is a simple test:  find /etc -name "hosts" -exec md5sum {} \;    Is there a shell, for which I really need to mask the braces? Note, that it doesn't depend upon whether the file found contains a blank (invoked from bash):   find ~ -maxdepth 1 -type d -name "U*" -exec ls -d {} \;  /home/stefan/Ubuntu One   This changes if the found file is passed to a subshell:  find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d {}' \;  ls: cannot access /home/stefan/Ubuntu: No such file or directory ls: cannot access One: No such file or directory   which can be solved by:  find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d "$0"' {} \;   in contrast to:   find ~ -maxdepth 3 -type d -name "U*" -exec bash -c 'ls -d "{}"' \;  /home/stefan/Ubuntu One   but that's not what the man page is talking about, is it? So which shell treats {} in a different way?
53046
I have files in a directory (/home/user/example) that I need to verify and match. Each file has a control and data file. I want to check if for each file there is a corresponding file of the other. For example, if example.ctl has a match with example.out or example.out has a corresponding file with example.ctl.   I had written a nested for loop and  with many if else statements. But this seemed to be far too complex for a basic check like this. I wanted to see if anyone had a better solution.   Example files in directory:  example.ctl example.out   example_1.ctl example_1.out   example_2.ctl example_2.out
96588
I came up with the following snippet for counting files in each subdirectory:  for x (**/*(/)); do print $x; find $x -maxdepth 1 -type f | wc -l; done   The command outputs consecutive pairs (one below the other) as follows:  directory_name # of files   I would like to change the code above to:   Print each match on the same line (i.e. directory_name ':' # of files) Only count files if the folders are leaves in the directory tree (i.e. they don't have any subfolders).    How can I do that?
117087
I want to search all files in the current directory and below for the substring $form['#node']. So, I have tried, initially:  grep -R "\$form\[\\\\'" . and grep -R "\$form\[\'" .  But it returns no results. However,   grep -R "\$form\[" returns plenty of results, as there are instances of entries such as $form['#id'] or $form['#node'] in the files. Is there any reason why adding the escaped single quote causes an issue? I can't seem to find any clear indication of exactly how to escape a single quote in this case.  I need to check that my escaped characters are working as intended in this scenario.
12202
Say I have the following files:   |-- bar `-- foo     |-- type_A_1     |-- type_A_2     |-- type_B_1     |-- type_B_2     |-- type_B_xx     |-- type_B_xx     `-- something_else    I thought the following command  print -l foo/*~{type_B*}   would print everything under foo except things that start with type_B but it doesn't, instead it prints everything under foo:  foo/type_A_1 foo/type_A_2 foo/type_B_1 foo/type_B_2 foo/type_B_xx foo/something_else   I also tried print -l foo/*~type_B and got the same thing.  How does the exception wildcard ~ work in zsh?
61308
I've a simple bash script. PFB :  CWD=/cygdrive/c/Users/abhisek.samanta/Desktop/New_folder cd $CWD for i in `cat req_files.txt` do echo "file_found : $i"&gt;a.txt done   Note : req_files.txt is having a list of files which i need to find in this directory . If the files are found, it should list the name of the file which was found &amp; print it in "a.txt".   The req_files.txt is having multiple files,but only the first filename is getting printed &amp; not the rest of the files. Pl help.
60761
I'm looking for the string foo= in text files in a directory tree. It's on a common Linux machine, I have bash shell: grep -ircl &quot;foo=&quot; *  In the directories are also many binary files which match &quot;foo=&quot;. As these results are not relevant and slow down the search, I want grep to skip searching these files (mostly JPEG and PNG images). How would I do that? I know there are the --exclude=PATTERN and --include=PATTERN options, but what is the pattern format? The man page of grep says: --include=PATTERN     Recurse in directories only searching file matching PATTERN. --exclude=PATTERN     Recurse in directories skip file matching PATTERN.  Searching on grep include, grep include exclude, grep exclude and variants did not find anything relevant If there's a better way of grepping only in certain files, I'm all for it; moving the offending files is not an option. I can't search only certain directories (the directory structure is a big mess, with everything everywhere). Also, I can't install anything, so I have to do with common tools (like grep or the suggested find).
72552
How do I work recursively through a directory tree and execute a specific command on each file, and output the path, filename, extension, filesize and some other specific text to a single file in bash.
2861
I wrote the following script to diff the outputs of two directores with all the same files in them as such:  #!/bin/bash  for file in `find . -name "*.csv"`   do      echo "file = $file";      diff $file /some/other/path/$file;      read char; done   I know there are other ways to achieve this.  Curiously though, this script fails when the files have spaces in them.  How can I deal with this?  Example output of find:  ./zQuery - abc - Do Not Prompt for Date.csv
35461
I'd like to write something like this:  $ ls **.py   in order to get all .py filenames, recursively walking a directory hierarchy.  Even if there are .py files to find, the shell (bash) gives this output:  ls: cannot access **.py: No such file or directory   Any way to do what I want?  EDIT: I'd like to specify that I'm not interested in the specific case of ls, but the question is about the glob syntax.
37870
I have a script doSmth in /usr/bin. Is it possible to get and print the directory the script was called from?  So if I call doSmth from /home/me the output will be /home/me.
65652
In bash, I know that it is possible to write a for loop in which some loop control variable i iterates over specified integers.  For example, I can write a bash shell script that prints the integers between 1 and 10: #!/bin/bash  for i in {1..10} do  echo $i done  Is it possible to instead iterate over a loop control variable that is a string, if I provide a list of strings?  For example, suppose that I have a string fname that represents a file name.  I want to call a set of commands for each file name.  For example, I might want to print the contents of fname using a command like this: #!/bin/bash  for fname in {&quot;a.txt&quot;, &quot;b.txt&quot;, &quot;c.txt&quot;} do  echo $fname done  In other words, on the first iteration, fname should have the value fname=&quot;a.txt&quot;, while on the second iteration, fname should have the value fname=&quot;b.txt&quot;, and so on.  Unfortunately, it seems that the above syntax is not quite correct.  I would like to obtain the output:  a.txt b.txt c.txt  but when I try the above code, I obtain this output:  {a.txt, b.txt, c.txt}  Can you please help me determine the correct syntax, so that I can iteratively change the value/contents of the variable fname?  Thank you for your time.
112882
Something like the following is what I what I'm after,  but my code doesn't work, no matter how I escape {} and + ;     find ./ -maxdepth 1 -type d -name '.*' -exec \     find {} -maxdepth 1 -type f -name '*.ini' -exec \         md5sum \{\} \\; \;   After seeing this ,  I found that the following code works, but it isn't nesting find as such, and I suspect there is a better way to do this particular job.       find ./ -maxdepth 1 -type d -name '.*' \ -exec bash -c 'for x; do     find "$x" -maxdepth 1 -type f -name "*.ini" \     -exec md5sum \{\} \;; \ done' _ {} \+   Is there some way to nest find -exec without the need to invoke  a shell (as above), with all its whacky quoteing and escape constraints?    Or can this be done directly in a single find command,  using a blend of its many parameters?