Just wondering the above. Also, is there a way to store a list of frequently used commands?
It is possible to show frequently used commands.
For example:
awk '{print $1}' ~/.zsh_history | sort | uniq -c | sort -nr | head -n 5
For me it gives output:
530 ls
320 nano
299 cd
144 git
130 ag
@jdrch good issue beginner command line issue. Refences regarding this issue https://duckduckgo.com/?q=beginning+command+line+site%3Atldp.org at these links about beginning with the Linux CLI (Command Line Interface) in Termux on Android, Chromebook and Fire OS.
@xeffyr thank you for posting this cool one-liner:
[18:29 ~ ]$ awk '{print $1}' ~/.bash_history | sort | uniq -c | sort -nr | head -n 5 for Termux.
These are interesting results:
70 e
52 l
38 startarch
29 mv
28 pkg
Curiosity makes me wonder about the personal impact of the results of this command for Termux on Linux device users.
Thanks guys, but what I meant is the ability to access commands from a previous session upon starting a new session by using the up arrow as done on Linux desktops.
Commands from previous sessions are saved in history file. In bash this file called .bash_history, in zsh you have to set it manually.
using the up arrow
Up arrow is not workin in Termux ? I'm using Termux on smartphone, so I have to type volumeup+w to get previous command. If your keyboard has an arrows, they should work.
If your keyboard has an arrows, they should work.
@xeffyr That's what I thought too, but when I press the up arrow the app vibrates to tell me that keypress isn't accepted. I'm using SwiftKey Beta.
I use Ctrl+P (previous) and Ctrl+N (next) and it remembers the last closed session. (Up arrow works on my CodeBoard and Terminal IDE keyboards in both orientations, and wide Hackers Keyboard, though I don't use them as much.)
@Quasic Awesome. How do I use Ctrl on software keyboards like SwiftKey?
@jdrch, I downloaded SwiftKey Beta 6.7.4.24, and up arrow works for me. I didn't find Ctrl as an option, but termux let's you use the volume down button, or you can swipe from the left side and long press the keyboard button for a row of keys including Ctrl.
@Quasic I'm not sure what I'm doing wrong then. Even using BeHe keyboard, touching the up arrow upon launching Termux does not retrieve commands from previous sessions.
@jdrch, does it recall commands from the current session, but not prior sessions, or is any history remembered? Have you used chsh to switch the login shell to non-bash or set bash to not save .bash_history to disk?
When I delete the history file, it vibrates when I press up or CTRL+P in the next session.
does it recall commands from the current session, but not prior sessions
This is exactly what it does.
Have you used chsh to switch the login shell to non-bash or set bash to not save .bash_history to disk?
I've never to my knowledge changed any Termux settings. The only things I've done since installing are installing coreutils, findutils, and Termux:Task.
it vibrates when I press up or CTRL+P in the next session.
This is exactly what I'm experiencing.
It sounds like ~/.bash_history isn't getting saved. Try these commands:
echo $HISTFILE should print /data/data/com.termux/files/home/.bash_history or another valid path to your history file
ls -al ~/.bash_history should start with -rw and have the same owner as other files in that folder, not root or anyone else. Also try ls -al $HISTFILE in case the above is different.
Here's what I did and what happened:
$ echo $HISTFILE
/data/data/com.termux/files/home/.bash_history
$ ls -al ~/.bash_history
ls: cannot access '/data/data/com.termux/files/home/.bash_history': No such file or directory
$ ls -al /data/data/com.termux/files/home/.bash_history
ls: cannot access '/data/data/com.termux/files/home/.bash_history': No such file or directory
Any ideas?
@jdrch Try touch ~/.bash_history. This may resolve your issue. Is your device rooted?
No it isn't rooted.
@jdrch That is good news.
Try
touch ~/.bash_history. This may resolve your issue.
Is your ls -al output still the same? If it is, try rm ~/.bash_history then touch ~/.bash_history.
I did the touch ~/.bash_history command, which results in ls -al producing:
total 12
drwx------ 3 u0_a330 u0_a330 4096 Jan 21 22:34 .
drwx------ 4 u0_a330 u0_a330 4096 Dec 24 09:24 ..
-rw------- 1 u0_a330 u0_a330 0 Jan 21 22:34 .bash_history
drwx------ 3 u0_a330 u0_a330 4096 Jan 3 09:25 .termux
However even after that, touching the up arrow upon starting Termux doesn't recall commands from previous sessions. What's the next step in the process?
-rw------- 1 u0_a330 u0_a330 0 Jan 21 22:34 .bash_history
How do you exit your Termux sessions? What command do you use?
touching the up arrow
Are you using the physical volumeUp key + w?
I use the Exit button in the notifications. Is there something else I should be using instead?
Try using: exit and logout to leave a session.
From http://www.tldp.org/LDP/intro-linux/html/sect_02_02.html
That worked! Thanks so much!
I simply tried the combination; Volume Up + w key, and it brought out the extra keyboard keys.
Closing since this more about shell scripting and command history functionality.
NOTE* I use keyboard(bluetooth), and commands fail to be saved in .bash_history.
P.S went into it when i needed to find my installed packages for the latest program...
How can reopen the closed session in termux!!
Plz tell,,,,
How can reopen the closed session in termux!!
How I can get thing that no longer exists? Answer: create a new one ;)