终端操作的记录在哪里?
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
-
- 帖子: 86
- 注册时间: 2007-03-01 11:44
终端操作的记录在哪里?
安装好ubuntu后,首先与终端打交道,写了N个sudo apt-get。还好,通过方向键(↑),能够把所有的操作召唤回来,非常方便。那么,这些终端操作的记录在哪里呢? 我想把第一次键入的命令保留下来。
不会是通过方向键(↑),来实现我的目的吧。
不会是通过方向键(↑),来实现我的目的吧。
- bones7456
- 帖子: 8495
- 注册时间: 2006-04-12 20:05
- 来自: 杭州
- 联系:
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
- bones7456
- 帖子: 8495
- 注册时间: 2006-04-12 20:05
- 来自: 杭州
- 联系:
- xhy
- 帖子: 3916
- 注册时间: 2005-12-28 1:16
- 系统: Ubuntu 12.10 X64
- 来自: 火星
根据退出的顺序bones7456 写了:我是在想,同时开了N个终端的时候,怎么记的?
每退出一个shell 就记录那个shell下的命令
代码: 全选
static int
history_do_write (filename, nelements, overwrite)
const char *filename;
int nelements, overwrite;
{
register int i;
char *output;
int file, mode, rv;
#ifdef HISTORY_USE_MMAP
size_t cursize;
mode = overwrite ? O_RDWR|O_CREAT|O_TRUNC|O_BINARY : O_RDWR|O_APPEND|O_BINARY;
#else
mode = overwrite ? O_WRONLY|O_CREAT|O_TRUNC|O_BINARY : O_WRONLY|O_APPEND|O_BINARY;
#endif
output = history_filename (filename);
rv = 0;
if ((file = open (output, mode, 0600)) == -1)
{
FREE (output);
return (errno);
}
#ifdef HISTORY_USE_MMAP
cursize = overwrite ? 0 : lseek (file, 0, SEEK_END);
#endif
if (nelements > history_length)
nelements = history_length;
/* Build a buffer of all the lines to write, and write them in one syscall.
Suggested by Peter Ho (peter@robosts.oxford.ac.uk). */
{
HIST_ENTRY **the_history; /* local */
register int j;
int buffer_size;
char *buffer;
the_history = history_list ();
/* Calculate the total number of bytes to write. */
for (buffer_size = 0, i = history_length - nelements; i < history_length; i++)
#if 0
buffer_size += 2 + HISTENT_BYTES (the_history[i]);
#else
{
if (history_write_timestamps && the_history[i]->timestamp && the_history[i]->timestamp[0])
buffer_size += strlen (the_history[i]->timestamp) + 1;
buffer_size += strlen (the_history[i]->line) + 1;
}
#endif
/* Allocate the buffer, and fill it. */
#ifdef HISTORY_USE_MMAP
if (ftruncate (file, buffer_size+cursize) == -1)
goto mmap_error;
buffer = (char *)mmap (0, buffer_size, PROT_READ|PROT_WRITE, MAP_WFLAGS, file, cursize);
if ((void *)buffer == MAP_FAILED)
{
mmap_error:
rv = errno;
FREE (output);
close (file);
return rv;
}
#else
buffer = (char *)malloc (buffer_size);
if (buffer == 0)
{
rv = errno;
FREE (output);
close (file);
return rv;
}
#endif
for (j = 0, i = history_length - nelements; i < history_length; i++)
{
if (history_write_timestamps && the_history[i]->timestamp && the_history[i]->timestamp[0])
{
strcpy (buffer + j, the_history[i]->timestamp);
j += strlen (the_history[i]->timestamp);
buffer[j++] = '\n';
}
strcpy (buffer + j, the_history[i]->line);
j += strlen (the_history[i]->line);
buffer[j++] = '\n';
}
#ifdef HISTORY_USE_MMAP
if (msync (buffer, buffer_size, 0) != 0 || munmap (buffer, buffer_size) != 0)
rv = errno;
#else
if (write (file, buffer, buffer_size) < 0)
rv = errno;
free (buffer);
#endif
}
close (file);
FREE (output);
return (rv);
}
目前负债150多万
-
- 帖子: 86
- 注册时间: 2007-03-01 11:44
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
是追加模式?.. 不会覆盖掉其他shell写的?xhy 写了:根据退出的顺序bones7456 写了:我是在想,同时开了N个终端的时候,怎么记的?
每退出一个shell 就记录那个shell下的命令
代码: 全选
static int history_do_write (filename, nelements, overwrite) const char *filename; int nelements, overwrite; { register int i; char *output; int file, mode, rv; #ifdef HISTORY_USE_MMAP size_t cursize; mode = overwrite ? O_RDWR|O_CREAT|O_TRUNC|O_BINARY : O_RDWR|O_APPEND|O_BINARY; #else mode = overwrite ? O_WRONLY|O_CREAT|O_TRUNC|O_BINARY : O_WRONLY|O_APPEND|O_BINARY; #endif output = history_filename (filename); rv = 0; if ((file = open (output, mode, 0600)) == -1) { FREE (output); return (errno); } #ifdef HISTORY_USE_MMAP cursize = overwrite ? 0 : lseek (file, 0, SEEK_END); #endif if (nelements > history_length) nelements = history_length; /* Build a buffer of all the lines to write, and write them in one syscall. Suggested by Peter Ho (peter@robosts.oxford.ac.uk). */ { HIST_ENTRY **the_history; /* local */ register int j; int buffer_size; char *buffer; the_history = history_list (); /* Calculate the total number of bytes to write. */ for (buffer_size = 0, i = history_length - nelements; i < history_length; i++) #if 0 buffer_size += 2 + HISTENT_BYTES (the_history[i]); #else { if (history_write_timestamps && the_history[i]->timestamp && the_history[i]->timestamp[0]) buffer_size += strlen (the_history[i]->timestamp) + 1; buffer_size += strlen (the_history[i]->line) + 1; } #endif /* Allocate the buffer, and fill it. */ #ifdef HISTORY_USE_MMAP if (ftruncate (file, buffer_size+cursize) == -1) goto mmap_error; buffer = (char *)mmap (0, buffer_size, PROT_READ|PROT_WRITE, MAP_WFLAGS, file, cursize); if ((void *)buffer == MAP_FAILED) { mmap_error: rv = errno; FREE (output); close (file); return rv; } #else buffer = (char *)malloc (buffer_size); if (buffer == 0) { rv = errno; FREE (output); close (file); return rv; } #endif for (j = 0, i = history_length - nelements; i < history_length; i++) { if (history_write_timestamps && the_history[i]->timestamp && the_history[i]->timestamp[0]) { strcpy (buffer + j, the_history[i]->timestamp); j += strlen (the_history[i]->timestamp); buffer[j++] = '\n'; } strcpy (buffer + j, the_history[i]->line); j += strlen (the_history[i]->line); buffer[j++] = '\n'; } #ifdef HISTORY_USE_MMAP if (msync (buffer, buffer_size, 0) != 0 || munmap (buffer, buffer_size) != 0) rv = errno; #else if (write (file, buffer, buffer_size) < 0) rv = errno; free (buffer); #endif } close (file); FREE (output); return (rv); }
^_^ ~~~
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
- xhy
- 帖子: 3916
- 注册时间: 2005-12-28 1:16
- 系统: Ubuntu 12.10 X64
- 来自: 火星
-
- 帖子: 5
- 注册时间: 2012-01-15 21:48
Re: 终端操作的记录在哪里?
我不知道别的版本在哪,ubuntu11.10是在用户的home中。
- photor
- 论坛版主
- 帖子: 11004
- 注册时间: 2008-04-26 12:41