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

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.

Related

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 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]

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*'

Bash: How to list only files with read permissions? [duplicate]

This question already has answers here:
Find all writable files in the current directory
(11 answers)
Closed 7 years ago.
How can I list all the files with read permissions on current directory ?
find -maxdepth 1 -type f -perm xxx
Where xxx indicate the file permission on your targer file, according to this question.

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

how to list full paths of folders inside a directory in linux? [duplicate]

This question already has answers here:
Show full path when using options
(8 answers)
Closed 8 years ago.
I have a folder /home/Documents/myFolder and inside this folder there are lots other folders. I want to have a file list.txt which contains all the paths of the folders. I want the text file content like this:
/home/Documents/myFolder/1234
/home/Documents/myFolder/asd2
/home/Documents/myFolder/asdawgf
/home/Documents/myFolder/dawt
.
.
.
I tried this one but it was not what I want ls > /home/Documents/myFolde/list.txt
it just prints the folder names. I want the full paths.
Use find listing all directories (-type d) and then sed the output to get the full path correct:
find . -type d | sed -n 's:^\./:/home/Documents/myFolder/:'p > /home/Documents/myFolder/list.txt
you can use find:
find . > /home/Documents/myFolde/list.txt

Resources