One, file view

Note: First check whether you are in the correct directory

1. Press CTRL + C to terminate the command

2. View the command:

  • PWD: Displays the absolute path of the directory

  • Ls: View the contents of the directory

  • Ls + path: Displays the contents of the specified directory

3. View file contents:

  • The cat + path

  • Head + path: The first ten lines are displayed by default

    You can view the first N lines in the head path -n(a number)

  • Tail + path: The last ten lines are viewed by default

    You can view the last N lines with the tail path -n(a number)

  • Less + path: If the file content is large, use less rather than cat. You can view the file page by page

4. Exit view: Press Q(quit)

2. Document addition

1. Create file:

  • Touch 1.txt (create 1.txt file)

  • Echo hi > 1.txt (add hi to 1.txt)

  • Echo hihi >> 1.txt (add hihi to 1.txt)

  • Echo -e “1\n “>>1.txt

  • Touch 1.txt 2.txt (create multiple files)

2. Create directory:

  • Mkdir a (create directory a)

  • Mkdir -p a/b/c/d/e

  • Kdir a b create multiple directories a b

3. Copy files:

  • cp 1.txt 2.txt(copy 1.txt file to 2.txt)

4. Copy the directory:

  • cp -r a b

3. File deletion

1. Delete files:

  • rm 1.txt(delete 1.txt file)

2. Delete a directory:

  • Rm -r a or RM -rf a(Delete directory a)

Iv. File modification

1. Empty the file:

  • echo "" > 1.txt

2. Move files:

  • The mv 1. TXT directory(Move 1.txt to directory)

3. Rename files:

mv 1.txt 2.txt

4. Update file modification time:

Run the ls -l command to view the update time of the file

Touch file name (update file modification time)

Fifth, help

NPM i-g TLDR or YARN Global add TLDR

You can use TLDR to view common commands

6. Combine commands

(1) && : The next command is executed only after the current command is successfully executed

Eg: rm 1. TXT && echo Succeeded

(2); : The next command is executed regardless of whether the previous command is executed successfully

Eg: the rm 1. TXT. Echo Completion

Turn your commands into documents

  1. Create a file, the suffix does not matter, can not have

Touch run (create file named run, no file suffix)

  1. code run(Open the run file with VSCode)

In VSCode, type:

#! /usr/bin/env sh (shebang, specifies what program to run the current script with)

Mkdir $1 ($1 accepts the passed argument)

cd $1

touch index.html

touch style.css

touch main.js

echo -e "<! DOCTYPE HTML >\n<h1> Title <\h1>" >> index.html

Save and close the file

  1. Add executable permission (Windows can skip)

chmod + x ./run

  1. ./run XXX (must add./ to create a directory named XXX) or sh run XXX (create a directory named XXX)

  2. You can use the file name as the command if you put the directory of the executable in path