zoukankan      html  css  js  c++  java
  • linux常见终端命令和一些小问题的解决

    此文章为linux常见终端命令汇总和一些小问题的解决方法,会不定期更新。

    [常见指令]

    1. 误按 Ctrl+s 锁住终端。

        ubuntu16命令行误按 Ctrl + s 导致终端锁定,很多文章都说可以按 Ctrl + p 解锁,但我在ubuntu上试了很多次无法解锁,后来发现 Ctrl + c 可以解锁。

    2. 查看当前目录下所有文件总大小:

        du -sh (-sh中的h为自动选择单位K/M/G,想要查看精确大小只需 -s)

    3. 查看当前目录下文件数量:

        ls |wc -w

    4. 查看系统实时资源使用情况:

        top

    5. 查看CPU个数:

        grep 'physical id' /proc/cpuinfo | sort -u

    6. 查看CPU核心数:

        grep 'core id' /proc/cpuinfo | sort -u | wc -l

    7. 查看CPU线程数:

        grep 'processor' /proc/cpuinfo | sort -u | wc -l

    8. 查看当前登录用户名

        whoami

        可以用在shell脚本判断当前运行者的身份,以找到用户目录。root-/root; user-/home/username/

    9. 树莓派查看系统版本

        lsb_release -a

        Codename对应的一项就是系统版本

    10. zip 文件解压

        unzip 压缩包.zip -d 解压路径

    11. ubuntu终端粘贴复制

        常用的Ctrl+c 和 Ctrl+v 命令在ubuntu终端无法使用,可以使用鼠标右键进行粘贴复制,也可以使用快捷键Ctrl+shift+c 复制,Ctrl+shift+v 粘贴。

    12. 时间戳相关

        转换指定日期为Unix时间戳:

            date -'2020-12-30 10:23' +%s     (-> 1609294980)

        Unix时间戳转换为日期时间:

            date -@1609294980     (->2020年 12月 30日 星期三 10:23:00 CST)

            指定格式转换:

            date -@1609294980 +"%Y-%m-%d %H:%M:%S"     (->2020-12-30 10:23:00)

        来源:https://www.cnblogs.com/openstack-elk/p/6825888.html

    13. 快速清空一个文件

        echo -n > 文件名

    14. 向文件中写内容

        覆盖:

            echo "内容" > 文件名

        追加并换行:

            echo "内容" >> 文件名

    [问题解决]

    1.windows和linux文件格式不兼容。在windows上创建了文件,再在linux上打开,经常会提示如"aaa^M,未识别的符号"等问题。

        解决:使用vi编辑器打开文件,输入":set ff=unix",之后保存退出":wq",就不会报错了。

    2. vim实现字符串全局替换

        输入":%s/原字符串/新字符串/g",之后保存退出":wq"。

    3. 备用工具 atitude,自动解决依赖问题,可当作apt的备用版本

        安装:sudo apt-get install atitude

        使用:sudo atitude install 应用

                   sudo atitude remove 应用

    4. ubuntu桌面卡死

        ctrl+alt+F1(F2/F3..)切换tty终端

        命令行输入:sudo pkill Xorg 或 sudo restart lightdm

        解决方案来源:https://www.cnblogs.com/mrcharles/p/11879734.html

  • 相关阅读:
    PAT (Advanced Level) 1010. Radix (25)
    PAT (Advanced Level) 1009. Product of Polynomials (25)
    PAT (Advanced Level) 1008. Elevator (20)
    PAT (Advanced Level) 1007. Maximum Subsequence Sum (25)
    PAT (Advanced Level) 1006. Sign In and Sign Out (25)
    PAT (Advanced Level) 1005. Spell It Right (20)
    PAT (Advanced Level) 1004. Counting Leaves (30)
    PAT (Advanced Level) 1001. A+B Format (20)
    PAT (Advanced Level) 1002. A+B for Polynomials (25)
    PAT (Advanced Level) 1003. Emergency (25)
  • 原文地址:https://www.cnblogs.com/brian-sun/p/13652782.html
Copyright © 2011-2022 走看看