Sort .bash_history content alphabetically

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm using HISTIGNORE to ignore the most used commands and HISTCONTROL=ignoreboth:erasedups to remove duplicates.



Is there a way to periodically sort the contents of the .bash_history in alphabetical order?










share|improve this question























  • Please define ”periodically”, and where would you like to store the output; once sorted.
    – maulinglawns
    Aug 23 at 17:48










  • like once a week or something ... in => ~/.bash_history
    – Ash
    Aug 23 at 17:54














up vote
0
down vote

favorite












I'm using HISTIGNORE to ignore the most used commands and HISTCONTROL=ignoreboth:erasedups to remove duplicates.



Is there a way to periodically sort the contents of the .bash_history in alphabetical order?










share|improve this question























  • Please define ”periodically”, and where would you like to store the output; once sorted.
    – maulinglawns
    Aug 23 at 17:48










  • like once a week or something ... in => ~/.bash_history
    – Ash
    Aug 23 at 17:54












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm using HISTIGNORE to ignore the most used commands and HISTCONTROL=ignoreboth:erasedups to remove duplicates.



Is there a way to periodically sort the contents of the .bash_history in alphabetical order?










share|improve this question















I'm using HISTIGNORE to ignore the most used commands and HISTCONTROL=ignoreboth:erasedups to remove duplicates.



Is there a way to periodically sort the contents of the .bash_history in alphabetical order?







bash cron






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 26 at 18:28









agc

4,1751935




4,1751935










asked Aug 23 at 17:35









Ash

1064




1064











  • Please define ”periodically”, and where would you like to store the output; once sorted.
    – maulinglawns
    Aug 23 at 17:48










  • like once a week or something ... in => ~/.bash_history
    – Ash
    Aug 23 at 17:54
















  • Please define ”periodically”, and where would you like to store the output; once sorted.
    – maulinglawns
    Aug 23 at 17:48










  • like once a week or something ... in => ~/.bash_history
    – Ash
    Aug 23 at 17:54















Please define ”periodically”, and where would you like to store the output; once sorted.
– maulinglawns
Aug 23 at 17:48




Please define ”periodically”, and where would you like to store the output; once sorted.
– maulinglawns
Aug 23 at 17:48












like once a week or something ... in => ~/.bash_history
– Ash
Aug 23 at 17:54




like once a week or something ... in => ~/.bash_history
– Ash
Aug 23 at 17:54










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted











  1. To see a sorted history without changing it, do:



    history | sort -k2



  2. To sort the history file, do:



    sort -o ~/.bash_history ~/.bash_history


    Then log out of bash by typing exit, and log back in. The new
    terminal instance will have an alphabetically sorted history.




  3. For the most cautious possible way to sort the history file, first exit all
    running instances of bash, (for the current user anyway), then do:



    sort -o ~/.bash_history ~/.bash_history



    Note: Users generally have no bad results from editing ~/.bash_history while still logged in. But it's fairly certain that exiting all running instance of bash is as safe or safer.







share|improve this answer






















  • This answer would be better with a cron job method as well, but I'm undecided on how to handle systems where terminals are left open for long periods of time. Maybe the job could remind them to log out and log back in, but suppose that's not convenient. Better still would be to have a method that doesn't require and exit at all.
    – agc
    Aug 26 at 17:05










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464462%2fsort-bash-history-content-alphabetically%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted











  1. To see a sorted history without changing it, do:



    history | sort -k2



  2. To sort the history file, do:



    sort -o ~/.bash_history ~/.bash_history


    Then log out of bash by typing exit, and log back in. The new
    terminal instance will have an alphabetically sorted history.




  3. For the most cautious possible way to sort the history file, first exit all
    running instances of bash, (for the current user anyway), then do:



    sort -o ~/.bash_history ~/.bash_history



    Note: Users generally have no bad results from editing ~/.bash_history while still logged in. But it's fairly certain that exiting all running instance of bash is as safe or safer.







share|improve this answer






















  • This answer would be better with a cron job method as well, but I'm undecided on how to handle systems where terminals are left open for long periods of time. Maybe the job could remind them to log out and log back in, but suppose that's not convenient. Better still would be to have a method that doesn't require and exit at all.
    – agc
    Aug 26 at 17:05














up vote
2
down vote



accepted











  1. To see a sorted history without changing it, do:



    history | sort -k2



  2. To sort the history file, do:



    sort -o ~/.bash_history ~/.bash_history


    Then log out of bash by typing exit, and log back in. The new
    terminal instance will have an alphabetically sorted history.




  3. For the most cautious possible way to sort the history file, first exit all
    running instances of bash, (for the current user anyway), then do:



    sort -o ~/.bash_history ~/.bash_history



    Note: Users generally have no bad results from editing ~/.bash_history while still logged in. But it's fairly certain that exiting all running instance of bash is as safe or safer.







share|improve this answer






















  • This answer would be better with a cron job method as well, but I'm undecided on how to handle systems where terminals are left open for long periods of time. Maybe the job could remind them to log out and log back in, but suppose that's not convenient. Better still would be to have a method that doesn't require and exit at all.
    – agc
    Aug 26 at 17:05












up vote
2
down vote



accepted







up vote
2
down vote



accepted







  1. To see a sorted history without changing it, do:



    history | sort -k2



  2. To sort the history file, do:



    sort -o ~/.bash_history ~/.bash_history


    Then log out of bash by typing exit, and log back in. The new
    terminal instance will have an alphabetically sorted history.




  3. For the most cautious possible way to sort the history file, first exit all
    running instances of bash, (for the current user anyway), then do:



    sort -o ~/.bash_history ~/.bash_history



    Note: Users generally have no bad results from editing ~/.bash_history while still logged in. But it's fairly certain that exiting all running instance of bash is as safe or safer.







share|improve this answer















  1. To see a sorted history without changing it, do:



    history | sort -k2



  2. To sort the history file, do:



    sort -o ~/.bash_history ~/.bash_history


    Then log out of bash by typing exit, and log back in. The new
    terminal instance will have an alphabetically sorted history.




  3. For the most cautious possible way to sort the history file, first exit all
    running instances of bash, (for the current user anyway), then do:



    sort -o ~/.bash_history ~/.bash_history



    Note: Users generally have no bad results from editing ~/.bash_history while still logged in. But it's fairly certain that exiting all running instance of bash is as safe or safer.








share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 26 at 17:00

























answered Aug 23 at 17:51









agc

4,1751935




4,1751935











  • This answer would be better with a cron job method as well, but I'm undecided on how to handle systems where terminals are left open for long periods of time. Maybe the job could remind them to log out and log back in, but suppose that's not convenient. Better still would be to have a method that doesn't require and exit at all.
    – agc
    Aug 26 at 17:05
















  • This answer would be better with a cron job method as well, but I'm undecided on how to handle systems where terminals are left open for long periods of time. Maybe the job could remind them to log out and log back in, but suppose that's not convenient. Better still would be to have a method that doesn't require and exit at all.
    – agc
    Aug 26 at 17:05















This answer would be better with a cron job method as well, but I'm undecided on how to handle systems where terminals are left open for long periods of time. Maybe the job could remind them to log out and log back in, but suppose that's not convenient. Better still would be to have a method that doesn't require and exit at all.
– agc
Aug 26 at 17:05




This answer would be better with a cron job method as well, but I'm undecided on how to handle systems where terminals are left open for long periods of time. Maybe the job could remind them to log out and log back in, but suppose that's not convenient. Better still would be to have a method that doesn't require and exit at all.
– agc
Aug 26 at 17:05

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464462%2fsort-bash-history-content-alphabetically%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay