终端操作的记录在哪里?

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
dongr
帖子: 86
注册时间: 2007-03-01 11:44

终端操作的记录在哪里?

#1

帖子 dongr » 2007-09-29 9:40

安装好ubuntu后,首先与终端打交道,写了N个sudo apt-get。还好,通过方向键(↑),能够把所有的操作召唤回来,非常方便。那么,这些终端操作的记录在哪里呢? 我想把第一次键入的命令保留下来。



不会是通过方向键(↑),来实现我的目的吧。
oiniya
帖子: 256
注册时间: 2007-07-26 15:07

#2

帖子 oiniya » 2007-09-29 9:45

~/.bash_history
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#3

帖子 bones7456 » 2007-09-29 9:48

我是在想,同时开了N个终端的时候,怎么记的?
关注我的blog: ε==3
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#4

帖子 eexpress » 2007-09-29 9:50

● 鸣学
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#5

帖子 bones7456 » 2007-09-29 10:07

ee干嘛哦?弄个不相关的链接...
关注我的blog: ε==3
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

#6

帖子 xhy » 2007-09-29 10:09

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多万
dongr
帖子: 86
注册时间: 2007-03-01 11:44

less .bash_history 能看到自己的操作历史

#7

帖子 dongr » 2007-09-30 18:06

:D :D :D :D
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

#8

帖子 BigSnake.NET » 2007-09-30 18:09

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);
}
是追加模式?.. 不会覆盖掉其他shell写的?
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

#9

帖子 xhy » 2007-09-30 19:08

追加模式不会覆盖的
如果不是追加模式 就要使用文件锁了

当前文件长度记录在V表中 每个文件的V节点在内核中只有一份
追加模式打开文件 每次写的时候都会把文件表中的偏移量设置为V节点中记录的数值
磁盘IO的write 当数据量不是太大的时候 一般可以认为是原子操作完成
目前负债150多万
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

#10

帖子 eexpress » 2007-09-30 19:37

我上面那帖子里面就有这设置的啊。
● 鸣学
dgsnow
帖子: 5
注册时间: 2012-01-15 21:48

Re: 终端操作的记录在哪里?

#11

帖子 dgsnow » 2012-01-15 21:51

我不知道别的版本在哪,ubuntu11.10是在用户的home中。
回复