Linux File Management commands

Source: Internet
Author: User

Linux File Management commands

Linux directories and Paths

CD: Switch directories

For example: CD ~willhua, go back to user Willhua's home folder

CD ~ or CD, it means back to your home folder

CD-, which means back to the previous directory

PWD: Displays the directory where you are currently

Parameters:

    • -P, display the current path instead of using the connection path

mkdir: Create new directory

Parameters:

    • -M: Permissions for the direct profile, regardless of default permissions umask, such as Mkdir-m 711 Test1, Test1 has a permission of 711
    • -P: To help you directly create the desired directory recursively, such as Mkdir-p Test1/test2/test3, the system will be recursively created TEST1,TEST2,TEST3

RmDir: Delete Empty directory

Parameters:

    • -P: Along with the empty directory on the upper level, the empty directory here means that the directory contains only the folders in the deleted path and cannot contain any other files or folders.

For example: Rmdir-p test1/test2/test3, if the folder chain contains other files will delete the failure

File and Directory Management

LS: View file directory

Parameters:

    • -A: List all files, along with implied files
    • -D: Lists only the files themselves, not the files in the directory, and the PWD almost
    • -L: Lists Long data strings that contain data such as the attributes and permissions of the file, and in most versions ll is equivalent to Ls-l

CP: Copy file, cp parameter source file target file

Parameters:

    • -A: equivalent to-PDR
    • -I: If the target file is present, ask if the overwrite operation
    • -R: Recursive replication for directory replication

For example: Cp-r/temp/test/temp/test2, it means that the test directory is recursively copied to Test2

Cp-r/temp/test Test.txt/etc/test3/temp/test2, the test,test.txt,test3 are copied to the Test2.

RM: Remove files or directories

Parameters:

    • -F: Force Delete, ignore nonexistent files, do not appear warning message
    • -I: will ask whether to delete
    • -r: Recursively delete folders

MV: Moving files or directories, or renaming

Parameters:

    • -F: If the destination file already exists, overwrite it directly without asking
    • -I: will ask whether to overwrite
    • -U: If the destination file already exists, only the source file is newer

For example: MV Test test2, if test2 exists, the test is moved to Test2, if the test2 does not exist, it is equivalent to the test renamed to Test2

File Content Lookup

Cat: Display file contents starting from the first line

Parameters:

    • -A: List some special characters, not blanks.
    • -N: Prints the number of trips, including blank lines, and-B does not contain blank rows

For example: Cat-an/etc/my.txt, the My.txt file is displayed starting from the first line, and special characters are printed, showing the line number

TAC: Start displaying files from the last line

NL: Displays file contents and automatically adds line numbers

Parameters:

    • -B A: The travel number is listed even if it is a blank line
    • -B T: The line number of a blank row is not listed, the default value
    • -N LN: line number is displayed on the left of the screen
    • -N RZ: The line number is displayed at the far right of the field, plus 0 of the row number
    • -W N: Number of line digits, n indicates number of digits

For example: Nl-b a-n rz-w 5 my.txt, indicating that line numbers are displayed to the right of the field at 5-bit width, including blank lines

Less: Displays the file page on the screen

Operation:

    • SPACEBAR: Flip one PAGE Down
    • PageDown: Same Space
    • PAGEUP: Flip one page Up
    • ? String: query string up
    • /string: query string down
    • Q: Exit
    • n/n: General-Purpose Continuation query

Head: Show only the previous lines

For example: Head-n my.txt, only the My.txt front 20 rows are displayed, Head-n -30 my.txt, only the data before the last 30 lines are displayed;

Tail: Show only the following lines

For example: Tail-n my.txt, only show my.txt after 20 rows, Tail-n -30 my.txt, only 30 rows after the data is displayed;

OD: Display non-text files

Parameters:

The optional parameters of the-T Type,type are:

    • A: Use default characters to output
    • C: Use ASCII to output
    • D: Use decimal to Output
    • x: use hexadecimal to output

For example: Od-t c/usr/bin/passwd, indicates that the passwd is displayed in ASCII form

Touch: Modify the file time or create a new file

For example: Touch NewFile, if NewFile does not exist, it means to create a file named NewFile, if NewFile exists, NewFile mtime and Atime are modified to the current time

Umask: When creating a new file/directory, its corresponding default permissions should be subtracted from the value of the permission

For example: For a new directory, the default permission is drwxrwxrwx, and if you do: Umask 022, the default permissions will change to Drwxr-xr-x

Chattr: Setting hidden properties of a file

Parameters:

    • +: Add a special parameter, the other unchanged
    • -: Remove a special parameter, other unchanged
    • =: Only the following parameters are followed
    • A: After setting the A property, this file can only add data, cannot be changed or deleted, only root can set this property
    • I: Let the file cannot be deleted, renamed, set the connection can not write or add data, only root can set this property

For example: Chattr +i attrtest, the Attrtest file will not be deleted, renamed, and the connection cannot be written or added to the data

File: View files Type

For example: FILE/USR/BIN/PASSWD, it will show that passwd this file is ASCII or this is data or binary file, there is no use of information such as dynamic function library

Locate: Finding Files

Parameters:

    • -I: Ignore case differences
    • -R: Can be followed by the display of regular expressions

For example: Locate passwd, all passwd related file names will be found, and passwd represents a partial name. However, because locate is database-based, the general database is updated daily, so you may not find the situation, you can use the UpdateDB command to manually update the database

Find: Finds files, slower, but belongs to hard drive find, can find

For example: Find/-name passwd, the file named passwd will be found in the system. where/represents the lookup path, which is the root directory

Manuscripts: Diligent Learning qkxue.net

Extended reading:

Http://qkxue.net/info/31365/Linux

Http://qkxue.net/info/31502/Linux

Http://qkxue.net/info/31426/linux

Linux File Management commands

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.