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

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

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.

How can I search for specific file contents in all files in both current folder and all subfolders [duplicate]

This question already has answers here:
How do I recursively grep all directories and subdirectories?
(26 answers)
Closed 4 years ago.
Using Mac terminal server linux/bash commands, how can I search for a particular text string in all *.txt files in the current folder plus all files in the subfolders inside the current folder?
grep -i "xxx" */*
xxx is the target text I am trying to find.
find . -type f -print | egrep ".txt$" | xargs grep "SearchPatern"
Explained as
Find all the file names in the current directory and below send to ....
grep which picks out the file name that end in .txt and send names to ....
xargs which will execute a grep command on each file to look for SearchPatern.

How do I concatenate file contents into a single file in bash? [duplicate]

This question already has answers here:
Concatenating multiple text files into a single file in Bash
(12 answers)
Closed 4 years ago.
I have files in different directories under a parent directory, something like this:
Parent Dir
Dir 1 - File 1
Dir 2 - File 2
I want to have an output file that appends the content of File1 with File2. How do I do it in Bash?
Converting my comment to an answer. You can use following find + xargs pipeline command:
cd /parent/dir
find home -name "*.orc" -print0 | xargs -0 cat > test.orc

shell command to extract the part of filename having characters? [duplicate]

This question already has answers here:
Extract filename and extension in Bash
(38 answers)
In Bash, how to strip out all numbers in the file names in a directory while leaving the file extension intact
(1 answer)
Closed 5 years ago.
I have a file named(multi_extension123.txt). Before copying this file into the directory I need to remove files like
[multi_extension1234.txt
multi_extension1234.txt
multi_extension12345.txt] if present in the directory and then copy the earlier one to this directory. Can anyone give the solution with shellscript.
note: i need to remove only numerical numbers and extension alone.
I have tried this
$ filename= $file1
$ echo "${filename%[0-9].*}"
find . -type f maxdepth 0 mindepth 0 -name "'$filename'[0-9]*.txt" -exec rm -f {} \;

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.

Resources