Some linux usage record

记录自己在使用linux中渐渐使用的命令和一些方法。



  1. 在一个终端中打开另一个窗口

    1
    ctrl + shift + t
  2. 回到上一次目录

    1
    cd -
  3. 列出当前登录用户

    1
    w
  4. Linux进出sudo的方法

    进入sudomode: sudo -i
    退出sudomode: ctrl + d

  5. grep(general regular expression print)
    ls | grep "linux": List file that its name includes string “linux”.

  6. Clear commands history
    history -c

  7. 终端锁定与退出锁定(终端无法输入的假死问题)^1

  • 终端锁定
    ctrl + s
  • 退出锁定
    ctrl + q
  1. File permission
  • chmod
    Change mode.
    10number: d(directory) or -(that represents file)
    Permission:
    - r: (100)2 //4
    - w: (010)2 //2
    - x: (001)2 //1
    eg. chmod 777 file/dir // Give file/dir rwx permission.
  • chgrp
    Change file group.
  • chown
    Change file owner.
  1. Change font size in terminal

    Change bigger: ctrl -
    Change smaller: ctrl +

  2. Rename

    将test.jpg改成test1.jpg

    1
    mv {test,test1}.jpg
  3. 在linux中跳出很深的文件夹,如果没有记住文件路径,就要一层层cd过去,浪费很多的时间。

    解决方法1
    /etc/profile.d/目录下新建例如dd.sh文件,文件内容如下

    1
    alias dd='cd /media/folder1/folder2/.../'

    接下来保存退出

    1
    source dd.sh

    效果: 在命令行中输入dd即可实现挑入指定目录。
    并且重启之后在命令行中依然生效。

    解决方法2
    ~/.bashrc中添加

    1
    alias dd='cd /media/folder1/folder2/.../'

    也可以有同样的效果。

  4. Linux光标移动

    ctrl + a: 行首
    ctrl + e: 行尾

    ctrl + f: 光标右移
    ctrl + b: 光标左移

    esc + f: 右移一个单词
    esc + b: 左移一个单词

  5. Linux mv
    功能
    (1) 修改名称
    (2) 移动文件

  6. Bash
    (1) 注释: #
    (2) #!/bin/bash的意义
    #代表是个注释,但是#!并不是注释了,它用来指明这个脚本所需要的Shell
    (3) shell变量类型
    变量类型只有字符串

  7. caps -> ctrl(reference 32)

  8. Download video in CLI
    (1) you-get
    (2)youtube_dl

  9. du(disk usage)

  10. ctrl + u: 从光标处删除文本直到行首

  11. ctrl + k: 从光标处删除文本直到行尾

  12. alt + f: 向后一个单词

  13. alt + b: 向前一个单词

  14. 重复使用上一个命令: !!

  15. dstat
    View the net speed in late 10 seconds and other functions.

  16. Symbolic links

  17. I/O redirection

    I/O redirection allows us to change where output goes and where input comes from. Normally, output goes to the screen and input comes from the keyboard, but with I/O redirection we can change that.

  18. The Letter-Based Method

    In addition to the method described above there is a second way to change permissions. Chmod uses either the hexadecimal representation of the permissions or a letter-based representation. The letter-based representation is [ugoa][+-][rwx]. This is one of the letters u (user=file owner), g (group), o (others), a (all users, groups and others); followed by + or - to add or remove permissions; and then the symbolic representation of the permissions in the form of r(read) w(write) x(execute). To extend Write permissions to all for the file “file.txt”,

    For example, you would type:

    1
    chmod a+w file.txt
  19. uptime
    Tell how long the system has been running.

  20. Change user

    1
    su [username]

    退出此用户: exit

  21. Add user

    1
    2
    useradd [username]
    passwd [username]
  22. Delete user

    1
    userdel [-r] [username]

    -r: remove the home dir of [username]

  23. Print current effective user

    1
    whoami
  24. linux将cpas->ctrl

    (1) Edit /etc/default/keyboard

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # KEYBOARD CONFIGURATION FILE

    # Consult the keyboard(5) manual page.

    XKBMODEL="pc105"
    XKBLAYOUT="cn"
    XKBVARIANT=""
    - XKBOPTIONS=""
    + XKBOPTIONS="ctrl:nocaps"

    BACKSPACE="guess"

    (2) 运行如下命令,设置生效

    1
    sudo dpkg-reconfigure keyboard-configuration
  25. cp 排除某个目录
    例. 有目录b, c, 复制到/f下,排除b

    1
    cp -r !(b) /f
  26. 在linux下弹出u盘命令(假设u盘设备是sdb1)

1
sudo eject -s /dev/sdb1
  1. ccat

内置的cat查看命令没有语法高亮,但是使用ccat可以有这个作用。

下载二进制代码文件

1
wget https://github.com/jingweno/ccat/releases/download/v1.1.0/linux-amd64-1.1.0.tar.gz

解压
1
tar xfz linux-amd64-1.1.0.tar.gz

ccat文件复制到/usr/local/bin/文件夹下
1
cp linux-amd64-1.1.0/ccat /usr/local/bin/

使用ccat命令查看文件会发现文件显示变成彩色的了。

  1. ssh & public key

(1) 本地生成公钥

1
ssh-keygen -t rsa

之后全部默认回车即可。

(2) 将本地公钥~/.ssh/id_rsa.pub复制到远程主机~/.ssh/autoorized_keys文件中,如果目录和文件皆不存在,直接创建新的文件。
(3) 重启ssh服务

1
service ssh restart

之后与主机相连就不必再输入密码。

  1. ls-S选项

    sort by WORD instead of name: none (-U), size (-S), time (-t), version (-v), extension (-X)

准确来说就是将文件从大到小进行排序。

  1. tab

(1) 命令补全: tab接在一串指令的第一个字的后面
(2) 文件补齐: tab接在一串指令的第二个字的后面

  1. find
1
$ find dir_name -name filename_to_be_searched
  1. 在 bash 里,使用 Ctrl-R 而不是上下光标键来查找历史命令。
  2. 使用 man ascii 来查看 ASCII 表。
  3. 命令行注释命令: alt + #

Linux各目录

etc

  1. 含义: and so on
  2. 功能: 存放零零碎碎的东西

linux各种解压命令汇总

.tar.xz

1
2
$xz -d filename.tar.xz
$tar -xvf filename.tar

tar.gz

1
tar -zxvf xxx.tar.gz

.rar

1
unrar e file.rar # e: 解压压缩包中的全部问价至文件夹

今天因要下载win10 iso文件,奈何文件太大,只好利用winrar软件将4g的iso文件分成了4个1g的小文件,转到linux下后,直接将4个小文件提取了出来,但问题是4个提取出来的文件并没有合并在一起,这可不是我想要的结果,百度一查,赶紧在linux安装了rar,只需用rar e name.part1.rar,提取后的文件就是合并后的文件了。


Problems

在ubuntu19.01上安装curl出现问题curl : Depends: libcurl4 (= 7.58.0-2ubuntu3.8) but 7.65.3-1ubuntu3 is to be installed

问题如下

1
2
3
The following packages have unmet dependencies:
curl : Depends: libcurl4 (= 7.58.0-2ubuntu3.8) but 7.65.3-1ubuntu3 is to be installed
E: Unable to correct problems, you have held broken packages.

解决方法:

1
sudo apt-get purge libcurl4

接下来就可以正常安装curl了。

linux升级gdb

gdb官网下载太慢,清华大学镜像站可以下载