Operating System and Common commands

Source: Internet
Author: User
Tags builtin

Operating System and Common commands
Linux02

-- Linux02_01? Operating System and Common commands


GNU: GNU is Not Unix.
GPL: General Public License, General Public License, copyright
Copyright, Copyleft
Open-source protocols
LGPL: lesser
GPLv2
GPLv3

Shell:
GUI: Graphic User Interface
Windows
X-Window
Gnome
KDE
Xface
CLI: Command Line Interface
Sh
Bash
Csh
Ksh
Zsh
Tcsh


Google:
Linux filetype: pdf
Linux site: ibm.com

Google hack


IDE: integrated development environment


Login:
User name: User ID

Authentication Mechanism: Authentication is the object mechanism declared for identification and determination.
Authorization: Authorization
Audit: Audition (log)


Prompt, Command prompt:
Command:
Magic number: magic number
Shebang

#! /Bin/bash

# Command options... arguments... (Operation object)

Option:
Short options
Long Options
Parameters:

List: ls
List

Directory: file, path ing

Path: from the specified start point to the destination location

File system: file system

FHS: hierarchical File System

List objects in a specified path


Directory: working directory, current directory

Pwd: Printing Working directory

Ls
-L: long format
File Type:
-: Common file (f)
D: directory file
B: block Device Files)
C: character device file (character)
L: symbolic link file)
P: Command pipeline file (pipe)
S: socket File)
File Permission: 9 bits, each 3 bits, each group: rwx (read, write, execute), r --
Number of file hard links
File owner)
File group)
File size (size), in bytes
Timestamp: The last modification time.
Access: access
Modify: modify. The file content has changed.
Change: change, metadata, metadata (attribute)
-H: converts units.
-A: displays hidden files starting ".".
. Indicates the current directory
.. Indicates the parent directory
-
-D: displays the directory attributes.
Drwxr-x --- 18 root 4096 Jan 28.
-I: index node and inode (display index node number)
851969 drwxr-x --- 18 root 4096 Jan 28.
-R: reverse display
-R: recursive display
.:
Anaconda-ks.cfg DOS install. log Unix
C exit install. log. syslog vms
Desktop grant Solaris

Cd: change directory
Home directory, home directory, home directory
Cd ~ USERNAME: Enter the Home Directory of the specified user, but only the root permission can enter the directory of another user
Cd-: switch back and forth between the current directory and the previous directory
[Root @ localhost ~] # Cd ~ Oracle
[Root @ localhost oracle] # pwd
/Home/oracle
[Root @ localhost oracle] # cd-
/Root
[Root @ localhost ~] # Cd-
/Home/oracle
[Root @ localhost oracle] # cd-
/Root
[Root @ localhost ~] #

Command type:
Built-in commands (shell built-in), internal and built-in (when a command prompt is prompted after Logon: #, $, etc., then we enter a shell, shell is also an application, therefore, it also provides self-recognition commands for users: No need to configure environment variables)
[Root @ localhost ~] # Type cd
Cd is a shell builtin: shell built-in command
External command: an executable file corresponding to the command name under a path of the file system
[Root @ localhost ~] # Type su
Su is/bin/su
Environment variable: named memory space
Variable assignment
NAME = Jerry

PATH: PATH separated by a colon
O (1): A standard used to measure the execution speed of a program. The hash O (1) is so fast that the query cache is saved to the cache.
Hash: the number of times that commands have been executed in the cache and saved to the cache (key-value pairs exist in the hash)
[Root @ localhost ~] # Hash
Hits command
14/bin/ls
6/usr/bin/clear


-- Linux02_02? Operating System and Common commands
Type: display the specified type

Date: Time Management
Linux: rtc

Hardware clock: The Clock maintained by a hardware-level Oscillator
[Root @ localhost ~] # Hwclock
Wed 28 Jan 2015 07:25:47 pm pst-0.764336 seconds
[Root @ localhost ~] #
System clock: the system time maintained by the Linux kernel. There is an error because of cpu execution problems.
[Root @ localhost ~] # Date
Weds Jan 28 19:20:35 PST 2015

Get Command help:
Internal command:
Help COMMAND
External commands:
COMMAND -- help

Common query method --> command manual: manual. Since the manual must be a file and a compressed file
Man COMMAND: displays COMMAND Information:
1. Is it in the built-in shell?
2. Name
3. Syntax
4. Optional parameters
[Root @ localhost ~] # Man cd
BASH_BUILTINS (1)
BASH_BUILTINS (1)
NAME...

[Root @ localhost ~] # Man ls
LS (1) -- indicates the ls command User Commands LS (1) in the first section)

