[Email protected] ~]#ls [-aadffhilnrrst] Directory name[Email protected] ~]#ls [--color={never,auto,always}] Directory name[Email protected] ~]#ls [--full-time] Directory nameOptions and Parameters:-a: All the files, together with the hidden files (the file starting with.), are listed (common)-A: All files, together with hidden documents, but not included. With. These two directories- D: Lists only the directory itself, not the file data in the directory ( Frequently used)-F: Lists the results directly without sorting (the LS is sorted by default in the file name!) F: According to files, directories and other information, to give additional data structure, such as: *: representative of the executable file;/: representative Directory; =: represents a socket file; |: Represents a FIFO file; h: Lists the file capacity in a human-readable manner (e.g. GB, KB, etc.); : List inode number, the meaning of the Inode the next chapter will be introduced;-L: Long data string list, including file attributes and permissions and so on data; (common)-N: List uid and GID instead of user and group name (UID and GID will be mentioned in account management!). )-R: Reverse output of the sorting results, for example: the original file name from small to large, the reverse is from large to small;-R: Together with the subdirectory contents, all the files in that directory will be displayed;-S: Sort by file size, not by filename;-T: Sort by time, not by file name. --color=never: Do not give color display according to the file characteristics;--color=always: Display color--color=auto: Let the system to determine whether to give color--full-time: In full time mode (including year, month, day, hour, minute Output--time={atime,ctime}: Output access time or Change permission attribute time (CTime) instead of content change time (modification times)
[Email protected] ~]#CP [-adfilprsu] source file (source) target file (destination)[Email protected] ~]#CP [Options] Source1 source2 source3 .... Directoryoptions and Parameters:-A: equivalent to the meaning of-PDR, for PDR please refer to the following instructions; (common)-D: If the source file is a link file attribute (link file), the link file property is copied instead of the file itself;-F: For force, if the target The file already exists and cannot be opened, then it is removed and then tried again;-I: if the target file (destination) already exists, it will ask for the action to be made (common)-L: Create the link file of hard link, not copy the file itself; -P: Copy the past along with the properties of the file, rather than using the default properties (backup is often used); - R: Recursive continuous replication, used for directory replication behavior, (common)-s: Copy into a symbolic link file (symbolic link), that is, "shortcut" files;-u: If destination is older than source upgrade destination! Finally, note that if the source file has more than two, then the last destination file must be "directory"!
Example one: Copy the. BASHRC from the home directory to/TMP under root, and rename it to BASHRC[Email protected] ~]#CP ~/.BASHRC/TMP/BASHRC[Email protected] ~]#cp-i ~/.BASHRC/TMP/BASHRCCp:overwrite '/TMP/BASHRC '?N <==n not covered, Y is covered# Repeat two times, since the BASHRC already exists under/TMP, plus the-i option, the # will ask the user if it is OK before overwriting! You can press N or y to confirm it two times! Example Two: Transform the directory to/TMP and copy the/VAR/LOG/WTMP to/TMP and observe the properties:[Email protected] ~]#cd/tmp[Email protected] tmp]#cp/var/log/wtmp. <== want to copy to the current directory, the last. Don't forget[Email protected] tmp]#ls-l/var/log/wtmp wtmp-rw-rw-r--1 rootutmp96384 SEP 2411:54/var/log/wtmp-rw-r--r--1 rootRoot96384 SEP 2414:06WtmpNote the above special font, in the case of no option, some properties/permissions of the file will change; # This is a very important feature! Be careful! Also, the time to create files is not the same! # So what if you want to copy all the features of the file together? Can add-a Oh! As shown below:[Email protected] tmp]#cp-a/var/log/wtmp wtmp_2[Email protected] tmp]#ls-l/var/log/wtmp wtmp_2-rw-rw-r--1 root utmp 96384 Sep 11:54/var/log/wtmp-rw-rw-r--1 root utmp 96384 Sep 11:54 wtmp_2# Come on! The entire data feature is exactly the same sunglass! This is a feature of-a!
example Three: Copy all the contents of the/etc/directory to/TMP[Email protected] tmp]#cp/etc//tmpCp:omitting directory '/etc '<== If the directory is not directly copied, to add the-r option[Email protected] tmp]#cp-r/etc//tmp# still want to emphasize again Oh! -R is a directory that can be copied, however, the permissions of the file and directory may be changed # So, you can also use "cp-a/etc/tmp" to give orders Oh! Especially in the case of backup! Example four: Create a Nexus file (symbolic link) with a copy of the sample BASHRC[Email protected] tmp]#ls-l BASHRC-rw-r--r--1 root root 176 Sep 14:02 BASHRC<== First look at the file situation[Email protected] tmp]#cp-s BASHRC Bashrc_slink[Email protected] tmp]#cp-l BASHRC Bashrc_hlink[Email protected] tmp]#ls-l bashrc*-rw-r--r--2Root root 176 Sep 14:02 BASHRC<== is not the same as the original file! -rw-r--r--2Root root 176 Sep 14:02 bashrc_hlinklrwxrwxrwx 1 root root 6 Sep 14:20 Bashrc_slink-BASHRC
Example Five: If ~/.BASHRC is newer than/TMP/BASHRC, copy it.[Email protected] tmp]#cp-u ~/.BASHRC/TMP/BASHRC# this-u feature is only copied when the target file differs from the source file. # So, it's more often used in "Backup" work! ^_^Example Six: Copying the bashrc_slink caused by paradigm four into bashrc_slink_1 and Bashrc_slink_2[Email protected] tmp]#CP Bashrc_slink Bashrc_slink_1[Email protected] tmp]#cp-d Bashrc_slink bashrc_slink_2[Email protected] tmp]#ls-l BASHRC bashrc_slink*-rw-r--r--2 root root 176 Sep 14:02 bashrclrwxrwxrwx 1 root root 6 Sep 14:20 Bashrc_slink-bashrc-rw-r--r-- 1 root root 176 Sep 14:32 Bashrc_slink_1<== the same as the original filelrwxrwxrwx 1 root root 6 Sep 14:33 bashrc_slink_2-BASHRC<== is the link file! # This example is also very interesting! The original copy is a link file, but the actual file of the link is copied over the # that is, if there is no option, CP is copying the original file, not the properties of the link file! # to copy the properties of a linked file, you have to use the-D option! As shown in the Bashrc_slink_2. Example VII: Copy the home directory's. BASHRC and. Bash_history to/tmp[Email protected] tmp]#CP ~/.BASHRC ~/.bash_history/tmp# Multiple data can be copied to the same directory at once! The last side must be the catalogue!
Example Five: If ~/.BASHRC is newer than/TMP/BASHRC, copy it.[Email protected] tmp]#cp-u ~/.BASHRC/TMP/BASHRC# this-u feature is only copied when the target file differs from the source file. # So, it's more often used in "Backup" work! ^_^Example Six: Copying the bashrc_slink caused by paradigm four into bashrc_slink_1 and Bashrc_slink_2[Email protected] tmp]#CP Bashrc_slink Bashrc_slink_1[Email protected] tmp]#cp-d Bashrc_slink bashrc_slink_2[Email protected] tmp]#ls-l BASHRC bashrc_slink*-rw-r--r--2 root root 176 Sep 14:02 bashrclrwxrwxrwx 1 root root 6 Sep 14:20 Bashrc_slink-bashrc-rw-r--r-- 1 root root 176 Sep 14:32 Bashrc_slink_1<== the same as the original filelrwxrwxrwx 1 root root 6 Sep 14:33 bashrc_slink_2-BASHRC<== is the link file! # This example is also very interesting! The original copy is a link file, but the actual file of the link is copied over the # that is, if there is no option, CP is copying the original file, not the properties of the link file! # to copy the properties of a linked file, you have to use the-D option! As shown in the Bashrc_slink_2. Example VII: Copy the home directory's. BASHRC and. Bash_history to/tmp[Email protected] tmp]#CP ~/.BASHRC ~/.bash_history/tmp# Multiple data can be copied to the same directory at once! The last side must be the catalogue!
[Email protected] ~]#MV [-FIU] source destination[Email protected] ~]#mv [options] Source1 source2 source3 .... Directoryoptions and Parameters:-f:force mandatory meaning, if the target file already exists, will not ask and directly overwrite;-I: If the target file (destination) already exists, you will be asked to overwrite it! -U: If the target file already exists and source is newer, it will be upgraded (update)Example One: Copy a file, create a directory, move the file to the directory[Email protected] ~]#cd/tmp[Email protected] tmp]#CP ~/.BASHRC BASHRC[Email protected] tmp]#mkdir mvtest[Email protected] tmp]#MV BASHRC mvtest# Move a file to a directory, that's it! Example two: renaming a newly renamed directory name to Mvtest2[Email protected] tmp]#MV Mvtest Mvtest2 <== that's the name! Simple ~In fact, there is an interesting command under Linux, named rename , # The command is renamed at the same time as multiple file names, not for a single file name change, unlike MV. Please man rename. Example Three: Create two more files and move them all to/tmp/mvtest2[Email protected] tmp]#CP ~/.BASHRC BASHRC1[Email protected] tmp]#CP ~/.BASHRC BASHRC2[Email protected] tmp]#mv Bashrc1 bashrc2 mvtest2# Notice this way, if there are multiple source files or directories, the last destination must be "Directory!" "# meaning to say, move all the data to the meaning of that directory!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Linux file and directory management-LS, CP, MV