Common commands for Linux

Source: Internet
Author: User
Tags parent directory

Mac ifconfig View IP address

Linux is case-sensitive

1. The LS command is the same as the dir command, which lists all the contents of the folder

Ls-l display of long-form content

Ls-a Show all content, including hidden files, there will be one in front of the hidden file.

Ls-al can be combined, and the result is a combination of two.

ls-d This option is for the directory, you can view the properties of the specified directory, generally with-l,

2. CD switch directory commands, CD Desktop go to destop directory, CD. Return to Parent Directory

3. mkdir Create a directory, you cannot create it repeatedly under the same folder

Mkdir-p Tmp/test, if the directory does not exist to force the creation of the directory, this is created in this directory, if written mkdir-p/tmp/test if not have the right to error, should be unable to write, can only operate this directory of things, can not add/

Mkdir-m is used to specify the permissions to create a directory, which is usually set with chmod, as explained below

Touch Create File

RmDir Delete Empty directory, also has the-p parameter, but also delete a series of empty directories, but if there are directories or files in the directory will be error

4. CP Copy file, Cp-r (-R) Copy directory, no case

Cp-i If you encounter an existing file when copying a file, you will be asked to overwrite

If this directory is duplicated, the use of-ri (IR) will not be queried, only the duplication of the file will

Need to meet the conditions, the first copy of the file if the current directory of files, otherwise cannot be copied, and then copied to the directory under the current directory, otherwise it cannot be copied.

CP FileName Directory/name after copy (can be modified)

Cp-r file directory name directory/Copy name (can be modified)

5. RM Delete file, rm-r Delete directory, can be deleted unless empty directory,

Rm-f indicates forced removal of directory

Rm-i will ask you to delete files or folders when you delete them

can be combined with

6. PWD Get full path

7. VI

Go inside the file

VI index.js go inside the file, press I to enter the content, press ESC, and then enter: Wq exit the file.

Input more How to delete it, how to choose up and down

Command Highlights: Http://man.linuxde.net/vi

i/a

Esc

DD//Double-click in non-edit state

/FMT//Search, press N to find the next

: q! Force exit

: Wq//Save and exit

8. Cat Index.js View File contents

-N to display the line number also on the screen

-A This is case-sensitive, indicating that all content is displayed, including special characters. Do not know why there is a $ symbol at the end of each line.

The TAC is the inverse of cat, and it also displays the contents of the file on the screen, but is displayed in reverse order and now displays the last line.

More also used to view the contents of the file, followed by the filename, when the file content too much, a screen display when using more, press the space (or ctrl+f) down the screen, press ctrl+d up the screen, read all the content will be self-exit, if you want to quit by the Q-Jian can be early.

Less is also used to view the file, followed by the file name, but more than more features more, press the empty SPACEBAR can page, press J can move down, click to move one line, press K Jian can move upward.

When using more and less to view a file, you can press the/health, and enter a string, and then return, so you can find the string, if you find more than one string, you can press N to display the next, in addition, you can also use? Instead of/to search for strings, the difference is that/is the current line down search,? is the current line up search.

The head is used to display the first 10 lines of the file, followed directly by the filename, and if the-n option is added, the first few lines of the file can be written-n2, or-2.

The tail is used to display the last ten lines of a file, followed by a file name, and if you add-N, the last few lines of the file can be written-n2, or-2.

The-f option is also commonly used to dynamically display the last ten lines of a file, and if the file is constantly increasing, using-f is very intuitive and convenient to view the log on the line.

(or the same sentence version of the actual operation of the situation is different, but will have these commands)

9. MV Mobile folder (file), the original directory (file) will not exist, this command can manipulate folders and files

MV filename target path (/modified name)

This will be the first of two cases, the target file is a directory (that is, the source of the move is a directory), if the directory does not exist, the source directory will be renamed to the target directory name, if the directory exists, the source is moved to the directory.

The second, the target file is a file (that is, the source of the move is a file), if the file does not exist, the source file will be renamed to the specified target file, if the file exists, it will ask whether to overwrite (some versions of Linux will ask, because they are mv-i by default, and some do not, need to own-i)

