Delete and create Linux folders and files __linux

Source: Internet
Author: User
Tags mkdir parent directory time and date touch command

Today I learned a few commands, is to create, delete files and folders, in Linux, folder is a directory, the following next I learn the command.


Create a folder "MkDir" one, mkdir command use permissions

All users can create folders or directories in a folder that has permissions by using the mkdir command at the terminal.

Second, the mkdir command to use the format

Format: mkdir [options] DirName

Three, mkdir command function

The mkdir command enables you to create a folder or directory named DirName (the specified file name) at the specified location. To create a folder or directory, the user must have write access to the parent folder of the folder you are creating (see Linux Files-folder permissions click here). Also, the folder (directory) You create cannot have the same name as the file name in its parent directory (that is, the parent folder), that is, the same directory cannot have the same names (case-sensitive).

Four, mkdir command option description

The options in the command generally have the following two types:

-M is used to set access permissions on a new directory, or it can be set with the chmod command.

-P creates an upper-level folder (or directory) when it is needed and is not considered an error if the folder (or directory) already exists.

Five, mkdir command use examples

Example: Create a folder named "Demo" under the desktop.

Use the following command.

mkdir Desktop/demo

Example two: Create a folder named "Demo" under the desktop and assign permissions to the folder with permissions of 123.

mkdir 123 Desktop/demo


Delete Folder "rm" one, RM command usage rights

All users can delete the directory using the RM command at the terminal.

II. RM Command Use Format

Format: RM [Options] DirName

Third, RM command function

Delete files and directories.

Four, RM command option description

The options in the command generally have the following:

-I check to confirm before deleting.

-F Even if the original file property is set to read-only, also delete directly, do not need to confirm each.

-R Deletes the directory and the file below.

Five, RM command use examples

Example one: Delete all C language Program documents and ask for confirmation before deleting.

Rm-i *.c

Example two: Delete all files in the finished subdirectory and subdirectories.

Rm-r finished

Note: In the Linux does not have the Recycle Bin, when tries the RM command, must be careful, after deleting can not recover again.

Create File "VI"

First, the order to enter VI

VI FileName: Open or create a new file and place the cursor at the beginning of the first line

VI +n FileName: Open the file and place the cursor at the beginning of nth

VI + FileName: Open the file and place the cursor at the end of the line

VI +/pattern FileName: Open the file and place the cursor in the first matching string

Vi-r filename: A system crash occurred during the last edit with VI, filename restored

VI filename....filename: Open multiple files, edit in sequence

Second, Move cursor class command

H: Move the cursor one character to the left

L: The cursor moves one character to the right

Space: The cursor moves one character to the right

Backspace: Move the cursor one character to the left

K or ctrl+p: Move the cursor up one line

J or CTRL + N: Move the cursor down one line

Enter: Move the cursor down one line

W or W: Move the cursor right one word to the top of the word

B or B: Move the cursor left one word to the top of the word

E or E: Move the cursor right one word to the end of the word

): The cursor moves to the end of the sentence

(: The cursor moves to the beginning of the sentence

}: The cursor moves to the beginning of the paragraph

