[Youtube学习笔记]Linux的50个实用指令



  • 50 Most Popular Linux and Terminal Commands

    这篇文章的内容主要来源于Youtube视频The 50 Most Popular Linux & Terminal Commands - Full Course for Beginners
    建议大家可以follow一下这个博主来支持。

    另外,推荐这个网站 Linux Commands Handbook,里面有可以查询的Linux指令。

    为什么要掌握这些指令呢?

    • 更好地控制你的电脑
    • 运行速度很快
    • 可以自动化很多工作

    操作系统

    Linux和Mac都来源于一个叫做Unix的操作系统,因此可以指令基本是通用的。但是Windows有一套自己的系统。
    Linux本身是指一个Kernel, Kernel就是链接application和CPU / Memory的东西。

    在Windows上安装LInux

    windows一般是不可以直接用Linux指令的,但是现在我们可以用下面的命令来在Windows里面安装一个小的Linux系统。
    wsl --install

    电脑上用管理员权限运行 PowerShell (不是 PowerShell(86) )
    d6bff47b-27ca-49d2-9849-8ed9d5144ffa-image.png

    重启电脑后就可以搜索到一个叫做Ubuntu的程序
    1ea47f79-a9d6-4e27-8e12-fd1603444a05-image.png
    打开这个程序后,需要自定义用户名和密码(用户名需要是小写英文)
    然后就可以在这里运行Linux指令啦

    为了更好地运行这些不同的Shell,可以安装一下Windows Terminal。(免费软件,在Microsoft Store里面可以安装)
    安装后,它可以允许我们自定义运行命令的背景等等。如果我们要运行一个Windows Powershell,可以点击加号,有不同的Shell可供选择
    f9e555c7-6ba9-43e3-b063-622046ae4582-image.png

    Basics

    一些基本指令

    whoami 'print the username
    man <command> 'open a manual for that command
    man whoami
    clear 'clear the terminal screen
    clear -x 'clear the terminal screen but remains the history
    pwd 'print working directory
    ls 'list a contents of the current folder
    ls <target folder path> 'list the contents for a target folder
    
    ls -l 'long format of files. (with file names etc)
    ls -a 'does not hide files starting with .
    cd 'change directory
    cd .. 'Go back to previous folder
    cd ~ 'Go to the folder with username
    help <command> 'the help file for any command
    

    Linux File Structure.

    All absolute path starts with /

    In the home folder, for all users using this machine, there will be a username for him/her
    26f7270d-850d-4d1b-a2ea-d7bcf0dc8eb3-image.png

    mkdir 'make a directory
    mkdir a b 'make two folders
    mkdir -p a/b 'create parent directory when necessary
    touch 'change file timestamps. if a file does not exist, it creates this file for us
    touch 
    rmdir 'remove a directory (only for empty )
    rm 'remove a file
    rm -rv <folder> 'recursively delete all files in a folder
    rm -V 'print the output
    
    open 'open a file or folder (mac only)
    open . 'open the current directory
    xdg-open 'open command in linux
    
    mv 'move files
    cp 'copy a file or folder
    cp -r 'copy recursively for files in a folder
    
    head 'output the first part of files
    head <filename> -n <number> 'n is for the number of lines to output
    tail 'output the last part of files
    
    date 'prints out the current date
    date > today.txt 'output the current date to today.txt
    date >> today.txt 'appending to a file instead of rewrite it
    cat
    

Log in to reply