Linux Basics Common File management rollup

Source: Internet
Author: User
Tags aliases clear screen create directory numeric mkdir parent directory readable egrep

Document management and the common commands detailed

Linux file system is a basic inverted tree structure, we have to further study the file or directory operation and management commands:

Directory-related operations: CDs, PWD, mkdir, rmdir
Directory and file search: ls
Copy, move, delete: CP, MV, RM
File content view: Cat, TAC, more, less, head, tail
View file type: Type: View command types
Command and File search: Which, Whereis, find

Let's explain each one individually:

1.cd

The abbreviation for change directory, the command to transform the working directory.
The simplest use of CD [dir], can be an absolute or a relative path to a directory
CD ~ $USERNAME means switch to $username's home directory
2, PWD

Print Working directory, showing the path to the current directory
"OPTION"
-P [dir] represents the actual path instead of using the path of link
"For Exampor"
[Root@localhost ppp]# cd-p/var/mail/
[Root@localhost mail]# pwd
/var/spool/mail
[Root@localhost mail]# Pwd-p
/var/spool/mail
3, mkdir

Make directories, creating a catalog file


"OPTION"


-M,--Mode=mode


Set file Mode,not a=rwx-umask specify permissions, unaffected by umask


-P,--Parents


No error if Existing,make parent directories as needed


The parent directory is generated as needed (if the parent directory does not exist) and no error is given


-v,--verbose


Print a For each created directories.


Print Create directory message


"For EXAMPLE"


[root@localhost tmp]# mkdir-m 555 Test


[Root@localhost tmp]# Umask


0022


[Root@localhost tmp]# Ll-a


Dr-xr-xr-x. 2 Root 6 Sep 22:45 test


[Root@localhost tmp]# MKDIR-PV Test/testx/testy


mkdir:created directory ' Test/testx '


mkdir:created directory ' Test/testx/testy


4, RmDir

Remove empty directories, delete empty directory


"Synopsis"


rmdir [option] ... [dir] ...


"OPTION"


-P,--parents


Remove DIRECTORY and its ancestors (ancestor, ancestors)


Delete a directory with its parent directory


-v,--verbose


"For EXAMPLE"


[Root@localhost tmp]# ls-ld/tmp/*


-rw-r--r--. 1 root 134 Sep 23:07/tmp/issue


DRWX------. 2 FTP FTP (SEP) 22:20/tmp/skel


Dr-xr-xr-x. 3 Root Sep 22:53/tmp/test


-RWX------. 1 Root 0 Sep 20:27/tmp/test1


Drwxr-xr-x. One root root 4096 Sep 01:35/tmp/x


[Root@localhost tmp]# rmdir-p Test/testx/testy


[Root@localhost tmp]# ls-ld/tmp/*


-rw-r--r--. 1 root 134 Sep 23:07/tmp/issue


DRWX------. 2 FTP FTP (SEP) 22:20/tmp/skel


-RWX------. 1 Root 0 Sep 20:27/tmp/test1


Drwxr-xr-x. One root root 4096 Sep 01:35/tmp/x


5, LS

List Directory contents, listing the path directory


"Synopsis"


ls [option] ... [File] ...


"OPTION"


-a,--all


Don ' t ignore entries starting with.


Enumerate all documents, along with hidden documents (. Beginning of document)


-a,--almost-all


Don ' t list implied. and..


-L Use a long listing format


Display with long format, each row of data represents a file or directory


-F do not sort, enable-au, Disable-ls--color


Display without sorting


-h,--human-readable


With-l,print sizes in human readable format


Used in conjunction with the-l option, displayed in human-readable format (e.g., KB,MB,GB, etc.)


-i,--inode


Print the index number for each file


Display the inode number for each file


-s,--size


Print the allocated size of each file,in blocks


Show the size of each file allocation


-s sort by file size


Sorted by file size, with the-l option used more clearly


-r,--reverse (reverse)


Reverse order while sorting


Reverse order display, contrary to the results used by the LS command alone


-r,--recursive


List subdirectories recursively


Listed together with the contents of the subdirectory (this command is carefully used)


-G like-l,but don ' t list owner


-g,--no-group


6, CP

Copy files and directories, and if the target does not exist, create the destination file or directory, and if the target exists, directly overwrite


"Synopsis"


CP [OPTION] ... [-T] SOURCE DEST/* single-source copy, source file, destination target * *


CP [OPTION] ... SOURCE ... DIRECTORY//multi-source Replication * *


CP [OPTION] ...-t DIRECTORY source .../* Multi-source Replication */


