File and directory management and the use of the VI editor
File and directory management, just beginning to learn this piece of feeling a lot of content is miscellaneous, but after the completion of the summary, found in fact very organized and no difficulty, just master these commonly used commands on the line. As for the Vim editor, I have to say that after using this editor, I feel that Windows Notepad is very technical.
Briefly summarize the commands commonly used in files and directories, and simply skip the usage.
File operation commands: Touch, file, which, find,CP, RM, MV, lN
File content Operations Commands: Cat, More, Less,head, TAIL,WC, grep
Directory operation commands: PWD, CD, ls, mkdir, du
Archive and Compress commands: gzip, bzip2, tar
[[email protected] ~]$ pwd ==> show current directory/home/jzhou[[email protected] ~]$ mkdir dirtest ==> Create a directory [[email& Nbsp;protected] ~]$ CD dirtest ==> enter this directory [[email protected] dirtest]$ touch testfile ==> Create a file [[EMAIL&NB Sp;protected] dirtest]$ mkdir dirtest1 ==> Create subdirectories [[email protected] dirtest]$ ls ==> list current directory contents Dirtest1 TESTF Ile[[email protected] dirtest]$ echo Hello linux >>testfile ==> append content to file [[email protected] dirtest]$ Cat testfile ==> display file contents Hello linux[[email protected] dirtest]$ file testfile ==> view files type Testfile:ascii text[[ Email protected] dirtest]$ du-sh testfile ==> show file space occupied 8.0K testfile[[email protected] dirtest]$ WC Testfi Le ==> statistics file lines, number of words, characters 1 2 testfile[[email protected] dirtest]$ echo haha,i love Linux >> testfile ==> additional content [[[email protected] dirtest]$ echo no,no, I hate C plus plus >> testfile[[email protected] dirtest]$ E Cho ok,the End >> TESTFIle[[email protected] dirtest]$ cat testfile ==> view content Hello Linuxhaha,i love linuxno,no, I hate C plus plusok,the End[[email protected] dirtest]$ head-2 testfile ==> View the first two lines of the file Hello Linuxhaha,i love linux[[email Protected] dirtest]$ tail-2 testfile ==> View the last two lines of the file No,no, I hate C plus plusok,the end[[email protected] dirtest] $ Cat Testfile | grep "Linux" Find specific keywords haha,i love linux[[email protected] dirtest]$
The above is just a simple use of the show part of the command, many options are not added, the head and tail command is displayed the first 10 rows and the last 10 rows of records, Du is to view the directory or file occupied space, usually larger than the actual size, and usually 4 of the integer times.
The more and less commands are also a way to view the contents of a file, but little has gradually replaced more because all of the features of more are not available, and no can be paged up, more can not, cat is directly display the contents of the file on a screen, no matter how long, All if the file is long, use the less command, and also press the Q key to exit.
[[email protected] dirtest]$ CD Dirtest1 ==> into the sub-directory just built [[email protected] dirtest1]$ touch testfile1 ==&G t; Create a new file in a subdirectory [[email protected] dirtest1]$ echo haha >> testfile1[[email protected] dirtest1]$ CD. ==> returns to the previous directory [[email protected] dirtest]$ ls dirtest1 testfile[[email protected] dirtest]$ CP testfile. dirtest1/==> Copy the file testfile to a subdirectory dirtest1 [[email protected] dirtest]$ CD dirtest1/==> into subdirectories [[email Protected] dirtest1]$ ls ==> view subdirectory a copy of the file that you just copied over testfile testfile1[[email protected] dirtest1]$ CD. [[email protected] dirtest]$ lsdirtest1 testfile[[email protected] dirtest]$ rm-f testfile ==> Forcibly delete the Testfile file under the Dirtest directory [[[email protected] dirtest]$ ls ==>testfile file has been deleted dirtest1[[email protected ] dirtest]$ CD./dirtest1/==> into subdirectories [[email protected] dirtest1]$ mv Testfile./testfile ==> Here I try to move the target directory error TE Stfile testfile1 [[email protected] dirtest1]$ pwd ==> So I'm going to checkLook at the current directory to use the absolute path/home/jzhou/dirtest/dirtest1[[email protected] dirtest1]$ mv testfile/home/jzhou/dirtest/==> Move the testfile file to the dirtest directory [[email protected] dirtest1]$ CD: [[email protected] dirtest]$ ls ==> good, testfile file has been moved over Dirtest1 testfile[[email protected] dirtest]$ Ln-s testfile linkfile ==> Establish soft links [[email protected] dirtest]$ ls-l ==> Note the following soft link file display total 20drwxrwxr-x 2 Jzhou jzhou 4096 03-05 22:43 dirtest1lrwxrwxrwx 1 jzhou jzhou 8 03-05 22:45 linkfile -> testfile-rw-rw-r-- 1 jzhou jzhou 03-05 22:40 testfile[[email protected] dirtest]$
RM file The only difference between a file and a directory is whether it has the-r option, because directories may be nested with files and directories when the directory is deleted, so the-r option is required, and the CP and RM formats are: CP/RM Original file Destination file (note the path problem here)
ln link files: Soft links and hard links, soft links are also called Symbolic links, with the-s option. A soft link is equivalent to a shortcut under Windows, the Wakahara file is corrupted, the shortcut is invalid, and a hard link is equivalent to a copy of the original file, usually with very little hard links. So when you create a linked file, you usually add the-s option to create a soft link. The file type bit for the linked file is: L, this bit is described in the subsequent notes file permissions.
Also note that you cannot establish a hard-link file for the directory, and that the hard link must be in the same partition (file system) as the original file.
[[email protected] ~]$ CD dirtest/[[email protected] dirtest]$ lsdirtest1 linkfile testfile[[email Protected] dirtest]$ tar CF test.tar dirtest1 testfile ==> Archive directory and file [[email protected] dirtest]$ ls ==> A newly-built return File Test.tardirtest1 linkfile testfile test.tar[[email protected] dirtest]$ rm-rf dirtest1 testfile ==> Delete the original file, Easy to follow to confirm that the file is archived [[email protected] dirtest]$ lslinkfile test.tar[[email protected] dirtest]$ pwd ==> Take a look at the current directory, after which you want to archive it in this directory/home/jzhou/dirtest[[email protected] dirtest]$ tar xf test.tar-c/home/jzhou/dirtest/= = > Unpack archive, testfile file released [[email protected] dirtest]$ lsdirtest1 linkfile testfile test.tar[[email protected ] dirtest]$ rm-f Test.tar ==> Delete this archive package to help back test [[email protected] dirtest]$ lsdirtest1 linkfile TESTFILE[[EMAIL&NB Sp;protected] dirtest]$ gzip-9 testfile ==> compress this file in GZ format [[email protected] dirtest]$ lsdirtest1 linkfile TESTF Ile.gz ==> This is the file name that is automatically generated after compression [[email protected] dirtest]$ gzip-d testfile.gz ==> Unpack the newly compressed package [[email protected] dirtest]$ lsdirtest1 linkfile testfile ==> Look, Testfile was extracted. [[email protected] dirtest]$ bzip2-9 testfile ==> This file in bz2 format [[email protected] dirtest]$ ls dirtest1 linkfile testfile.bz2 ==> See, this bz2 is just generated [[email protected] dirtest]$ bzip2-d testfile.bz2 ==> untied this compression pack [[email protected] dirtest]$ lsdirtest1 linkfile testfile ==> See, it was released [[email protected] D irtest]$ tar jcf test.tar.bz2 testfile ==> This is the BZ2 format archive compression, note option is j[[email protected] dirtest]$ lsdirtest1 linkfile Testfile test.tar.bz2[[email protected] dirtest]$ rm-r testfile[[email protected] dirtest]$ lsdirtest1 Linkfile test.tar.bz2[[email protected] dirtest]$ tar jxf test.tar.bz2-c/home/jzhou/dirtest/==> Unlock archive compression [[ Email protected] dirtest]$ lsdirtest1 linkfile testfile test.tar.bz2[[email protected] dirtest]$ tar zcf test . tar.gz Dirtest1 ==> This is the GZ format archive compression, the note option is z[[Email protected] dirtest]$ lsdirtest1 linkfile testfile test.tar.bz2 test.tar.gz[[email protected] dirtest] $ rm-rf dirtest1[[email protected] dirtest]$ lslinkfile testfile test.tar.bz2 test.tar.gz[[email protected] dirtest]$ tar zxf test.tar.gz-c/home/jzhou/dirtest/==> Unlock archive compression [[email protected] dirtest]$ lsdirtest1 linkfil E testfile test.tar.bz2 test.tar.gz[[email protected] dirtest]$
The above command display is not very friendly, because in the real world, if the original file is deleted, the soft link file will be in an unusable state background will become red bottom. But this does not affect the understanding hehe.
Note that the archive simply hits a file or directory in a package, does not compress, and gzip and bzip2 are compressed, the last few lines of the above are used together, that is, archive and then compress.
The command format for tar and gzip bzip2 is as follows:
tar [options] ... Archive file name source file or directory = = "Make an archive
tar [options] ... Archive file name [-c target directory] = = "Unpack Archive"
GZIP/BZIP2 [-9] File name or directory = = "Making a compressed file
gzip/bzip2-d. gz/.bz2 format Compressed File = = "Unpack the compressed file
For the above command, just cite the simplest usage, as to achieve more powerful functions, it is necessary to check each command with what options, or directly to the Man command help, those options are too many, so I think as long as you know there is a command, as for the specific use of the use of the time to check and do not need to remember all the meaning of the
the usual shortcut editing methods of the VIM editor
A text editor can be used to create or modify text files, as well as to maintain various configuration files in a Linux system. The first contact with this editor will be due to the lack of proficiency, but affect the efficiency of editing, but mastered the common shortcuts, very fast. The following is a simple introduction to the Vim editor, for more in-depth usage you can find online.
UNIX and early Linux in the default use of the text editor is VI, now used are the enhanced version of the VI vim, because VI used by the comparative habit, it is still called VI, in fact, aliases alias Vi= '/usr/bin/vim ', this can be ordered which VI See.
Vim Editor has 3 modes of operation: Command mode, input mode, last line mode, in some data may say there are 2 working mode, not the ' last line mode ' listed in it, this is not important, in short, the first two models are really important, because in these two modes can do a lot of things. Switching between the various modes such as:
The conversion of these modes is also very skilled.
Basic operations in the command mode:
(1) Display line number:: Set nu Cancel line number:: Set Nonu
(2) Quick jump between the lines: #G: Jump to the file # # line, G: Jump to the end of the file line, 1G or GG: Jump to the beginning of the file.
(3) in-line quick jump: Home End
about deleting Copy and paste: (Command mode)
Delete |
X or Del |
Delete a single character at the cursor |
Dd |
Deletes the current cursor in the row |
#dd |
Delete the # line content that starts at the cursor |
d^ |
Delete all characters before the current cursor to the beginning of the line |
d$ |
Delete all characters at the end of the line at the current cursor |
Copy |
Yy |
Copy the contents of the entire row of the current row to the Clipboard |
#yy |
Copy the # line content starting at the cursor |
Paste |
P |
Pastes the contents of the buffer after the cursor position |
P |
Before pasting at the cursor position |
Look in the file contents:
Operation Keys |
Function |
/word |
Look up the string "word" from the top down in the file |
? word |
Bottom find the string "word" in the file |
N |
Locate the next matching found string |
N |
Locate the previous matching found string |
Undo Edit and Save exit:
U |
Press once to cancel the most recent operation Double-Press the U key multiple times to redo a multi-step operation |
U |
Used to cancel all edits made to the current line |
Zz |
Save the current file contents and exit the VI editor |
save file and Exit VI Editor: (last line mode)
Save File |
|
|
: W/root/newfile |
Save As other file |
Exit VI |
: Q |
Exit not modified |
: q! |
Discard changes to the contents of the file and Exit VI |
Save File Exit VI |
: Wq |
|
File Content substitution: (in the last line mode)
: s/old/new |
Replace the first character "old" string found in the current line with "new" |
: s/old/new/g |
Replace all the string "old" found in the current row with "new" |
: #,# s/old/new/g |
Replace all strings "old" with "new" in the line number "#,#" range |
:% s/old/new/g |
Replace all strings "old" with "new" for the entire file range |
: s/old/new/c |
Adding the C command at the end of the Replace command will prompt the user for each substitution action to confirm |
To be proficient in the Vim editor, it is essential to master these shortcuts first.
If there is any mistake, please correct me, 3q!
Linux Learning Note (ii)--File/directory/vim