Skip to main content
Don't put the solution into the question, accept the most helpful answer it instead ;)
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

I've checked some answers online, but they do not work when there's a -name parameter in the command (maybe I'm doing something wrong, not sure). What I'd like to do is to list only filenames (not the directory/path), and to complicate more, I have same filename with different extension, so I need to filter the result using -name and -o, the trouble is the suggestions that I saw use either -printf or basename, and those doesn't work well when there's -name *.txt -o name *.pdf. Is there any other way to solve this problem? example

Example of my files:

/dir1/dir2/dir3/dir4/ /file1.txt /file1.pdf /file1.ods ...etc. 

I'm only interested in listing one or more type of file per listing (by using -name to filter my results. Is

Is it possible to accomplish it using only 1 find command or I have to do it in 2 steps (saving the result in a temporary file, then filter/strip the directory from the temp file)? The result I'm trying to accomplish is a text file with filename per line:

file1.txt file1.pdf file1.ods file2.txt file2.pdf etc. 

The command I was using was find /dir1/dir2/dir3/dir4/ -type f -name '*.txt' -o -name '*.pdf' -o -name '*.ods' -printf "%f\n",is

find /dir1/dir2/dir3/dir4/ -type f -name '*.txt' -o -name '*.pdf' -o -name '*.ods' -printf "%f\n" 

I did notam using GNU find.

Update

It turned out I have to put \(...\), as reminded by αғsнιη

I've checked some answers online, but they do not work when there's a -name parameter in the command (maybe I'm doing something wrong, not sure). What I'd like to do is to list only filenames (not the directory/path), and to complicate more, I have same filename with different extension, so I need to filter the result using -name and -o, the trouble is the suggestions that I saw use either -printf or basename, and those doesn't work well when there's -name *.txt -o name *.pdf. Is there any other way to solve this problem? example of my files:

/dir1/dir2/dir3/dir4/ /file1.txt /file1.pdf /file1.ods ...etc. 

I'm only interested in listing one or more type of file per listing (by using -name to filter my results. Is it possible to accomplish it using only 1 find command or I have to do it in 2 steps (saving the result in a temporary file, then filter/strip the directory from the temp file)? The result I'm trying to accomplish is a text file with filename per line:

file1.txt file1.pdf file1.ods file2.txt file2.pdf etc. 

The command I was using was find /dir1/dir2/dir3/dir4/ -type f -name '*.txt' -o -name '*.pdf' -o -name '*.ods' -printf "%f\n", I did not put \(...\) as reminded by αғsнιη

I've checked some answers online, but they do not work when there's a -name parameter in the command (maybe I'm doing something wrong, not sure). What I'd like to do is to list only filenames (not the directory/path), and to complicate more, I have same filename with different extension, so I need to filter the result using -name and -o, the trouble is the suggestions that I saw use either -printf or basename, and those doesn't work well when there's -name *.txt -o name *.pdf. Is there any other way to solve this problem?

Example of my files:

/dir1/dir2/dir3/dir4/ /file1.txt /file1.pdf /file1.ods ...etc. 

I'm only interested in listing one or more type of file per listing (by using -name to filter my results.

Is it possible to accomplish it using only 1 find command or I have to do it in 2 steps (saving the result in a temporary file, then filter/strip the directory from the temp file)? The result I'm trying to accomplish is a text file with filename per line:

file1.txt file1.pdf file1.ods file2.txt file2.pdf etc. 

The command I was using is

find /dir1/dir2/dir3/dir4/ -type f -name '*.txt' -o -name '*.pdf' -o -name '*.ods' -printf "%f\n" 

I am using GNU find.

Update

It turned out I have to put \(...\), as reminded by αғsнιη

added 170 characters in body
Source Link
michaelbr
  • 121
  • 3
  • 11

I've checked some answers online, but they do not work when there's a -name parameter in the command (maybe I'm doing something wrong, not sure). What I'd like to do is to list only filenames (not the directory/path), and to complicate more, I have same filename with different extension, so I need to filter the result using -name and -o, the trouble is the suggestions that I saw use either -printf or basename, and those doesn't work well when there's -name *.txt -o name *.pdf. Is there any other way to solve this problem? example of my files:

/dir1/dir2/dir3/dir4/ /file1.txt /file1.pdf /file1.ods ...etc. 

I'm only interested in listing one or more type of file per listing (by using -name to filter my results. Is it possible to accomplish it using only 1 find command or I have to do it in 2 steps (saving the result in a temporary file, then filter/strip the directory from the temp file)? The result I'm trying to accomplish is a text file with filename per line:

file1.txt file1.pdf file1.ods file2.txt file2.pdf etc. 

The command I was using was find /dir1/dir2/dir3/dir4/ -type f -name '*.txt' -o -name '*.pdf' -o -name '*.ods' -printf "%f\n", I did not put \(...\) as reminded by αғsнιη

I've checked some answers online, but they do not work when there's a -name parameter in the command (maybe I'm doing something wrong, not sure). What I'd like to do is to list only filenames (not the directory/path), and to complicate more, I have same filename with different extension, so I need to filter the result using -name and -o, the trouble is the suggestions that I saw use either -printf or basename, and those doesn't work well when there's -name *.txt -o name *.pdf. Is there any other way to solve this problem? example of my files:

/dir1/dir2/dir3/dir4/ /file1.txt /file1.pdf /file1.ods ...etc. 

I'm only interested in listing one or more type of file per listing (by using -name to filter my results. Is it possible to accomplish it using only 1 find command or I have to do it in 2 steps (saving the result in a temporary file, then filter/strip the directory from the temp file)? The result I'm trying to accomplish is a text file with filename per line:

file1.txt file1.pdf file1.ods file2.txt file2.pdf etc. 

I've checked some answers online, but they do not work when there's a -name parameter in the command (maybe I'm doing something wrong, not sure). What I'd like to do is to list only filenames (not the directory/path), and to complicate more, I have same filename with different extension, so I need to filter the result using -name and -o, the trouble is the suggestions that I saw use either -printf or basename, and those doesn't work well when there's -name *.txt -o name *.pdf. Is there any other way to solve this problem? example of my files:

/dir1/dir2/dir3/dir4/ /file1.txt /file1.pdf /file1.ods ...etc. 

I'm only interested in listing one or more type of file per listing (by using -name to filter my results. Is it possible to accomplish it using only 1 find command or I have to do it in 2 steps (saving the result in a temporary file, then filter/strip the directory from the temp file)? The result I'm trying to accomplish is a text file with filename per line:

file1.txt file1.pdf file1.ods file2.txt file2.pdf etc. 

The command I was using was find /dir1/dir2/dir3/dir4/ -type f -name '*.txt' -o -name '*.pdf' -o -name '*.ods' -printf "%f\n", I did not put \(...\) as reminded by αғsнιη

edited body
Source Link
michaelbr
  • 121
  • 3
  • 11

I've checked some answers online, but they do not work when there's a -name parameter in the command (maybe I'm doing something wrong, not sure). What I'd like to do is to list only filenames (not the directory/path), and to complicate more, I have same filename with different extension, so I need to filter the result using -name and -o, the trouble is the suggestions that I saw use either -fprintprintf or basename, and those doesn't work well when there's -name *.txt -o name *.pdf. Is there any other way to solve this problem? example of my files:

/dir1/dir2/dir3/dir4/ /file1.txt /file1.pdf /file1.ods ...etc. 

I'm only interested in listing one or more type of file per listing (by using -name to filter my results. Is it possible to accomplish it using only 1 find command or I have to do it in 2 steps (saving the result in a temporary file, then filter/strip the directory from the temp file)? The result I'm trying to accomplish is a text file with filename per line:

file1.txt file1.pdf file1.ods file2.txt file2.pdf etc. 

I've checked some answers online, but they do not work when there's a -name parameter in the command (maybe I'm doing something wrong, not sure). What I'd like to do is to list only filenames (not the directory/path), and to complicate more, I have same filename with different extension, so I need to filter the result using -name and -o, the trouble is the suggestions that I saw use either -fprint or basename, and those doesn't work well when there's -name *.txt -o name *.pdf. Is there any other way to solve this problem? example of my files:

/dir1/dir2/dir3/dir4/ /file1.txt /file1.pdf /file1.ods ...etc. 

I'm only interested in listing one or more type of file per listing (by using -name to filter my results. Is it possible to accomplish it using only 1 find command or I have to do it in 2 steps (saving the result in a temporary file, then filter/strip the directory from the temp file)? The result I'm trying to accomplish is a text file with filename per line:

file1.txt file1.pdf file1.ods file2.txt file2.pdf etc. 

I've checked some answers online, but they do not work when there's a -name parameter in the command (maybe I'm doing something wrong, not sure). What I'd like to do is to list only filenames (not the directory/path), and to complicate more, I have same filename with different extension, so I need to filter the result using -name and -o, the trouble is the suggestions that I saw use either -printf or basename, and those doesn't work well when there's -name *.txt -o name *.pdf. Is there any other way to solve this problem? example of my files:

/dir1/dir2/dir3/dir4/ /file1.txt /file1.pdf /file1.ods ...etc. 

I'm only interested in listing one or more type of file per listing (by using -name to filter my results. Is it possible to accomplish it using only 1 find command or I have to do it in 2 steps (saving the result in a temporary file, then filter/strip the directory from the temp file)? The result I'm trying to accomplish is a text file with filename per line:

file1.txt file1.pdf file1.ods file2.txt file2.pdf etc. 
added 199 characters in body
Source Link
michaelbr
  • 121
  • 3
  • 11
Loading
Source Link
michaelbr
  • 121
  • 3
  • 11
Loading