System settings
Default output device: Standard output, STDOUT, 1
Default input device: standard input, STDIN, 0
Standard error Output: STDERR, 2
Standard input: Keyboard
Standard output and Error output: Display
I/O redirection:
Linux:
: Overwrite output
[Email protected] ~]# ll/var/>/tmp/var.out
[Email protected] ~]# cat/tmp/var.out
Total 76
Drwxr-xr-x. 2 root root 4096 June
Drwxr-xr-x. Root root 4096 June
Drwxr-xr-x. 2 root root 4096 June crash
Drwxr-xr-x. 3 root root 4096 June
Drwxr-xr-x. 3 root root 4096 June
Drwxr-xr-x. 2 root root 4096 June
#
#/etc/fstab
# Created by Anaconda on Sun June 21 02:15:00 2015
#
# Accessible filesystems, by reference, is maintained under '/dev/disk '
# See mans Pages Fstab (5), Findfs (8), mount (8) and/or Blkid (8) for more info
#
UUID=57D85756-7680-4C7C-9125-6AD67DAE2C45/EXT4 Defaults 1 1
Uuid=2622a4b4-ddc9-47a3-aa2b-f06bc9bec085/boot EXT4 Defaults 1 2
uuid=33d94759-fa01-4c4f-b4ac-bf3a1fe5e84f swap swap defaults 0 0
TMPFS/DEV/SHM TMPFS Defaults 0 0
Devpts/dev/pts devpts gid=5,mode=620 0 0
Sysfs/sys Sysfs Defaults 0 0
PROC/PROC proc Defaults 0 0
>>: Append output
2>: Redirect Error output
[Email protected] ~]# Ls/varr >/tmp/var2.out
Ls:cannot access/varr:no such file or directory
[Email protected] ~]# Ls/varr 2>/tmp/var2.out
[Email protected] ~]# cat/tmp/var2.out
Ls:cannot access/varr:no such file or directory
[Email protected] ~]#
2>>: Append method
&>: Redirect standard output or error output to the same file
[Email protected] ~]# LS/VAR6 &>/tmp/var3.out
[Email protected] ~]# cat/tmp/var3.out
Ls:cannot access/var6:no such file or directory
[Email protected] ~]# Ls/var &>/tmp/var3.out
[Email protected] ~]# cat/tmp/var3.out
Account
Cache
Crash
Db
Empty
Input redirect
<: Input redirection
[[Email protected] ~]# TR ' A-Z ' A-Z ' </etc/fstab
#
#/etc/fstab
# CREATED by ANACONDA on SUN June 21 02:15:00 2015
#
# ACCESSIBLE filesystems, by REFERENCE, is maintained under '/dev/disk '
# See Mans PAGES FSTAB (5), Findfs (8), MOUNT (8) and/or BLKID (8) for more INFO
#
UUID=57D85756-7680-4C7C-9125-6AD67DAE2C45/EXT4 DEFAULTS 1 1
Uuid=2622a4b4-ddc9-47a3-aa2b-f06bc9bec085/boot EXT4 DEFAULTS 1 2
uuid=33d94759-fa01-4c4f-b4ac-bf3a1fe5e84f swap swap DEFAULTS 0 0
Tmpfs/dev/shm TMPFS DEFAULTS 0 0
Devpts/dev/pts devpts gid=5,mode=620 0 0
Sysfs/sys SYSFS DEFAULTS 0 0
Proc/proc PROC DEFAULTS 0 0
[Email protected] ~]#
<<: Here is the document
[[email protected] ~]# cat << END
> The first line
> The second line
> END
The first line
The second line
[Email protected] ~]#
Read data from the keyboard and save it in the document
Cat >>/tmp/myfile.txt << EOF
[email protected] ~]# cat >>/tmp/myfile.txt << EOF
> The first line
> The second line
> EOF
[Email protected] ~]# Cat/tmp/myfile.txt
The first line
The second line
[Email protected] ~]#
Pipeline: The output of the previous command, as input to the latter command
Command 1 | Command 2 | Command 3 | ...
[Email protected] ~]# echo "Hello,world" | Tr ' A-Z ' A-Z
Hello,world
[Email protected] ~]#
[Email protected] ~]# echo "Redhat" | passwd--stdin Hive
Changing password for user hive.
Passwd:all authentication tokens updated successfully.
[Email protected] ~]#
Output to screen and file at the same time
[Email protected] ~]# echo "Hello,world" | Tee/tmp/hello.out
Hello,world
[Email protected] ~]# cat/tmp/hello.out
Hello,world
[Email protected] ~]#
Number of statistics file lines
[Email protected] ~]# wc-l/etc/passwd
32/etc/passwd
[Email protected] ~]# Wc-l/etc/passwd | Cut-d '-f1
32
[Email protected] ~]#
Practice:
1, Statistics/usr/bin/the number of documents under the directory;
# Ls/usr/bin | Wc-l
2. Take out the shell of all the users on the current system and request that each shell be displayed only once and in order;
# cut-d:-f7/etc/passwd | Sort-u
3, thinking: How to display the content type of each file in the/var/log directory?
4. Take out the 6th line of the/etc/inittab file;
# head-6/etc/inittab | Tail-1
5. Take out the user name and shell of the 9th user in the/etc/passwd file, display it to the screen and save it to the/tmp/users file;
# tail-9/ETC/PASSWD | head-1 | Cut-d:-f1,7 | Tee/tmp/users
6. Display all files starting with PA in/etc directory, and count the number of them;
# ls-d/etc/pa* | Wc-l
7, do not use a text editor, add alias Cls=clear a line of content to the current user's. bashrc file;
# echo "Alias Cls=clear" >> ~/.BASHRC
Linux Fundamentals-i/o Redirect, pipeline