Linux Common management commands use

Source: Internet
Author: User


1. What are the file management commands on Linux, their commonly used methods and their related examples?

Common commands: LS, CD, PWD, mkdir, CP, RM, MV, Touch, cat, more, less, head, tail, Du, WC


LS:-A&NBSP: Lists all the files in the current directory, together with the hidden file, but excludes  .  and     these two directories-d : Lists only the directory itself, not the file data in the directory  -h : List the file capacity in a human-readable way (such as  GB, KB , etc.)  -i  : List  inode  number,inode  the next chapter will introduce  -l : Long data string list, including file properties and permissions and so on data-r : Listed along with subdirectory content, equals all files in that directory will be displayed  CD: example [[email protected] ~]# cd /home/    # Switch to home directory [[email protected] home]# cd -       #返回切换到home前的目录/ ROOT[[EMAIL PROTECTED] ~]# CD&NBSP, .... /        #切换到上一级目录 [[email protected] /]# cd ~           #切换当前用户的home目录pwd:p wd  Display current directory-L: Show current directory-P: Displays the actual physical address of the current directory example [[ email protected] bxx]# pwd/opt/bxx[[email protected] bxx]# pwd -p/home/bss# Pwd -p shows the actual physical address, not the mkdir:-m created by the soft connection: Set the permission mode (like chmod) instead of rwxrwxrwx  minus UMASK-P: Create the upper-level directory of the target directory when needed, But even if these directories already exist and are not treated as error-V: Each time a new directory is created, an example of information is displayed[[email protected] ~]# mkdir rice    #创建目录 [[email protected] ~]#  mkdir -m a=rw rice    #创建指定属性的目录 [[Email protected] ~]# mkdir  -p 111/rice/backup   #这里我个人是将其理解为, creating a directory recursively
rm:rm [-fir]  file or directory   options and Parameters:-F: Is  force  means, ignore nonexistent files, do not appear warning message-I: interactive mode, Before the deletion will ask the user whether the action-r: hand-back Delete Ah! Most commonly used in directories are removed (this is a very dangerous option) example [[email protected] ~]# rm rice.php          #删除文件需要确认 [[email protected] ~]# rm -f rice.php       #强制删除文件不确认 [[email protected] ~]# rm -rfv ./rice       #强制删除当前的test目录, and displays the detailed procedure for deleting mv:mv [-fiu] source destination  options and Parameters:-f :force  Mandatory meaning, if the target file already exists, will not ask and directly overwrite-i&nbsp: If the target file   (destination)   already exists, will ask whether to overwrite-u : If the target file already exists and   source  newer, only upgrade   (update) Note: MV There is also a use of renaming, the most common day is also the most examples [[EMAIL PROTECTED] ~]# MV ABC  abc.php   #将abc移动成abc. php[[email protected] ~]$ mv /home/rice.txt / database      #将rice. txt moved to the database directory touch:-a : Revision only  access time-c  : Only the time of the file is modified, if the file does not exist the new text is not createdPiece-d : the date after which you want to revise it instead of the current date, you can also use the  --date= "date or Time"-M : Modify only  mtime-t : The time after which you want to revise it instead of the current time, in the format [YYMMDDHHMM] Example [[email protected] ~]# touch test.php                     #将test. php file time changed to, current time, file not exist [[ email protected] ~]# touch -c -t 05071803 test.php    # Change the archive time to, May 7 18:3 [[email protected] ~]# touch -r abc.php test.php          #将test. php file changed to root abc.php [[email protected] ~]# touch - d  "2 days ago"  test.php    #将test. PHP Date modified to 2 days ago
cat:cat [-abentv]  options and Parameters:-a : equivalent to-vet  integration options, Some special characters can be listed instead of blank-b : List line numbers, only for non-blank lines to do the line number display, blank lines do not mark the line number-e : The end of the break byte  $  display-n : Print the travel number, along with the blank line will also have line number, Unlike the  -b  options   (commonly used)-T&NBSP: The  [tab]  key is displayed in  ^I -v : lists some special characters that are not visible more:more   (one-page turn to view) Common shortcut keys: Blank key   (space): Represents a downward row enter        : Represents a downward row/ String         : Represents the keyword in this display, searching down the string for the word:f           &NBSP: Displays the file name immediately and the number of rows currently displayed q            &NBSP: Represents exit b  or  ctrl+b  : Represents a page back, but this action is only useful for files 
Less:less (page by page) Less and more difference: In more time, we have no way to turn front, can only look back, but if you use less, you can use [PageUp] [PageDown] The function of the key to go back to look at the file commonly used shortcut keys: Blank key: [PageDown]: Turn down a page [PageUp]: Flip a page/string: down to search the function of the string? String: Search for the function of the string N: Repeat the previous Search (with/or about!) N: Reverse the repetition of the previous search (with/or?)! Q: Leave less this program Head:head [-N number] file options and Parameters:-N: followed by numbers, indicating the meaning of a few lines (default is the first 10 rows) Tail:tail [-N number] file options and Parameters:-N: followed by number The word, which represents the meaning of a few lines (the default after 10 lines)-F: Indicates a continuous view of the subsequent files, to wait until the CTRL + C to end tail view (Tail–f is very useful when we look at some frequently updated logs, example: Tail-f/var/log/maillog)



