Common basic commands for Linux 02

Source: Internet
Author: User

Cp
Role: Copying files
Common options:
-L Establish a hard link to the source file instead of copying the file
-S creates a symbolic link to the source file instead of copying the file
-P preserves the properties of the source file or directory, including the owner, the owning group, the permissions and the time
-F forcibly copy a file or directory, regardless of whether the destination file or directory already exists
Note: Echo is a echo-,> representative to export the echo to a file,> overwrites the file,>> is to append something to the file
Instance:

[Email protected] ~]# cp/etc/passwd.  [[email protected] ~]# Lspasswd[[email protected] ~]# echo 1 >/A enter 1[[email protected] ~]# cp-l/A a.a establish a hard link [email Protected] ~]# Echo 2 >> a.a input to a.a 2[[email protected] ~]# Cat/a12[[email protected] ~]# cat a.a 12 File/A and home directory AA content Consistent, hard link real-time updates
[[email protected] ~]# touch/tmp/123[[email protected] ~]# chmod 777/tmp/123[[email protected] ~]# ll/tmp/123-rwxrwxrwx . 1 root root 0 Mar 22:59/tmp/123 create file 123 in/tmp and change the permission to 777[[email protected] ~]# cp/tmp/123. [Email protected] ~]# lltotal 0-rwxr-xr-x. 1 root root 0 Mar 18 23:00 123 copy/tmp/123 to current directory, permissions change [[email protected] ~]# cp-p/tmp/123. Cp:overwrite './123 '? Y[[email protected] ~]# lltotal 0-rwxrwxrwx. 1 root root 0 Mar 18 22:59 123 plus-p option, permissions unchanged

Rm
Action: Delete a file or directory
Common options:
-I prompt for deletion before deleting a file
-R Delete Directory
-F Force Delete silent
-V Show Detailed steps
Instance:

[[email protected] ~]# touch 1 2 [[email  protected] ~]# mkdir 3 4[[email protected] ~]# ls1  2   3  4 Create file 1, 2  create directory 3, 4[[email protected] ~]# rm -i 1rm: remove  regular empty file  ' 1 '?  y prompt confirmation before deleting [[EMAIL PROTECTED] ~]# RM 3RM:  cannot remove  ' 3 ':  is a directory cannot delete directory [[email protected] ~]# rm  -r 3rm: remove directory  ' 3 '?  y Plus-r option to delete directory [[email protected]jacken ~]#  ls2  4[[email protected] ~]# rm -rfv *removed  ' 2 ' removed  directory:  ' 4 ' [[email protected] ~]#  force delete silently and display the procedure 

MV
Action: Move or rename a directory or file
Common options:
 -f If the destination file already exists and does not ask for a direct override of
 -i if the destination file (destination) already exists, you will be asked to overwrite
 -u Update
Instance if the destination file already exists and the source file is newer:

[[EMAIL PROTECTED] ~]# TOUCH /TMP/1[[EMAIL PROTECTED] ~]# MV /TMP/1 &NBSP: Move the/TMP/1 to the current directory [[email protected] ~]# ls /tmp/[[email protected] ~]#  ls 1[[email protected] ~]# mv 1 2[[email protected] ~]#  LS2 renaming the file 1 to 2[[EMAIL PROTECTED] ~]# TOUCH /TMP/2[[EMAIL PROTECTED] ~]# MV  -F /TMP/2&NBSP: Current directory with file 2, move/TMP/2 to current directory  -f option to overwrite directly, silently [[email protected] ~]#  Lltotal 0-rw-r--r--.  1 root root 0 mar 18 23:30 2 There is an old file in the current directory 2[[ email protected] ~]# touch  /tmp/2[[email protected] ~]# ll /tmp/ 2-rw-r--r--.  1 ROOT ROOT 0 MAR 18 23:34 /TMP/2 Create a new file in/tmp 2[[email  protected] ~]# mv -u 2 /tmp/2 [[email protected] ~]#  Lltotal 0-rw-r--r--.  1 rOot root 0 mar 18 23:30 2[[email protected] ~]# ll /tmp/2  -rw-r--r--.  1 ROOT ROOT 0 MAR 18 23:34 /TMP/2 Move the current directory from 2 to/TMP in 2, Because the current directory is 2 older, it will not move, tail.

Useradd
Role: Create user
Comment:/etc/default/useradd create user default option,-D Specify home directory, folder should not exist, ID user name, can display user information. The
 ID -G displays the ID of the group to which the user belongs. The
  -G displays the ID of the group to which the user belongs and the additional group.
  -u Display User ID
Common options:
 -d change preset
 -d Specify user home directory
 -r establish system account
 -s Specifies the shell
 -u specified user ID
 -m automatically establishes the user's login directory
 -m do not automatically establish the user's login directory
 -g Specify the group to which the user belongs
 -G the specified user belongs to the attachment group
 -c with the memo text, the memo text is saved in the comment field of the passwd
 -n the group
instance with the name of the user is canceled:

[[Email protected] ~]# useradd user1[[email protected] ~]# tail -1  /etc/passwduser1:x:503:503::/home/user1:/bin/bash Normal User user1[[email protected] ~]#  useradd -s /sbin/nologin -d /123 -u 666 -g 501 -g 503 - c testuser2   user2[[email protected] ~]# id user2uid=666 (user2)   gid=501 (Jacken)  groups=501 (Jacken), 503 (User1) [[Email protected] ~]# tail -1 /etc /passwduser2:x:666:501:testuser2:/123:/sbin/nologin creates a user user2 and cannot log in, the home directory is/123 uid 666, the primary group ID is 501, the additional group ID is 503, Description information for testuser2[[email protected] ~]# useradd -d -s /sbin/nologin  set default logon script Q/ Sbin/nologin[[email protected] ~]# useradd user3[[email protected] ~]# tail  -1 /etc/passwduser3:x:667:667::/home/user3:/sbin/nologin the newly created user default script is/sbin/nologin (depending on/etc/default/ Useradd

Userdel
Role: Delete User
Common options:
-R Even delete user home directory
Instance:

[[email protected]/]# ID user3uid=667 (user3) gid=667 (User3) groups=667 (USER3) [[email protected]/]# Userdel-r User3[[em AIL protected]/]# ID user3id:user3:No Such user delete users User3


This article is from the "Step Into the Linux World" blog, please be sure to keep this source http://linuxnote.blog.51cto.com/9876511/1622062

Common basic commands for Linux 02

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.