English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic Commands of Linux (Note 1)

Many friends who are just starting to learn Linux are definitely going to need to learn the common Linux commands before getting into Linux. I have just organized them recently. Specifically as follows:
1、Linux startup level [linit n]}

0—System shutdown state

1—Single-user working state

2—Multi-user state (without NFS)

3—Multi-user state (with NFS)

4—System not used, left for users

5—Graphical interface

6—System normal shutdown and restart

 Command

Commands related to files and directories­­

ls [List directory]

  • ls -L    //d starting directory,-List files starting with, vertically listed
  • ls –m   //List horizontally
  • ls –R   //List in tree structure
  • //…. Page through

cd [Absolute path, and relative path ]
..      //Represents the current path

pwd [Current path]­

whoami [Current user]

mkdir [Create directory]

  • -m: Set access permissions for the new directory, or you can also use the chmod command to set;
  • -p: Can be a path name. If some directories in the path do not exist, adding this option will cause the system to automatically create those non-existent directories, that is, multiple directories can be created at one time; if it exists, no action will be taken, that is, it will not overwrite the existing folder.
  • mkdir -p ./js/login

rmdir [Delete directory, can only delete empty directories]

rm [Delete directory or file]

  • rm  -r  File name   //Recursive deletion
  • rm  -rf  Directory name  //Recursive deletion, without 'ask'
  • rm  -rf  *.js   //Delete all js files

touch [Create file]

cp [Copy]

  • cp  1.txt  2.txt   //Copy the directory d under the current directory1.txt copy a copy named2.txt
  • cp  -r  d1  d2      //Copy the directory d under the current directory1Copy the directory to a new directory named d2

mv [Move file]

  • mv  1.txt  Path     //Move file
  • mv  d1   Path   //Move directory

vi [Edit file; there are two modes, edit mode and command mode; the default is to enter command mode]

Command mode:

  • a  append
  • dd  Delete a line
  • dw  Delete a word
  • o  Insert a line below
  • O  Insert a line above
  • i  Enter insert mode
  • :w  Save
  • :q  Exit
  • :q!  Exit without saving
  • :wq  Save and exit

Edit mode:

  • Esc  Enter command mode

Display file content

  • More    3.txt  [Page through the file]
  • Cat    3.txt  [Normal order]
  • tac    3.txt  [Reverse order]
  • head    -n    3.txt  [The first n lines]
  • tail    -n    3.txt  [The following n lines]

ln [Link file; divided into soft links and hard links]

  • ln   3.txt   3.link.txt 
  • Both are independent files, but they are synchronized updates. Deleting any file will not affect the other file
  • ln   -s   3.txt   3.link.txt [Equivalent to a shortcut, synchronized update, actually a file]

whereis ls [Query the relevant content of the ls command, such as the called file, the help document]

echo $PATH [View environment variables]

find  /etc   -name my*[Find files starting with my in the etc directory]

Create mount point: mount

mount device mount point

  • The device refers to a specific file system, which can be represented by the device name or volume label
  • The mount point must be an existing directory. If there are files in the directory, they cannot be accessed temporarily after the file system is mounted. Until the mounted file system is unmounted.
  • We usually use/An empty directory under the mnt directory is a mount point.
  • Users can check the currently mounted file system by directly entering mount and pressing Enter
  • Users can also check/etc/mtab file to view the currently mounted file system
sudo mount /dev/cdrom /mnt/cdr
# The cdrom directory of Ubuntu is usually "/dev/cdrom"

Unmount mount point: umount

umount [Parameter] device/Mount point

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

# The above two lines of code perform the same function

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 the student group]
  • groupdel student [Delete the student group, if there are users in the group, they cannot be deleted directly]
  • usermod   -g student kang [Move kang user to the student group]
  • useradd kang  -g student [The group kang user belongs to is student]
  • su kang [Switch user login] exit [Return]

File permissions

 -rw-r--r--

  • r [Read] w [Write]   -[No permissions] x [Execute, run]
  • Divided into three groups, three in a group
  • First group: file owner
  • Second group: group members
  • Third group: others

chmod [Modify file permissions]

  • chmod   +x    4.txt group members to add executable permissions for4.txt
  • chmod u+x   4.txt owner
  • chmod g+x   4.txt group members
  • chmod o+x   4.txt [Others]

Learn chamod   755   4.txt

                111|101|101

n chown kang   4.txt [Change file owner]

Permission Setting: chmod

chmod [-[R] Permission Filename

  chmod  777 *.js	#Permissions of all ".js" files in the current directory are changed to "777"
  chmod  777 ./css/   #Permissions of the "css" folder in the current directory are changed to "777" but the permissions of its subfolders and subfiles are not changed
  chmod  777 ./css/*  #Permissions of all "first-level folders and files" in the "css" folder in the current directory are changed to "777" but the permissions of the css folder remain unchanged
  chmod -R 777 ./css/   #Permissions of the "css" folder, its subfolders, and subfiles in the current directory are changed777"

Pipe and others

 ls –l   /etc | more

  • [Paging display of vertical file directory]
  • Pass the output of the last command to the next command to execute

cat   /etc/passwd | grep student1

grep student   4[In the file .txt]4[Find lines containing the character 'student' in .txt]

wc [Count the number of lines and words in the file]

  • wc  -l [Line number]

ls  -l | grep "^- | wc –l [Count the number of files in the directory below]

wall “My Name Is Kang !”

  • wall `date`

That's all for this article. Hope it helps everyone's learning and also hope everyone will support the呐喊 tutorial more.

Declaration: The content of this article is from the Internet, the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, does not undergo human editing, and does not assume relevant legal responsibility. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)

You May Also Like