Linux basic commands

Source: Internet
Author: User
Tags builtin parent directory readable

Linux basic commands.

Linux is strictly case-sensitive

Categories of commands:

commands that the internal command shell implements in internal code

Man type view commands from bash shell

commands other than external command shell

View internal or external commands with the type command

Type CD hint CD is a shell builtin the instructions are internal commands

Type mount tip Mount Is/bin/bash tells the location of the external command

-------------------------------------------------------------

Help commands

Man focuses on application and is the most common help method

Where the man's help document is stored

/usr/share/man

Help for man document classification

1 General User commands

2 function tools for system core calls

3 Common functions and libraries

4 description of the device file

5 configuration files with some other format files

6 games related

7 Network protocol related

8 Administrator-Actionable commands

9 System kernel-related files

In the man help:

/C Search Keywords

N Next keyword

N a keyword above

Q exit

Info focuses on introductions, not commonly used

Help document where to store

/usr/share/info

Enter the Help screen

? Info Command Help

SPACEBAR to turn down one page

tab moves between nodes, where nodes are usually displayed with a *, move the cursor to the node position and press ENTER to enter the node.

b move the cursor to the first node of the article

E move the cursor to the last node of the article

n Go to the next info page

P go to the previous Info page

U Move up one layer

S (/) search in Info

H Display Help Menu

Q exit

-------------------------------------------------------------

Directory commands

PWD View the path to the current directory

CD Switch current directory

Absolute path

Cd/root/desktop refers to the path starting from the root directory

Relative path

CD root/refers to the path starting with the current directory

. Represents the current directory

.. Represents the current parent directory

-Represents the last directory in which it was located

~ Represents the home directory of the currently logged in user

mkdir Creating a Directory

mkdir test to create the test directory under the current directory

Mkdir/tmp/test Create the test directory in the TMP directory under the root directory

mkdir file{1..100} Creates a directory of File1 to file100 in the current directory, where 100 directories are created

mkdir "file{1..100}" in the current directory to create file{1..100} directory, where only one directory is created

Mkdir-p a/b/c Create a/b/c directory tree in current directory

RmDir only empty directories can be deleted

RmDir test deletes the current directory's test directory, test must be an empty directory

Rmdir/tmp/test Delete the test directory under/tmp

RmDir file{1..100} Delete file1 to file100 directory

RmDir "file{1..100}" delete file{1..100} directory

-------------------------------------------------------------

File commands

LS lists all files under the current folder

LS-A lists all files in the current directory, including hidden files

Ls-l lists all files in the current directory as a detailed list

Ls-r list all files in the current directory, including all files within subdirectories

Drwxr-xr-x 1 root root 2062 2011-01-04 file1

File type and file permissions file the hard-link number of files to which the user file belongs to user group file size file last Modified Date file name

File type: the

C-Character device

B-Block Equipment

L Symbolic Link

s socket file

P Pipeline File

D folder

-Normal file

Common collocation:

Ls-al Show all files including hidden files list

LS-LT displays a list of files sorted by date time

LS-LH displays a list of files with a calculated size of KB

LS-DL Show folder details list

Touch New File

Touch file creates file empty files and updates file access and modification times if file exists

Touch-c file does not create files if it does not exist

Touch-r file1 file Update file time and File1 same

TOUCH-A file update access time for file

TOUCH-M file Update modification time for file

Touch file{2,3,4} creates file2,file3,file4 three empty files at a time

Touch "file{2,3,4}" create file{2,3,4} an empty file

CP Copy File

CP file dirs/Copy the file files to the dirs directory

Cp-r dir1/dir2/Copy the Dir1 directory to the DIR2 directory

Cp-a file dirs/copy files to dirs directory, preserving the original properties

CP-RF dir1/dir2/Force Copy folder, do not prompt

CP-RVF dir1/dir2/copies the Dir1 directory to the DIR2 directory and displays the copy process

MV Move and rename files

MV file dirs/to move the file files to the dirs directory

MV file file2 rename file to File2