NAME
Ls-list directory contents

SYNOPSIS
Ls [OPTION]... [FILE]...

DESCRIPTION

Whatis COMMAND: displays the chapters of a COMMAND.
[Root @ localhost ~] # Whatis ls
Ls (1)-list directory contents
Ls (1 p)-list directory contents
[Root @ localhost ~] #
You can specify the chapters to search:
[Root @ localhost ~] # Man 1 ls

Man:
1: USER command (/bin,/usr/bin,/usr/local/bin): used by common users
2: System Call
3: database users
4: Special files (device files)
5: File Format (Configuration File Syntax): the syntax of the configuration file corresponding to a command
6: Games
7: Miscellaneous (Miscellaneous)
8: management commands (/sbin,/usr/sbin,/usr/local/sbin): Can Be Used by administrators

<>: Required.
[]: Optional
...: Can appear multiple times
|: Select one more
{}: Group

MAN:
NAME: command NAME and function description
SYNOPSIS: usage instructions, including available options
DESCRIPTION: A detailed DESCRIPTION of the command function, which may include the meaning of each option.
OPTIONS: Meaning of each option
FILES: configuration file related to this command
BUGS: WHO reports the bug?
EXAMPLES: Example
See also: For more information, SEE

Screen flip:
Flip back: SPACE
One screen forward: B
Flip One Line Backward: ENTER
One row forward: k

Search:
/KEYWORD: backward
N: Next
N: Previous

? KEYWORD: Forward
N: Next
N: Previous

Q: Exit


Online Documentation:
Info COMMAND

Document:/usr/share/doc

Google

Apache and hadoop

Exercise:
Use date to obtain the current year, month, day, hour, minute, and second of the system.

Hwclock
-W: synchronize system time to hardware
-S: Read the hardware time to the System
Date and hwclock usage:
[Root @ localhost ~] # Date 01282020.00 -- modification time
Weds Jan 28 20:20:00 PST 2015
[Root @ localhost ~] # Date + "date is % D" -- print time
Date is 01/28/15
[Root @ localhost ~] #
[Root @ localhost ~] # Hwclock-w
[Root @ localhost ~] # Hwclock
Wed Jan 28 20:22:39 2015-0.449991 seconds
[Root @ localhost ~] # Date
Weds Jan 28 20:22:45 PST 2015
[Root @ localhost ~] # Hwclock-s

Cal: calendar
[Root @ localhost yum-3.2.22] # cal 10 2014
October 1, 2014
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31


Exercise:
1. Is echo an internal command or an external command?
[Root @ localhost yum-3.2.22] # type echo
Echo is a shell builtin
2. What is its role?
[Root @ localhost yum-3.2.22] # date + "today is % A % n date is % D"
Today is Wednesday
Date is 01/28/15
[Root @ localhost yum-3.2.22] # echo-e "today is Tu \ n date is 1/29" -- '-e' means start escape characters
Today is Tu
Date is 1/29
[Root @ localhost yum-3.2.22] # echo "today is Tu \ n date is 1/29"
Today is Tu \ n date is 1/29
[Root @ localhost yum-3.2.22] # echo-n "today is Tu \ n date is 1/29" -- remove line breaks
Today is Tu \ n date is 1/29 [root @ localhost yum-3.2.22] #
3. How do I display "The year is 2013. Today is 26." As two rows?
[Root @ localhost yum-3.2.22] # date + "today is % A % n date is % D"
Today is Wednesday
Date is 01/28/15

Escape means escape characters.

Exercise:
1. Is printf an internal command or an external command?
[Root @ localhost ~] # Type printf
Printf is a shell builtin
2. What is its role?
[Root @ localhost yum-3.2.22] # printf "today is Tu \ n date is 1/29 \ n"
Today is Tu
Date is 1/29
[Root @ localhost yum-3.2.22] # printf "today is Tu \ n date is 1/29"
Today is Tu
Date is 1/29 [root @ localhost yum-3.2.22] #
Therefore, the difference between printf and echo is that the previous line breaks by default.
3. How do I display "The year is 2013. Today is 26." As two rows?