2. Bash's work characteristics the command execution status return value and command line expansion are involved in the content and its sample demonstration.

Features in Bshell: Command completion Command History view command history: History-c: Empty command history-D: Delete command at specified location-w: Save command history to history file command alias alias cmdalias= ' command [options] [   Arguments] ' aliases defined in the shell are valid only for the current shell life cycle; The valid range of aliases is only the current shell process; command-line edit Ctrl + A: Skip to command line ctrl+e: Skip to command end Ctrl+u: Delete the cursor to the beginning of the command CTRL+K: Delete the cursor to the end of the command line

3. Use the command line expansion function to complete the following exercises:


(1), create/tmp directory: A_c, A_d, B_c, B_d

Mkdir-p/tmp/{a_c,a_d,b_c,b_d}


(2), create the/tmp/mylinux directory:

mylinux/

├──bin

├──boot

│└──grub

├──dev

├──etc

│├──rc.d

││└──init.d

│└──sysconfig

│└──network-scripts

├──lib

│└──modules

├──lib64

├──proc

├──sbin

├──sys

├──tmp

├──usr

│└──local

│├──bin

│└──sbin

└──var

├──lock

├──log

└──run


Mkdir-p/mylinux/{bin,boot,dev,etc,lib,lib64,proc,sbin,sys,tmp,usr,var,lock,log,run}mkdir-p/mylinux/boot/ Grubmkdir-p/mylinux/etc/{rc.d,sysconfig}mkdir-p/mylinux/etc/rc.d/init.d/mkdir-p/mylinux/etc/rc.d/sysconfig/ Network-scriptsmkdir-p/mylinux/lib/modulesmkdir-p/mylinux/usr/local/{bin,sbin}



4, what is the metadata information of the file, what does it mean, how to view it? How to modify timestamp information for a file.

For:

Access: Last access time modify: Last Modified time change: state changed time (system maintained, cannot be arbitrarily modified) TOUCH-A: Update only access times (while updating the change to current time) touch- M: Update modify time only (update change to current time) Touch-c: Do not create a new file touch-t: Update the timestamp example with the specified time: touch-t [[CC]YY]MMDDHHMM[.SS] FileName

5, how to define the alias of a command, how to reference the execution result of another command in the command?

(1) [[Email protected] ~] alias dir= ' Ls-ar ' #设置别名可以是命令带参数 (2) You can define an environment variable, or write it as a shell script to invoke.


6. Display all files or directories in the/var directory that start with L, end with a lowercase letter, and have at least one digit (can have other characters) appear in the middle.

find/var/-maxdepth 1-name "l*[0-9]*[a-z]"


7. Displays files or directories that start with any number in the/etc directory and end with a non-numeric number.

find/etc/-maxdepth 1-name "[0-9]*[!0-9]"

8, Show/etc directory, start with a non-letter, followed by a letter and any other arbitrary length of any character file or directory.

find/etc/-maxdepth 1-name "[0-9]*[a-z-a-z]*"

9. In the/tmp directory, create a file that starts with Tfile, followed by the current date and time, with a filename such as: tfile-2016-08-06-09-32-22.

Touch tfile ' date + '%y-%m-%d-%h-%m-%s '

10. Copy all the files or directories in the/etc directory to the/tmp/mytest1 directory that begin with P and do not end with a number.

ls/etc/| grep "^p[^0-9]*$" | Xargs-i Cp-r {}/tmp/mytest1

11. Copy all files or directories ending with. D in the/etc directory into the/tmp/mytest2 directory.

Find/etc-maxdepth 1-name "*.D" | Xargs Cp-r/tmp/mytest2/

12. Copy all files in the/etc/directory that begin with L or M or N and end with. conf to the/TMP/MYTEST3 directory.

find/etc/-type f-name "[lmn]*conf" |xargs cp-rf/tmp/mytest3/


Linux Common management commands use

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.