Linux Directory and file operations

Source: Internet
Author: User
Tags touch command

Linux Common Commands--directory and file operations[Directory] Delete, copy, move:

1. Delete folder by: RmDir folder name

However, RmDir cannot delete a non-empty folder, then how to delete a non-empty folder:

2. Typically, delete files by: RM file name
-D or--directory delete the hard connection data for the directory that you want to delete directly by deleting the directory by 0.
-F or--force forces the deletion of files or directories.
-I or--interactive to ask the user before deleting both files or directories.
-R or-R or--recursive recursively handles all files and subdirectories under the specified directory.
-V or--verbose shows the instruction execution process.
--help online Help.
--version Displays version information.
So the command to delete a non-empty folder: Rm-rf a non-empty folder name

It is recommended to do a good backup before use, as if this command is not put in the Recycle Bin, deleted will never see the following file.

3. Copying folders
CP command
Format: CP [option] source file or directory destination file or directory
Option Description:-

-A or--archive the effect of this parameter with the same as specifying the "-DPR" parameter.
-B or--backup Delete, overwriting the backup of the target file before the backup file is added with a backup string at the end of the word.
-D or--no-dereference when a symbolic connection is copied, the destination file or directory is also established as a symbolic connection and points to the original file or directory connected to the source file or directory.
-F or--force forcibly copies a file or directory regardless of whether the destination file or directory already exists.
-I or--interactive overwrite existing files before asking the user first.
-L or--link to make a hard connection to the source file instead of copying the file.
-P or--preserve preserves the properties of the source file or directory.
-P or--parents retains the path to the source file or directory.
-R recursive processing, the files under the specified directory and subdirectories are processed together.
-R or--recursive recursively handles all files in the specified directory with subdirectories.
-S or--symbolic-link to create a symbolic connection to the source file instead of copying the file.
-s< Backup Tail string > or--suffix=< backup string > After backing up the destination file with the "-B" parameter, a backup string is added to the end of the backup file, and the default back-end string is the symbol "~".
-U or--update Use this parameter to copy a file only if the source file is changed at a later time than the target file is updated or if the name corresponds to the target file that does not exist.
-V or--verbose shows the instruction execution process.
-v< Backup method > or--version-control=< backup method > After backing up the target file with the "-B" parameter, the tail of the backup file is added with a backup string that can be changed not only with "-S" parameter when using "-V" parameter specifies a different backup method, a different tail of the backup string is also generated.
The file system in which the file or directory is copied by-X or--one-file-system must be the same as the file system where the CP instruction is executed, otherwise it will not be copied.

4. Move or rename the existing file or directory. (MV)
MV Oldfilename NewFileName

-B or--backup overwrite the file, overwriting the previous backup.
-F or--force if the destination file or directory is duplicated with an existing file or directory, overwrite the existing file or directory directly.
-I or--interactive to ask the user before overwriting.
-s< additional word > or
--suffix=< additional tail > with the-b parameter, you can specify the end of the backup file that you want to append.
-U or--update does not overwrite the destination file when it moves or changes the file name, if the destination file already exists and its file date is newer than the source file.

--------------------------------

Common basic commands

Pwd

View current directory Contents

Ls

View the current directory contents in a long format. Entries for each file will include the number of connections, owner, size, last modified time, permissions, and so on

Ls-l

Changes the current directory. The destination directory name can be represented by a relative path or by an absolute path.

CD [Destination directory name]

Move to the top level directory

Cd..

Create a Directory

mkdir [new directory name]

Example: Mkdir/var/ftp

Delete Empty Directory

RM [Directory Name]

Example: Rm/var/ftp

Recursively deletes all the files in a directory and the directory itself.

rm-r [directory Name]

Copying files

CP [source file name] [target file name]

Renaming files

MV [source file name] [target file name]

Example: mv/etc/rc.d/rc3.d/k50xinetd/etc/rc.d/rc3.d/s50xinetd

deleting files

RM [File name]

Delete multiple files without having to be confirmed

rm-f [filename with wildcard characters]

Hard-link files. You cannot make hard links to directory files, and you cannot make hard links between different file systems.

ln [source file name] [target file name]

Example: mv/etc/rc.d/rc3.d/k50xinetd/etc/rc.d/rc3.d/s50xinetd

Soft link file. This is the symbolic link. You can use this method to create a shortcut to a file.

ln-s [source file or folder name] [target name]

Find files by file name.

Find/-name Nametofind-print

Change the file owner.

Example: Chown workman.workgroup/data/pub/upload

Change file access Permissions

Example: Chmod-r 755/usr/local/lumaqq

See how many lines a file has

Wc-l Usr.bin

See how many bytes a file has

Wc-c Usr.bin

View the contents of a text file

Cat Usr.bin

Copy folder: Copy folder 1 to Folder 2

Cp-a Folder 1 folder 2 create file VI [filename] After editing your file, you can save it with wq!.
This makes it possible to create a file that you edit well
And the Vim gedit file Editor touch [filename] Touch command can be used to create a new file with the following: "Touch filename"Documentation:http://www.magiclinux.org/To view the contents of a file:http://blog.csdn.net/yuyongpeng/article/details/1818713Note: See Help if you have unclear commands to use[command]--help

Linux directory and file operations

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.