Removing certain file types that do not contain the hostname in the file nameRemoving the period from a hostnameAccess Windows machines from Ubuntu on local network by hostnameLocal hostname resolution with local Ubuntu DNS server failsAfter changing hostname, Ubuntu does not recognize the nameUse Nautilus to open an SSH connection using hostnamehow to remove old kernels in grub2, including files?
What is the purpose of R1 in this circuit?
Really bizarre dystopian children’s film with hundreds of young boys forced to play piano
Definition of NMR peak
Why didn't Abraham ask the single best question?
Where do I put nobles/royalty in a scifi military
Doing chemistry under water?
Does a small cup of coffee result in a 45% reduced blood flow to the brain?
Joining elements of a list if those elements are in between two whitespaces
Adding bug screen to 3/4 PVC
Christmas party and autism
What's the difference between words "tongue" and "lingua"?
Should I report a security vulnerability?
Are the expansion number tokens in 5-6 players expansion different from the basic Catan?
Average Two Letters
Why does the media continue to hide the identity of the Trump-Ukraine whistle blower when they have already been outed?
What is `stty line NUMBER` even doing?
Driverless car Puzzle
The quietest classical orchestra instrument to play at home
Is it possible to get reverse life insurance?
Are the DigiNotar certificates supposed to be present in Firefox in a clean install?
Did any astronauts on a mission complain about waking up?
Mordhau grip for bludgeoning damage?
MLE vs Binomial - Beta conjugate pairs
Is camera at risk of condensation in cold temperatures if never removed from bag?
Removing certain file types that do not contain the hostname in the file name
Removing the period from a hostnameAccess Windows machines from Ubuntu on local network by hostnameLocal hostname resolution with local Ubuntu DNS server failsAfter changing hostname, Ubuntu does not recognize the nameUse Nautilus to open an SSH connection using hostnamehow to remove old kernels in grub2, including files?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I am doing a file deployment for multiple machines per site, so it is much easier for me to zip all the files once and deploy to every machine. However I would like to remove the config for all the other PC's.
The zip contains various generic files, and also a specific config for each machine.
For example a less of the zip would provide:
generic1.xjson
generic2.xjson
generic3.xjson
generic1.yjson
generic2.yjson
PC-1-1.json
PC-1-2.json
PC-1-3.json
So I am looking to remove every PC-1-*.json that does not contain the PC's hostname.
(the PC hostnames are always exactly PC-1-1, etc.)
I was trying to do something along the lines of:
ls -1 | grep -v *$hostname* | xargs -0 rm *PC-*-*.json
This would remove all the files including the one for the current hostname.
Looking for what I have wrong in this, or if there is a better way of doing this function.
bash files uninstall hostname xargs
add a comment
|
I am doing a file deployment for multiple machines per site, so it is much easier for me to zip all the files once and deploy to every machine. However I would like to remove the config for all the other PC's.
The zip contains various generic files, and also a specific config for each machine.
For example a less of the zip would provide:
generic1.xjson
generic2.xjson
generic3.xjson
generic1.yjson
generic2.yjson
PC-1-1.json
PC-1-2.json
PC-1-3.json
So I am looking to remove every PC-1-*.json that does not contain the PC's hostname.
(the PC hostnames are always exactly PC-1-1, etc.)
I was trying to do something along the lines of:
ls -1 | grep -v *$hostname* | xargs -0 rm *PC-*-*.json
This would remove all the files including the one for the current hostname.
Looking for what I have wrong in this, or if there is a better way of doing this function.
bash files uninstall hostname xargs
add a comment
|
I am doing a file deployment for multiple machines per site, so it is much easier for me to zip all the files once and deploy to every machine. However I would like to remove the config for all the other PC's.
The zip contains various generic files, and also a specific config for each machine.
For example a less of the zip would provide:
generic1.xjson
generic2.xjson
generic3.xjson
generic1.yjson
generic2.yjson
PC-1-1.json
PC-1-2.json
PC-1-3.json
So I am looking to remove every PC-1-*.json that does not contain the PC's hostname.
(the PC hostnames are always exactly PC-1-1, etc.)
I was trying to do something along the lines of:
ls -1 | grep -v *$hostname* | xargs -0 rm *PC-*-*.json
This would remove all the files including the one for the current hostname.
Looking for what I have wrong in this, or if there is a better way of doing this function.
bash files uninstall hostname xargs
I am doing a file deployment for multiple machines per site, so it is much easier for me to zip all the files once and deploy to every machine. However I would like to remove the config for all the other PC's.
The zip contains various generic files, and also a specific config for each machine.
For example a less of the zip would provide:
generic1.xjson
generic2.xjson
generic3.xjson
generic1.yjson
generic2.yjson
PC-1-1.json
PC-1-2.json
PC-1-3.json
So I am looking to remove every PC-1-*.json that does not contain the PC's hostname.
(the PC hostnames are always exactly PC-1-1, etc.)
I was trying to do something along the lines of:
ls -1 | grep -v *$hostname* | xargs -0 rm *PC-*-*.json
This would remove all the files including the one for the current hostname.
Looking for what I have wrong in this, or if there is a better way of doing this function.
bash files uninstall hostname xargs
bash files uninstall hostname xargs
asked Aug 9 at 19:19
Andrew WilliamsAndrew Williams
182 bronze badges
182 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
Your command does not work as expected because of rm *PC-*-*.json
! it would expands by shell and includes all PC-x-x.json
files.
Actually you're using xargs
in a wrong way.
Something like this should do the job:
ls -Q1 | grep -v $hostname | grep -E "PC-1-[0-9]+.json" | xargs echo
change echo
with rm
when you where sure that it works.
A better solution would be using find
:
find -type f -name "PC-*-*.json" -not -name "*$hostname*" -exec rm -i +
- remove
-i
fromrm
after you were sure that command is working correctly.
I ended up using the: ls -Q1 | grep -v $HOSTNAME | grep -E "[0-99]+.json" | xargs rm Variant, I cut off the PC-1 part of the second grep, as there should never be any json in my environment that is formatted like this expect the files I want to target. Also, like an idiot, I was using $hostname in place of $HOSTNAME, which, being relatively new to this I didn't know was not printing the hostname in my query. Thanks for the help!
– Andrew Williams
Aug 9 at 19:52
1
Nice! I think it makes a difference if you switch the filename tests and do-iname "PC-*-*.json" -not -iname "*$hostname*"
instead as the second one has to be evaluated much more seldom this way. Also, OP wants-type f
(as the first test). Oh and wait, why-iname
? OP definitely wantsname
for both tests.
– dessert
Aug 9 at 19:54
@dessert You're right... I'll update the answer.iname
is somehow burned into my memory and I always use it...
– Ravexina
Aug 10 at 5:54
@AndrewWilliams You're welcome... aboutHOSTNAME
you are correct! I thoughthostname
is a variable you defined youreslf ;)
– Ravexina
Aug 10 at 5:57
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1164664%2fremoving-certain-file-types-that-do-not-contain-the-hostname-in-the-file-name%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your command does not work as expected because of rm *PC-*-*.json
! it would expands by shell and includes all PC-x-x.json
files.
Actually you're using xargs
in a wrong way.
Something like this should do the job:
ls -Q1 | grep -v $hostname | grep -E "PC-1-[0-9]+.json" | xargs echo
change echo
with rm
when you where sure that it works.
A better solution would be using find
:
find -type f -name "PC-*-*.json" -not -name "*$hostname*" -exec rm -i +
- remove
-i
fromrm
after you were sure that command is working correctly.
I ended up using the: ls -Q1 | grep -v $HOSTNAME | grep -E "[0-99]+.json" | xargs rm Variant, I cut off the PC-1 part of the second grep, as there should never be any json in my environment that is formatted like this expect the files I want to target. Also, like an idiot, I was using $hostname in place of $HOSTNAME, which, being relatively new to this I didn't know was not printing the hostname in my query. Thanks for the help!
– Andrew Williams
Aug 9 at 19:52
1
Nice! I think it makes a difference if you switch the filename tests and do-iname "PC-*-*.json" -not -iname "*$hostname*"
instead as the second one has to be evaluated much more seldom this way. Also, OP wants-type f
(as the first test). Oh and wait, why-iname
? OP definitely wantsname
for both tests.
– dessert
Aug 9 at 19:54
@dessert You're right... I'll update the answer.iname
is somehow burned into my memory and I always use it...
– Ravexina
Aug 10 at 5:54
@AndrewWilliams You're welcome... aboutHOSTNAME
you are correct! I thoughthostname
is a variable you defined youreslf ;)
– Ravexina
Aug 10 at 5:57
add a comment
|
Your command does not work as expected because of rm *PC-*-*.json
! it would expands by shell and includes all PC-x-x.json
files.
Actually you're using xargs
in a wrong way.
Something like this should do the job:
ls -Q1 | grep -v $hostname | grep -E "PC-1-[0-9]+.json" | xargs echo
change echo
with rm
when you where sure that it works.
A better solution would be using find
:
find -type f -name "PC-*-*.json" -not -name "*$hostname*" -exec rm -i +
- remove
-i
fromrm
after you were sure that command is working correctly.
I ended up using the: ls -Q1 | grep -v $HOSTNAME | grep -E "[0-99]+.json" | xargs rm Variant, I cut off the PC-1 part of the second grep, as there should never be any json in my environment that is formatted like this expect the files I want to target. Also, like an idiot, I was using $hostname in place of $HOSTNAME, which, being relatively new to this I didn't know was not printing the hostname in my query. Thanks for the help!
– Andrew Williams
Aug 9 at 19:52
1
Nice! I think it makes a difference if you switch the filename tests and do-iname "PC-*-*.json" -not -iname "*$hostname*"
instead as the second one has to be evaluated much more seldom this way. Also, OP wants-type f
(as the first test). Oh and wait, why-iname
? OP definitely wantsname
for both tests.
– dessert
Aug 9 at 19:54
@dessert You're right... I'll update the answer.iname
is somehow burned into my memory and I always use it...
– Ravexina
Aug 10 at 5:54
@AndrewWilliams You're welcome... aboutHOSTNAME
you are correct! I thoughthostname
is a variable you defined youreslf ;)
– Ravexina
Aug 10 at 5:57
add a comment
|
Your command does not work as expected because of rm *PC-*-*.json
! it would expands by shell and includes all PC-x-x.json
files.
Actually you're using xargs
in a wrong way.
Something like this should do the job:
ls -Q1 | grep -v $hostname | grep -E "PC-1-[0-9]+.json" | xargs echo
change echo
with rm
when you where sure that it works.
A better solution would be using find
:
find -type f -name "PC-*-*.json" -not -name "*$hostname*" -exec rm -i +
- remove
-i
fromrm
after you were sure that command is working correctly.
Your command does not work as expected because of rm *PC-*-*.json
! it would expands by shell and includes all PC-x-x.json
files.
Actually you're using xargs
in a wrong way.
Something like this should do the job:
ls -Q1 | grep -v $hostname | grep -E "PC-1-[0-9]+.json" | xargs echo
change echo
with rm
when you where sure that it works.
A better solution would be using find
:
find -type f -name "PC-*-*.json" -not -name "*$hostname*" -exec rm -i +
- remove
-i
fromrm
after you were sure that command is working correctly.
edited Aug 10 at 15:50
answered Aug 9 at 19:38
RavexinaRavexina
36.9k15 gold badges101 silver badges131 bronze badges
36.9k15 gold badges101 silver badges131 bronze badges
I ended up using the: ls -Q1 | grep -v $HOSTNAME | grep -E "[0-99]+.json" | xargs rm Variant, I cut off the PC-1 part of the second grep, as there should never be any json in my environment that is formatted like this expect the files I want to target. Also, like an idiot, I was using $hostname in place of $HOSTNAME, which, being relatively new to this I didn't know was not printing the hostname in my query. Thanks for the help!
– Andrew Williams
Aug 9 at 19:52
1
Nice! I think it makes a difference if you switch the filename tests and do-iname "PC-*-*.json" -not -iname "*$hostname*"
instead as the second one has to be evaluated much more seldom this way. Also, OP wants-type f
(as the first test). Oh and wait, why-iname
? OP definitely wantsname
for both tests.
– dessert
Aug 9 at 19:54
@dessert You're right... I'll update the answer.iname
is somehow burned into my memory and I always use it...
– Ravexina
Aug 10 at 5:54
@AndrewWilliams You're welcome... aboutHOSTNAME
you are correct! I thoughthostname
is a variable you defined youreslf ;)
– Ravexina
Aug 10 at 5:57
add a comment
|
I ended up using the: ls -Q1 | grep -v $HOSTNAME | grep -E "[0-99]+.json" | xargs rm Variant, I cut off the PC-1 part of the second grep, as there should never be any json in my environment that is formatted like this expect the files I want to target. Also, like an idiot, I was using $hostname in place of $HOSTNAME, which, being relatively new to this I didn't know was not printing the hostname in my query. Thanks for the help!
– Andrew Williams
Aug 9 at 19:52
1
Nice! I think it makes a difference if you switch the filename tests and do-iname "PC-*-*.json" -not -iname "*$hostname*"
instead as the second one has to be evaluated much more seldom this way. Also, OP wants-type f
(as the first test). Oh and wait, why-iname
? OP definitely wantsname
for both tests.
– dessert
Aug 9 at 19:54
@dessert You're right... I'll update the answer.iname
is somehow burned into my memory and I always use it...
– Ravexina
Aug 10 at 5:54
@AndrewWilliams You're welcome... aboutHOSTNAME
you are correct! I thoughthostname
is a variable you defined youreslf ;)
– Ravexina
Aug 10 at 5:57
I ended up using the: ls -Q1 | grep -v $HOSTNAME | grep -E "[0-99]+.json" | xargs rm Variant, I cut off the PC-1 part of the second grep, as there should never be any json in my environment that is formatted like this expect the files I want to target. Also, like an idiot, I was using $hostname in place of $HOSTNAME, which, being relatively new to this I didn't know was not printing the hostname in my query. Thanks for the help!
– Andrew Williams
Aug 9 at 19:52
I ended up using the: ls -Q1 | grep -v $HOSTNAME | grep -E "[0-99]+.json" | xargs rm Variant, I cut off the PC-1 part of the second grep, as there should never be any json in my environment that is formatted like this expect the files I want to target. Also, like an idiot, I was using $hostname in place of $HOSTNAME, which, being relatively new to this I didn't know was not printing the hostname in my query. Thanks for the help!
– Andrew Williams
Aug 9 at 19:52
1
1
Nice! I think it makes a difference if you switch the filename tests and do
-iname "PC-*-*.json" -not -iname "*$hostname*"
instead as the second one has to be evaluated much more seldom this way. Also, OP wants -type f
(as the first test). Oh and wait, why -iname
? OP definitely wants name
for both tests.– dessert
Aug 9 at 19:54
Nice! I think it makes a difference if you switch the filename tests and do
-iname "PC-*-*.json" -not -iname "*$hostname*"
instead as the second one has to be evaluated much more seldom this way. Also, OP wants -type f
(as the first test). Oh and wait, why -iname
? OP definitely wants name
for both tests.– dessert
Aug 9 at 19:54
@dessert You're right... I'll update the answer.
iname
is somehow burned into my memory and I always use it...– Ravexina
Aug 10 at 5:54
@dessert You're right... I'll update the answer.
iname
is somehow burned into my memory and I always use it...– Ravexina
Aug 10 at 5:54
@AndrewWilliams You're welcome... about
HOSTNAME
you are correct! I thought hostname
is a variable you defined youreslf ;)– Ravexina
Aug 10 at 5:57
@AndrewWilliams You're welcome... about
HOSTNAME
you are correct! I thought hostname
is a variable you defined youreslf ;)– Ravexina
Aug 10 at 5:57
add a comment
|
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1164664%2fremoving-certain-file-types-that-do-not-contain-the-hostname-in-the-file-name%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown