Linux (CentOS) directory operations commands, file manipulation commands, compression decompression commands

Source: Internet
Author: User
Tags bz2 printable characters unpack touch command

first, the directory Operation command
ls command
-Feature Description: Displays a list of files and directories.
-command format: ls [parameter] [< file or directory > ...]
-Common parameters:
-A: Do not hide anything with "." The entry for the start of the character.
-B: Non-printable characters are displayed in octal form.
-R: Recursively lists all subdirectories.
-D: Lists the directory itself instead of files within the directory when the directory is encountered, and does not follow the symbolic link.
-F: Add an indicator of the file type after the entry (*,/, =, @, |, one of them).
-L: Lists information in a longer format.
-L: When displaying the file information of a symbolic link, the object indicated by the symbolic link is displayed instead of the information of the symbolic link itself.
-X: List items line by row instead of columns by column.
-1: Only one file per line is listed.
-R: Arranged in reverse order.
-S: Sort by file size.
-X: Sort by extension.
-C: Sort by state change time (CTime).
-T: sorted by last Modified time (mtime).
-U: sorted by last access time (atime).
-use Example:
Ls
Ls-a
Ls-f
Ls-l
Ls-r
Ls-sl
Ls-rl
Ls-cl
Ls-tl
Ls-ul
LS Some/dir/file
LS some/dir/
Ls-d some/dir/
Tree command
-Feature Description: Displays files and directory trees.
-Command format: Tree [parameter] [< directory;]
-Common parameters:
-A: Do not hide anything with "." The entry for the start of the character.
-D: Displays only directories that do not display files.
-F: The path is displayed for each file.
-F: Add an indicator of the file type (*,/,=,@,|, one of them) after the entry.
-R: Arranged in reverse order.
-T: sorted by last Modified time (mtime).
-L N: Displays only n-level directories (n is numeric).
–dirsfirst: The directory appears after the previous file is displayed.
-use Example:
Tree
Tree-d
Tree-f
Tree-l 3
tree/some/dir/
PWD command
-Function Description: Displays the current working directory.
-command format: pwd [parameter]
-Common parameters:

-P: If the directory is a symbolic link, the physical path is displayed instead of the symbolic link.
-use Example:
Pwd
Pwd-p
CD command
-Function Description: switch directories.
-Command format: cd [parameter] [< directory;]
-Common parameters:
-P: If the directory is a symbolic link, the physical path is displayed instead of the symbolic link.
-use Example:
cd/some/dir/
Cd-p Examples
Cd
CD ~
Cd..
Cd.. /..
CD-
mkdir command
-Function Description: Create a directory.
-Command format: mkdir [parameters] < contents >
-Common parameters:
-P: Create a directory tree and create a top-level directory when needed, such as a directory already exists and is not considered an error.
-use Example:
mkdir somedir/,
Mkdir-p some/path/dir/
rmdir command
-Function Description: Delete empty directory.
-Command format: rmdir [parameters] < contents >
-Common parameters:
-P: Deletes the directory and then attempts to delete all the upper-level directories in the specified path. For example: The effect of rmdir-p a/b/c is equal to RmDir a/b/c A/b.
-use Example:
RmDir somedir/
Rmdir-p some/path/dir/


