Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am running as root. I want to copy all the users on the system's .bash_history files into my home directory. I can do this to combine all of them into one, but then I can't tell who's commands are who's.

find /home/ -maxdepth 2 -iname ".bash_history" -type f -exec cat {} >> ~/combined.txt \;

I would like to either put the user names between each of the files in the combined.txt file, or I would like to copy the files in this type of structure:


How can I accomplish either one (or both) of these?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

In zsh, using zmv:

autoload zmv; alias zcp='zmv -C'  # this can go into your .zshrc
zcp '/home/(*)/.bash_history' '~/user-bash/$1.txt'

In other shells:

for x in /home/*/.bash_history; do
  u=${x%/*}; u=${u##*/}
  cp "$x" ~/user-bash/"$u.txt"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.