Frequently used commands that explain Linux file handling in detail

Source: Internet
Author: User
Tags file handling

Original blog. Reprint please indicate the source

Attach several Linux blogs with a high number of previous visits

My 8 tips for using the shell

GREP's nine classic usage scenarios

SED command specific explanation

The awk command specifically explains

Everything in Linux is a file, and the command is a binary file.

1, LS

/bin/ls

Frequently used options

-A All files (including hidden files)

-L Specific Information

-D folder Properties

-I view Inode

Example

[Email protected] testforcsdn]# lsfilelist first  second[[email protected] testforcsdn]# ls-a ...  FileList  First  second[[email protected] testforcsdn]# ls-ltotal 16-rw-r--r--1 root root Oct 23:12 Filelis t-rw-r--r--1 root root   0 Oct 18:04 first-rw-r--r--1 root root   0 Oct 18:04 second[[email protected] Testfor csdn]# ls-altotal 32drwxr-xr-x  2 root root 4096 Oct 18:04. drwxr-x---root root 4096 Oct 24 17:56. -rw-r--r--  1 root root  Oct 23:12 filelist-rw-r--r--  1 root root    0 Oct 18:04 first-rw-r--r--
   1 root root    0 Oct 18:04 second[[email protected] testforcsdn]# ls-d.[[email protected] testforcsdn]# ls-i225 6719 fileList  2256718 first  2256730 second
Analysis under

-rw-r--r--1 root root Oct 23:12 fileList
For this line, analyze from left to right

-Indicates that this is a binary file

rw-r--r--respectively R for Read permission, W for write permission,-Indicates no permission. The assumption is that x represents the operational permissions, total 9, three groups. Represent the creator, the group, and others

Therefore, for the creator is rw-is can read and write not run, for the group is r--only have Read permission, others only have Read permission

1 indicates the number of hard links

The first root indicates a user

The second root indicates a user group

100 indicates the size of the file, assuming that the folder is the folder and sub-folder size

OCT 18 23:13:12 Indicates the time of the last change

FileList indicates the file name


2. cd

Change direction

Frequently used commands with CD mates and

PWD View current Folder

Change Folder

First explain the next folder

/ root partition, all files and folders start with this

/bin users can run files

/sbin system can run files, mainly for administrators to use. S is super

/ etc configuration file

/ Dev Device files

/proc process information. If the/proc/cpuinfo includes processor information

/ var variable file such as Log,mail

/ usr user program. Storing files for user applications

/ Home User Master folder

/ Boot Load entry

/OPT Optional applications

/mnt Mount folder

/media removable media such as/media/cdrom

/srv Service data

Example

[[email protected] etc]# cd/etc/[[email protected] etc]# Pwd/etc[[email protected] etc]# CD ~[[email protected] ~]# pwd/r Oot
This is to show that

CD ~ represents back to the home folder of the currently logged in user

Let's say Root goes back to/root/.

If it's a normal user, go back to/home/


3. Touch

Create a blank file file or change the timestamp of the file

Frequently used options

- A just change the access time

- C does not establish no matter what document

- D use the specified date

- m just change the time of change

- R Change the date time of the specified document or folder to the same as the reference document

- T sets the specified timestamp

Example

[Email protected] testforcsdn]# ls-ltotal 16-rw-r--r--1 root root Oct 23:12 filelist-rw-r--r--1 root root   0 Oct 18:04 first-rw-r--r--1 root root   0 Oct 18:04 second[[email protected] testforcsdn]# Touch Thrid[[email Pro Tected] testforcsdn]# ls-ltotal 20-rw-r--r--1 root root Oct 23:12 filelist-rw-r--r--1 root root   0 Oct 24 18: first-rw-r--r--1 root root   0 Oct 18:04 second-rw-r--r--1 root root   0 Oct 18:34 thrid[[email protected] testforcsdn]# touch-t 201410250935.40 thrid [[email protected] testforcsdn]# ls-ltotal 20-rw-r--r--1 root root Oct  23:12 filelist-rw-r--r--1 root root   0 Oct 18:04 first-rw-r--r--1 root root   0 Oct 18:04 second-rw-r--r-- 1 root root   0 Oct  thrid
Can see that the timestamp was changed with-t

