How do AWK, grep and Find commands differ from each other, sice all these three command looks for a specific phrase in text file or directory? [duplicate] - linux

This question already has answers here:
Find all files with name containing string [closed]
(8 answers)
Closed 5 years ago.
I just want to know how AWK, grep and find command differ from each other in terms of functionalities and which command to use when?

The command would be
find . -type d -name '*word*'

Related

How to write script displaying all subdirectories in the location [duplicate]

This question already has answers here:
List sub-directories with ls [closed]
(3 answers)
Closed 3 years ago.
I need help. How to write script displaying all subdirectories in the location. I've got something like that:
ls -al | grep ^d
but it only works in the home directory
find(1) may be a better choice here:
find . -type d
which would list all directories from the current directory and all subdirectories.

Search recursively all files with a given name replacing a word [duplicate]

This question already has answers here:
BASH: recursive program to replace text in a tree of files
(3 answers)
Closed 5 years ago.
From a given folder, I want to search recursively accross all subfolders searching for files with name file.txt replacing all occurences of Foo -case sensitive-
with Bar.
Which is the simplest way of achieving this with basic scripting (Bash / sed / grep / find...).
find + sed solution:
find . -type f -name "file.txt" -exec sed -i 's/Foo/Bar/g' {} \;

Grep for a file with a specific name [duplicate]

This question already has answers here:
Exclude a string from wildcard search in a shell
(3 answers)
Closed 5 years ago.
In my repository I have several files, including two specific JAR files named as follows:
backend-0.0.1-SNAPSHOT.jar
backend-0.0.1-SNAPSHOT.jar.original
I need to get only the first one, and I need to fetch it only with its name: "backend". The version is not static; it can change.
So I have done this:
ls | grep 'backend'
But this one get me both of them, so I need to grep for files beginning with backend and ending by .jar.
How can I use this?
Don't use the output of ls for scripting. Use find instead:
find . -maxdepth 1 -type f -name 'backend*.jar'
Or, without using grep:
ls backend*.jar
ls | grep '^backend.*.jar$'
$ means, that there are no symbols after r in jar.

How to find both files and folders that are used in some process? [duplicate]

This question already has answers here:
Delete files older than 10 days using shell script in Unix [duplicate]
(3 answers)
Closed 7 years ago.
I want to delete files and folders older than 15 days.
But Before deletion I want to check that those file and folders shouldn't use anywhere. How can i do that ?
is ps -ef works for this ?
Using the find command:
find /path/to/folder -type f -mtime +15 -delete

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.

Resources