Second, the file Operation command
Touch command
-Feature Description: Generate a new empty file or change the timestamp of an existing file.
-Command format: Touch [parameters] < file > ...
-Common parameters:
-A: Change the access time only.
-M: Only change the modification time.
-T <STAMP>: Use time in [[CC]YY]MMDDHHMM[.SS] format instead of current time.
-R < Reference file or directory >: Use the time attribute of the specified file instead of the current time.
-use Example:
Touch NewFile
Touch file
Touch-a file
Touch-m file
Touch-t 200701311200 File
There are 3 types of timestamps for-gnu/linux files:
Mtime: Last Modification Time (LS–LT)
CTime: State Change Time (LS–LC)
Atime: Last Access Time (LS–LU)
Attention:
1. CTime is not a file creation time.
2. Overwriting a file will change all three classes of time: Mtime, CTime, and Atime.
3. Changing the access rights or the owner of the file will change the CTime and atime of the file.
4. Reading a file will change the atime of the file.
CP command
-Function Description: Copy files or directories.
-command format: CP [parameters] < source > < target >
-Common parameters:
-A: equivalent to –DPR.
-D: When you copy a symbolic link's source file, the destination file also creates a symbolic link and points to the original file that the source file is linked to.
-F: Force replication, regardless of whether the target exists.
-I: Interactive replication requires confirmation before overwriting the file.
-P: Preserves file attributes during file copying, including owner, group, permission, and timestamp.
-r,-r: Recursively replicates all items in the directory and directory.
-L: Create a hard link to the source file instead of copying the file, or you can use the LN command.
-S: Create a symbolic link to the source file instead of copying the file, or you can use the Ln-s command.
-U: Replication occurs only if the modification time of the source file (CTime) is newer than the target file or the target does not already exist.
-use Example:
CP file1 File2
CP Some/dir/file1 someother/dir/
CP Some/dir/file1 Someother/dir/file2
CP Some/dir/file.
CP Some/dir/files someother/dir/
CP some/dir/file1 Some/dir/file2 Some/dir/file3 someother/dir/
Cp-r some/dir/someother/dir/
Cp-au some/dir/someother/dir/
MV Command
-Function Description: Move file or directory, file or directory rename.
-Command format: MV [parameters] < source > < target >
-Common parameters:
-F: Forces the move, regardless of whether the target exists.
-I: Interactive move, need confirmation before overwriting file.
-U: Move only if the source file's modification time (CTime) is newer than the target file or the target does not already exist.
-use Example:
mv/some/dir/file1/someother/dir/
Mv/some/dir/file1/someother/dir/file2
mv/some/dir/files/someother/dir/
MV File Newname_file
MV Dir newname_dir
RM command
-Feature Description: Delete files or directories.
-Command format: RM [parameters] < file > ...
-Common parameters:
-F: Skip files that do not exist, and do not display any information.
-I: Must be confirmed before any delete operation.
-r,-r: Recursively deletes all directory tiers under this directory.
-use Example:
Rm/some/dir/file1
Rm-i/some/dir/file1
Rm-f/some/dir/file1
rm-rf/some/dir/
Attention
1. By default, RM does not delete the directory. Use the-recursive (-R or –r) option to delete each given directory, along with all of its contents.
2. To delete a file with the first character "-" (for example, "-foo"), use one of the following methods:
Rm--foo
Rm./-f
ln command
-Feature Description: Create a linked file.
-Command format: ln [parameters] < linked file > < link file name >
-Common parameters:
-S: Creates symbolic links instead of hard links.
-F: Forcibly creates a link, whether or not it exists.
-I: Ask the user before overwriting the original file.
-use Example:
ln somefile hardlinkfile
Ln-s Somefile Softlinkfile
Ln-s Somedir Softlinkfile
symlinks command
-Function Description: Check the symbolic link in the directory and display the symbolic link type.
-Command format: symlinks [parameters] < catalogue > [< directory;
-Type of link:
Absolute: Use symbolic links for absolute paths.
Dangling: Symbolic link where the original file does not already exist.
Lengthy: The path to the symbolic link contains an extra ". /”。
Messy: The path to the symbolic link contains an extra "/".
OTHER_FS: The original file is located in another file system.
Relative: A symbolic link that uses a relative path.
-Common parameters:
-C: Converts a symbolic link of type Absolute/messy to the relative type.
-D: Removes symbolic links of type dangling.
-R: Checks for symbolic links in all subdirectories under the directory.
-S: Shorten the symbolic link of the lengthy type.
-V: Displays all types of symbolic links.
-use Example:
Symlinks-v-R.
Symlinks-v/usr/bin
Symlinks-c Somedir
Symlinks-s-D Somedir

  
three, file packaging compression command
gzip command
-Function Description: Compression and decompression program for. gz files.
-Command format: gzip [parameters] < file > ...
-Common parameters:
-A: Use ASCII text mode.
C: The compressed file output to the standard output device, do not change the original file.
-D: Unpack the compressed file.
-F: Forcibly compresses the file, ignoring the existence of the file name or hard link and whether the file is a symbolic link.
-L: Lists information about compressed files.
-L: Displays version and copyright information.
-N: When compressing a file, the original file name and timestamp are not saved.
-N: Saves the original file name and timestamp when compressing the file, which is the default.
-Q: No warning message is displayed.
-R: Recursively handles all files and subdirectories under the specified directory.
-T: Test that the compressed file is correct.
-V: Displays the instruction execution process.
-V: Displays the gzip version information.
-< compression Rate >: The compression rate is a value between 1~9, the default value is "6", the higher the value the higher the compression rate.
–best: The effect of this parameter is the same as specifying the "-9" parameter.
–fast: The effect of this parameter is the same as specifying the "-1" parameter.
-use Example:
gzip filename
Gzip-v file1 file2
Gzip-c file1 file2 > foo.gz
Gzip-l *.gz
Gzip-d filename.gz
bzip2 command
-Function Description: Compression and decompression program for. bz2 files.
-Command format: bzip2 [parameters] < file > ...
-Common parameters:
C: The compressed file output to the standard output device, do not change the original file.
-D: Unpack the compressed file.
-F: Forcibly compress the file.
-K: Preserves the original file, which, by default, deletes the original file after it is compressed or uncompressed.
-S: Reduces the amount of memory used during program execution, but takes longer to execute.
-T: Test that the compressed file is correct.
-V: Displays the instruction execution process.
-V: Displays BZIP2 version information.
-< compression level >: The compression level is a numeric value between 1~9, specifying the chunk size at the time of compression.
–repetitive-best: This parameter can be used to improve the compression effect if there is duplicate data in the file.
–repetitive-fast: This parameter can be used to speed up execution if there is duplicate data in the file.
-use Example:
bzip2 filename
BZIP2-VK file1 file2
Bzip2-c file1 file2 > foo.bz2
Bzip2-t *.bz2
Bzip2-d filename.bz2
-Tip: bzip2 compresses files in chunks, each chunk as a separate unit. Therefore, when a chunk is damaged, you can use the Bzip2recover command to try to separate the chunks in the file so
The blocks that are normal are retracted. Usually only applies if the compressed file is a very large case.
Tar command
-Function Description: File package and unpacking.
-Command format: tar [parameters] < directory > ...
-Common parameters:
-F Name: Use name to specify the archive file name or device name.
-V: Lists processing details.
-C: Used to create a new archive file.
-X: Restore the backup file from the archive file.
-T: Used to list the file names in an archive file.
-Z: Compress files or unzip with GNU Gzip.
-Z: Compress files or unzip with compress.
-j: Compress files or unzip with bzip2.
-use Example:
TAR-CVF Myball.tar Somedirname
TAR-TF Myball.tar
TAR-XVF Myball.tar
TAR-ZCVF myball.tar.gz Somedirname
TAR-ZTF myball.tar.gz
TAR-ZXVF myball.tar.gz
TAR-JCVF myball.tar.bz2 Somedirname
TAR-JTF myball.tar.bz2
TAR-JXVF myball.tar.bz2
(Cd/source/directory && tar cpf–.) | (Cd/dest/directory && tar xvfp-)
Prompted
Similarities and differences between compressed files (compressed file) and archived files (archive file)
-Same: Is a collection of files and directories.
Different
The disk space occupied by the archive is the sum of all the files and directories in it.
In general, compressed files consume less disk space than the sum of all the files and directories in them.
The archive file is not a compressed file, but the compressed file can be an archive file.

Linux (CentOS) directory operations commands, file manipulation commands, compression decompression commands

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.