linux-(LS,MV)

Source: Internet
Author: User
Tags parent directory

ls command

The LS command is the most commonly used command under Linux. The LS command is the abbreviation for list, and the missing LS is used to print out the list of current directories. If LS specifies a different directory, then the list of files and folders in the specified directory is displayed.

The LS command not only allows you to view the files contained in a Linux folder but also to view file permissions (including directories, folders, file permissions) to view directory information, and so on.

1. Command format:

ls [options] [directory name]

2. Command function:

Lists all subdirectories and files in the destination directory.

3. Common parameters:

-a,–all lists all files under the directory, including the. The implied file at the beginning

-A with-a, but not listed "." (represents the current directory) and ".." (Represents the parent directory of the current directory).

-h,–human-readable list file sizes in an easy-to-understand format (e.g. 1K 234M 2G)

-h,–dereference-command-line the true destination indicated by using symbolic links in the command column

-i,–inode Prints the inode number of each file

-K is the –block-size=1k that represents the size of the file in K-byte form.

-l lists the permissions, owner, file size, and so on, in addition to the file name.

-l,–dereference when displaying the file information for a symbolic link, displays the object indicated by the symbolic link instead of the information of the symbolic link itself

-m all items are separated by commas and fill the entire row width

-r,–recursive listing all subdirectory tiers at the same time

-F, which allows the LS command to display a subdirectory with a slash ("/") character after its filename, and the asterisk ("*") character following the file indicates that this is an executable program

-s,–size to list the size of all files in block size

-s sort by file size

-T sorted by file modification time

-U mate-lt: Show access time and sort by access time; L: Show access time but sort by name

-C mate-lt: Sorts and displays ctime based on CTime (the last time the file state was changed), mate-L: Show CTime but sort by name

-V Sort by version

-W,–WIDTH=COLS Specifies the screen width without using the current value

-X list items line by row instead of columns by column

-x Sort by extension

-1 list only one file per line

Help display this help message and leave

4. Common examples: to list the absolute path of a file in LSCommand: LS | Sed "s:^:p wd/:"

Output:

[[email protected] opt]# ls | Sed "s:^: ' pwd '/:"/opt/log/opt/script/opt/soft/opt/src/opt/svndata
lists the absolute path to all files (including hidden files) in the current directory, without recursion to the directoryCommand: Find $PWD-maxdepth 1 | Xargs Ls-ld

Output:

[[email protected] opt]# find $PWD-maxdepth 1 | Xargs ls-lddrwxr-xr-x 8 root root 4096 10-11 03:43/optdrwxr-xr-x 2 root root 4096 2012-03-08/opt/  Logdrwxr-xr-x 2 root root 4096 2012-03-08/opt/scriptdrwxr-xr-x 5 root root 4096 10-11 03:21/opt/soft
Extensions:

1. Display a list of color catalogs

Open/ETC/BASHRC and add the following line:

Alias ls= "Ls–color"

The next time you start bash, you'll be able to display a list of colored catalogs as you would in Slackware, where the meanings of colors are as follows:

1. Blue –> Directory

2. Green –> executable file

3. Red –> Compressed file

4. Light blue –> link file

5. Grey –> Other files

MV Command

The MV command is the abbreviation for move, which can be used to move files or rename files (rename), which is a common command under Linux, often used to back up files or directories.

1. Command format:

MV [option] source file or directory destination file or directory

2. Command function:

Depending on the second parameter type in the MV command (either the destination file or the destination directory), the MV command renames the file or moves it to a new directory.

When the second parameter type is a file, the MV command completes the file rename, at which point the source file can only have one (or the source directory name), which renames the given source file or directory to the specified destination file name.

When the second parameter is a directory name that already exists, the source file or directory parameter can have more than one , and the MV command moves the source files specified by each parameter to the destination directory. When you move a file across a file system, theMV copies the original file , and the link to the file is lost.

3. Command parameters:

-B: Overwrite the previous backup if you need to overwrite the file.

-f:force mandatory Meaning, if the target file already exists, will not be asked and directly covered;

-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, update (update)

- T: Specifies the target directory for MV, which is used when moving multiple source files to a directory, at which point the target directory is before the source file.

linux-(LS,MV)

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.