"OPTION"


-a,--archive


Same AS-DR--preserve=all


Retains all properties of the source file, recursively replicates


-i,--interactive


Prompt before overwrite before overwriting an interaction hint


-f,--force


If an existing destination file cannot is opened,remove it and try again


If the destination file cannot be opened, delete it and try copying again. That is, do not prompt, force replication


-r,-r,--recursive


Copy directories recursively recursive replication


-d,same as--no-dereference--preserve=links


If the source file is a linked file, copies the source file contents of the linked file, but does not point to the source file, and the option is the same as P


7, MV

Move or Rename files
    "Synopsis"
    MV [OPTION] ... [-T] SOURCE DEST
    mv [OPTION] ... SOURCE ... Directory
    MV [OPTION] ... t directory SOURCE ...
    option
       -i,--interactive move interactively or rename
       -f,--force  force Move or rename
        -n,--no-clobber
            don ' t overwrite an Existing file does not override
8, RM

for existing files

Remove Files and directories
"Synopsis"
RM [OPTION] ... FILE ...
"OPTION"
-f,--force forced deletion does not prompt
-I prompt confirmation for each deletion of a file
-I only prompt once when I delete more than 3 files
--no-preserve-root don ' t treat '/' specially can be deleted/
9, Cat

Concatenate files and print on the standard output standard export file contents


"Synopsis"


Cat [option] ... [File] ...


"OPTION"


-a,--show all equivalent To-vet


-b,--number-nonblank


Number nonempty output Lines,overrides-n


Non-blank lines display line number display content, as opposed to-n option


-e,--show-ends


Display $ At ' end of '


Show with $ symbol at the end of each line


-n,--number


Number all output lines line numbers per line, including blank lines


-t,--show-tabs


Display tab characters as ^i, replace TAB-blank characters with ^i to show files


-v,--show-nonprinting


Use ^ and m-notation,except for LFD and TAB


-s,--squeeze-blank


Suppress repeated empty output lines duplicate blank lines show only one row


"For EXAMPLE"


10. Tac

Concatenate files and print in reverse the reverse output document content, is the cat's antisense <br/>
11, more

The file perusal filter for CRT viewing Page view of the contents of the files, similar to Cat


"Synopsis"


More [options] file [...]


"OPTION"


-number This option specifies an integer number which


is the screen size (in lines)


Set the number of rows to display per page


-D display Help instead the ring bell


Display Help information: space continue to view, Q exit


-L suppress pause after form feet


Browsing is not terminated when the ^ character is encountered


-p Clear screen after display content


-C to clean up other content after displaying content


-S displays only one row after consecutive, duplicate blank rows


+num display file beginning from line number NUM


Show all content starting with the given line number


+/string display file beginning from search string match


Displays the contents of a document based on the location of the matching string


"For EXAMPLE"


[Root@localhost tmp]# more-10 +/unset functions


... skipping


. /etc/profile.d/lang.sh 2&gt;/dev/null


# avoid propagating langsh_sourced any further


Unset langsh_sourced


Fi


# Read in our configuration


If [-Z "${bootup:-}"]; Then


if [-f/etc/sysconfig/init]; Then


. /etc/sysconfig/init


Else


--more--(13%)


12, less

Opposite of more is also a page-flipping display, except that less can page up and down and other functions


"OPTION"


-B &lt; buffer size &gt; Setting buffer size


-e automatically leave when file display is finished


-F forced to open special files, such as peripheral device codes, directories, and binaries


-G only flags the last search keyword


-I ignores capitalization when searching


M displays a percentage similar to the more command


-N Displays the line number of each row


-o &lt; filename &gt; Save the contents of the less output in the specified file


-Q Do not use warning tones


-s shows continuous empty behavior row


-S line too long to discard part


-X &lt; number &gt; Display the TAB key as a specified number space


13, head

Output the first part of the files display a portion of the file


"Synopsis"


Head [OPTION] ... [FILE] ...


"OPTION"


-c,--bytes output by Byte, for example:-C 20 Displays the first 20 bytes of content


-n,--lines display by number of rows


-q,--quiet silent mode, no file name displayed


-v,--verbose Always show file name


"For EXAMPLE"


[Root@localhost tmp]# head-v-N 3 functions


==&gt; functions &lt;==


#-*-shell-script-*-


#


# functions This file contains functions to is used by most or all


[Root@localhost tmp]# head-c Issue


