Linux Learning record 4

Source: Internet
Author: User
Tags stdin

involves file management; standard I/O and pipelines; inode


LN creates a link

-D hard links are equivalent to file aliases; Multiple names point to the same chunk address

Creates a new file name in the selected location that shows the same size as the source file, but does not occupy disk space

Only a very small amount of inode data is added, and a and B both point to the hard disk data block

-S soft connection equivalent to a shortcut, can be created across partitions;! Best created with absolute paths

Ls-s/spath (The absolute path of the original file, or relative path; relative to the soft-link dpath path)/dpath

generates a file in the location you selected, saves the path information, and a path to B

Either a hard link or a soft link does not copy the original file data, only consumes a very small amount of disk space.

Number of hard links = number of names




Inode Index node: The area where file meta information is stored

Each inode has a number that uses the Inode number to identify the file without using the file name within the Unix/linux system.

When you delete a file by using RM, the Inode information that points to the file's hard disk data block is actually deleted

A directory is also a file; a directory is a mapping between a file name and an inode number in a directory

inode contains meta information for files : Available stat FILENAME view

* Number of bytes in the file

* User ID of the owner of the file

* The group ID of the file

* file read, write, execute permissions

* The timestamp of the file, a total of three:

CTime refers to the time when the inode was last changed;

Mtime refers to the time of the last change in the contents of a document;

Atime refers to the time the file was last opened.

* Number of links, that is, how many filenames point to this inode

* Location of File data block


Df-i View the total number of inode per hard disk partition and the quantity already used

Ll-i View File | Directory node number

Dumpe2fs-h/dev/sda# | grep "Inode size" looks at the size of each inode node #为硬盘分区号

Attention:

1. Different partitions of the file can appear the same node number, each partition has independent inode information

2. Sometimes the file name contains special characters and cannot be deleted properly.

At this point, using Find to delete the Inode node directly, you can play the role of deleting files.

Example Find/path-inum inodenum-exec rm-i {} \;


3. Move or rename the file, just change the file name without affecting the inode number.

4. After opening a file, the system will identify the file with the Inode number and no longer consider the filename.

As a result, the system cannot know the file name from the inode number.


* * * Program: Instruction + data

Read-in data: Input

Outputs data: Output

Open files have a Fd:file descriptor (file descriptor)

All files opened by the/PROC/PID/FD process


Linux provides three I/O devices to Programs

Standard input (STDIN)-0 accepts input from the keyboard by default

Standard output (STDOUT)-1 default output to the current terminal window

Standard error (STDERR)-2 default output to terminal window error message


I/O redirection : Change the default position ls >/dev/pts/0 Redirect to another terminal window

stdout and stderr can be redirected to a file:

Command Action Symbol file name

Operation symbols :

> redirect stdout to file [1]>

2> redirect stderr to a file will only redirect the wrong information

&> Redirect all output to file

Example ls/testdir/xxx >r 2>e the standard output and standard errors are stored separately;

There are standard output and standard error conditions that may occur


*> Redirect to an existing file, the content will overwrite the file

2>: Overwrite redirect error output data stream;

&>: Overwrite redirect all outputs


Example #cat > Filea

Zhou

Save user input information to a file

Press Ctrl+d to leave.

*>> content on the basis of the original content

2>>: Append redirect error output data stream;

&>>: Append redirect all outputs


*< REDIRECT Standard input

Tr ' A-Z ' A-z ' </etc/issue converts lowercase characters in/etc/issue to uppercase characters

Use files instead of keyboard input

Cat > Filea < Fileb

REDIRECT Fileb content overlay to Filea

* Use the << stop word command to redirect multiple lines from the keyboard to stdin in-place text

All information before terminating the word position is appended to stdin

The terminating word is usually eof, customizable, and must end with a single line of purely terminating words

# Set-c: block content from overwriting existing files, but can append >>

Forced Overwrite: >| Delete Rebuild

# set +c: Allow overwrite

1. the standard output and error outputs are directed to different locations:

COMMAND >/path/to/file.out 2>/path/to/error.out

2. Merge standard output and error output to the same file:

COMMAND >/path/to/file.out2> &1

COMMAND >>/path/to/file.out2>> &1

2>&1 converting 2 standard errors in output information to 1 standard outputs


3. Do not display error message/dev/null receive all data

Find/etc-namepasswd2>/dev/null


4.(): Merge stdout of multiple programs

(Pwd;ls) >/testdir/aa.log

(cal2007;cal2008) > All.txt




*tr[option] ... SET1 [SET2] (translate) convert and delete characters

-C or--complerment: take input complement

-D or--delete: Delete the SET1 of the input word character;

-S or-squeeze-repeats: merges multiple consecutive repeating characters

-T or--truncate-set1: First remove characters from the first character set that are more than the second character set

Example tr ' abcd ' ' xyz ' ABCDE Xyzze!

Example tr-t ' abcd ' xyz ' ABCDE Xyzde!


*| piping

Send the sdout of the pipe before the command to the stdin of the pipeline command

StdErr cannot be piped forward by default and can be implemented with 2>&1 or |&

The last command will be in the child shell process of the current shell process


*Tee can simultaneously redirect output information to pipe |> and standard output (terminal screen)

Save output at different stages

Troubleshooting Complex Pipelines

View and record output at the same time

Ls|tee>list.txt



5. The contents of the File1 file are: "1 2 3 4 5 6 7 8 9 10" Calculates the sum of all numbers

Tr ' + ' <FILE1|BC

55


6, processing string "Xt.,l 1 jr#! $mn 2 c*/fe3 uz4", keep only the numbers and spaces

Echo ' xt.,l 1 jr#bcmn2 c*/fe3 uz4 ' |tr-d-c [[:d Igit:] ' "]

1 2 3 4


7. Display the path variable in a separate row for each directory

echo $PATH |tr ":" \ n "

/usr/lib64/qt-3.3/bin

/usr/local/sbin

/usr/local/bin

/sbin

/bin

/usr/sbin

/usr/bin

/root/bin


8. Delete blank lines of the specified file

Cat crontab |tr-s "\ n"


9. Display each word (letter) in the file in a separate line with no blank lines

Cat crontab|tr-s "" \ n "word


10, create user Gentoo, additional group is bin and root, the default shell is/BIN/CSH, the annotated message is "Gentoo distribution"

Useradd gentoo-g bin,root-s shell-c "Gentoo distribution"


11. Create the following user, group, and group memberships

Group with the name Admins

Groupadd Admins


User Natasha, using admins as a subordinate group

Useradd natasha-g Admins


User Harry, also use admins as a subordinate group

Useradd harry-g Admins


User Sarah, no interactive login system, and not a member of admins, Natasha,harry,sarah password is CentOS

Useradd Sarah

echo "CentOS" |PASSWD--stdin Natasha

echo "CentOS" |PASSWD--stdin Natasha

Passwd-l Sarah




This article is from the "mediocre" blog, please be sure to keep this source http://zzjasper.blog.51cto.com/9781564/1832166

Linux Learning record 4

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.