Command Documentation most suitable for beginners of Centos

Source: Internet
Author: User
You can query this command help Document 1. create the directory mkdirNO1. create a level-1 directory in the current path [root @ rehatroot] # mkdirtestN

You can query the help documentation of this command.
1. create a directory
Mkdir
NO1.Create a level-1 directory in the current path
[Root @ rehat root] # mkdir test

NO2.Create a multi-level directory in the current path
[Root @ rehat root] # mkdir-p mytest/test1/test1_1

NO3.Grant permissions to the newly created directory while creating the Directory
[Root @ rehat root] # mkdir-m 777 testmod
In this way, anyone has any permission for this directory.

2. copy files and folders
Cp
NO1.Copy the file from the specified directory to the current directory and rename it
[Root @ rehat root] # cp ~ /. Bashrc bashrc_bak

NO2.Forcibly copy the file from the specified directory to the current directory, regardless of whether the current directory contains the file
[Root @ rehat root] # cp-f ~ /. Bashrc

NO2.Copy the specified directory to the current directory
[Root @ rehat root] # cp-r/root/test.
[Root @ rehat root] # cp-r/root/test /.
The two have the same effect. when copying a directory, all the last-level directories in the source path will be copied, including the directory itself.

NO3.Copy the files in the specified directory to the specified directory.
[Root @ rehat root] # cp ~ /. Bashrc/bak/. bashrc

NO4.During the copy, all the properties of the source file are also copied. If no parameter is specified, the properties of the target file and the source file may be inconsistent.
[Root @ rehat root] # cp-~ /. Bashrc/bak/. bashrc

NO5.If the two folders need to be synchronized, one file is changed and the other file is changed, but the files of the two files must be the latest.
[Root @ rehat root] # cp-u/src/. bashrc/bak_src/bashrc

3. create a link file, including hard links and soft links.
Ln

NO1.SimilarWindowsShortcut
[Root @ rehat root] # ln-s test.txt _ slnk

NO2.If you want to back up a file with insufficient space, you can create a hard connection for the file. In this way, even if the original file is deleted

If the linked file is not deleted, it is still not deleted in the bucket.
[Root @ rehat root] # ln-l test.txt _ hlnk

4. delete an object
Rm

NO1.Delete files in the current directory
[Root @ rehat root] # rm test.txt

NO2.Force delete files in the current directory. no prompt is displayed.
[Root @ rehat root] # rm-f test.txt

NO3.Force delete the entire directory, including deleting all directories and files. administrator permission is required.
[Root @ rehat root] # rm-r-f test

5. delete folders
Rmdir

NO1.Delete an empty directory
[Root @ rehat root] # rmdir emptydir

NO2.Delete a multi-level empty directory
[Root @ rehat root] # rmdir-p emptydir/d1/d11

6. Mount and detach a file system
Mount/umount

NO1.Attach optical drive
[Root @ rehat root] # mount-t iso9660/dev/cdrom/mnt/cdrom

NO2.Attach the optical drive, supporting Chinese characters
[Root @ rehat root] # mount-t iso9660-o codepage = 936, iocharset = cp936/dev/cdrom/mnt/cdrom

NO3.MountWindowsPartition,FATFile system
[Root @ rehat root] # mount-t vfat/dev/hda3/mnt/cdrom

NO4.MountWindowsPartition,NTFSFile system
[Root @ rehat root] # mount-t ntfs-o iocharset = cp936/dev/hda7/mnt/had7

No5.MountISOFile
[Root @ rehat root] # mount-o loop/abc. iso/mnt/cdrom

NO6.Mount Soft drive
[Root @ rehat root] # mount/dev/fd0/mnt/floppy

NO7.Mount a flash disk
[Root @ rehat root] # mount/dev/sda1/mnt/cdrom

NO8.MountWindowsFolder shared by operating system
[Root @ rehat root] # mount-t smbfs-o username = guest, password = guest // machine/path/mnt/cdrom

NO9.Display mounted file systems
[Root @ rehat root] # mount
[Root @ rehat root] # cat/etc/fstab: displays the file system automatically loaded when the system starts.
[Root @ rehat root] # cat/etc/mtab displays the currently loaded file system

7. check disk space
Df

NO1.Show all storage system space usage,Displays the file system type of the storage system.S
[Root @ rehat root] # df-

NO2.Displays the space usage of the specified file system.
[Root @ rehat root] # df-t ext3

NO3.Display the size of each storage space in a user-friendly manner
[Root @ rehat root] # df-ah

NO4.Sometimes a network file system is mounted. if you only want to view the local file system, run the following command:
[Root @ rehat root] # df-ahlT

NO5.View the disk usage of a file system
[Root @ rehat root] # df-h/dev/cdrom


8. check the directory space size.
Du

NO1.View the current folder size
[Root @ rehat root] # du-sh

NO2.View the size of subfolders in the current file and file
[Root @ rehat root] # du-ch

NO3.View the file size
[Root @ rehat root] # du-h test1.txt

NO4.View the size of multiple files at the same time
[Root @ rehat root] # du-h test1.txt test2.txt

