"Find" command: highlight matching literal parts [closed] - linux

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I use find a lot, generally using the -name or -iname parameters.
I would like it to highlight the matching part in the files it finds (like grep does).
For example: find . -iname "*FOO*" would highlight instances for FOO
I know I could pipe it into grep but I'd rather not write two commands each time.
Is there a simple way to do it?

eg. like this:
find /home/ -type f | grep -i --color=always *.cpp

Related

Rich globbing `ls [G-S]*` in fish shell? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
In Bash it is possible to
ls [G-S]*
and it would list all files from g-s and G-S.
How is that done in Fish shell?
Fish currently does not support a rich glob syntax. The current thinking is that a glob command should be added in keeping with the fish goal of doing things via commands rather than magic syntax. See, for example, https://github.com/fish-shell/fish-shell/issues/3681. The solution is to create a function that filters the results. For example, the ** glob matches all files and directories in and below the CWD. I frequently want just the plain files and want to ignore the .git subdir. So I wrote this function:
function ff --description 'Like ** but only returns plain files.'
# This also ignores .git directories.
find . \( -name .git -type d -prune \) -o -type f | sed -n -e '/\/\.git$/n' -e 's/^\.\///p'
end
Which I can then use like this: grep something (ff). You could create a similar function that uses the find -name pattern matching feature or filter the results with string match --regex.
You can use find -iregex "./[G-S].*". Fish is quite limited in this regard.

linux command to empty all files of a directory [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I´d like to empty all files from a directory. I´d tried this:
find myFolderPath/* -exec cat /dev/null > {} ';'
but it does not work. How can I do it?
You can't use redirection (>) within find -exec directly because it happens before the command runs and creates a file called {}. To get around this you need to do it in a new shell by using sh -c.
Also, note that you don't need to cat /dev/null > file in order to clobber a file. You can simply use > file.
Try this:
find . -type f -exec sh -c '>"{}"' \;
This will do what you want:
for f in *; do >$f; done

Change filenames to lowercase in Ubuntu in all subdirectories [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I know it's been asked but what I've found has not worked out so far.
The closet I came is this : rename -n 'y[A-Z]/[a-z]/' *
which works for the current directory. I'm not too good at Linux terminal so what
should I add to this command to apply it to all of the files in all the sub-directories from which I am in, thanks!
Here's one way using find and tr:
for i in $(find . -type f -name "*[A-Z]*"); do mv "$i" "$(echo $i | tr A-Z a-z)"; done
Edit; added: -name "*[A-Z]*"
This ensures that only files with capital letters are found. For example, if files with only lowercase letters are found and moved to the same file, mv will display the are the same file error.
Perl has a locale-aware lc() function which might work better:
find . -type f | perl -n -e 'chomp; system("mv", $_, lc($_))'
Note that this script handles whitespace in filenames, but not newlines. And there's no protection against collisions, if you have "ASDF.txt" and "asdf.txt" one is going to get clobbered.

In Linux, how do I find find directory with the most subdirectories or files? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How can I find the directory with the largest number of files/subdirectories in it on the system? Obviously the clever answer is /, but that's not what I'm looking for.
I’ve been told the filesystem is out of nodes, so I suspect that somewhere there are a lot of files/directories which are just garbage, and I want to find them.
I’ve tried running this:
$ find /home/user -type d -print | wc -l
to find specific directories.
starting from the current directory, you could try
find . -type d | cut -d/ -f 2 | uniq -c
This will list all directories starting from the current one, split each line by the character "/", select field number "2" (each line starts with "./", so your first field would be ".") and then only outputs unique lines, and a count how often this unique line appears (-c parameter).
You could also add an "sort -g" at the end.

How can I find all *.js file in directory recursively in Linux? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
In Linux, how can I find all *.js files in a directory recursively? The output should be an absolute path (like /pub/home/user1/folder/jses/file.js)
this answer worked for me:
find $PWD -name '*.js' > out.txt
It finds all *.js files, output absolute path, writes the results into out.txt.
find /abs/path/ -name '*.js'
Edit: As Brian points out, add -type f if you want only plain files, and not directories, links, etc.
Use find on the command line:
find /my/directory -name '*.js'
If you just want the list, then you should ask here: http://unix.stackexchange.com
The answer is: cd / && find -name *.js
If you want to implement this, you have to specify the language.

Resources