Avoid listing of files with ~ or twin files

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
My requirement is to list all files in a directory. I tried to use command :
ls -l | grep -v ~
This is to list all files, and to avoid all files or twin files. But the output I get is
asdasad
asdasad~
file_names.txt
normaltest.txt
target_filename
testshell1.sh
testshell1.sh~
testshell2.sh
testshell2.sh~
testtwo.txt
testtwo.txt~
test.txt
test.txt~
I want to get only these files
asdasad
file_names.txt
normaltest.txt
target_filename
testshell1.sh
testshell2.sh
testtwo.txt
test.txt
Please help.
linux command-line filenames
New contributor
curious_one is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
1
down vote
favorite
My requirement is to list all files in a directory. I tried to use command :
ls -l | grep -v ~
This is to list all files, and to avoid all files or twin files. But the output I get is
asdasad
asdasad~
file_names.txt
normaltest.txt
target_filename
testshell1.sh
testshell1.sh~
testshell2.sh
testshell2.sh~
testtwo.txt
testtwo.txt~
test.txt
test.txt~
I want to get only these files
asdasad
file_names.txt
normaltest.txt
target_filename
testshell1.sh
testshell2.sh
testtwo.txt
test.txt
Please help.
linux command-line filenames
New contributor
curious_one is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
My requirement is to list all files in a directory. I tried to use command :
ls -l | grep -v ~
This is to list all files, and to avoid all files or twin files. But the output I get is
asdasad
asdasad~
file_names.txt
normaltest.txt
target_filename
testshell1.sh
testshell1.sh~
testshell2.sh
testshell2.sh~
testtwo.txt
testtwo.txt~
test.txt
test.txt~
I want to get only these files
asdasad
file_names.txt
normaltest.txt
target_filename
testshell1.sh
testshell2.sh
testtwo.txt
test.txt
Please help.
linux command-line filenames
New contributor
curious_one is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
My requirement is to list all files in a directory. I tried to use command :
ls -l | grep -v ~
This is to list all files, and to avoid all files or twin files. But the output I get is
asdasad
asdasad~
file_names.txt
normaltest.txt
target_filename
testshell1.sh
testshell1.sh~
testshell2.sh
testshell2.sh~
testtwo.txt
testtwo.txt~
test.txt
test.txt~
I want to get only these files
asdasad
file_names.txt
normaltest.txt
target_filename
testshell1.sh
testshell2.sh
testtwo.txt
test.txt
Please help.
linux command-line filenames
linux command-line filenames
New contributor
curious_one is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
curious_one is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 13 mins ago
Jeff Schaller
32.8k849110
32.8k849110
New contributor
curious_one is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 48 mins ago
curious_one
61
61
New contributor
curious_one is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
curious_one is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
curious_one is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
5
down vote
ls has an option for that: -B Ignore backups:
ls --ignore-backups
That's a GNU feature, though probably fine since this was tagged linux. But e.g. on FreeBSD,ls -Bmeans something different.
â ilkkachu
38 mins ago
add a comment |Â
up vote
4
down vote
Make sure extglob is enable:
shopt -s extglob
Then you can use:
ls -d !(*~)
-dto not show directories contents!(*~)all files except the ones ending with~
But I would go with: ls --ignore-backups.
given the Linux tab, it's not a stretch to assume bash, butshopt -s extglobis a bash-specific feature.
â Jeff Schaller
14 mins ago
add a comment |Â
up vote
2
down vote
This should help:
ls -l | grep -v '~'
Reason: The ~ char is replaced by your home directory before the command is executed. Try
echo ~
and
echo '~'
add a comment |Â
up vote
2
down vote
ls -l | grep -v ~
The reason this doesn't work is that the tilde gets expanded to your home directory, so grep never sees a literal tilde. (See e.g. Bash's manual on Tilde Expansion.) You need to quote it to prevent the expansion, i.e.
ls -l | grep -v "~"
Of course, this will still remove any output lines with a tilde anywhere, even in the middle of a file name or elsewhere in the ls output (though it's probably not likely to appear in usernames, dates or such).
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
ls has an option for that: -B Ignore backups:
ls --ignore-backups
That's a GNU feature, though probably fine since this was tagged linux. But e.g. on FreeBSD,ls -Bmeans something different.
â ilkkachu
38 mins ago
add a comment |Â
up vote
5
down vote
ls has an option for that: -B Ignore backups:
ls --ignore-backups
That's a GNU feature, though probably fine since this was tagged linux. But e.g. on FreeBSD,ls -Bmeans something different.
â ilkkachu
38 mins ago
add a comment |Â
up vote
5
down vote
up vote
5
down vote
ls has an option for that: -B Ignore backups:
ls --ignore-backups
ls has an option for that: -B Ignore backups:
ls --ignore-backups
answered 45 mins ago
hschou
1,71349
1,71349
That's a GNU feature, though probably fine since this was tagged linux. But e.g. on FreeBSD,ls -Bmeans something different.
â ilkkachu
38 mins ago
add a comment |Â
That's a GNU feature, though probably fine since this was tagged linux. But e.g. on FreeBSD,ls -Bmeans something different.
â ilkkachu
38 mins ago
That's a GNU feature, though probably fine since this was tagged linux. But e.g. on FreeBSD,
ls -B means something different.â ilkkachu
38 mins ago
That's a GNU feature, though probably fine since this was tagged linux. But e.g. on FreeBSD,
ls -B means something different.â ilkkachu
38 mins ago
add a comment |Â
up vote
4
down vote
Make sure extglob is enable:
shopt -s extglob
Then you can use:
ls -d !(*~)
-dto not show directories contents!(*~)all files except the ones ending with~
But I would go with: ls --ignore-backups.
given the Linux tab, it's not a stretch to assume bash, butshopt -s extglobis a bash-specific feature.
â Jeff Schaller
14 mins ago
add a comment |Â
up vote
4
down vote
Make sure extglob is enable:
shopt -s extglob
Then you can use:
ls -d !(*~)
-dto not show directories contents!(*~)all files except the ones ending with~
But I would go with: ls --ignore-backups.
given the Linux tab, it's not a stretch to assume bash, butshopt -s extglobis a bash-specific feature.
â Jeff Schaller
14 mins ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Make sure extglob is enable:
shopt -s extglob
Then you can use:
ls -d !(*~)
-dto not show directories contents!(*~)all files except the ones ending with~
But I would go with: ls --ignore-backups.
Make sure extglob is enable:
shopt -s extglob
Then you can use:
ls -d !(*~)
-dto not show directories contents!(*~)all files except the ones ending with~
But I would go with: ls --ignore-backups.
edited 38 mins ago
answered 42 mins ago
Ravexina
1,037719
1,037719
given the Linux tab, it's not a stretch to assume bash, butshopt -s extglobis a bash-specific feature.
â Jeff Schaller
14 mins ago
add a comment |Â
given the Linux tab, it's not a stretch to assume bash, butshopt -s extglobis a bash-specific feature.
â Jeff Schaller
14 mins ago
given the Linux tab, it's not a stretch to assume bash, but
shopt -s extglob is a bash-specific feature.â Jeff Schaller
14 mins ago
given the Linux tab, it's not a stretch to assume bash, but
shopt -s extglob is a bash-specific feature.â Jeff Schaller
14 mins ago
add a comment |Â
up vote
2
down vote
This should help:
ls -l | grep -v '~'
Reason: The ~ char is replaced by your home directory before the command is executed. Try
echo ~
and
echo '~'
add a comment |Â
up vote
2
down vote
This should help:
ls -l | grep -v '~'
Reason: The ~ char is replaced by your home directory before the command is executed. Try
echo ~
and
echo '~'
add a comment |Â
up vote
2
down vote
up vote
2
down vote
This should help:
ls -l | grep -v '~'
Reason: The ~ char is replaced by your home directory before the command is executed. Try
echo ~
and
echo '~'
This should help:
ls -l | grep -v '~'
Reason: The ~ char is replaced by your home directory before the command is executed. Try
echo ~
and
echo '~'
answered 43 mins ago
Nico Mittenzwey
6114
6114
add a comment |Â
add a comment |Â
up vote
2
down vote
ls -l | grep -v ~
The reason this doesn't work is that the tilde gets expanded to your home directory, so grep never sees a literal tilde. (See e.g. Bash's manual on Tilde Expansion.) You need to quote it to prevent the expansion, i.e.
ls -l | grep -v "~"
Of course, this will still remove any output lines with a tilde anywhere, even in the middle of a file name or elsewhere in the ls output (though it's probably not likely to appear in usernames, dates or such).
add a comment |Â
up vote
2
down vote
ls -l | grep -v ~
The reason this doesn't work is that the tilde gets expanded to your home directory, so grep never sees a literal tilde. (See e.g. Bash's manual on Tilde Expansion.) You need to quote it to prevent the expansion, i.e.
ls -l | grep -v "~"
Of course, this will still remove any output lines with a tilde anywhere, even in the middle of a file name or elsewhere in the ls output (though it's probably not likely to appear in usernames, dates or such).
add a comment |Â
up vote
2
down vote
up vote
2
down vote
ls -l | grep -v ~
The reason this doesn't work is that the tilde gets expanded to your home directory, so grep never sees a literal tilde. (See e.g. Bash's manual on Tilde Expansion.) You need to quote it to prevent the expansion, i.e.
ls -l | grep -v "~"
Of course, this will still remove any output lines with a tilde anywhere, even in the middle of a file name or elsewhere in the ls output (though it's probably not likely to appear in usernames, dates or such).
ls -l | grep -v ~
The reason this doesn't work is that the tilde gets expanded to your home directory, so grep never sees a literal tilde. (See e.g. Bash's manual on Tilde Expansion.) You need to quote it to prevent the expansion, i.e.
ls -l | grep -v "~"
Of course, this will still remove any output lines with a tilde anywhere, even in the middle of a file name or elsewhere in the ls output (though it's probably not likely to appear in usernames, dates or such).
answered 42 mins ago
ilkkachu
51.6k678143
51.6k678143
add a comment |Â
add a comment |Â
curious_one is a new contributor. Be nice, and check out our Code of Conduct.
curious_one is a new contributor. Be nice, and check out our Code of Conduct.
curious_one is a new contributor. Be nice, and check out our Code of Conduct.
curious_one is a new contributor. Be nice, and check out our Code of Conduct.
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%2f471577%2favoid-listing-of-files-with-or-twin-files%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