10. Add content to the file can use echo ' aaaa ' > Index.js, this is to add to the first line, if continue to be > will delete all previous content, re-add the first line,>> this is the meaning of append, will be appended in the file, Without deleting the original content

How do I add a user to a group of Linux files, Groupadd,useradd, adding groups and adding users? Back add

There are three types of file and directory permissions, R read, w write, x executable, for a directory, open this directory is to execute this directory, so a directory must have X permission to open and view content within the directory.

We create a new directory permission list is

Drwxr-xr-x, D represents the directory, followed by each three-bit group, representing the owner, all groups, and other users ' permissions to the directory. Set permissions is also a set of three sets, rwx corresponding values are 4,2,1, the new directory permission is 755, the permissions of the new file is 644, that is,-rw-r--r--, the first bit-represents the file.

Ubuntu Modify the root login method: Because if not the root login, you cannot modify the permissions

http://blog.csdn.net/sunxiaoju/article/details/51993091

Modify the permissions of a group CHGRP [-R] (applies only to directories, the Cascade modifies files inside the folder, because the file is not written) [group name] [file name] (change), this command does not work very much, with less

Modify Owner Chown [-R] (IBID.) [account name] [file name] (change owner) or Chown [-r] [account name: Group name] [filename] This command modifies the file to be the owner of the account name, and all groups are group names.

Chown-r WW:LWW Test.js

The result of Ls-l out is

Ubuntu Modify the root login method: Because if not the root login, you cannot modify the permissions

-rw-r--r--1 ww LWW 0 February 3 22:59 test.js

File-, permissions nine bits, the number of bits, the file owner, the file of all groups, the size of the file, February 3 22:59 indicates the last time the file was modified, file name

Where WW is not necessarily a user in the LWW group

/ETC/PASSWD and/etc/shadow/etc/group

First two directories one is the user's basic information, one is to save the user's password, and the third is the group information

Groupadd Add a group, the group will have a GID, that is, GroupID, the custom group starts with 1000,

Groupadd test1

Viewing groups using Tail-1/etc/group

Will contain GID information for the group

Groupdel test1 Delete a group, if there are users in the group, you cannot delete the reorganization, you need to delete the user before deleting the group

Useradd add user, user will also have UID, custom user ID starting from 1000, this command has a lot of parameters, but different system parameters will vary slightly, need to see the help command, usually

Useradd [-u uid] [-g GID] [-D custom user's home directory] | [-M means no home directory created] [-S custom shall]

Useradd-u 1000-g 1000-d/home/test1-s/sbin/bash test1

So test1 users are built in the Test1 group, the home will create a new Test1 folder, not write some of the system will be automatically created, some will not, according to the actual situation

Userdel-r Test1-r is deleted together with the home directory, without-R will not delete home directory

CHFN change the user's finger, that is, the comment information in the user

grep ' test1 '/etc/passwd grep command is to search the/etc/passwd file for the keyword ' test1 '

passwd test1 to the user to set the password, if not write the user behind, it is to the current user to set the password, it should be noted that only the root user can modify the information of other accounts, ordinary users can only modify their own password

User Identity Switch command

Login As:test1 will switch to the Test1 user, but the command cannot be switched to the root account

WHOAMI View Current User

Root user is #, other users are $

The SU command also switches users and can switch back and forth with the root account

Su-root-When switching, the current directory will be the home directory of the current account, if not plus-the directory is unchanged. The password is not required when switching to a normal user by the root user

12. Find Files

Find/-name filename

Systemctl status httpd//view Apache startup status

The Ubantu command differs from SYSTEMCTL status apache2

SSH [email protected]//Login to remote server

IP, router, ifconfig

IP addr

/etc/sysconfig/network-scripts//This directory is about the configuration of the network

Wget Curl

16

17.

18. View the process list using

Top

Exit Press Q

The PS command is static and also a list of view processes

PS aux

Find a process

PS aux | grep process Name

Kill ( -9) PID

Pkill Bulk Delete

W command to see if the server is being used by others

 

Common commands for Linux

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.