Basic commands for Linux under directory

Source: Internet
Author: User
Tags create directory

Use version: Centos 6.6


Basic commands for catalogs (mkdir, tree, Touch, RM, CP, MV)

Create directory MkDir

mkdir AA bb cc Create multiple folders in this directory at the same time

[[email protected] tmp]# mkdir AA bb cc[[email protected] tmp]# LSAA BB cc Yum.log

mkdir-p aa/bb/cc add p to recursively create a directory

[email protected] tmp]# tree-c aa/#查看aa目录的结构
aa/
└──bb
└──cc
MKDIR-PV dd/ee/ff Plus v visual display Create directory procedure

[[email protected] tmp]# MKDIR-PV dd/ee/ffmkdir:created directory ' dd ' mkdir:created directory ' dd/ee ' mkdir:created dir Ectory ' Dd/ee/ff '


Create a file Touch

[email protected] ~]# Touch 123[[email protected] ~]# ls-l 123-rw-r--r--. 1 root root 0 Mar 18 10:06 123


RmDir used to delete empty directories, files in the directory can not be deleted, not commonly used;

[[email protected] ~]# mkdir-v AAA bbbmkdir:created directory ' AAA ' mkdir:created directory ' BBB ' [[email protected] ~]# RmDir AAA BBB


Delete File rm

[email protected] tmp]# which RM
Alias rm= ' rm-i ' # rm=rm-i plus I option action will prompt for deletion

/bin/rm

RM 11 Delete file will prompt whether to remove y delete n do not delete

[[email protected] tmp]# Touch 11
[[email protected] tmp]# RM 11
Rm:remove Regular empty file ' 11 '? N

rm-f Add F Force Delete file , does not prompt

/bin/rm 11 Direct Plus Absolute path , delete files directly won't prompt

[[email protected] tmp]# rm-f 11[[email protected] tmp]#/bin/rm 11


Add parameter rm-r after deleting folder

[email protected] tmp]# RM aa #直接删除文件夹会提示是一个目录
Rm:cannot remove ' AA ': is a directory

Rm-r BB Delete folder will prompt whether to delete, y delete n do not delete

[email protected] tmp]# rm-r bb
Rm:remove directory ' BB '? Y

RM-RF AA forcibly deletes the folder without prompting

/bin/rm-r 11 Direct plus absolute path, directly delete folder will not prompt

Use unalias Command After that, you will not be prompted to delete it directly. expires only when the current shell is active and exits the current shell ;

[[email protected] tmp]# unalias rm[[email protected] tmp]# lsaaa aaa_bak yum.log[[email protected] tmp]# rm-r Aaa[[ema Il protected] ~]# exit[[email protected] ~]# rm-r 111rm:remove directory ' 111 '? N


Copy file CP

CP AAA Aaa_bak Copy AAA file, back up one copy to Aaa_bak

/BIN/CP AAA Aaa_bak force copy overwrite with absolute command , does not prompt

[[email protected]  tmp]# cp new.log /root/ New.log         #复制同名文件会提示是否删除, y delete n do not delete
cp: overwrite   '/root/new.log '  n
[email protected]  tmp]# /bin/cp new.log /root/ new.log 

CP -r  aa aa_bak        copy folder aa, back up a copy of Aa_bak   need to add the-R parameter

[[email protected] tmp]# mkdir aaa[[email protected] tmp]# cp-r AAA aaa_bak[[email protected] tmp]# lsaaa Aaa_bak YUM.L og

[[email protected] tmp]# CP AAA BBB #直接拷贝文件夹会提示略过目录
Cp:omitting directory ' AAA '


When you copy a directory, the destination directory has a directory with the same name and does not prompt if the directory has files to copy files to the target directory.

[[email protected]~]# ls
Anaconda-ks.cfg install.log install.log.syslog Test test1
[Roo[email protected]~]# cp-r 12/tmp/Copy directories of the same name into another directory without prompting
[[email protected]~]# ls/tmp/
111 Huang Yum.log
[[email protected]~]# Touch 12/1.txt Create a new file in the directory
[[email protected]~]# Cp-r 12/tmp/is copied again, the files under the directory are copied to another directory
[[email protected]~]# ls/tmp/12/
1.txt


Cp-v visual display of copy process, copy BB for DD

[[email protected] tmp]# cp-v BB dd BB ' dd '


Moving files or renaming MV

The destination file or folder does not exist in the same directory, renaming

Files are moved under different directories, and the destination file exists to indicate whether or not to overwrite.

[email protected] tmp]# mv/root/bb.
Mv:overwrite './bb '? N
[[email protected] tmp]# /bin/mv/root/bb./ Use absolute path to force overwrite will not prompt;

Mobile if the target file exists, you can rename it

[email protected] tmp]# cat/root/aaa

Def
[email protected] tmp]# mv/root/aaa./aa #移动root目录下的aaa到当前目录并改名aa
[[email protected] tmp]# cat AA
Def

[[email protected] tmp]# mv-v aa bb #mv-V visual display move process, AA renamed BB
' AA ', ' BB '




This article is from the "Model Student's Learning blog" blog, please be sure to keep this source http://8802265.blog.51cto.com/8792265/1621744

Basic commands for Linux under directory

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.