4 mkdir

Create a folder

Frequently used options

- m Specify permissions when creating

- p specifies the path. If some folders on the path do not exist, they are created. is the ability to create multi-tiered folders at once

- v displays specific information

Example

[[email protected] testforcsdn]# mkdir-m 777 Firstdir[[email protected] testforcsdn]# ls-altotal 44drwxr-xr-x  3 root Root 4096 Oct 18:41 drwxr-x---root root 4096 Oct 24 17:56. -rw-r--r--  1 root root  Oct 23:12 filelist-rw-r--r--  1 root root    0 Oct 18:04 firstdrwxrwxrwx  2 root root 4096 Oct 18:41 firstdir-rw-r--r--  1 root root    0 Oct 18:04 second-rw-r--r--  1 root root
   0 Oct  thrid[[email protected] testforcsdn]# mkdir-p Firstdir/seconddir/thriddir[[email protected] testforcsdn]# CD Firstdir/seconddir/thriddir/[[email protected] thriddir]# pwd/root/testforcsdn/firstdir/seconddir/ Thriddir
Can see. Multi-tier folders are created through-p once. -M gives 777 permissions at the same time as the folder is created


5 CP

Copy

Frequently used options

- B back up when overwriting destination file is deleted

- I asks whether to overwrite

- p preserves the properties of the source file or folder: All, group, permission time

- R Copy Folder

Example

[[email protected] testforcsdn]# lsfilelist  firstdir  second  thrid[[email protected] testforcsdn]# ls Firstdir/filelist  Second[[email protected] testforcsdn]# CP thrid  firstdir/[[email protected] testforcsdn]# Cp-b fileList firstdir/cp:overwrite ' firstdir/filelist '? Y[[email protected] testforcsdn]# ls firstdir/filelist  filelist~  second thrid[[email  protected] testforcsdn]# mkdir seconddic[[email protected] testforcsdn]# cp-r firstdir/seconddic/[[email protected] testforcsdn]# LS Seconddic/firstdir

By the way, SCP: Give me a sample.

SCP is a remote copy, assuming that you want to remotely replicate the folder with-R

scp-r [Email protected]:~/testcsdn/localcsdn/

Copy the 192.168.0.12 ~/testcsdn to localcsnd.

6, MV

Cut and rename

Example

[Email protected] testforcsdn]# lsfilelist  firstdir  second seconddic thridyou have  new mail in/var/ Spool/mail/root[[email protected] testforcsdn]# mkdir tempdic[[email protected] testforcsdn]# lsfilelist  firstdir  second  seconddic  tempdic  thrid[[email protected] testforcsdn]# mv FileList newname[[email protected ] testforcsdn]# MV NewName tempdic/[[email protected] testforcsdn]# lsfirstdir  second  seconddic  tempdic  thrid[[email protected] testforcsdn]# ls tempdic/newname

7 Cat More

are used to view the contents of a file

Cat is suitable for shorter files

More will be paged view: Space page. Enter the next line. Q exit

Cat filename

More filename



8 Head Tail

View the first few lines of a file, followed by a few lines

Tail-f can be used to dynamically view the following lines of a file

Example


9 Ln

Creating soft joins and hard links

Soft Links: Similar to shortcuts in Windows

Hard Links: Two file sync updates

Soft links can cross file systems, hard links cannot be

Example

Create a soft connection

[Email protected] ~]# ln-s file.txt file.hardlink

Create a hard link

[Email protected] ~]# LN file.txt file.hardlink

Can see. The number of hard links in File.txt becomes 2.

-rw-r--r--2 Root root   07:54 Oct file.hardlinklrwxrwxrwx 1 root root     8 Oct 19:14 file.softlink fil e.txt-rw-r--r--2 root root   07:54 Oct file.txt

And then. Change file.txt

Type TESTCSDN at the beginning of the file

View Hard Links again

[Email protected] ~]# head-5 file.hardlink Testforcsdnbackupbinbootdev
Can see that the content is updated synchronously






Frequently used commands that explain Linux file handling in detail

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.