Hwo Are you?


Fine,th[root@localhost tmp]#


14, tail

    Print The last lines of standard output. The final 10 lines of each file
    SYN Opsis "
    tail [OPTION] ... [FILE] ...
    option
       -f,--follow      Append content to standard output as the file grows
       -n,--lines      Set the number of rows to display
       -s,--sleep-interval=n
                 used with the-f parameter to indicate the refresh interval
        -c,--bytes=k    display content from K-byte position
    for EXAMPLE        
        Basic usage is similar to head
15, file

Determine type of files detail-specific file types
"Synopsis"
File [OPTION ...] [FILE ...]
"OPTION"
"For EXAMPLE"
[Root@localhost tmp]# file X/af1.txt
X/af1.txt:ascii text
Metadata for files

Stat

Display file or file system status
[Root@localhost tmp]# Stat Issue
File: ' issue ' filename
size:191 File size blocks:8 block size IO block:4096 regular file
device:fd00h/64768d inode:101365706 links:1
Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)
Context:unconfined_u:object_r:user_tmp_t:s0
access:2016-09-25 11:42:52.578622335 +0800 Access time
modify:2016-09-25 11:42:48.371622436 +0800 Modified Time
change:2016-09-25 11:42:48.372622436 + 0800 meta data Change time
Birth:-
Stat The file's metadata by default, which includes all the information on the file as above; we can usually determine the use of the file according to the timestamp of the file, and we can modify the timestamp data by the command touch without further explanation.
Command Alias

Alias

Define or display aliases defines or displays aliases
Alias as a built-in Linux command, you can redefine the format of an existing command; For example: after alias Rm=rm-i, using the RM command means deleting file and confirming that it is deleted
"OPTION"
-P Print all defined aliases in a reusable format shows all defined aliases
"For EXAMPLE"
[Root@localhost ~]# Alias-p
Alias cp= ' Cp-i '
Alias egrep= ' Egrep--color=auto '
Alias fgrep= ' Fgrep--color=auto '
Alias grep= ' grep--color=auto '
Alias l.= ' ls-d. *--color=auto '
Alias ll= ' Ls-l--color=auto '
Alias ls= ' ls--color=auto '
Alias mv= ' Mv-i '
Alias rm= ' Rm-i '
Alias Vi= ' Vim '

[root@localhost ~] #alias tail= ' tail-f '
Command Reference

There are many ways to perform the results of a command, one of which is as follows:

"That's 1 (!) ) before the symbol, which indicates the priority of the execution

[Root@localhost tmp]# cat ' pwd '
Cat:/tmp:is a directory
[Root@localhost tmp]# pwd
/tmp
[Root@localhost tmp]# Cat/tmp
Cat:/tmp:is a directory
Variable, a simple command reference can use a variable

[Root@localhost ~]# cat $ (PWD)
Cat:/root:is a directory
The same as the result of the previous command.
Command line expand Demo

Create the A_c,a_d,b_c,b_d in the/tmp directory

[Root@localhost tmp]# Mkdir-pv/tmp/{a,b}_{c,d}
mkdir:created directory '/tmp/a_c '
mkdir:created directory '/tmp/a_d '
mkdir:created directory '/tmp/b_c '
mkdir:created directory '/tmp/b_d '
[Root@localhost tmp]# ls
A_c a_d B_c b_d issue Skel test1 X
Create/tmp/mylinux Directory

[Root@localhost tmp]# mkdir-pv/tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-


Scripts},lib64,proc,sbin,sys,tmp,usr/local/{bin,sbin},var/{lock,log,run}}


mkdir:created directory '/tmp/mylinux '


mkdir:created directory '/tmp/mylinux/bin '


mkdir:created directory '/tmp/mylinux/boot '


mkdir:created directory '/tmp/mylinux/boot/grub '


mkdir:created directory '/tmp/mylinux/dev '


mkdir:created directory '/tmp/mylinux/etc '


mkdir:created directory '/TMP/MYLINUX/ETC/RC.D '


mkdir:created directory '/TMP/MYLINUX/ETC/RC.D/INIT.D '


mkdir:created directory '/tmp/mylinux/etc/sysconfig '


mkdir:created directory '/tmp/mylinux/etc/sysconfig/network-scripts '


mkdir:created directory '/tmp/mylinux/lib64 '


mkdir:created directory '/tmp/mylinux/proc '


mkdir:created directory '/tmp/mylinux/sbin '


mkdir:created directory '/tmp/mylinux/sys '


