for the following command
find . -name "*.java"
the result is what I expected, find the filename with extension .java under current directory and its subdirectory, but I cannot understand the following command output
find . -name *.java
without the double quote, I know * has special meaning in ksh, but what is this command do exactly?
It depends on how many *.java files you have in the current directory:
0: the shell passes the mask to 'find': find . -name *.java
1: the shell passes the filename to 'find': find . -name 1.java
2+: the shell passes the filenames to 'find': find . -name 1.java 2.java 3.java ...
Of course 'find' won't know what to do with the extra filenames after the first one
You want to give *.java to find, not something that is substituted by bash before giving the command to find. You can do this by putting *.java in double quotes, or by escaping the special characters:
find . -name \*.java
You can see what is happening with
set -x
find . -name *.java
set -
Related
I'm trying to locate all folders that match a certain path.
The path is public_html/core/cache
I can find all instances of cache with the command below, however this does return results from elsewhere which are undesired!
find . -name cache -print
I've tried the below, but it presents an error.
find . -name public_html/core/cache -print
I'd like to run the script once to ensure the results are accurate, then afterwards run it again, removing all contents of the returned folder.
Many thanks in advance
A kind friend gave me the solution:
find / -type d -path "*core/cache" -print
I would like to add an External Tool to my Eclipse CDT Project.
This external tool, which is a program that I have written myself, requires different arguments (the map file and a list of all *.c *.cpp and *.h files). I already managed to hand over the map file but is there any way of getting a list of all *.c and *.h files (maybe with an Eclipse Variable) so that I can directly add this to the argument field?
I found one solution which can be used on a linux system. Just use a a pipe with the following command and put it in a shell script.
First of all, how to find all source code files:
find <rootfolder> -name '*.c' -o -name '*.cpp' -o -name '*.h'
Complete command:
find <rootfolder> -name '*.c' -o -name '*.cpp' -o -name '*.h' | xargs <myTool>
The first command will find out all absolute paths to the all .c .cpp and .h files listed in the rootfolder and the second one will convert its input into a set on arguments. The result will be the same as if every found file path would have been handed over as a single argument to mytool.
First of all, this is my first post here and I must specify that I'm a total Linux newb.
We have recently bought a QNAP NAS box for the office, on this box we have a large amount of data which was copied off an old Mac XServe machine. A lot of files and folders originally had forward slashes in the name (HFS+ should never have allowed this in the first place), which when copied to the NAS were all replaced with a colon.
I now want to rename all colons to underscores, and have found the following commands in another thread here: pitfalls in renaming files in bash
However, the flavour of Linux that is on this box does not understand the rename command, so I'm having to use mv instead. I have tried using the code below, but this will only work for the files in the current folder, is there a way I can change this to include all subfolders?
for f in *.*; do mv -- "$f" "${f//:/_}"; done
I have found that I can find al the files and folders in question using the find command as follows
Files:
find . -type f -name "*:*"
Folders:
find . -type d -name "*:*"
I have been able to export a list of the results above by using
find . -type f -name "*:*" > files.txt
I tried using the command below but I'm getting an error message from find saying it doesn't understand the exec switch, so is there a way to pipe this all into one command, or could I somehow use the files I exported previously?
find . -depth -name "*:*" -exec bash -c 'dir=${1%/*} base=${1##*/}; mv "$1" "$dir/${base//:/_}"' _ {} \;
Thank you!
Vincent
So your for loop code works, but only in the current dir. Also, you are able to use find to build a file with all the files with : in the filename.
So, as you've already done all this, I would just loop over each line of your file, and perform the same mv command.
Something like this:
for f in `cat files.txt`; do mv $f "${f//:/_}"; done
EDIT:
As pointed out by tripleee, using a while loop is a better solution
EG
while read -r f; do mv "$f" "${f//:/_}"; done <files.txt
Hope this helps.
Will
Can you give a script in perl or shell to search and replace strings "windows" to "android", across only some specific folders, and strings should be replaced only in files, not in folders name?
find . -type f|xargs perl -pi -e 's/windows/android/g'
-type f -this will find only files and not directories.
remaining part after the pipe will search and replace windows with android in all the files returned by teh find command
I would like to translate the following Unix 1 Liner to PowerShell.
Synopsis of the command:
This command will search recursively form the PWD (pressent working directory) for any file with the extenstion .jsp, and look inside the file for a simple string match of 'logoutButtonForm'. If it finds a match, it will print the file name and the text that it matched.
find . -name "*.jsp" -exec grep -aH "logoutButtonForm" {}\;
I am new to power shell and have done some googling/binging but have not found a good answer yet.
ls . -r *.jsp | Select-String logoutButtonForm -case
I tend to prefer -Filter over -Include. Guess I never trusted the -Exclude/-Include parameters after observing buggy behavior in PowerShell 1.0. Also, -Filter is significantly faster than using -Include.