Linux basic commands (note 1)

  • 2020-05-13 04:13:38
  • OfStack

For those of you who just started learning linux, you must learn linux's common commands first. The details are as follows:
1. Linux startup level [linit n]

0 - system shutdown status

1 -- single user working status

2 -- multi-user status (no NFS)

3 -- multi-user status (with NFS)

4 -- the system is not in use and is left to the user

5 -- graphical interface

6 -- the system is normally shut down and restarted

The command

Commands related to files and directories. & shy;

ls [listing the contents]

ls-L //d start directory, -start file, vertical column ls, m // horizontal columns ls, R // tree-like columns / /... The paging

cd [absolute and relative paths]
. // represents the current path

pwd [current path] ­

whoami [current user]

mkdir [create a directory]

-m: set access rights to the new directory, or use the chmod command; -p: can be 1 path name. At this point, if some directories in the path do not exist, plus this option, the system will automatically set up those directories that do not exist, that is, one can set up more than one directory; If it exists, nothing is done, that is, existing folders are not overwritten. mkdir -p ./js/login

rmdir [delete directories, only empty directories can be deleted]

rm [delete directory or file]

rm-r file name // recursively deleted rm-rf directory name // recursively deleted, no "ask" rm -rf *.js // delete all js files

touch [create file]

cp [copy]

cp 1.txt 2.txt // make a copy of 1.txt under the current directory named 2.txt cp-r d1 d2 // copy the current directory d1 and name it d2

mv [moving files]

mv 1.txt path // move the file mv d1 path // move directory

vi [edit file; there are two modes, edit mode and command mode; enter command mode by default]

Command mode:

a append dd removes 1 row dw delete 1 word o inserts 1 row down O inserts 1 row up i goes into insert mode : w inventory : q exit : q! Exit without saving :wq

Edit mode:

Esc goes into command mode

Display file contents

More 3.txt Cat 3.txt tac 3.txt 3. 3.txt [previous n line] tail-n 3.txt

ln [link file; split into soft and hard links]

ln 3.txt 3.link.txt [2 is two independent files, but synchronously updated, delete any one file, will not affect the other file] ln-s 3.txt 3.link.txt

whereis ls [query the ls command, e.g., call file, help document]

echo $PATH

find/etc-name my* [find files in the etc directory that begin with my]

Create mount point: mount

mount device hardpoint

A device is a specific file system that can be represented by a device name or volume label name The hardpoint must be an existing directory. If a file originally exists in the directory, the original file is temporarily inaccessible after the file system is mounted. Until the mounted file system is unmounted. We generally use an empty directory in the /mnt directory as the mount point. The user can check the current mounted file system by directly typing mount and hitting enter Users can also view the currently mounted file system by viewing the /etc/mtab file

sudo mount /dev/cdrom /mnt/cdr
# Ubuntu the cdrom directory 1 As for the "/dev/cdrom"

Unmount mount point: umount

umount devices/hardpoints


sudo umount /dev/cdrom
sudo umount /mnt/cdr

The two lines above do the same thing

The concept of users and groups

useradd kang [add kang user] passwd kang [add password for kang user] userdel kang [delete kang user] groupadd student [add student group] groupdel student [delete student group, if any user in the group cannot delete directly] usermod -g student kang [move kang users to student group] useradd kang g student [new kang user group is student] su kang exit

File permissions

- rw - r - r -

r [read] w [write] - [no permission] x Divided into 3 groups, 3 groups 1 Group 1: file owner Group 2: others in the same group Group 3: others

chmod [modify file permissions]

chmod +x 4.txt [add executable permissions to all users, for 4.txt] chmod u+x 4.txt chmod g+x 4.txt 4. chmod o+x

Learn to chamod 755

111|101|101

n chown kang 4.txt

Permission Settings: chmod

chmod [-R] permission file name


  chmod  777 *.js    # All in the current directory ".js" The permissions of the file have been changed to "777"
  chmod  777 ./css/   # In the current directory "css" The permissions of the folder have been changed to "777" , but permissions for subfolders and subfiles are not convenient 
  chmod  777 ./css/*  # In the current directory "css" All the" 1 The permissions for level 2 folders and files have been changed to "777" , but css Folder permissions remain the same 
  chmod -R 777 ./css/   # In the current directory "css" Permissions for folders, subfolders, and subfiles are changed "777"

Piping and others

ls, l /etc |, more

[paging display vertical file directory] Hand over the output from the last run to the next command

cat /etc/passwd | grep student1

grep student 4.txt [find lines with student characters in file 4.txt]

wc [count the number of lines and words in a document]

wc -l

En 291en-l | grep "^-" | wc, l

wall "My Name Is Kang!"

wall `date`

Related articles: