一些Linux的使用

2020/05/03

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

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

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

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

    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
  8. 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.
  9. Change font size in terminal

    Change bigger = ctrl - Change smaller = ctrl +

  10. Rename

    将test.jpg改成test1.jpg

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

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

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

    接下来保存退出

    source dd.sh
    

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

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

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

    也可以有同样的效果。

  12. Linux光标移动

    ctrl + a = 行首 ctrl + e = 行尾

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

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

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

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

  15. caps -> ctrl(reference 32)

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

  17. du(disk usage)

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

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

  20. alt + f = 向后一个单词

  21. alt + b = 向前一个单词

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

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

  24. Symbolic links

  25. 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.

  1. 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

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

  3. Change user

    su [username]
    

    退出此用户: exit

  4. Add user

    useradd [username]
    passwd [username]
    
  5. Delete user

    userdel [-r] [username]
    

    -r = remove the home dir of [username]

  6. Print current effective user

    whoami
    
  7. linux将cpas->ctrl

    (1) Edit /etc/default/keyboard

    # KEYBOARD CONFIGURATION FILE
    
    # Consult the keyboard(5) manual page.
    
    XKBMODEL="pc105"
    XKBLAYOUT="cn"
    XKBVARIANT=""
    - XKBOPTIONS=""
    + XKBOPTIONS="ctrl =nocaps"
    
    BACKSPACE="guess"
    

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

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

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

    sudo eject -s /dev/sdb1
    
  10. ccat

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

    下载二进制代码文件

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

    解压

    tar xfz linux-amd64-1.1.0.tar.gz
    

    ccat文件复制到/usr/local/bin/文件夹下

    cp linux-amd64-1.1.0/ccat /usr/local/bin/
    

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

  11. ssh & public key

    (1) 本地生成公钥

    ssh-keygen -t rsa
    

    之后全部默认回车即可。

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

    service ssh restart
    

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

  12. ls-S选项

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

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

  13. tab

    • 命令补全 = tab接在一串指令的第一个字的后面
    • 文件补齐 = tab接在一串指令的第二个字的后面
  14. find

    $ find dir_name -name filename_to_be_searched
    
  15. 在 bash 里,使用 Ctrl-R 而不是上下光标键来查找历史命令。

  16. 使用 man ascii 来查看 ASCII 表。

  17. 命令行注释命令: alt + #


Linux各目录

/etc

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

linux各种解压命令汇总

.tar.xz

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

tar.gz

tar -zxvf xxx.tar.gz

.rar

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

问题如下

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.

解决方法:

sudo apt-get purge libcurl4

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

linux升级gdb

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


  1. https://www.cnblogs.com/guochaoxxl/p/10428991.html ↩︎