how to enable bash history for users?

Peace, when I execute a command as a user, it appears when I press the up arrow. But when i exit from the user and su again, the up arrow display zilch. There is no such problem in gentoo.

Hello and welcome here.

Please be a bit more descriptive (or better, show it).

You say “when I exit from the user”, but then there is no session. Then you say “and su again” but there is no session to do any “su” command in, nor was there any “su” in your description earlier, thus why the “again”?

Confusing to me.

Oh, and allow me, you being new here:

There is an important, but not easy to find feature on the forums.

Please use CODE tags around copied/pasted computer text in a post. It is the # button in the tool bar of the post editor. When applicable copy/paste complete, that is including the prompt, the command, the output and the next prompt.

Only guessing (see Henke’s comments) but have you read the man page for su or tried “su --help”. To switch to the target user’s environment you have to:

 user1: > su - user2

Also if user2 has multiple logins, only the last to logout’s history is preserved, and command-lines that start with white-space are not saved in history.

su - kadish

did not help. after executing some commands and exiting and then su’ing again, history is null. the history is only on root.

ok, the problem that /home/kadish did not exist, once created history works, or is it that I tried the new command without exiting from su without “-”…

I have no idea what you are trying to tell. Please SHOW by copy/paste instead of telling vague stories.

Do you have a problem or are you trying to tell that it is solved?

No, just think about this question: How would the system store used commands in ~/.bash_history if ~/ doesn’t even exist? You’ve already seen the answer to this question. :slight_smile:

BTW: new here? Welcome !!

Do you think he really means he is/was having a user without a home directory?

Unless you show us what you are doing and what happens as was explained before, you reduce us to guessing and wasting our time. Your initial post never mentioned root. You also did not show how you created the user “kadesh”. (YaST or useradd -m). If you had shown your working the answer would have been apparent.

Apologies, I am tired and crabbit.

I don’t only think so, see

ok, the problem that /home/kadish did not exist, once created history works, or is it that I tried the new command without exiting from su without “-”…

Yes, I know, there’s a "read the … " expression which is disapproved of in this Forum but, I suspect that, it’s time for an exception: >:)
Manual page bash(1) line 762/4256 20%

              The  name  of  the  file  in  which command history is saved (see HISTORY below).  The default value is
              ~/.bash_history.  If unset, the command history is not saved when a shell exits.

 > echo $HISTFILE
 > echo $HISTSIZE



I read that also, but how is that possible? And as I am still missing any facts about the problem I laid it aside in the hope of more trustworthy information coming forward.

Henk, bash history is very simple:

  • If there ain’t no history file then, there ain’t no history.

I am not missing factual information about how the bash history functions. Of course when a user has no home directory, (s)he will have no history file and then >s)he will have no history. We can go some steps further. When you have no computer, you have no operating system and then you will not even have a user. But I do not want to speculate on what the OP has or has not. I am missing any factual description on what the OP is doing.

That’s very easy to do. If you use “vipw” to create a new user, then that does not create the user home directory. You must do that separately.

This is not the recommended way to create a new user. But it is what an old time unix user might first try.

Works fine for me.

Don’t know about any missing User directory, but maybe you are forgetting that su and the normal User are completely different users so will not share the same history?


I’m not sure which UNIX® systems suggested that Admins should add users with ‘vipw’ and then ‘vigr’ and then ‘mkdir’ and then ‘cp’ and then ‘chown’ – except, possibly, for some of the real-time systems …
There’s a Stack Exchange article here: <>.
But, why do it?

AFAIK, ‘useradd’ has been around, also for UNIX® for for quite a while now, and it’s included in openSUSE by default, as is ‘newusers’ …
‘adduser’ is a Debian thing which is useful for setting up system users from a CLI – it also create a ‘home’ directory for system users which ‘useradd’ doesn’t …

My recollection of BSD UNIX (the one that was shipped from Berkley, Ca on tapes) is that it came with useradd and we created our own adduser as an alias for “useradd -m -k … ” and there were deluser equivalents. Now when useradd has defaults (-D) I do not bother with adduser because “useradd -m” and “userdel -r” don’t involve much extra typing. I have never heard of anyone using vipw yo create users.