-- Linux02_03? Operating System and Common commands File command and its usage.
[Root @ localhost ~] # File-I.
.: Application/x-not-regular-file
[Root @ localhost ~] # File-s.
.: Directory
[Root @ localhost ~] # File
Usage: file [-bcikLhnNsvz] [-f namefile] [-F separator] [-m magicfiles] file...
File-C-m magicfiles
Try 'file -- help' for more information.
[Root @ localhost ~] # File/dev/hdc
/Dev/hdc: block special (22/0)
[Root @ localhost ~] # File-s/dev/hdc
/Dev/hdc: ISO 9660 CD-ROM filesystem data 'rhel/5.5 x86_64 DVD '(bootable)
[Root @ localhost ~] #
Windows: PE
Linux: ELF



File System: partition-based, but all partition file systems must be under the root file

Rootfs: root file system

FHS: Directory standards that Linux complies with (file system level standards)

/Boot: files related to system startup, such as kernel, initrd, and grub (bootloader)
[Root @ localhost ~] # Ls/boot/
Config-2.6.18-194.el5 symvers-2.6.18-194.el5.gz
Grub System. map-2.6.18-194.el5
Initrd-2.6.18-194.el5.img vmlinuz-2.6.18-194.el5
Lost + found
(Everything in Linux is a file, and the device is also a file, the portal)
/Dev: Device File
DEVICE file:
Block devices: Random Access, data blocks
Character device: Linear access, in characters
Device No.: main device No. (major) and sub-device No. (minor ):
Crw-rw ---- 1 root tty 4, 37 Jan 28 tty37
/Etc: Configuration File
/Home: the home directory of a user. The default home directory of each user is/home/USERNAME.
/Root: Administrator's home directory;
You cannot log on to the production environment by using the root user, because it has the most permissions and can easily delete files by mistake.
/Lib: library file (which has been written and can be called directly)
/Lib/modules: kernel module File
Static library,.
[Root @ localhost lib] # file libdevmapper.
Libdevmapper. a: symbolic link to 'libdevmapper. a.1.02'
Dynamic library,. dll (in window),. so (shared object)
[Root @ localhost lib] # file libc-2.5.so
Libc-2.5.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, not stripped
[Root @ localhost lib] #
Dynamic and Static differences:
Static libraries are compiled together with library files during static compilation, so during migration
It must be transplanted together with the library.
A dynamic library is also called a shared library, that is, multiple programs are compiled and shared at a time.
Why are the following two files executable, but the first one is not executable?
[Root @ localhost lib] # file libc-2.5.so
Libc-2.5.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, not stripped
[Root @ localhost lib] # file/bin/ls
/Bin/ls: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs ), for GNU/Linux 2.6.9, stripped
[Root @ localhost lib] #
Because: The above is the library file, the library file is not executed independently, it can only be called

/Lost + found: used to save special circumstances such as sudden power failure, used to save files for fear of loss
/Media: mount point directory, mobile device
/Mnt: mount point directory, additional temporary file system
Mount point: the point where the device is mounted to a directory in the file system.
Hanging Process: A device must be loaded to a directory of the current file system for access.
This process is the mounting process.

/Opt: optional Directory. The installation directory of third-party programs is now in/usr/local
/Proc: pseudo file system, kernel ing File
/Sys: pseudo file system, property ing file related to hardware devices
/Tmp: temporary file,/var/tmp
/Var: changeable File
The following two executable files and commands must be executed by the system before it is started.
/Bin: executable file, USER command
/Sbin: Management command

/Usr: shared, read-only
The following are the executable files and commands provided to improve other functions of the system after the system is started:
/Usr/bin
/Usr/sbin
/Usr/lib

/Usr/local: installation path for third-party software, non-critical Program
/Usr/local/bin
/Usr/local/sbin
/Usr/local/lib

Naming rules:
1. The length cannot exceed 255 characters;
2. Cannot Use/when the file name
3. Case Sensitive

Relative Path:
Absolute path:



File Management

Directory management
Ls
Cd
Pwd

Mkdir: Create an empty directory
-P: If the created parent directory does not exist, create the parent directory first.
-V: verbose displays execution details
/Root/x/y/z

/Mnt/test/x/m, y
Mkdir-pv/mnt/test/x/m/mnt/test/y
Mkdir-pv/mnt/test/{x/m, y}

~ USERNAME

