How to list down the full paths to all files in multiple directories of a certain file format? - linux

I am looking for a Bash solution to my dilemma here. I have directory project, and within that I have project/Batch1 project/Batch2 project/Batch3 and so on.
Within each Batch folder, I have a mix of files but what I am interested in are files in the .txt format, for example. I am able to recursively acquire the names of every file in my project directory using the ls -LR command. However, how should I get full paths including the file names, and also only for .txt files?
Thanks!

Use find command. Open man 1 find and check possible option you need for above task.
Here is the simple example. Open terminal and run
find pwd -type f -name "*.txt"
Or
find pwd -name "*.txt"
Or you can do same using bash script also.

Related

Creating file in all system directories and displaying their paths LINUX

I have a problem with a task I've been given "Create files in each system directory and display the paths to those files". As I understand I need to create a file in all of the directories, I tried with using find . -type d -exec touch {}/file \; but I don't think it's what im asked for.

Find -perm finds file (or something else) that dosent exist

Hello i am new in the world of linux and i have a simple question:
I created a directory named testfiles and 10 textfiles inside of it with various permissions.
I tried using find -perm -u=wr | wc -l in order to count all files with rw prem for user but it counts 1 more file than it is supposed to have. I then used find -perm -u=wr to see the list and realized there is an extra line in the beginning which i am not sure what it is can someone help? How do I get rid of that?
The '.' and '..' are references to the current directory and the parent directory respectively. These exist in all linux directories. As these are treated as directories, you can ignore them by using the '-type' option of the find command, where 'f' specifies files only.
find -perm -u=wr -type f | wc -l
Note that the find command as you have it will recursively find files if another directory exists where you are running the command. You can limit it to the current directory only by using the max depth option. Run 'man find' in the terminal to see all the other options you have with the find command.

How to list all files in all directory in linux using linux cmd

I'm trying to read all the files available in all directories along with complete path, using bash script. Have tried
ls -R cmd but it is not listing the files properly.
My requirement is to have the output which should have complete path for the file.
Maybe you want the find utility which is recursive by default.
find . -type f
The . means the current pwd/directory
You can use find command for listing all the files from a particular directory.
find /your_path/ -type f 2>/dev/null
/your_path/ : provide the path from where you will execute the command, the output will have the complete path of the files.
2>/dev/null : to suppress the STDERR
right now what you are trying is to list all of the sub-directories using ls -R, so this would not fulfill what you are trying to achieve.
See man ls:
-R, --recursive
list subdirectories recursively

How to search for files ending/starting/containing a certain letter in terminal?

I have been looking all over the internet to help me with this. I want to list all files that start/end/contain a certain letter but the results I found on the internet do not seem to work for me. I need to use the ls command for this (assignment).
I tried this code from another question:
ls abc* # list all files starting with abc---
ls *abc* # list all files containing --abc--
ls *abc # list all files ending with --abc
but when ever I try any of those it comes back with "ls: cannot access '*abc': No such file or directory"
Use find for finding files:
find /path/to/folder -maxdepth 1 -type f -name 'abc*'
This will give you all regular filenames within /path/to/folder which start with abc.

Shell Script to finding files in specific folder and based on "age" of files

hello i got homework to make a shell script in linux to find a file in specific folder based on the "age" of those files. and after that i want to move that file to other specific folder.
thank you before
One way is to use the find command, and specify the "age" with -mtime (or -newer if age relative to other files). See man find for more details.
To move the files you can use mv (again, see man mv).
Directories can be passed as arguments or stored in variables and then used
as variables in the commands.
Without knowing anything else about your assignment I'd say use something like this:
find <directory> -mtime <n> | xargs mv -t <destination>
where xargs is used to pass the results from find to the mv command.

Resources