How to find and print specific file paths with exclusions?
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Goal: Output .txt file with the full directory path, including name, of all .html files except for those with "txt" or "text" in the .html file name.
I found the following line gives me the desired .txt file with the file's full directory path. The only problem is that it gives me ALL of the folder's contents:
ls -d "$PWD"/* > fileList.txt
Example Results:
/Users/username/Desktop/WebsiteFiles/notes.txt
/Users/username/Desktop/WebsiteFiles/index.html
/Users/username/Desktop/WebsiteFiles/index-TEXT.html
/Users/username/Desktop/WebsiteFiles/answers.html
/Users/username/Desktop/WebsiteFiles/answers_txt.html
/Users/username/Desktop/WebsiteFiles/image.jpg
/Users/username/Desktop/WebsiteFiles/image2.jpg
/Users/username/Desktop/WebsiteFiles/about.html
/Users/username/Desktop/WebsiteFiles/about_TXT.html
/Users/username/Desktop/WebsiteFiles/contact.html
/Users/username/Desktop/WebsiteFiles/contact_text.html
/Users/username/Desktop/WebsiteFiles/images
Desired Results:
/Users/username/Desktop/WebsiteFiles/index.html
/Users/username/Desktop/WebsiteFiles/answers.html
/Users/username/Desktop/WebsiteFiles/about.html
/Users/username/Desktop/WebsiteFiles/contact.html
Experimenting:
I'm fairly new to using the command line. I've been experimenting trying to figure this stuff out. I found that the following find helps find all .html files:
find . -iname '*.html'
When used on the parent directory it will give me all .html files but not the full directory path, example result:
./index.html
./index-TEXT.html
./answers.html
./answers_txt.html
./about.html
./about_TXT.html
./contact.html
./contact_text.html
I'm not familiar enough with the parameters or assembling these commands and haven't been successful in getting a print of just the .html files without the ones with any of the variation of "text" in the name.
I have a ton of files to find with this and need that .txt file with the full paths. I want to understand this stuff so please provide detailed responses!
find osx ls pwd
add a comment |Â
up vote
2
down vote
favorite
Goal: Output .txt file with the full directory path, including name, of all .html files except for those with "txt" or "text" in the .html file name.
I found the following line gives me the desired .txt file with the file's full directory path. The only problem is that it gives me ALL of the folder's contents:
ls -d "$PWD"/* > fileList.txt
Example Results:
/Users/username/Desktop/WebsiteFiles/notes.txt
/Users/username/Desktop/WebsiteFiles/index.html
/Users/username/Desktop/WebsiteFiles/index-TEXT.html
/Users/username/Desktop/WebsiteFiles/answers.html
/Users/username/Desktop/WebsiteFiles/answers_txt.html
/Users/username/Desktop/WebsiteFiles/image.jpg
/Users/username/Desktop/WebsiteFiles/image2.jpg
/Users/username/Desktop/WebsiteFiles/about.html
/Users/username/Desktop/WebsiteFiles/about_TXT.html
/Users/username/Desktop/WebsiteFiles/contact.html
/Users/username/Desktop/WebsiteFiles/contact_text.html
/Users/username/Desktop/WebsiteFiles/images
Desired Results:
/Users/username/Desktop/WebsiteFiles/index.html
/Users/username/Desktop/WebsiteFiles/answers.html
/Users/username/Desktop/WebsiteFiles/about.html
/Users/username/Desktop/WebsiteFiles/contact.html
Experimenting:
I'm fairly new to using the command line. I've been experimenting trying to figure this stuff out. I found that the following find helps find all .html files:
find . -iname '*.html'
When used on the parent directory it will give me all .html files but not the full directory path, example result:
./index.html
./index-TEXT.html
./answers.html
./answers_txt.html
./about.html
./about_TXT.html
./contact.html
./contact_text.html
I'm not familiar enough with the parameters or assembling these commands and haven't been successful in getting a print of just the .html files without the ones with any of the variation of "text" in the name.
I have a ton of files to find with this and need that .txt file with the full paths. I want to understand this stuff so please provide detailed responses!
find osx ls pwd
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Goal: Output .txt file with the full directory path, including name, of all .html files except for those with "txt" or "text" in the .html file name.
I found the following line gives me the desired .txt file with the file's full directory path. The only problem is that it gives me ALL of the folder's contents:
ls -d "$PWD"/* > fileList.txt
Example Results:
/Users/username/Desktop/WebsiteFiles/notes.txt
/Users/username/Desktop/WebsiteFiles/index.html
/Users/username/Desktop/WebsiteFiles/index-TEXT.html
/Users/username/Desktop/WebsiteFiles/answers.html
/Users/username/Desktop/WebsiteFiles/answers_txt.html
/Users/username/Desktop/WebsiteFiles/image.jpg
/Users/username/Desktop/WebsiteFiles/image2.jpg
/Users/username/Desktop/WebsiteFiles/about.html
/Users/username/Desktop/WebsiteFiles/about_TXT.html
/Users/username/Desktop/WebsiteFiles/contact.html
/Users/username/Desktop/WebsiteFiles/contact_text.html
/Users/username/Desktop/WebsiteFiles/images
Desired Results:
/Users/username/Desktop/WebsiteFiles/index.html
/Users/username/Desktop/WebsiteFiles/answers.html
/Users/username/Desktop/WebsiteFiles/about.html
/Users/username/Desktop/WebsiteFiles/contact.html
Experimenting:
I'm fairly new to using the command line. I've been experimenting trying to figure this stuff out. I found that the following find helps find all .html files:
find . -iname '*.html'
When used on the parent directory it will give me all .html files but not the full directory path, example result:
./index.html
./index-TEXT.html
./answers.html
./answers_txt.html
./about.html
./about_TXT.html
./contact.html
./contact_text.html
I'm not familiar enough with the parameters or assembling these commands and haven't been successful in getting a print of just the .html files without the ones with any of the variation of "text" in the name.
I have a ton of files to find with this and need that .txt file with the full paths. I want to understand this stuff so please provide detailed responses!
find osx ls pwd
Goal: Output .txt file with the full directory path, including name, of all .html files except for those with "txt" or "text" in the .html file name.
I found the following line gives me the desired .txt file with the file's full directory path. The only problem is that it gives me ALL of the folder's contents:
ls -d "$PWD"/* > fileList.txt
Example Results:
/Users/username/Desktop/WebsiteFiles/notes.txt
/Users/username/Desktop/WebsiteFiles/index.html
/Users/username/Desktop/WebsiteFiles/index-TEXT.html
/Users/username/Desktop/WebsiteFiles/answers.html
/Users/username/Desktop/WebsiteFiles/answers_txt.html
/Users/username/Desktop/WebsiteFiles/image.jpg
/Users/username/Desktop/WebsiteFiles/image2.jpg
/Users/username/Desktop/WebsiteFiles/about.html
/Users/username/Desktop/WebsiteFiles/about_TXT.html
/Users/username/Desktop/WebsiteFiles/contact.html
/Users/username/Desktop/WebsiteFiles/contact_text.html
/Users/username/Desktop/WebsiteFiles/images
Desired Results:
/Users/username/Desktop/WebsiteFiles/index.html
/Users/username/Desktop/WebsiteFiles/answers.html
/Users/username/Desktop/WebsiteFiles/about.html
/Users/username/Desktop/WebsiteFiles/contact.html
Experimenting:
I'm fairly new to using the command line. I've been experimenting trying to figure this stuff out. I found that the following find helps find all .html files:
find . -iname '*.html'
When used on the parent directory it will give me all .html files but not the full directory path, example result:
./index.html
./index-TEXT.html
./answers.html
./answers_txt.html
./about.html
./about_TXT.html
./contact.html
./contact_text.html
I'm not familiar enough with the parameters or assembling these commands and haven't been successful in getting a print of just the .html files without the ones with any of the variation of "text" in the name.
I have a ton of files to find with this and need that .txt file with the full paths. I want to understand this stuff so please provide detailed responses!
find osx ls pwd
find osx ls pwd
edited Sep 26 '17 at 16:09
Anthon
58.7k1796159
58.7k1796159
asked Sep 26 '17 at 15:32
Melissa McCollum
132
132
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
find
will output the found names with the path that you give it, so you can start building the command with
find /Users/username/Desktop/WebsiteFiles
or, if that's where you're located currently,
find "$PWD"
Next, we restrict the found names to only names matching *.html
:
find "$PWD" -type f -name '*.html'
If you have both *.html
and *.HTML
(or *.hTmL
) files, and if you want to include these, then change -name
to -iname
(which does case-insensitive name matching).
I also added -type f
on the off chance that you have any directories with names matching *.html
(we don't want to see these in the result). -type f
restricts the name to those of regular files only.
Then you wanted to remove particular filenames from the result. Names containing the strings txt
or text
(up or down case). This can be done through negating the -iname
test with !
:
find "$PWD" -type f -name '*.html' ! -iname "*txt*" ! -iname "*text*"
And there you have it.
Each "predicate" (-type f
etc.) acts like a test against the names in the given directory, and there's an implicit logical AND between the tests. If all tests pass, the name is printed.
Running in a temporary directory on my machine, with the files that you have in your directory (just empty files for testing):
$ ls -l
total 24
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 about.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 about_TXT.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 answers.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 answers_txt.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 contact.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 contact_text.html
-rw-r--r-- 1 kk wheel 596 Sep 26 17:46 files
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 image.jpg
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 image2.jpg
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 images
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 index-TEXT.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 index.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 notes.txt
-rw-r--r-- 1 kk wheel 10240 Sep 26 19:11 test.tar
$ find "$PWD" -type f -name '*.html' ! -iname "*txt*" ! -iname "*text*"
/tmp/shell-ksh.p56GA7BA/index.html
/tmp/shell-ksh.p56GA7BA/answers.html
/tmp/shell-ksh.p56GA7BA/about.html
/tmp/shell-ksh.p56GA7BA/contact.html
1
Thank you! This worked for me. And thanks for explaining. I was able to add the output of > fileList.txt to the end and it did exactly what I wanted.
â Melissa McCollum
Sep 26 '17 at 17:39
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
find
will output the found names with the path that you give it, so you can start building the command with
find /Users/username/Desktop/WebsiteFiles
or, if that's where you're located currently,
find "$PWD"
Next, we restrict the found names to only names matching *.html
:
find "$PWD" -type f -name '*.html'
If you have both *.html
and *.HTML
(or *.hTmL
) files, and if you want to include these, then change -name
to -iname
(which does case-insensitive name matching).
I also added -type f
on the off chance that you have any directories with names matching *.html
(we don't want to see these in the result). -type f
restricts the name to those of regular files only.
Then you wanted to remove particular filenames from the result. Names containing the strings txt
or text
(up or down case). This can be done through negating the -iname
test with !
:
find "$PWD" -type f -name '*.html' ! -iname "*txt*" ! -iname "*text*"
And there you have it.
Each "predicate" (-type f
etc.) acts like a test against the names in the given directory, and there's an implicit logical AND between the tests. If all tests pass, the name is printed.
Running in a temporary directory on my machine, with the files that you have in your directory (just empty files for testing):
$ ls -l
total 24
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 about.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 about_TXT.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 answers.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 answers_txt.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 contact.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 contact_text.html
-rw-r--r-- 1 kk wheel 596 Sep 26 17:46 files
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 image.jpg
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 image2.jpg
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 images
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 index-TEXT.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 index.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 notes.txt
-rw-r--r-- 1 kk wheel 10240 Sep 26 19:11 test.tar
$ find "$PWD" -type f -name '*.html' ! -iname "*txt*" ! -iname "*text*"
/tmp/shell-ksh.p56GA7BA/index.html
/tmp/shell-ksh.p56GA7BA/answers.html
/tmp/shell-ksh.p56GA7BA/about.html
/tmp/shell-ksh.p56GA7BA/contact.html
1
Thank you! This worked for me. And thanks for explaining. I was able to add the output of > fileList.txt to the end and it did exactly what I wanted.
â Melissa McCollum
Sep 26 '17 at 17:39
add a comment |Â
up vote
2
down vote
accepted
find
will output the found names with the path that you give it, so you can start building the command with
find /Users/username/Desktop/WebsiteFiles
or, if that's where you're located currently,
find "$PWD"
Next, we restrict the found names to only names matching *.html
:
find "$PWD" -type f -name '*.html'
If you have both *.html
and *.HTML
(or *.hTmL
) files, and if you want to include these, then change -name
to -iname
(which does case-insensitive name matching).
I also added -type f
on the off chance that you have any directories with names matching *.html
(we don't want to see these in the result). -type f
restricts the name to those of regular files only.
Then you wanted to remove particular filenames from the result. Names containing the strings txt
or text
(up or down case). This can be done through negating the -iname
test with !
:
find "$PWD" -type f -name '*.html' ! -iname "*txt*" ! -iname "*text*"
And there you have it.
Each "predicate" (-type f
etc.) acts like a test against the names in the given directory, and there's an implicit logical AND between the tests. If all tests pass, the name is printed.
Running in a temporary directory on my machine, with the files that you have in your directory (just empty files for testing):
$ ls -l
total 24
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 about.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 about_TXT.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 answers.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 answers_txt.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 contact.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 contact_text.html
-rw-r--r-- 1 kk wheel 596 Sep 26 17:46 files
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 image.jpg
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 image2.jpg
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 images
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 index-TEXT.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 index.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 notes.txt
-rw-r--r-- 1 kk wheel 10240 Sep 26 19:11 test.tar
$ find "$PWD" -type f -name '*.html' ! -iname "*txt*" ! -iname "*text*"
/tmp/shell-ksh.p56GA7BA/index.html
/tmp/shell-ksh.p56GA7BA/answers.html
/tmp/shell-ksh.p56GA7BA/about.html
/tmp/shell-ksh.p56GA7BA/contact.html
1
Thank you! This worked for me. And thanks for explaining. I was able to add the output of > fileList.txt to the end and it did exactly what I wanted.
â Melissa McCollum
Sep 26 '17 at 17:39
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
find
will output the found names with the path that you give it, so you can start building the command with
find /Users/username/Desktop/WebsiteFiles
or, if that's where you're located currently,
find "$PWD"
Next, we restrict the found names to only names matching *.html
:
find "$PWD" -type f -name '*.html'
If you have both *.html
and *.HTML
(or *.hTmL
) files, and if you want to include these, then change -name
to -iname
(which does case-insensitive name matching).
I also added -type f
on the off chance that you have any directories with names matching *.html
(we don't want to see these in the result). -type f
restricts the name to those of regular files only.
Then you wanted to remove particular filenames from the result. Names containing the strings txt
or text
(up or down case). This can be done through negating the -iname
test with !
:
find "$PWD" -type f -name '*.html' ! -iname "*txt*" ! -iname "*text*"
And there you have it.
Each "predicate" (-type f
etc.) acts like a test against the names in the given directory, and there's an implicit logical AND between the tests. If all tests pass, the name is printed.
Running in a temporary directory on my machine, with the files that you have in your directory (just empty files for testing):
$ ls -l
total 24
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 about.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 about_TXT.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 answers.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 answers_txt.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 contact.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 contact_text.html
-rw-r--r-- 1 kk wheel 596 Sep 26 17:46 files
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 image.jpg
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 image2.jpg
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 images
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 index-TEXT.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 index.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 notes.txt
-rw-r--r-- 1 kk wheel 10240 Sep 26 19:11 test.tar
$ find "$PWD" -type f -name '*.html' ! -iname "*txt*" ! -iname "*text*"
/tmp/shell-ksh.p56GA7BA/index.html
/tmp/shell-ksh.p56GA7BA/answers.html
/tmp/shell-ksh.p56GA7BA/about.html
/tmp/shell-ksh.p56GA7BA/contact.html
find
will output the found names with the path that you give it, so you can start building the command with
find /Users/username/Desktop/WebsiteFiles
or, if that's where you're located currently,
find "$PWD"
Next, we restrict the found names to only names matching *.html
:
find "$PWD" -type f -name '*.html'
If you have both *.html
and *.HTML
(or *.hTmL
) files, and if you want to include these, then change -name
to -iname
(which does case-insensitive name matching).
I also added -type f
on the off chance that you have any directories with names matching *.html
(we don't want to see these in the result). -type f
restricts the name to those of regular files only.
Then you wanted to remove particular filenames from the result. Names containing the strings txt
or text
(up or down case). This can be done through negating the -iname
test with !
:
find "$PWD" -type f -name '*.html' ! -iname "*txt*" ! -iname "*text*"
And there you have it.
Each "predicate" (-type f
etc.) acts like a test against the names in the given directory, and there's an implicit logical AND between the tests. If all tests pass, the name is printed.
Running in a temporary directory on my machine, with the files that you have in your directory (just empty files for testing):
$ ls -l
total 24
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 about.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 about_TXT.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 answers.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 answers_txt.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 contact.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 contact_text.html
-rw-r--r-- 1 kk wheel 596 Sep 26 17:46 files
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 image.jpg
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 image2.jpg
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 images
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 index-TEXT.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 index.html
-rw-r--r-- 1 kk wheel 0 Sep 26 17:47 notes.txt
-rw-r--r-- 1 kk wheel 10240 Sep 26 19:11 test.tar
$ find "$PWD" -type f -name '*.html' ! -iname "*txt*" ! -iname "*text*"
/tmp/shell-ksh.p56GA7BA/index.html
/tmp/shell-ksh.p56GA7BA/answers.html
/tmp/shell-ksh.p56GA7BA/about.html
/tmp/shell-ksh.p56GA7BA/contact.html
edited Sep 26 '17 at 17:36
answered Sep 26 '17 at 15:39
Kusalananda
106k14209327
106k14209327
1
Thank you! This worked for me. And thanks for explaining. I was able to add the output of > fileList.txt to the end and it did exactly what I wanted.
â Melissa McCollum
Sep 26 '17 at 17:39
add a comment |Â
1
Thank you! This worked for me. And thanks for explaining. I was able to add the output of > fileList.txt to the end and it did exactly what I wanted.
â Melissa McCollum
Sep 26 '17 at 17:39
1
1
Thank you! This worked for me. And thanks for explaining. I was able to add the output of > fileList.txt to the end and it did exactly what I wanted.
â Melissa McCollum
Sep 26 '17 at 17:39
Thank you! This worked for me. And thanks for explaining. I was able to add the output of > fileList.txt to the end and it did exactly what I wanted.
â Melissa McCollum
Sep 26 '17 at 17:39
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394570%2fhow-to-find-and-print-specific-file-paths-with-exclusions%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password