{: The cursor moves to the end of the paragraph

NG: The cursor moves to the beginning of nth

n+: Move the cursor down n line

N: Move n line up on cursor

n$: The cursor moves to the end of the nth line

H: The cursor moves to the top line of the screen

M: The cursor moves to the middle line of the screen

L: The cursor moves to the last line of the screen

0: (note is the number 0) the cursor moves to the current beginning

$: The cursor moves to the end of the current line

Third, screen rolling class command

Ctrl+u: Turn to file first half screen

Ctrl+d: Turn to file tail half screen

CTRL+F: Flip a screen to the end of the file

Ctrl+b to the first screen of a file

NZ: Rolls the nth row to the top of the screen and rolls the current row to the top of the screen without specifying N.

Iv. inserting text class commands

I: Before the cursor

I: At the beginning of the current

A: After the cursor

A: At the end of the current line

O: Open a new row below the current line

O: Open a new line above the current line

R: Replace the current character

R: Replaces the current character and its subsequent characters until the ESC key is pressed

S: replaces the specified number of characters with the input text, starting at the current cursor position

S: Deletes the specified number of rows and replaces them with the text entered

NCW or NCW: Modifying a specified number of words

NCC: Modify specified number of rows

V. Delete command

NDW or NDW: Deletes the beginning of the cursor and the n-1 word after it

Do: Delete to the beginning of the line

d$: Delete to end of line

NDD: Deletes the current row and its n-1 line

X or x: Deletes a character, x deletes the cursor, and x deletes the cursor before the

Ctrl+u: Deletes the text entered in the input mode

Vi. Search and Replace commands

/pattern: Searches the end of the file for pattern at the beginning of the cursor

Pattern: Search for pattern from the beginning of the cursor to the first file

N: Repeat the last search command in the same direction

N: Repeat the last search command in the opposite direction

: s/p1/p2/g: Replaces all P1 in the current row with P2

: n1,n2s/p1/p2/g: All P1 in the N1 to N2 line are replaced with P2

: g/p1/s//p2/g: Replace all P1 in the file with P2

Seven, vi command use examples

Example one: Create a file a.txt.

VI a.txt

Hello everyone!

: Wq//In the exit, direct input: Wq will find out, exit the method is: After editing, press ESC, and then enter: Q is to quit, and: Wq is saved after the exit, add an exclamation point is mandatory

  

  

  

Modify file Time "touch"

First, Touch command permission to use

All users can use the Touch command at the terminal.

Second, Touch command use format

Format: Touch [-acfm][-d < date time >][-r < reference file or directory >][-t < date time >][--help] [--version][file or directory ...] or touch [-acfm][- -help][--version][date Time [file or directory ...]

(Touch [-acfm][-r reference-file] [--file=reference-file][-t mmddhhmm[[cc]yy][.ss]][-d time] [--date=time][--time={ ATIME,ACCESS,USE,MTIME,MODIFY}][--NO-CREATE][--HELP] [--version]file1 [file2 ...] )

Third, touch command function

Touch Filea, if Filea exists, use the Touch command to change the date and time of the file or directory, including the access time and the change time; if Filea does not exist, the touch command creates a new blank file in the current directory Filea.

Note: Use the touch instruction to change the date and time of the file or directory, including access time and change time. The time attribute of the file includes the last access time for the file, the last modification time, and the last time it was modified on disk, and the command stat display results showing three time attributes.

Four, touch command option description

A change the read time record of the file.

M changes the file's modification time record.

c If the destination file does not exist, no new files will be created. The same as the--no-create effect.

F is not used and is reserved for compatibility with other UNIX systems.

R use the reference file's time record as--file.

D Set the time and date, you can use a variety of different formats.

T sets the file's time record in the same format as the date instruction. [[Cc]yy] mmddhhmm[. SS],CC is the first two in the number of years, namely "century number"; YY is the latter two digits of the number of years, The number of years in a century. If you do not give a value for cc, the touch command parameter in Linux will limit the number of years Ccyy to 1969--2068. MM is the number of months, DD for days will be the number of years Ccyy limited within the 1969--2068. MM for the number of months, DD for days, HH Is the number of hours (points), MM is the number of minutes, SS is seconds. The set of seconds here is 0--61, which allows you to handle leap seconds. These numbers consist of a time in the specified time zone of the environment variable TZ. Due to system constraints, the time earlier than January 1, 1970 is wrong.

--no-create will not create new files.

--HELP lists the instruction formats.

--version lists version messages.

V. Use examples of touch command

Example one: Update the file1.txt access and modification time.

Touch File1.txt

Example two: If File1.txt does not exist, the file is not created

Touch-c file1.txt

Example three: Update file1.txt with the same time stamp as Ref+file

Touch-r Ref+file File1.txt

Example four: Set the file timestamp to May 18, 2011 9:45 10 seconds

Ls-l file1.txt

Touch-t 1105190945.10 File1.txt


When you create a new file, you can create an empty file with the Touch command, and the VI command can edit the contents of the file and save it directly. Touch commands are rarely used in Linux, I personally prefer VI command, you can directly edit the document. Today's study on these, a little progress every day, yesterday did not finish, today continued to write. O (∩_∩) o~

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.