9. disk fragmentation
In linux, there is basically no need for fragment. it will be automatically organized at intervals.

10. create/change a file system
NO1. create a file system type
[Root @ rehat root] # umount/dev/sdb1
[Root @ rehat root] # mkfs-t ext3/dev/db1
[Root @ rehat root] # mount/dev/sdb1/practice

 

11. change file or folder permissions

Chmod

NO1.Set your notes to be read only by yourself
[Root @ rehat root] # chmod go-rwx test.txt
Or
[Root @ rehat root] # chmod 700 test.txt

NO2.Modify the permissions of multiple files at the same time
[Root @ rehat root] # chmod 700 test1.txt test2.txt

NO3.Modify the permissions of a directory, including its subdirectories and files.
[Root @ rehat root] # chmod 700-R test

12. change the owner of a file or folder

Chown this command can only be used by the root user

NO1.Change the owner of a file
[Root @ rehat root] # chown jim: usergroup test.txt

NO2.Change the owner of a directory and contain subdirectories
[Root @ rehat root] # chown jim: usergroup-R test
13. View text file content

Cat

NO1.View the file content and add a row number before each line
[Root @ rehat root] # cat-n test.txt

NO2.View the file content, and add a row number before it is not a blank line
[Root @ rehat root] # cat-B test.txt

NO3.Merge the content of two files
[Root @ rehat root] # cat test1.txt test2.txt> test_new.txt

NO4.Complete the content of the two files and trace back to a file
[Root @ rehat root] # cat test1.txt test2.txt> test_total.txt

NO5.Clears the content of a file.
[Root @ rehat root] # cat/dev/null> test.txt

NO6.Create a new file
[Root @ rehat root] # cat> new.txt press CTRL + C to end the input

14. edit a file

Vi

NO1.Create a file
[Root @ rehat root] # vi newfile.txt

NO2.Modify an archive file
[Root @ rehat root] # vi test.txt already exists

NO3. viTwo working modes: command mode and edit mode

NO4.After entering vi, enter the command mode and press the Insrt key to enter the edit mode.
Press ESC to enter the command mode. you cannot edit the command mode. you can only enter the command

NO5.Common commands in command mode
: W save the current document
: Q: Exit vi directly.
: Wq is saved first and then exited

15. path operations

Cd pwd

NO1.Show current path
[Root @ rehat root] # pwd

NO2.Returns the user's home directory.
[Root @ rehat root] # cd

NO3.Change to another path
[Root @ rehat root] # cd/etc

NO4.Return to the upper-level Directory
[Root @ rehat root] # cd ..

NO5.Return to the root directory
[Root @ rehat root] # cd/
16. query files or folders

Find

NO1.Search for all files in the current user's home directory
[Root @ rehat root] # find ~

NO2.Allow the file owner in the current directory to have read and write permissions, and the users in the file group and other users to have read permissions;
[Root @ rehat root] # find.-perm 644-exec ls-l {}\;

NO3.To find all files in the system, the length is0And list their full paths;
[Root @ rehat root] # find/size 0-type f-exec ls-l {}\;

NO4.Search/Var/logsThe change time in the directory is7And ask them before they are deleted;
[Root @ rehat root] # find/var/logs-mtime + 7-type f-OK rm-I {}\;

NO5.Is/Find allRootGroup files;
[Root @ rehat root] # find/-group root-exec ls-l {}\;

NO6. findCommand will be deleted when the access time in the directory is7With a digital suffixAdmin. logFile
[Root @ rehat root] # find. -name "admin. log [0-9] [0-9] [0-9] "-atime-7-OK rm {}\;

NO7.To find and sort all directories in the current file system
[Root @ rehat root] # find.-type d | sort

NO8.To find allRmtTape device
[Root @ rehat root] # find/dev/rmt

17. display the file/folder list
Ls/dir

NO1.Display all files, including.Hidden File
[Root @ rehat root] # ls-

NO2.Displays detailed information about a file.
[Root @ rehat root] # ls-l

NO3.Displays information about the current directory and all subdirectories.
[Root @ rehat root] # ls-Rl

NO4.Display directories in chronological order,This is useful for finding the latest file.
[Root @ rehat root] # ls-tl

NO5.Sort by file size
[Root @ rehat root] # ls-Sl

NO6.Show file size,And sort by size
[Root @ rehat root] # ls-s-l-S

18. move or change the file/folder name
The usage of mv and cp commands is similar.

NO1.If the target file already exists, back up the original directory file before moving it.
[Root @ rehat root] # mv-B test.txt test2/
In this way, there will be two test.txt and text.txt ~ files under test2 ~
Test.txt ~ Is the hosts file. test.txt is the new file.

NO2.If the target file already exists but you do not want to overwrite it
[Root @ rehat root] # mv-f test.txt test2/

NO3.When both the source and target have the same file, if the source file matches the new object, the object will be moved; otherwise, the object will not be moved.
[Root @ rehat root] # mv-u test.txt test2/

NO4.Change file name
[Root @ rehat root] # mv test.txt test2.txt

NO5.Change directory name
[Root @ rehat root] # mv/test2/test2_2

Related Article

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.