Linux Common Command Summary--file management __linux

Source: Internet
Author: User
Tags mkdir parent directory


Directories in Linux

Path: That is, the directory (folder) in Linux has an absolute path and a relative path
Root directory:/
User home directory: In the/home directory, when a user logs on
Working directory (working directory): current directory

Current directory View command: PWD (print working directory)
Current directory:./
Top level of current directory:.. /or..
Go back to the previous level of the directory: CD.

Enter the Dirfile directory under the current directory: CD Dirfile
CD ~: Enter user home directory (account directory) or direct CD return
Cd-:(back to previous directory) create, delete view and display directories 1. Create a table of contents

format:mkdir [Options] Directory

Features: creating catalogs

Common Options Description:

-m set access permissions while creating a directory

-P Create multilevel catalogs once

"Example": Create the Test folder under the RootFile folder and create the file folder under the Test folder.

[Root@localhost rootfile]# mkdir-p test/file
[root@localhost rootfile]# ls
test
[root@localhost rootfile ]# CD test
[root@localhost test]# ls
file
[root@localhost test]#

"Example": Create a Test2 folder under the RootFile folder and set test2 permissions to 766

[Root@localhost rootfile]# mkdir-m 766 test2
[root@localhost rootfile]# ls
test  test2
[ Root@localhost rootfile]# ls-l Total
drwxr-xr-x 3 root root 4096 June 21:27 test
drwxrw-rw-2 root ro OT 4096 June 21:30 Test2

Note: rwxrw-rw-respectively corresponding to three different users of the rights, there are three binary system, 766 corresponds to the 2. Delete directory

format : rmdir [Options] Directory

Features: deleting catalogs

Common Options Description:

-p recursively deletes the directory, and when the subdirectory is deleted and its parent directory is empty, it is also deleted

"Example": Delete the file directory (folder) under test, and test also delete

[root@localhost rootfile]# ls
test  test2
[root@localhost rootfile]# rmdir-p test/file
[ Root@localhost rootfile]# ls
test2

3. View current directory

format: pwd

Features:pwd (print working directory), view the current directory.

Common Options Description:

"Example": View the current directory

[Root@localhost rootfile]# pwd
/home/rootfile

5. Display directory Contents

format:ls [options] [file directory]

Features: displays files and directory information in the specified directory, and displays file and subdirectory information in the current directory when no directory is specified

Common Options Description:

-a displays all files and subdirectories, including hidden files and home directories

-l Displays details of files and subdirectories, including file types, permissions, owner and group ownership, file size, last modified, file name

-D If the parameter is a directory, only directory information is displayed, not the file information contained therein

-t display in chronological order

-R not only displays the file and subdirectory information in the specified directory, but also recursively displays the file and subdirectory information under the subdirectory

Creating and Viewing files Create a file

format:touch filename

Features: creating files

Common Options Description:

"Example": Create files File.txt and Test2/file2.txt under RootFile

[Root@localhost rootfile]# touch file.txt
[root@localhost rootfile]# touch test2/file2.txt
[root@localhost rootfile]# ls
file.txt  test2
[root@localhost rootfile]# cd tes*
[root@localhost test2]# ls
File2.txt

Cat Command

format:cat [option] filename

function: read the contents of filename sequentially

Common Options Description:

"Example": Read the contents of the files in Test.java and file under RootFile

[root@localhost rootfile]# ls
file.txt  test2  test.class  test.java
[root@localhost rootfile]# VI test2
[root@localhost rootfile]# vi file*
[root@localhost rootfile]# cat Test.java Public
class Test { Public
        static void Main (String args[]) {
                System.out.println ("Hello linux!");
        }
[Root@localhost rootfile]# cat Test.java file.txt Public
class Test {public
        static void Main (String args[]) {
  system.out.println ("Hello linux!");
        }
This is a file test.

"Example": Merging Test.java and file.txt files into a combine.txt file

[Root@localhost rootfile]# cat Test.java file.txt > Combine.txt
[root@localhost rootfile]# cat comb*
Public Class Test {public
        static void Main (String args[]) {
                System.out.println ("Hello linux!");
        }
This is a file test.

More Command

format:more [options] filename

function: in turn, read the contents of filename, the command and the difference between the cat can be a screen page down to display, press Q exit.

Common Options Description:

-P to clear the screen before displaying the next screen

-s file is compressed into a blank line to display the continuous blank line

"Example": Displays the contents of the File.txt

[Root@localhost rootfile]# more file.txt This is
a file test.


"Example": Displays the contents of Test.java and File.txt

[Root@localhost rootfile]# more Test.java file.txt::::::::::;:::.:::
Class Test {public
        static void Main (String args[]) {
                System.out.println ("Hello linux!");
        }
:
:: ::::::::::.:------
file.txt
:


less Command

format:less [options] filename

function: read the contents of filename in turn, the command and more different is not only can page down, but also page up, using up and down keys, Enter, spaces, PageDown, PageUp can be achieved before and after the page, press Q exit.

Common Options Description:

"Example": Displays the contents of the Test.java

[Root@localhost rootfile]# less Test.java public
class Test {public
        static void Main (String args[]) {
                Sys Tem.out.println ("Hello linux!");
        }

Head Command

format:head [option] filename

Features: Displays the first few lines of a file

Common Options Description:

-N Displays the first n rows of the file, if there are no n values, the default is 10 lines

"Example": Displays the first 3 lines of Test.java

[Root@localhost rootfile]# head-3 Test.java public
class Test {public
        static void Main (String args[]) {
                Syst Em.out.println ("Hello linux!");

Tail Command

format:

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.