Expand the command line:
/Mnt/test2/
A_ B, a_c, d_ B, d_c
(A + d) (B + c) = AB + ac + db + dc
{A, d }_{ B, c}
[Root @ localhost ~] # Mkdir-pv./test/{a, B }_{ c, d}
Mkdir: created directory './Test'
Mkdir: created directory './test/a_c'
Mkdir: created directory './test/a_d'
Mkdir: created directory './test/B _c'
Mkdir: created directory './test/B _d'
[Root @ localhost ~] # Mkdir./test/{a, B}/{c, d}
Mkdir: created directory '/test/'
Mkdir: created directory '/test/a/C'
Mkdir: created directory '/test/a/d'
Mkdir: created directory '/test/B'
Mkdir: created directory '/test/B/C'
Mkdir: created directory '/test/B/d'


# Tree: view the directory tree

Delete directory: rmdir (remove directory)
Delete empty directory
-P: Only one-pulse, single-pass directories can be deleted:
[Root @ localhost test] # mkdir-p x/y/z
[Root @ localhost test] # tree
.
| -- A_c
| -- A_d
| -- B _c
| -- B _d
'-- X
'-- Y
'-- Z

7 directories, 0 files
[Root @ localhost test] # rmdir-p x/y/z
[Root @ localhost test] # tree
.
| -- A_c
| -- A_d
| -- B _c
'-- B _d

4 directories, 0 files

File Creation and Deletion
Files or directories with the same name cannot exist. This is also true in windows, but the file format is hidden by the system.
# Touch: Modify the file Timestamp
-A: Change the access time
-M: Change the modification time.
-T: specifies the time
-C: create a file
[Root @ localhost ~] # Stat test/
File: 'test /'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 802 h/2050d Inode: 852122 Links: 6
Access: (0755/drwxr-xr-x) Uid: (0/root) Gid: (0/root)
Access: 23:55:59. 000000000-0800
Modify: 23:55:59. 000000000-0800
Change: 23:55:59. 000000000-0800
[Root @ localhost ~] # Date
Weds Jan 28 23:56:12 PST 2015
[Root @ localhost ~] # Touch-m-t 201212121212 test/
[Root @ localhost ~] # Stat test/
File: 'test /'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 802 h/2050d Inode: 852122 Links: 6
Access: (0755/drwxr-xr-x) Uid: (0/root) Gid: (0/root)
Access: 23:55:59. 000000000-0800
Modify: 12:12:00. 000000000-0800
Change: 23:57:24. 000000000-0800
[Root @ localhost ~] # Touch-a test/
[Root @ localhost ~] # Stat test/
File: 'test /'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 802 h/2050d Inode: 852122 Links: 6
Access: (0755/drwxr-xr-x) Uid: (0/root) Gid: (0/root)
Access: 23:58:19. 000000000-0800
Modify: 12:12:00. 000000000-0800
Change: 23:58:19. 000000000-0800
[Root @ localhost ~] #
# Stat

Create a file. You can use the file editor.

ASCII:

128 different characters:
Binary:
2 ^ 6 = 0, 63
2 ^ 7 = 0,127
000 0000-111 1111

ASCII:
0000 1001: t

2 ^ 16: 65536

Standard: GB18030, GBK, GB2312, Unicode
0000 1001 0000 1110: Shang, Wei

Nano: Text Editor

Delete file: rm
-I
-F
-R

Rm-rf/
[Root @ localhost ~] # Type rm
Rm is aliased to 'rm-I '--> indicates that rm is an alias: rm-I
[Root @ localhost ~] # Rm-I te
Rm: remove regular empty file 'te '? Y
[Root @ localhost ~] # Touch te1 te2
[Root @ localhost ~] # Ls
C Desktop Unix exit install. log te1 test
DOS Solaris anaconda-ks.cfg grant install. log. syslog te2 vms
[Root @ localhost ~] # \ Ls
C Desktop Unix exit install. log te1 test
DOS Solaris anaconda-ks.cfg grant install. log. syslog te2 vms
[Root @ localhost ~] # Type ls
Ls is aliased to 'ls -- color = tty '--> is also an alias command, indicating that the corresponding file is colored. This alias command is not available to common users.
[Root @ localhost ~] # Rm-rf test --> delete a recursive file and force it to be deleted
[Root @ localhost ~] #


