Which file first get deleted first when deleting via rm -f with a glob pattern?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I've a folder with thousands of files with this pattern:
YYYYMMDD_HH24MISS_4DIGITSEQUENCE.
Example: 20180626_210123_0001
.
Now for example while I'm deleting via rm -f *20180626_1*
command its working fine.
My question is:
1. Which file is being deleted first?
2. Is it being picked randomnly?
3. If it maintains any sequence while choosing, then which one and how it decides?
linux rm
add a comment |Â
up vote
0
down vote
favorite
I've a folder with thousands of files with this pattern:
YYYYMMDD_HH24MISS_4DIGITSEQUENCE.
Example: 20180626_210123_0001
.
Now for example while I'm deleting via rm -f *20180626_1*
command its working fine.
My question is:
1. Which file is being deleted first?
2. Is it being picked randomnly?
3. If it maintains any sequence while choosing, then which one and how it decides?
linux rm
1
See How does a shell (bash, for example) expand wildcard patterns? and Does the Bash star * wildcard always produce an (ascending) sorted list?
â steeldriver
Jun 26 at 15:27
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I've a folder with thousands of files with this pattern:
YYYYMMDD_HH24MISS_4DIGITSEQUENCE.
Example: 20180626_210123_0001
.
Now for example while I'm deleting via rm -f *20180626_1*
command its working fine.
My question is:
1. Which file is being deleted first?
2. Is it being picked randomnly?
3. If it maintains any sequence while choosing, then which one and how it decides?
linux rm
I've a folder with thousands of files with this pattern:
YYYYMMDD_HH24MISS_4DIGITSEQUENCE.
Example: 20180626_210123_0001
.
Now for example while I'm deleting via rm -f *20180626_1*
command its working fine.
My question is:
1. Which file is being deleted first?
2. Is it being picked randomnly?
3. If it maintains any sequence while choosing, then which one and how it decides?
linux rm
edited Jun 26 at 15:21
ilkkachu
47.3k668130
47.3k668130
asked Jun 26 at 15:17
Leon
1033
1033
1
See How does a shell (bash, for example) expand wildcard patterns? and Does the Bash star * wildcard always produce an (ascending) sorted list?
â steeldriver
Jun 26 at 15:27
add a comment |Â
1
See How does a shell (bash, for example) expand wildcard patterns? and Does the Bash star * wildcard always produce an (ascending) sorted list?
â steeldriver
Jun 26 at 15:27
1
1
See How does a shell (bash, for example) expand wildcard patterns? and Does the Bash star * wildcard always produce an (ascending) sorted list?
â steeldriver
Jun 26 at 15:27
See How does a shell (bash, for example) expand wildcard patterns? and Does the Bash star * wildcard always produce an (ascending) sorted list?
â steeldriver
Jun 26 at 15:27
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Globs are expanded by the shell in lexicographic order (in the current locale), and the rm
implementation is likely to remove the files it gets as arguments in the same order it got them. So in your case the files would be removed starting with the oldest.
Sorting the glob results is required by POSIX. On a quick test, at least GNU rm removes files given on the command line in the order listed, and doesn't sort files found during recursive operation.
I looked at the GNUrm
implementation and traced my way down into thefts
calls fromrm.c
. There is one call tofts_sort
but it's conditional and I'm not 100% sure what it actually does.
â Kusalananda
Jun 26 at 15:33
@Kusalananda, I can't really understand whyrm
would want to sort anything...
â ilkkachu
Jun 26 at 15:50
Me neither, but there it is.
â Kusalananda
Jun 26 at 15:54
add a comment |Â
up vote
1
down vote
The shell expands the expression before it executes rm
, and that expansion is not specific to the command, so if you do:
echo *20180626_1*
Then the first thing that echos will be the first thing that the shell passes to rm
. The order isn't random, it's alphabetical. From the bash man page:
After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Globs are expanded by the shell in lexicographic order (in the current locale), and the rm
implementation is likely to remove the files it gets as arguments in the same order it got them. So in your case the files would be removed starting with the oldest.
Sorting the glob results is required by POSIX. On a quick test, at least GNU rm removes files given on the command line in the order listed, and doesn't sort files found during recursive operation.
I looked at the GNUrm
implementation and traced my way down into thefts
calls fromrm.c
. There is one call tofts_sort
but it's conditional and I'm not 100% sure what it actually does.
â Kusalananda
Jun 26 at 15:33
@Kusalananda, I can't really understand whyrm
would want to sort anything...
â ilkkachu
Jun 26 at 15:50
Me neither, but there it is.
â Kusalananda
Jun 26 at 15:54
add a comment |Â
up vote
1
down vote
accepted
Globs are expanded by the shell in lexicographic order (in the current locale), and the rm
implementation is likely to remove the files it gets as arguments in the same order it got them. So in your case the files would be removed starting with the oldest.
Sorting the glob results is required by POSIX. On a quick test, at least GNU rm removes files given on the command line in the order listed, and doesn't sort files found during recursive operation.
I looked at the GNUrm
implementation and traced my way down into thefts
calls fromrm.c
. There is one call tofts_sort
but it's conditional and I'm not 100% sure what it actually does.
â Kusalananda
Jun 26 at 15:33
@Kusalananda, I can't really understand whyrm
would want to sort anything...
â ilkkachu
Jun 26 at 15:50
Me neither, but there it is.
â Kusalananda
Jun 26 at 15:54
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Globs are expanded by the shell in lexicographic order (in the current locale), and the rm
implementation is likely to remove the files it gets as arguments in the same order it got them. So in your case the files would be removed starting with the oldest.
Sorting the glob results is required by POSIX. On a quick test, at least GNU rm removes files given on the command line in the order listed, and doesn't sort files found during recursive operation.
Globs are expanded by the shell in lexicographic order (in the current locale), and the rm
implementation is likely to remove the files it gets as arguments in the same order it got them. So in your case the files would be removed starting with the oldest.
Sorting the glob results is required by POSIX. On a quick test, at least GNU rm removes files given on the command line in the order listed, and doesn't sort files found during recursive operation.
edited Jun 26 at 15:49
answered Jun 26 at 15:26
ilkkachu
47.3k668130
47.3k668130
I looked at the GNUrm
implementation and traced my way down into thefts
calls fromrm.c
. There is one call tofts_sort
but it's conditional and I'm not 100% sure what it actually does.
â Kusalananda
Jun 26 at 15:33
@Kusalananda, I can't really understand whyrm
would want to sort anything...
â ilkkachu
Jun 26 at 15:50
Me neither, but there it is.
â Kusalananda
Jun 26 at 15:54
add a comment |Â
I looked at the GNUrm
implementation and traced my way down into thefts
calls fromrm.c
. There is one call tofts_sort
but it's conditional and I'm not 100% sure what it actually does.
â Kusalananda
Jun 26 at 15:33
@Kusalananda, I can't really understand whyrm
would want to sort anything...
â ilkkachu
Jun 26 at 15:50
Me neither, but there it is.
â Kusalananda
Jun 26 at 15:54
I looked at the GNU
rm
implementation and traced my way down into the fts
calls from rm.c
. There is one call to fts_sort
but it's conditional and I'm not 100% sure what it actually does.â Kusalananda
Jun 26 at 15:33
I looked at the GNU
rm
implementation and traced my way down into the fts
calls from rm.c
. There is one call to fts_sort
but it's conditional and I'm not 100% sure what it actually does.â Kusalananda
Jun 26 at 15:33
@Kusalananda, I can't really understand why
rm
would want to sort anything...â ilkkachu
Jun 26 at 15:50
@Kusalananda, I can't really understand why
rm
would want to sort anything...â ilkkachu
Jun 26 at 15:50
Me neither, but there it is.
â Kusalananda
Jun 26 at 15:54
Me neither, but there it is.
â Kusalananda
Jun 26 at 15:54
add a comment |Â
up vote
1
down vote
The shell expands the expression before it executes rm
, and that expansion is not specific to the command, so if you do:
echo *20180626_1*
Then the first thing that echos will be the first thing that the shell passes to rm
. The order isn't random, it's alphabetical. From the bash man page:
After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern.
add a comment |Â
up vote
1
down vote
The shell expands the expression before it executes rm
, and that expansion is not specific to the command, so if you do:
echo *20180626_1*
Then the first thing that echos will be the first thing that the shell passes to rm
. The order isn't random, it's alphabetical. From the bash man page:
After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The shell expands the expression before it executes rm
, and that expansion is not specific to the command, so if you do:
echo *20180626_1*
Then the first thing that echos will be the first thing that the shell passes to rm
. The order isn't random, it's alphabetical. From the bash man page:
After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern.
The shell expands the expression before it executes rm
, and that expansion is not specific to the command, so if you do:
echo *20180626_1*
Then the first thing that echos will be the first thing that the shell passes to rm
. The order isn't random, it's alphabetical. From the bash man page:
After word splitting, unless the -f option has been set, bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of file names matching the pattern.
edited Jun 26 at 15:29
answered Jun 26 at 15:23
Andy Dalton
4,7111520
4,7111520
add a comment |Â
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%2f452035%2fwhich-file-first-get-deleted-first-when-deleting-via-rm-f-with-a-glob-pattern%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
1
See How does a shell (bash, for example) expand wildcard patterns? and Does the Bash star * wildcard always produce an (ascending) sorted list?
â steeldriver
Jun 26 at 15:27