Mv-u dir1/* dir2/Move all the files under the Dir1 directory to the Dir2 directory and decide whether to move them according to the file time

Rename batch file renaming

Rename. conf. html *.conf All suffixes appear in the. conf file name. The conf is changed to. html

RM Delete File

RM file* Delete all files that begin with file

Rm-i file* prompt to determine whether to delete

Rm-f file* do not prompt, forcibly delete

Rm-r Dir2 Deleting a directory

-------------------------------------------------------------

File Read command

Cat File View Commands

CAT/ETC/PASSWD Viewing/etc/passwd content

Cat-n/etc/passwd View/etc/passwd content and number

Cat-b/etc/passwd viewing/etc/passwd content and numbering non-blank lines

More

MORE/ETC/PASSWD View/etc/passwd file contents by screen

Less

LESS/ETC/PASSWD View/etc/passwd file contents, and more different is can scroll up and down

Head

HEAD/ETC/PASSWD View/etc/passwd Top 10 lines of content

Head-n 30/ETC/PASSWD See the top 30 lines of/etc/passwd

Tail

TAIL/ETC/PASSWD view after/etc/passwd 10 lines of content

Tail-n 30/etc/passwd View 30 lines of content after/etc/passwd

Tail-f/etc/passwd View/etc/passwd file contents in real time

redirect

Standard input code 0 default device is keyboard

Standard output Code 1 default device is screen

Error input code 2 default device is screen

LS/ETC/PASSWD > output.txt standard correct output redirect to Output.txt

Ls/etc/shadow >> output.txt standard correct output append redirect to Output.txt

LS dddddd 2> error.txt standard error output redirected to Error.txt

LS dddddd 2>/dev/null standard error output redirected to Black hole

LS ddddd/etc/passwd &>/dev/null standard correct output standard error output all redirected to Black hole

Pipeline

cat/etc/passwd | Less | The results of the previous command execution | parameters of the POST command

==========================================

User Management

User Category

Administrator user ID must be 0, must be unique

System user pseudo user, user ID 1-499, default is not allowed to log on to the system, to give some services to use the identity of the runtime

User ID 500-60000 for normal user, by manual or all command set up users, by default can log on the system

User Management

User-related profiles

/etc/passwd

/etc/shadow

vim/etc/passwd

First column: User name

The second column: password x for the password is stored in the/etc/shadow, if the x is removed on behalf of the user does not have a password

Third column: UID User ID value operating system is not aware of the user name, only the UID

Third column: GID, ID of the user group

Fifth Column: Description item

Sixth column: Specify home directory

Seventh column: Specify bash

Vim/etc/shadow

First column: User name

The second column: The real password, encrypted, to * or both! Cannot log in

Column three: The last time the password was modified, Linux is counted from January 1, 1970 to the current number of days

Fourth column: Change the password within a few days after the change is not allowed, 0 means no Limit

The fifth column: How many days must change the password, 99999 represents does not limit

Sixth column: give you a warning message a few days before expiration

Seventh column: A wide time limit after password expiration

The eighth column: here can write a real account expiration date, also from January 1, 1970 to the present count, more for the toll system

Nineth column: Reserved, save later feature extension

User command related configuration file, save Useradd command to create default values used by user

/etc/default/useradd

/etc/login.defs

User-related commands

Useradd/adduser

Userdel/deluser

Usermod

passwd

Useradd a creates a user

Useradd-g Kyo a Create a new user and add a user to the Kyo user group

Userdel a Delete a user

Userdel-r a deletes a user and deletes A's home directory and Mail directory

passwd A modify a user password

Passwd-l a temporarily closes the user, or modifies the/etc/shadow second field plus *

Passwd-u a release a temporary shutdown user

Usermod Modifying user information

-U Modify UID

-G Modify GID

-D refers to its home directory

-S refers to using bash

Usermod-g Kyo A adds a user to the Kyo user group

Commands related to user information

CHFN Modify a user-related information

Finger viewing a user-related information

Group Management

Related configuration Files

/etc/group

/etc/gshadow

Vim/etc/group

First column: Group name

Second column: password, x for password in/etc/gshadow

Column three: GID

Fourth column: Represents the user name belonging to this group

Vim/etc/gshadow

First column: Group name

Second column: password

Column Three: Group admins

Fourth column: Group members

Related commands

Groupadd Adding a new user group

Groupdel Deleting a user group

Groupmod Modifying user group information

GPASSWD Modifying user group passwords

Gpasswd-a A root puts a user in the root user group

Gpasswd-a A root puts a user in the root user group and as an administrator

gpasswd-d A root removes a user from the root user group

NEWGRP Root temporarily adds the current user to the root user group and re-login fails

ID Displays the user's ID and group ID

User Identity Switch

Su-a completely switch, do not inherit the environment variables of the previous user, that is, the command under the Sbin directory does not work

Su A does not switch completely, inherits the environment variable of the previous user, can use the command under the Sbin directory

Create a user manually

First step: Add a line of information to the/ETC/PASSWD

Bean:x:534:603::/home/bean:/bin/bash

Step Two: Add a line of information to the/etc/shadow

Grub-md5-crypt Create a MD5 password, replace the password below two!! Position

Bean:!! : 15035:0:99999:7:3::

Step three: Add the group information in/etc/group

bean:x:603:

Fourth step: Add the password information of the group in/etc/gshadow

Bean:!::

Fifth step: Create a home directory

Mkdir/home/bean

Sixth step: Copy the user's environment variable file to the home directory

cp/etc/skel/.bash*/home/bean

