文章目录
  1. 1. 系统信息
  2. 2. 搜索命令
  3. 3. touch修改时间戳
  4. 4. bash命令
  5. 5. history命令
  6. 6. mysql数据库
  7. 7. 创建root用户
  8. 8. SSH
  9. 9. 任务快捷键
  • SSH-SERVER
    1. 1. sort
    2. 2. 解压
  • gcc
  • scp
  • 设置开机启动命令、vm下与主机共享目录 //mark
  • 设置默认进入文本模式
  • 安装vm工具
  • 升级vmware工具
  • 牯岭街少年杀人事件-CC修复版
    Linux常见操作:搜索、查看系统信息、配置环境等.

    系统信息

    1. 查看ubuntu系统版本号
    1
    # lsb_release    -a
    1. 查看文件 大小、blocks、访问、修改、改变 等信息

      1
      # stat     myself_takethat
    2. linux命令中说明:方括号、尖括号含义
      例如7z命令说明

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21

      Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
      [<@listfiles...>]

      <Commands>
      a: Add files to archive
      b: Benchmark
      d: Delete files from archive
      e: Extract files from archive (without using directory names)
      l: List contents of archive
      t: Test integrity of archive
      u: Update files to archive
      x: eXtract files with full paths
      <Switches>
      -ai[r[-|0]]{@listfile|!wildcard}: Include archives
      -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
      -bd: Disable percentage indicator
      -i[r[-|0]]{@listfile|!wildcard}: Include filenames
      -m{Parameters}: set compression Method
      -o{Directory}: set Output directory
      -p{Password}: set Password

    将文件a打包成名为waht的包

    1
    root@ubuntu:~/7z_test# 7z a what a

    在方括号内的表达式(“[” 和 “]”之间的字符)是可选的(写命令时要去掉括号)。

    在尖括号内的表达式(“<” 和 “>”之间的字符)是必须替换的表达式(而且要去掉括号)。

    省略号表示该选项可以单个或多个

    搜索命令

    1. find搜索命令

    注意find命令是递归搜索

    语法:find 搜索路径 匹配表达式
    常用的匹配条件:
    -name filename要查找的文件名。可使用通配符* (模糊搜索),但要加””

    # find ./ -name "*t" -print
    输出名字位数为t的文件路径

    # find . -name "*main*" -print
    输出带main的文件路径

    -user username查找属于 username的文件

    $ find ./ -user takethat
    -print显示找到的文件路径名。通常要选。例如:
    find . -name “for” -print
    查找当前目录下h开头的文件

       find / -name  hosts  -print
    

    查找系统中名为hosts的文件

    -exec cmd

    cmd指command prompt   命令提示符
    对找到的匹配的文件,执行由cmd表示的命令,参数{} 由find找到的当前的文件路径名取代,命令行末尾必须有\;如:

    # find ./private_takethat/ -user takethat -exec cat {} \;

    可参照资料: linux下find命令-atime,-ctime,-mtime真正含义

    1
    root@ubuntu:~# find / -name 'sour*' 

    find搜寻字符

    1
    find . | xargs grep 10

    touch修改时间戳

    1. 修改访问时间戳

      1
      touch -a  file 

      修改该file文件访问时间戳,为当前时间戳

    2. 修改 修改该时间戳

      1
      touch -m  file

      修改该file文件访问时间戳,使其为当前时间戳

    3. 修改自定义时间戳
      touch -t

      选项语法组成 [[CC]YY]MMDDhhmm [.SS]

      CC - 年份的前两位
      YY - 年份的后两位
      MM - 月份 [01-12]
      DD - 日期 [01-31]
      hh - 时 [00-23]
      mm - 分 [00-59]
      SS - 秒 [00-61]

    也可以使用-d参数进行修改时间戳

    1
    $ touch -d '10-December-2013' file_3.txt
    • +d 修改时区
      1
      $ touch -d GMT3 file_3.txt

      更改为GMT3时区

    为什么我们需要改变时间戳?

    bash命令

    • source

    source命令通常用于重新执行刚修改的初始化文件,使之立即生效,而不必注销并重新登录。
    用法:

    1
    source  filename 或 .  filename

    source命令(从 C Shell 而来)是bash shell的内置命令;点命令(.),就是个点符号(从Bourne Shell而来)是source的另一名称。

    1.当shell脚本具有可执行权限时,用sh filename与./filename执行脚本是没有区别得。./filename是因为当前目录没有在PATH中,所有”.”是用来表示当前目录的。

    2.sh filename 重新建立一个子shell,在子shell中执行脚本里面的语句,该子shell继承父shell的环境变量,但子shell新建的、改变的变量不会被带回父shell,除非使用export。

    3.source filename:这个命令其实只是简单地读取脚本里面的语句依次在当前shell里面执行,没有建立新的子shell。那么脚本里面所有新建、改变变量的语句都会保存在当前shell里面。

    history命令

    1
    root@ubuntu:~# history | grep for*

    筛选for

    mysql数据库

    启动mysql

    1
    /etc/init.d/mysqld start

    检查mysql服务是否启动

    1
    ps -ef | grep mysqld

    关闭mysql服务

    1
    2
    3
    root@host# cd /usr/bin
    ./mysqladmin -u root -p shutdown
    Enter password: ******

    登入数据库

    1
    mysql  -u  root  -p

    查看所有mysql数据库

    1
    2
    show  databases;

    显示当前数据库中所有表的名称

    1
    mysql> show  tables

    查询用户名

    用root登入才能查看

    1
    mysql> select * from user\G;

    查看当前mysql用户权限

    1
    select * from user\G;

    如果mysql不能开启,尝试安全启动

    1
    mysqld_safe

    重启neutron 网络

    1
    service neutron-server restart

    指定DNS解析域名

    1
    nslookup blog.fiochen.me 223.5.5.5

    创建root用户

    1. sudo passwd root

    2. 输入密码和确认

    SSH

    查看SSH服务是否启动

    1
    # ps -e  |grep  ssh

    如果只有ssh-agent那ssh-server还没有启动,或者没有安装
    需要/etc/init.d/ssh start,如果看到sshd那说明ssh-server已经启动了。

    • 安装SSH
      1
      sudo apt-get install openssh-server

      更新源列表sudo apt-get update

    允许远程登入:

    1
    vi /etc/ssh/sshd_config

    将PermitRootLogin without-password 修改为PermitRootLogin yes

    修改 PasswordAuthentication项为yes

    重启服务

    1
    service  ssh   restart

    任务快捷键

    ctrl + z
    挂起,将当前正在前台运行的命令放到后台,并且暂停

    1.可通过jobs查看当前暂停的进程
    2. **fg %N使第N个任务在前台运行

    bg  %N是第N个任务在后台运行

    ctrl+c
    强行中断当前程序的执行

    SSH-SERVER

    检查是否装了ssh-server

    1
    2
    root@iTOP4412-ubuntu-desktop:~# ps -e | grep ssh
    4897 ? 00:00:00 ssh-agent

    来查看,如果没有显示sshd则说明没有安装openssh-server

    安装openssh-server服务可能报错

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    root@iTOP4412-ubuntu-desktop:~# apt-get install openssh-server
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    You might want to run 'apt-get -f install' to correct these:
    The following packages have unmet dependencies:
    ssh : Depends: openssh-client (>= 1:6.6p1-2ubuntu1) but 1:5.9p1-5ubuntu1 is to be installed
    Depends: openssh-server (>= 1:6.6p1-2ubuntu1) but 1:5.9p1-5ubuntu1 is to be installed
    E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
    root@iTOP4412-ubuntu-desktop:~#

    分析与解决办法

    这是因为,openssh-server是依赖于openssh-clien的,那ubuntu不是自带了openssh-client吗?原由是自带的openssh-clien与所要安装的openssh-server所依赖的版本不同,这里所依赖的版本是

    1
    1:6.6p1-2ubuntu1

    所以要安装对应版本的openssh-clien,来覆盖掉ubuntu自带的


    sort

    -u选项

    它的作用很简单,就是在输出行中去除重复行。

    -r 降序

    降序排列

    解压

    1. tar命令-文件归档

    语法:tar [参数] 文件或目录名
    参数: -c:建立一个.tar文件
    -v:列出处理过程中的详细信息
    -f:指定新文件名
    -x:解压某个文件
    -u:仅仅添加比文档文件更新的文件,
    如原文档中不存在旧的文件,则追加它到文
    档中,如存在则更新它
    -z:用zip命令压缩或用unzip解压

    范例:
    1、$ tar –cvf back.tar backup
    备份backup目录下的所有文件和目录
    2、$ tar –xvf backup.tar
    将备份backup.tar文件还原
    3、$ tar –czvf backup.tar.gz backup
    备份backup目录下的所有文件和目录,并以zip压
    缩,命名文件为backup.tar.gz
    4、$ tar –xzvf backup.tar.gz
    将备份backup.tar.z文件还原
    5、$ tar –tf backup.tar
    列出备份文件backup.tar的内容
    6、$ tar –tzf backup.tar.gz
    列出备份文件backup.tar.gz的内容
    7、$ tar –rf backup.tar file1
    在备份backup.tar的尾部添加文件 file1

    如何解压.tar.xz包

    1
    # xz -d linux-4.7.tar.xz 

    它会将包解压成.tar
    再执行

    1
    # tar -vxf

    解压.tar.bz2包
    tar -jxvf xx.tar.bz2

    gcc

    64位编译器中编译32位程序如下:

    1
    gcc -m32 test.c -o test_run-32

    scp

    1
    # scp RS232-gx.cpp 192.168.126.141@root:/root/gx

    设置开机启动命令、vm下与主机共享目录 //mark

    http://blog.csdn.net/wujin8589/article/details/52062413

    二、解决安装VMWare tools后/mnt中有hgfs但没共享文件
    前提:在虚拟机软件中设置了共享目录
    此时在linux中进入 /mnt/hgfs 文件夹,但发现共享的文件没有显示
    使用以下办法解决(root权限):
    sudo passwd root
    输入root的密码就可以正常切换到root权限了

    1. vmware-hgfsclient 命令查看当前有哪些共享的目录,这里我只使用了shared文件夹
    2. 使用 mount -t vmhgfs .host:/shared /mnt/hgfs 命令挂载该共享文件夹(注意:带.号的哦),其中.host:/Documents是共享名,只需把Documents换成
      使用vmware-hgfsclient 命令得到的目录,/mnt/hgfs是挂载点
    3. 到此为止是可以使用该共享文件夹了,但每次都得重复mount一次,所以需要设置为随机启动后自动挂载
      编辑 /etc/fstab,添加下面一行
      .host:/shared /mnt/hgfs vmhgfs defaults 0 0 (按需写)

    设置默认进入文本模式

    http://www.2cto.com/os/201309/246497.html
    1.如果你想让系统默认从文本模式启动的话,则应该依次输入以下两条命令:

    sudo rm /etc/systemd/system/default.target //这条命令是删除原来的默认启动模式

    sudo ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target //这条命令是添加新的启动模式,将文本模式设置成默认启动模式

    2.如果你想让系统默认从图形界面启动的话,则应该依次输入以下两条命令:

    sudo rm /etc/systemd/system/default.target //这条命令是删除原来的默认启动模式

    sudo ln -s /lib/systemd/system/graphical.target /etc/systemd/system/default.target //这条命令是添加新的启动模式,将图形模式设置成默认启动模式

    注意一下:

    当你修改系统默认启动模式为文本模式后,重新启动操作系统后,linux就会默认进入tty1(终端1)的文本模式。如果你想要进入图形界面,则可以输入一面这条命令:

    startx //这是以普通用户登陆图形界面,如果你想以超级用户(root)进入图形界面的话,则应该输入sudo startx。

    安装vm工具

    • 选择菜单栏“虚拟机”——“安装VMware tools” ,等待系统自动更换ISO光盘
      /dev/cdromlink
      1
      2
      cd /mnt
      tar zxvf VMwareTools-9.6.0-1294478.tar.gz -C /root/vm_tools(安装到的目录)

      /root/vm_tools要自己手动建立

      1
      2
      3
      cd /root/
      cd vmware-tools-distrib/
      ./vmware-install.pl
      一路回车,完成后重启系统。

    升级vmware工具

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    进入光驱目录将文件拷贝到本地文件夹


    tar zxf VMwareTools-10.0.10-4301679.tar.gz


    cd vmware-tools-distrib

    ./vmware-install.pl
    >./vmware-install.pl之前请检查/mnt目录有没有被占用,不然会安装失败


    # ubuntu安装软件


    + ubuntu18.01安装 synergy
    ```linux
    root@acer:/home/takethat/Downloads# dpkg -i synergy_1.10.0.stable_b33+275cdc1c_ubuntu_amd64.deb
    Selecting previously unselected package synergy.
    (Reading database ... 128436 files and directories currently installed.)
    Preparing to unpack synergy_1.10.0.stable_b33+275cdc1c_ubuntu_amd64.deb ...
    Unpacking synergy (1.10.0.stable~b33+275cdc1c) ...
    dpkg: dependency problems prevent configuration of synergy:
    synergy depends on libavahi-compat-libdnssd1 (>= 0.6.16); however:
    Package libavahi-compat-libdnssd1 is not installed.
    synergy depends on libqt5core5a (>= 5.5.0); however:
    Package libqt5core5a is not installed.
    synergy depends on libqt5gui5 (>= 5.0.2) | libqt5gui5-gles (>= 5.0.2); however:
    Package libqt5gui5 is not installed.
    Package libqt5gui5-gles is not installed.
    synergy depends on libqt5network5 (>= 5.0.2); however:
    Package libqt5network5 is not installed.
    synergy depends on libqt5widgets5 (>= 5.2.0); however:
    Package libqt5widgets5 is not installed.

    dpkg: error processing package synergy (--install):
    dependency problems - leaving unconfigured
    Processing triggers for hicolor-icon-theme (0.17-2) ...
    Processing triggers for gnome-menus (3.13.3-11ubuntu1.1) ...
    Processing triggers for desktop-file-utils (0.23-1ubuntu3.18.04.1) ...
    Processing triggers for mime-support (3.60ubuntu1) ...
    Errors were encountered while processing:
    synergy

    再执行这个:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    root@acer:/home/takethat/Downloads# apt --fix-broken install
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Correcting dependencies... Done
    The following additional packages will be installed:
    libavahi-compat-libdnssd1 libdouble-conversion1 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5svg5 libqt5widgets5 libxcb-xinerama0
    qt5-gtk-platformtheme qttranslations5-l10n
    Suggested packages:
    qt5-image-formats-plugins qtwayland5
    The following NEW packages will be installed:
    libavahi-compat-libdnssd1 libdouble-conversion1 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5svg5 libqt5widgets5 libxcb-xinerama0
    qt5-gtk-platformtheme qttranslations5-l10n
    0 upgraded, 11 newly installed, 0 to remove and 3 not upgraded.
    1 not fully installed or removed.
    Need to get 9,418 kB of archives.
    After this operation, 40.9 MB of additional disk space will be used.
    Do you want to continue? [Y/n]
    文章目录
    1. 1. 系统信息
    2. 2. 搜索命令
    3. 3. touch修改时间戳
    4. 4. bash命令
    5. 5. history命令
    6. 6. mysql数据库
    7. 7. 创建root用户
    8. 8. SSH
    9. 9. 任务快捷键
  • SSH-SERVER
    1. 1. sort
    2. 2. 解压
  • gcc
  • scp
  • 设置开机启动命令、vm下与主机共享目录 //mark
  • 设置默认进入文本模式
  • 安装vm工具
  • 升级vmware工具