Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to copy the whole history file

Status
Not open for further replies.

libchk

Technical User
May 23, 2005
11
US
im trying to copy the whole history file e.g user .sh_history_adam to .sh_history_zebra, anyone can help? thanks
 
All you need to do is to copy the history file and then change the ownership! So assuming that zebra user have staff as its main group then this should be done this way:

Code:
cp -p /home/adam/.sh_history_adam /home/zebra/.sh_history_zebra
chown zebra:staff .sh_history_zebra

But i'm not sure whether appending the user name to the history file works as i'm used to .sh_history only! So if that doesn't work then rename your files back to .sh_history.

Regards,
Khalid
 
thanks for the reply, what i meant was, im trying to copy users history file which is alphabetically arranged from a -z
i mean the whole history, is there a simple script for that even a command. thanks

e.g

.sh_history.a .sh_history.b .sh_history.c .sh_history.d .sh_history.e .sh_history.f up to .sh_history.z
 
Still not clear to me what you want to achieve to be honest!

I understand that you want to copy all history files in your machine for all users into a separate directory and renaming them from a-z. Is that what you are trying to do?

If so then how many users do you have? I suggest its better to use numbers instead of limiting yourself with letters!

Now if my understanding is right then you can do this:

(assuming you've created a directory inside tmp to hold hisotry files called all_history)

Code:
n=0
for i in $(find /home -name .sh_history -print)
do
((n=n+1))
cp -p $i /tmp/all_history/.sh_history$n
done

Just put that code into a file, make it executable (chmod +x file) and then run it. Hope this is what you are looking for!

Regards,
Khalid
 
I understand that you want to copy all history files in your machine for all users into a separate directory and renaming them from a-z. Is that what you are trying to do?

No, the a-z is the lists of users history i want all of them to be copied, i get an error when i tried to copy them.

e.g files

.sh_history.hparial.200811071605 to
.sh_history.hpzebra.200811071679

which is arranged alphabetically. which starts from july december , i want to copy them all, if there is a script for this or command to copy much better, thanks.
 
It might help if you tell us the error you are getting.

I want to be good, is that not enough?
 
Sorry but its still not clear!

Could you give me a sample list of what you have of history files and how you want them to look like after the copy?

Regards,
Khalid
 
cp .sh_history* /new/dir

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top