Chown bean:bean/home/bean/-R

chmod 700/home/bean/-R

Seventh Step: Create a user's mail file

Touch/var/mail/bean

Chown Bean:bean/var/mail/bean

chmod 660/var/mail/bean

================================================================================

Linux Permissions

Ls-l

-rw-r--r--1 root root 4383 2011-03-01 01:37 readme.txt

Owning User Rights u user group permissions G other people rights o

R Read permission

For a folder with R permissions, it represents the right to list this folder

For a file with R permission, it represents the permission to read the contents of this file

W Write permission

For folders with W permission, which represents the ability to create modifications in this folder

For files with W permission, which represents the right to modify the contents of this file

X Execute Execute Permissions

For folders with x permissions, which means that you can switch to this folder

For a file, with X permission, the delegate can run it, the file must be executable or script, etc.

Binary turn octal:

0---

001 1--x

010 2-w-

011 3-WX

4 r--

101 5 R-x

6 rw-

111 7 rwx

RWX, R-x, r-x

7 5 5

-------------------------------------------------------------

chmod commands to modify permissions

chmod u+x,g+r,o-r file to modify the user rights and executable permissions, user groups plus Read permissions, other users minus Read permissions

chmod u=rwx,g=rw,o=r file Modify the user right of the files to read writable, user group is read writable, other users Read

chmod 755 file Modify the user rights of the files to read writable executable permissions, user groups are readable executable permissions, other users are also readable executable permissions

chmod 755 Dirs-r Modify the user rights of all files in the dirs directory are read writable executable permissions, user groups are read and write execution permissions, other users are also readable executable permissions

-------------------------------------------------------------

Chown modify the file to which the user belongs

Chown Tom file modifies the file to which the user belongs to Tom

Chown tom:jack File The user who modifies the files is Tom, the owning user group is Jack

chmod jack.root dirs-r Modify dirs directory All files belong to the user jack, the user group is the root

-------------------------------------------------------------

Umask create a file or folder permission mask by default

Admin default umask is 022

Normal user default umask is 002

The default Create Folder permission is 777, and the mask is set to 022, you subtract the mask, and the default Create folder permission becomes 755

The default Create file permission is 666, and the mask is set to 022, minus the mask, and the default Create file permission is 644

-------------------------------------------------------------

Privilege bit for command file, set setuid, Setgid

Set setuid, setgid for command files

The identity of the command to run is the identity of the runner, before it can be added to the throne.

After the privilege bit has been added, the command is not the identity of the runner, but the owner of the command itself.

Example: passwd touch

Setgid for directory settings

After you set the privileged bit for a group, you create sub-files or subdirectories under the folder that automatically inherit the identity of the group to which the folder belongs, and the subdirectories inherit the privileged bits of the directory

chmod u+s/g+s file sets the privilege bit for file

chmod u-s/g-s file to File de-privileged bit

-------------------------------------------------------------

Paste bit to prevent other users to delete files, for other users, administrators and I can delete, for the directory is valid, the file is not used

chmod o+t dirs Set paste bit for dirs directory

-------------------------------------------------------------

File Special Properties

Lsattr Viewing File Special properties

Chattr Adding or modifying File Special properties

Chattr +i file To add the I attribute, the administrator must not change

Chattr +a file can only append content, must not modify the content, if there is an I attribute, first Cancel to add a property

Chattr-i/-a File Cancellation Special properties

-------------------------------------------------------------------------------

System basic Commands

File View Files Type

Uname viewing the system basic information

-R kernel Version

-S what kernel

-O What operating system

-N What the release version

-M What platform

-A View all information

Cal Print Calendar

Cal 2005 Print 2005 calendar

BC supports extra large number of text calculators

Quit quitting

Date time-of-day command

+%y year

+%m Month

+%d Day

+%h hours

+%m min

+%s sec

......

echo Print string

-N No Line break

-e support \t\n, etc.

Shutdown-r restart

Suutdown-c canceling a scheduled shutdown or restart

Shutdown-p Direct Power off

Shutdown-h shut down the machine

Shutdown-h 30 "shutdown in 30 seconds" schedule shutdown and prompt for all terminals

Init changes the operating level of the system

0 Turn off the machine

1 single-user mode, no user and password authentication

2 text mode without network

3 text mode with a network

4 reserved

