ZEROCATH

身无长物江湖远,胸有沟壑天地宽

0%

Linux--命令行基本用法

ref:
https://www.taniarascia.com/how-to-use-the-command-line-for-apple-macos-and-linux/

command line for macos and linux

synatx

the terminal usually is:

Computer Name : Directory UsernameREADY

  • computer name : name of your computer
  • Directory( ~ ):directory next to the computer name is the current directory you’re working in,” ~ “ stands for the home directory
  • READY$:”$”means the prompt is ready to accept your command.on windows it is represented by “>”

command

  • you can end a command at any point by pressing ctrl+c
  • if you quit Terminal,you will end up back in your home directory

    pwd

print working directory,shows where i am at any point
- always remember to type pwb before typing any commands to make sure you know where you are

ls

list directory contents,prints the subfiles at where i am

clear

clear the terminal screen

cd

change directory: move to another directory

- the terminal will open a directory regardless of whether it is capital or not
- one dot(.)represents the current directory
- two dots (..) represent one directory backwards
- (../..)takes you two directories back

about space

if the name of the directory you’re about to move to has spaces

  • type a ‘' before each space
  • use “Directory Name”
  • simply type (cd A) and press tab,the shell will assume what you want to type

mkdir

make directory:create a new directory

touch

create a new file,and you can create multiple files at a time

echo

create a file with some content

quickly print text to a file

1
$echo "hello world">hello.txt

cat

view contents of a file

rm

remove a file,it will permanently delete the file(won’t send to the Trash bin)

can remove multiple files at a time

rm -r

remove a directory with files

rmdir

remove a directory with no files

cp

copy and paste files

1
$ cp source destination
  • destination can be a directory

you can also duplicate a file in the same folder

cp -R

copy an entire directory

mv

1
$ mv source destination

move(cut and paste)files and directories

&&

to run multiple commands

chmod

change mode

1
$ chmod 644 test.html

644:read and write by owner

  • sudo:Super User DO:

if you do not have sufficient permissions to perform a task,you can precede a command with sudo to run the command as administrator

1
2
$sudo su //log in as the super user
$exit //return to the regular account

ssh

Secure SHell:connect to another computer or server

  • using exit to return to your own computer

whoami

return the username of your computer

dig

DNS Lookup:check the IP address of a given domain when migrating a website

man

Manual:check the help guide

  • press q to exit the manual pages

nano

use nano command to open a file with Nano(a simple text editor)