Summary of common Linux commands-File Management

Source: Internet
Author: User

Summary of common Linux commands-File Management directory path in Linux: the directory (folder) in linux has an absolute path and a relative path root directory:/home directory ): in the/home directory, the user logs on to the working directory: Current directory view command: pwd (print working directory) Current directory :. /The upper-level directory of the current directory :.. /or .. return to the upper-level Directory: cd .. enter the dirfile directory in the current directory: cd dirfilecd ~: Enter the user's main directory (account directory) or press "cd"-(return to the previous directory) to create, delete, view, and display directories. create directory format: mkdir [Option] Directory function: common options for creating a directory Description:-m. Create a directory and set the access permission.-p. Create a one-time multi-level directory. [Example ]: create the test folder under the rootfile folder and the file folder under the test folder. [Cpp] [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 the test2 folder in the rootfile folder, set the test2 permission to 766 [cpp] [root @ localhost rootfile] # mkdir-m 766 test2 [root @ localhost rootfile] # ls test test2 [root @ localhost rootfile] # ls -l total 16 drwxr-xr-x 3 root 4096 Jul 21 21:27 test d Rwxrw-rw-2 root 4096 Jul 21 test2 Note: rwxrw-rw-corresponds to the permissions of three different users, each with three values in binary format, and 766 corresponds to 111 110 1102. delete directory format: rmdir [Option] Directory function: common options for deleting a directory Description:-p recursively deletes a directory. delete a directory when its parent directory is empty after the subdirectory is deleted. (example ]: delete the file directory (folder) under test ), test also deletes [cpp] [root @ localhost rootfile] # ls test test2 [root @ localhost rootfile] # rmdir-p test/file [root @ localhost rootfile] # ls test2 3. view the current directory format: pwd function: pwd (print working directory), view the current directory. common options: [Example]: view the current directory [Cpp] [root @ localhost rootfile] # pwd/home/rootfile 5. display directory content format: ls [Option] [file directory] function: displays the file and directory information in the specified directory. If no directory is specified, common options for displaying files and subdirectories in the current directory:-a displays all files and subdirectories, including detailed information about hidden files and directories in the main directory-l, including file type, permission, owner and group, file size, last modification time, file name-d. If the parameter is a directory, only the directory information is displayed, without displaying the file information contained in it-t display in chronological order-R not only displays the file and subdirectory information under the specified directory, it also recursively displays the file and subdirectory information under the subdirectory to create and view the file creation File Format: touch filename function: common options for creating a file Description: [Example ]: create file.txt and test2/file2.txt [cpp] [root @ localhost root under rootfile File] # 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 content in filename in sequence. Common options: [Example]: Read Test in rootfile. file Content in java and file [cpp] [root @ localhost rootfile] # ls file.txt test2 Test. class Test. java [root @ localhost rootfile] # vi test2 [root @ localhost ro Otfile] # 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]: Merge test.javaand file.txt files into the combine.txt file [cpp] [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 [Option] filename function: Read the content in filename in sequence. Different from cat, this command can be displayed page by page and exited by pressing q. Description of common options:-p: before the next screen is displayed, the consecutive blank lines in the-s file are compressed into a blank line to display [Example ]: displays the content of file.txt [cpp] [root @ localhost rootfile] # more file.txt this is a file test. [Example]: displays content of test.javaand file.txt [cpp] [root @ localhost rootfile] # more Test. java file.txt ::::::::::::::::::::: Test. java ::::::::::::::::::: public class Test {public static void main (String args []) {System. out. println ("Hello Linux! ") ;}}:::::::::::::::: File.txt ::::::::::::: this is a file test. less Command Format: less [Option] filename function: Read the content in filename in sequence. The difference between this command and more is that you can not only flip down, but also flip up, you can use the up and down keys, Enter, space, pageDown, and pageUp to flip pages and press q to exit. Common options: [Example]: Display Test. java content [cpp] [root @ localhost rootfile] # less Test. java public class Test {public static void main (String args []) {System. out. println ("Hello Linux! ") ;}} Head Command Format: head [Option] filename function: displays the first few lines of the file. Common options:-n displays the first n lines of the file. If n is not displayed, the default value is 10 rows (for example, Test is displayed. the first three lines of java [cpp] [root @ localhost rootfile] # head-3 Test. java public class Test {public static void main (String args []) {System. out. println ("Hello Linux! "); Tail Command Format: tail [Option] filename function: displays the following common options at the end of a file: + n: The last n rows of the file are displayed from line n. If n is not displayed, the last 10 rows are displayed by default. [Example]: show Test. the last three lines of java [cpp] [root @ localhost rootfile] # tail-3 Test. java System. out. println ("Hello Linux! ") ;}} File search format: find [Option] filename function: recursively searches its subdirectories from the specified directory, common options:-name 'string': name of the file to be searched. Wildcards *,?, []-Group 'string' the user group name to which the file belongs-the user name to which the file belongs the query condition provided by the "find" command can be a combination of logical operators and, or, not -a logic and-o logic or -! Logical non-[Example]: find the file named Test in the current directory [root @ localhost rootfile] # find-name 'test *'. /Test. class. /Test. java [Example ]: in the root directory, find all the files named 'temp 'or matching 'Install *' [java] [root @ localhost rootfile] # find/-name 'temp '-o-name 'instal * '/etc/rhgb/temp/etc/yum/pluginconf. d/installonlyn. conf/etc/vmware-tools/installer. sh/software/tomcat5/webapps/docs/appdev/installation.html/software/tomcat5/temp/sbin/install-info/sbin/ins Tallkernel/usr/share/aclocal-1.9/install-sh.m4/usr/share/icons/Bluecurve/96x96/mimetypes/install.png/usr/share/icons/Bluecurve/24x24/mimetypes/ install.png/usr/share/icons/Bluecurve/16x16/mimetypes/install.png/usr/share/icons/Bluecurve/48x48/mimetypes/install.png/usr/share/aclocal-1.7/ install-sh.m4/usr/share/doc/cyrus-sasl-lib-2.1.22/install.html/usr/share/doc/sgml-common-0.6.3/html/install -Catalog.html/usr/share/doc/m2crypto-0.16/demo/Zope27/install_dir/usr/share/doc/m2crypto-0.16/demo/ZopeX3/install_dir/usr/share/doc/libstdc + +- devel-4.1.1/html/install.html ...... [Example]: Search for files without Test * under rootfile [java] [root @ localhost rootfile] # find! -Name 'test *'.. /. test2.swp. /1q. /. test. java. swp. /test2. /test2/file2.txt. /combine.txt. /file.txt text statistics Command Format: wc [Option] filename function: the number of bytes, number of words, and number of lines of statistics files. Common options: -c: Count byte-l count the number of rows-w count [Example]: Count Test. java's number of bytes, number of lines, and number of words [java] [root @ localhost rootfile] # wc Test. java 5 14 105 Test. java [root @ localhost rootfile] # wc-wcl Test. java 5 14 105 Test. cp Command Format: cp [Option] source directory or file target directory or file function: copy the given file or directory to another file or directory common options Note:-B if there is a file with the same name, overwrite the original file backed up before-f forcibly overwrite the file with the same name-r or R in recursive mode, retain the original directory structure to copy the file [Example ]: copy the file.txt file to file2. If file2 already exists, back up file2. [java] [root @ localhost rootfile] # ls 1q combine.txt file.txt test2 Test. class Test. java [root @ localhost rootfile] # cp-B file.txt file2 [root @ localhost rootfile] # ls 1q combine.txt file2 file.txt test2 Test. class Test. java [root @ localhost rootfile] # cp-B file.txt file2 cp: overwrite 'file2 '? N [root @ localhost rootfile] # ls 1q combine.txt file2 file.txt test2 Test. class Test. java [root @ localhost rootfile] # cp-B file.txt file2 cp: overwrite 'file2 '? Y [root @ localhost rootfile] # ls 1q combine.txt file2 file2 ~ File.txt test2 Test. class Test. java [Example]: copy the test2 file to the test3 folder [java] [root @ localhost rootfile] # ls 1q combine.txt file2 file2 ~ File.txt test2 Test. class Test. java [root @ localhost rootfile] # [root @ localhost rootfile] # cp-r test2 test3 [root @ localhost rootfile] # ls 1q combine.txt file2 file2 ~ File.txt test2 test3 Test. class Test. java mv Command Format: mv [Option] source directory or file target directory or file function: Move or rename a file or directory common options Description:-B if a file with the same name exists, overwrite the original file backed up before-f forcibly overwrite the file with the same name [Example]: replace Test in/home/rootfile. java moves to [java] [root @ localhost rootfile] # mv Test under/home/rootfile/test2. java test2/Test [root @ localhost rootfile] # ls-R.: 1q combine.txt file2 file2 ~ File.txt test2 test3 Test. class. /test2: file2.txt Test. /test3: file2.txt rm Command Format: rm [Option] folder or directory function: delete a folder or directory common options Description:-f force delete a file, no confirmation prompt-r or R is displayed to delete the directory recursively. By default, only files are deleted (example ]: delete the test3 folder [java] [root @ localhost rootfile] # ls 1q combine.txt file2 file2 ~ File.txt test2 test3 Test. class [root @ localhost rootfile] # ls test3 file2.txt [root @ localhost rootfile] # rm-r test3 rm: descend into directory 'test3 '? Y rm: remove regular empty file 'test3/file2.txt '? Y rm: remove directory 'test3 '? Y [root @ localhost rootfile] # ls 1q combine.txt file2 file2 ~ File.txt test2 Test. class [Example]: Force Delete the test2 folder under the current directory [java] [root @ localhost rootfile] # ls 1q combine.txt file2 file2 ~ File.txt test2 Test. class [root @ localhost rootfile] # rm-rf test2 [root @ localhost rootfile] # ls 1q combine.txt file2 file2 ~ File.txt Test. class

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.