Linux Learning Log Linux command basic format and file processing commands

Source: Internet
Author: User
Tags clear screen syslog

Linux Common commands:

Practice more than 3 times


First, the command basic format

1. Command format:

[Root (Administrator) @localhost (hostname) ~]# (super User prompt, normal user prompt is $) adminis

/root First level directory with PWD print working directory (print working directory) view

/home/user1/Level Two Directory

[[email protected] ~]# cd/usr/local/src/switch current directory

[Email protected] src]#


command [options] [parameters] brackets indicate optional

Note: Individual commands do not follow this verse when they are used, and can be written together to simplify options and complete options when there are multiple options

-A equals--all

2. Querying the contents of the directory: LS [options] [file or directory]

Options:

-A all, show all files, including hidden files, hide files with dots "." Start,. BASHRC, hide is to prevent misoperation

-L display details longlist long display

-D View Directory Properties direct

-H humanized Display file size human

-I display inode as I node

Permissions: Default 10-bit-rw-r--r--

-File type (the main three kinds:-File d Directory | soft link file)

Four other file types: block device files, character device files, socket files, and piping pipe files

rw-r--r--

User owner G-owned group O other people

-rw-r--r--. L root root 1207 January 18:18 anaconda-ks.cfg

Explain:

-rw-r--r--: Distribution of permissions

.: Point. may represent ACL permissions

L: Number of references, Count called

1207: Character size, generally byte # Ls-lh: Display characters after unit, easy to read H,human humanization

First root: All groups, Master

Second Root: Owning group, user group

January 14 18:18: Time of last modification


Memory: R Read Read,w write Write,x execute Execute


Ii. File processing commands

1. Directory Processing commands

Directories are also files, directories are used to save files

(1). Build directory: mkdir make directories

mkdir-p [directory Name]

-P recursive creation, first create a parent directory, and then create a second level directory


[Email protected] ~]# mkdir-p Japan/cangls

[[email protected] ~]# ls

Anaconda-ks.cfg Bols Install.log install.log.syslog Japan

[Email protected] ~]# CD japan/

[[Email protected]ost japan]# ls

Cangls

(2). Switch directory: CD change directory

Simplified operation:

CD ~ Enter the current user's home directory

CD into the current user's home directory/ctrl+l xshell Clear screen

CD-Go to last directory

Cd.. Go to the top level directory

Cd. Go to current directory

[Email protected] japan]# cd/root/

[[email protected] ~]# ls

[Email protected] cangle]# pwd

/root/japan/cangls

[Email protected] cangls]# cd~

[Email protected] ~]# CD Japan/cangls

[[Email protected] cangls]# CD

[Email protected] ~]# CD-

/root/japan/cangls

[Email protected] cangls]# CD-

Root

[Email protected] ~]# CD.

[[email protected]/]# root directory


. Relative path: Search by reference to the current directory

such as: [[email protected] ~]# CD. /usr/local/src/

[[Email protected]/]# CD

[Email protected] ~]# pwd

/root

[[Email protected] ~] #cd. /usr/local/src/Relative path changes

[Email protected] src]# pwd

/usr/local/src

[Email protected] src]# CD. The/usr/local/src/path has changed, so the prompt error cannot be confirmed to the USR directory in src

-BASH:CD:.. /usr/local/src/: No file or directory

[Email protected] src]#


. Absolute path: Specified from the root, recursive lookup at the first level. In any directory, can enter the designated location, more reliable

such as: [[email protected] src]# cd/etc/

[Email protected] src]# cd/etc/

[Email protected] etc]# cd/etc/

[Email protected] etc]# cd/etc/

[Email protected] etc]# cd/etc/

[Email protected] etc]#

Commands can be run under any directory, after all, starting from the root directory

If you don't remember the target directory,


[[Email protected] src]# CD/(Press two tab) to complete commands or directories with tab


(3). The directory where the query is located: pwd

. PWD:p rint working directory Print working directory, display current directory


(4). Delete Empty directory: RmDir

. rmdir [Directory name]:remove empty directories Delete blank directory

[[email protected] ~]# ls

Anaconda-ks.cfg Bols Install.log install.log.syslog Japan

[Email protected] ~]# rmdir bols/

[[email protected] ~]# ls

Anaconda-ks.cfg Install.log install.log.syslog Japan

[Email protected] ~]# rmdir japan/

RmDir: Delete "japan/" failed: Directory not empty

Because there is a folder in Japan Cangls, so non-empty can not be deleted


(5). Delete files or directories: RM

. rm-rf [File or directory]

Command English is willing: remove

Options:

-R Delete directory, delete directory is indispensable

-F Mandatory

[[email protected] ~]# RM-RF/delete root 99% file, almost equivalent to formatted, suicidal command


(6). Copy command: CP

CP [Options] [Original file or directory] [target directory]

Command English is willing to: copy

Options:

-R Copy Directory

-P Joint File attribute copy

-D If the source file is a linked file, copy the link property

-A equals-pdr

[[email protected] ~]# Cpanaconda-ks.cfg/tmp/ana (Add this name to indicate that the copy used to change the file name, not fill in the past is still the source file name)

[[email protected] ~]# ls

Anaconda-ks.cfg Install.log install.log.syslog Japan