5 Mode with graphical interface

6 Restart your computer

RunLevel View current Run level

Sync Sync Disk

Cat/etc/issue viewing Linux system release information

W more detailed display of the online situation

21:55:44 up 1:49, 5 users, Load average:0.38, 0.35, 0.23

USER TTY from [email protected] IDLE jcpu PCPU

Root tty7:0 20:06 1:49m 1:52 0.12s gnome-session

Root pts/2:0.0 20:24 33.00s 0.10s 0.10s Bash

Root pts/3:0.0 21:37 11:18 0.02s 0.02s Bash

User name login terminal from where to log in to login time

Kick off a user who comes in remotely

Ps-aux | grep PTS/5 PTS/5 is a remote login terminal to view the PID of the terminal

Kill-9 3236 3236 is the PID of the PTS/5 found above

Command Category:

Commands for internal commands integrated into shell programs

commands for external commands for standalone executables

Difference method:

which command

If a path represents an external command and cannot be found, it represents an internal command

Type command

If the result shows that the is a shell builtin represents an internal command, otherwise an external command

Help command:

Man external command

Get help information for external commands

Q exit H get man manual help info

The Man Handbook is divided into chapters 1 ~ 8

1 Basic Command Help information

2 system call Function Help information

3 standard library functions Help information

5 Configuration file Help information

8 system administrator Commands help information

Help internal command

Get help information for internal commands

File Operations Command: RM MV CP Touch VIM Gedit

Directory-related commands: cd pwd mkdir rm ls

File Read command: Head tail cat more less

Head to view the number of header rows in the specified file

Head-n 5 File

List the first 5 lines of the file

Tail view the number of lines at the end of a specified file

Cat View all contents of a file

More rows to view the contents of a file

Q End View

Enter to view the next line

Less controllable View File command

Bash Shell provides:

redirect

0 Standard input

1 Standard output

2 Error Output

Output Redirect: > 1> 2> >> 1>> 2>>

Input Redirect: < <<

Pipeline |

Parse the output of the previous command to the following command

----------------------------------------------------

User management (user exists for permission)

Super Admin Root 0

System user 1-499/999 user for system service

More than 500/1000 ordinary users

User-related configuration (super Admin can only modify):

/ETC/PASSWD User Information

/etc/shadow User password information

/etc/group User Group Information

/etc/gshadow User group password information

User-related commands:

ID gets the current logged on user information

SU Switch User

Useradd/adduser adding users

Userdel Deleting a user

Default does not delete user home directory,-R will delete home directory

Userdel-r User Name

passwd Modifying user passwords

Permissions:

View file Details

Ls-l file

-rw-rw-r--. 1 Kyo Kyo 4633 February 11:18 env.txt

-rw-rw-r--file Types and permissions

1 Number of hard links

Kyo users

Kyo belongs to user group

4633 file Size (bytes)

February 16 11:18 Last modified on

Env.txt file name

-rw-rw-r--file Types and permissions

The first character represents a file type

-Normal file

Catalog D

L Soft Link

P Pipeline File

s socket file

C-Character device files

B-Block device files

The latter nine characters represent permissions (three characters for a paragraph)

rw-(u) user permissions for this file

rw-(g) Operation permissions for this file by the owning user group

r--(o) other users ' access to this file

R Read

For files, there is r to read the contents of this file

For directories, there is r in order to list content in the directory

W Write

For files, there is w to edit this file

For directories, a W is required to create or delete files or subdirectories in this directory

X executable

For files, there is x to run the file

For the directory, there is x to switch in (CD switch does not go in)

Modify Permissions: chmod

chmod u=rwx,g=r--, o=---file

chmod u+x,g-w,o+r File

Numeric representation of permissions (octal)

---000 0

--x 001 1

-w-010 2

-WX 011 3

r--100 4

R-x 101 5

RW-110 6

RWX 111 7

chmod 755 Directory/-R

Modify permissions for all files in the directory and directory to 755

Modify the owning user and group: chown

Chown User name: User group File-r

Paste bits (set permissions on folders for other users only setvtx)

Role: Prevent other users from deleting

chmod 777 Catalogue/

chmod o+t Directory/

Users can only delete their own things

ls View paste bit: directory If there is execute permission to display T, otherwise display T

Privileged bit (setuid setgid)

Can only be set for the owning user and the owning user group

The default executable file runs with the currently logged on user permission

The privileged bit executable file runs with permissions for the file's owning user

User privileges:

chmod u+s executable file

User group privileges:

chmod g+s executable file

File Special properties:

Lsattr viewing special properties of a file

CHATTR Special properties for modifying files

Linux basic commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.