mkdir:created directory '/tmp/mylinux/tmp '


mkdir:created directory '/tmp/mylinux/usr '


mkdir:created directory '/tmp/mylinux/usr/local '


mkdir:created directory '/tmp/mylinux/usr/local/bin '


mkdir:created directory '/tmp/mylinux/usr/local/sbin '


mkdir:created directory '/tmp/mylinux/var '


mkdir:created directory '/tmp/mylinux/var/lock '


mkdir:created directory '/tmp/mylinux/var/log '


mkdir:created directory '/tmp/mylinux/var/run '


[Root@localhost tmp]# tree-d/tmp/mylinux/


/tmp/mylinux/


├──bin


├──boot


│└──grub


├──dev


├──etc


│├──rc.d


││└──init.d


│└──sysconfig


│└──network-scripts


├──lib64


├──proc


├──sbin


├──sys


├──tmp


├──usr


│└──local


│├──bin


│└──sbin


└──var


├──lock


├──log


└──run


Directories


Displays all files or directories with the beginning of the/var directory ending in a lowercase letter with at least one digit (can have other characters) in the middle

[Root@localhost tmp]# Ls-dl/var/l*[0-9]*[a-z]
Displays a file or directory that starts with any number in the/etc directory and ends with a non-numeric

[root@localhost tmp] #ll-D/etc/[0-9]*[^0-9]
Displays a directory or file in the/etc directory, beginning with a non-letter, followed by a letter and any other character of any length

[root@localhost tmp] #ll-D/etc/[^a-z][^[:d igit:]]*
[Root@localhost tmp]# ll-d/tmp/[^[:alpha:]][^[:d igit:]]*
-rw-r--r--. 1 Root 0 Sep 12:22/tmp/1tfile2016n
-rw-r--r--. 1 Root 0 Sep 13:35/tmp/2absdf
-rw-r--r--. 1 Root 0 Sep 13:34/TMP/2ASDLJFL
Create a file in the/tmp directory starting with Tfile, followed by the current date and time, file format: tfile-2016-05-27-09-32-22

[root@localhost tmp] #touch/tmp/tfile-' Date +%y-%m-%d-%h-%m-%s '
[root@localhost tmp] #ll-A
-rw-r--r--. 1 root 0 Sep 13:39 tfile-2016-09-25-13-39-47
Copy all files or directories in the/ETC directory that start with P and end in Non-numeric to the/tmp/mytest1 directory

[root@localhost tmp] #mkdir mytest1
[root@localhost tmp] #cp-af/etc/p*[^0-9]/tmp/mytest1
[Root@localhost mytest1]# ls
PAM.D Passwd-plymouth popt.d PPP printcap PROFILE.D python
passwd PKI PM postfix PRELINK.CONF.D profile Protocols
Copy all files or directories ending with. D in the/etc directory to/tmp/mytest2/

[root@localhost tmp] #mkdir mytest2


[Root@localhost tmp]# cp-af/etc/*.d/tmp/mytest2/


[Root@localhost mytest2]# ls


BASH_COMPLETION.D dnsmasq.d logrotate.d popt.d rc2.d rc.d


BINFMT.D dracut.conf.d modprobe.d prelink.conf.d rc3.d rsyslog.d


CHKCONFIG.D grub.d modules-load.d PROFILE.D rc4.d RWTAB.D


CRON.D init.d my.cnf.d rc0.d rc5.d STATETAB.D


Depmod.d ld.so.conf.d pam.d rc1.d rc6.d sudoers.d


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

[root@localhost tmp]# mkdir mytest3
[root@localhost tmp]# cp-a/etc/[lmn]*.conf/tmp/mytest3/
[ Root@localhost tmp]# ls-al mytest3/
Total
-rw-r--r--.   1 root root   Feb 28  2013-Ld.so . conf
-rw-r-----.   1 root root  191 Oct 29  2014 libaudit.conf
-rw-r--r--.   1 root root 2391 O CT 13  2013 libuser.conf
-rw-r--r--.   1 root root   Sep a 22:32 locale.conf
-rw-r--r--. &nb Sp 1 root root  662 31  2013 logrotate.conf
-rw-r--r--.   1 root root 5171 June 10  2014 Man_db.con F
-rw-r--r--.   1 root root  936 mar  6  2015 mke2fs.conf
-rw-r--r--.   1 root root 1717 Se P 22:32 nsswitch.conf
-rw-r--r--.   1 root 2050 Sep 22:32 ntp.conf

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.