-- Linux02_04? Operating System and Common commands Exercise:
1. Create a directory
(1) Create boot and sysroot under/mnt;
(2) create grub under/mnt/boot;
(3) create proc, sys, bin, sbin, lib, usr, var, etc, dev, home, root, tmp under/mnt/sysroot
A) Create bin, sbin, lib under/mnt/sysroot/usr
B) Create modules under/mnt/sysroot/lib
C) Create run, log, lock under/mnt/sysroot/var
D) Create init. d under/mnt/sysroot/etc.


Copy and move files
Cp: copy
The default value is cp-L, which indicates the file to which the default copy link points.
Cp SRC (multiple) DEST (only one)
-R: recursive
-I: Interactive
-F: forcible
-D: copy the link
[Root @ localhost ~] # Cp-d/etc/rc test_cp/test
[Root @ localhost ~] # Ls-l test_cp/
Total 0
Lrwxrwxrwx 1 root 7 Jan 29 0:27 test-> rc. d/rc
[Root @ localhost ~] #
-P: reserved group-p same as -- preserve = mode, ownership, timestamps
-A: Archive replication, usually used for backup
-A, -- archive
Same as-dR -- preserve = all
-D same as -- no-dereference -- preserve = link
-P, -- no-dereference never follow symbolic links: Indicates copying a link without copying the file to which the link is directed.
-- Preserve = link: Save the link
-- Preserve = all: Keep all attributes of the Group
-R: recursive
[Root @ localhost test_cp] # cp/etc/init. d/test1
Cp: omitting directory '/etc/init. d /'
[Root @ localhost test_cp] # cp-r/etc/init. d/test1 --> The above indicates that the copy directory must be recursive.

[Root @ localhost test_cp] # cp/etc/init. d/acpid/etc/init. d/atd test1 --> rename the copied file name
Cp: overwrite 'test1/acpid '? N
Cp: overwrite 'test1/atd '? N

[Root @ localhost test_cp] # cp/etc/init. d/acpid/etc/init. d/atd test2 --> if multiple files are copied, the target must be a directory.
Cp: target 'test2' is not a directory
Cp file1 file2 file3
One file to one file
Multiple files to one directory
Cp/etc/{passwd, inittab, rc. d/rc. sysinit}/tmp/

Mv: move
Move files

Mv SRC DEST
Mv-t DEST SRC

[Root @ localhost test_cp] # mv test2/installActions2014-12-20_09-55-25PM.log ../test_cp/
[Root @ localhost test_cp] # ls
InstallActions2014-12-20_09-55-25PM.log (test2)
[Root @ localhost test_cp] # Music installActions2014-12-20_09-55-25PM.log installActions --> rename
[Root @ localhost test_cp] # ls
InstallActions test2
[Root @ localhost test_cp] # mv test2/installActions --> A directory cannot be used to overwrite a file.
Mv: cannot overwrite non-directory 'installactions' with directory 'test2 /'
[Root @ localhost test_cp] # mv ora installActions --> overwrite the file, but there is no overwrite between Directories
Mv: overwrite 'installactions '? Y
[Root @ localhost test_cp] #

Install
-D DIRECOTRY...: create a directory
SRC (file, cannot be a directory) DEST
Install-t directory src... (file, cannot be a DIRECTORY)

[Root @ localhost test_cp] # install-d dir --> creating a directory is equivalent to mkdir
[Root @ localhost test_cp] # ls
Dir installActions test2 [root @ localhost test_cp] # install dir/test2/--> install does not have a copy directory
Install: omitting directory 'dir /'
[Root @ localhost test_cp] # install installActions test2/
[Root @ localhost test_cp] # ls-l test2/
Total 4
-Rwxr-xr-x 1 root 0 Jan 29 installActions --> the default copy file is rwxr-xr-x
-Rw-r ----- 1 root 117 Jan 29 oraInstall2014-12-20_09-55-25PM.out
[Root @ localhost test_cp] # install-o oracle-m-rw test2/oraInstall2014-12-20_09-55-25PM.out ./
[Root @ localhost test_cp] # ls-l
Total 12
Drwxr-xr-x 2 root 4096 Jan 29 06:15 dir
-Rw-r ----- 1 root 0 Jan 29 0:42 installActions
---------- 1 oracle root 117 Jan 29 oraInstall2014-12-20_09-55-25PM.out
Drwxr-x --- 2 root 4096 Jan 29 test2
[Root @ localhost test_cp] #



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.