[[email protected] ~]# CP japan//tmp/Note space to separate japan/and/tmp/

CP: Skip Directory "japan/" need to add-r

[Email protected] ~]# cp-r japan//tmp/

[Email protected] ~]# ls/tmp/

Ana Japan Yum.log

You can use ll to view my file attributes and permission distributions

[email protected] ~]# ll or write ls-l

Total Dosage 48

-RW-------. 1 root root 1207 January 20:38 Ana

Normal copy out of file time old and new file time inconsistent

[Email protected] ~]# CP-PDR

The copied file and source file attributes are all consistent


(7) Cut or rename command: MV

MV [original file or directory] [target directory]

English intent: Move

Cut does not differentiate between files and directories, without the-R

[[Email protected] ~]# mv japan//tmp/japan1 not in the same directory is cut

[[email protected] ~]# ls

Anaconda-ks.cfg Install.log Install.log.syslog

[Email protected] ~]# cd/tmp/

[[email protected] tmp]# ls

Ana anaconda-ks.cfg Japan Japan1 yum.log

Renamed:

[[Email protected] tmp]# mv Anaconda-ks.cfg Longls in the same directory, it changed its name.

[[email protected] tmp]# ls

Ana Japan japan1 Longls yum.log


The role of a common level of directory:

/root directory

/bin command to save directories (commands that ordinary users can read)

The root directory/bin and the SBIN,USR directory under the bin and sbin four directories are used to save system commands, sbin only root to use, ordinary users do not sbin,super bin

/boot directory to start related files

/dev Device configuration file save directory

/etc configuration File Save Directory

/root home directory for super users

Home directory for normal users

/lib System Library Save directory, common function library

/MNT system mount file, CD-ROM mount CD, USB mount Drive

/media Mount Directory

/misc empty directory, the last three are loaded with a directory

Usage specifications, the customary directory name

/proc/Direct Write memory

/sys/

The proc and SYS directories are not directly operational and are used to hold the overloaded points of memory

Can not be used to store data, first memory can not be permanently saved, and storage will make the system slow

Contents of the/var system related documents

/tmp Storing temporary files

Summary: You can place content in the home directory root or home, as well as the TMP directory

The root directory only holds the necessary files


(8). LINK command: LN

Ln-s [Original document] [target document]

Command English original meaning: link

Function Description: Generate link file

Option:-S to create a soft link soft

. Hard-Link features:

1, have the same I node and Storage block block (4KB a block), can be seen as the same file

Equivalent to a different fetch entry for a stored file, a double copy is stored as a mirror

2, can be identified by the I node

3. Cannot cross partition

4. Cannot be used for directory

[[email protected] ~]# ls

Anacondalks.cfg Cangls Install.log Install.log.syslog

[Email protected] ~]# Ln/root/anaconda-ks.cfg/tmp/ana.hard

[email protected] ~]# LL

Total Dosage 44

-W--------. 2 root root 1207 January 18:18 anaconda-ks.cfg

...

[Email protected] ~]# ll/tmp/

Total Dosage 12

-W--------. 2 root root 1207 January 18:18 Ana.hard, reference count plus 1

Open the changes in any way, through another can still view the file, permissions consistent, is actually the same file

Defect: Cannot cross partition, cannot target directory


. Soft Link Features:

1, similar to Windows shortcut, easy to open

2, the soft link has its own I node and block blocks, but the data block to save the original file name and I node number, and no actual file data, is the original file of the I node and block blocks

3, lrwxrwxrwx | soft link

Soft link file permissions are rwxrwxrwx, view the permissions of the soft link file, different from the original file

4, modify any file, the other changes

5, delete the original file, soft links can not be used

Less restrictive, and flexible


[[email protected] ~]# ls

Anacondalks.cfg Cangls Install.log Install.log.syslog

[Ro[email protected] ~]# ln-s/root/anaconda-ks.cfg/tmp/cangls.soft

[Email protected] ~]# Ln/root/cangls/tmp/cangls.hard

[email protected] ~]# LL

Total Dosage 40

-rw-r--r--. 2 root root 1207 January 22:00 Cangls

...


[Email protected] ~]# ll-i

262419-rw-r--r--. 2 root root 0 January 22:00 Cangls

262147-rw-r--r--. 1 root root 24772 January 18:17 Install.log

...

[Email protected] ~]# ll-i/tmp/

262418-RW--------. 1 root root 1216 January 22:36 Ana.hard

932110-rw-r--r---. 1 root root 0 January 22:00 Cangls

262419-rw-r--r--. 2 root root 0 January 22:00 Cangls.hard

932061 lrwxrwxrwx. 1 root root 12 January 22:46 Cangls.soft-/root/cangls

Where rwx refers to access to the soft link permissions, not the original file permissions, the main analysis inode, permission changes, reference counting

...

use [[email protected] ~]# Cat/tmp/cangls.hard

[Email protected] ~]# Cat/tmp/cangls.soft

View Files

Do soft links need to use absolute target, otherwise it will be difficult to find, or modify in the same directory






This article is from the "8626774" blog, please be sure to keep this source http://8636774.blog.51cto.com/8626774/1676123

Linux Learning Log Linux command basic format and file processing commands

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.