Original blog, reprint please indicate the source
Attach a few Linux blogs with a higher number of previous visits
My 8 tips for using the shell
Nine classic usage scenarios for grep
SED command detailed
awk Command Detailed
Everything in Linux is a file, and the command is a binary file.
1, LS
/bin/ls
Common options
-A All files (including hidden files)
-L Detailed information
-D Directory Properties
-I view Inode
Example
[root@localhost testforcsdn]# ls
filelist-i second
[root@localhost testforcsdn]# ls-a ... filelist Second
[root@localhost testforcsdn]# ls-l Total
-rw-r--r--1 root root Oct 23:12 filelist
-rw-r--r--1 root 0 Oct 18:04 A-
1 root root 0 Oct 24 18:04 second
[root@localhost testforcsdn]# ls-al total drwxr-xr-x 2 root 4096 Oct 24 18:04. C20/>drwxr-x---root root 4096 Oct 17:56.
-rw-r--r-- 1 root Oct 23:12 filelist
-rw-r--r-- 1 root 0 Oct 18:04 first
-rw-r--r-- 1 root 0 Oct 18:04 Second
[root@localhost testforcsdn]# ls-d
.
[Root@localhost testforcsdn]# ls-i
2256719 filelist 2256718-A-2256730
Analysis under
-rw-r--r--1 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,-to indicate that there is no permission, if X is an executable, a total of 9, three groups, respectively, representing the creator, the group, the others
Therefore, for the creator is rw-is read-write is not executable, for the owning group is r--only Read permission, others only Read permission
1 indicates the number of hard links
The first root represents a user
The second root represents the user group
100 indicates file size, if directory is directory and subdirectory size
OCT 18 23:13:12 Indicates the last modified time
FileList indicates file name
2, CD
Change direction
The usual commands for matching CDs and
PWD View current directory
Change Directory
First, explain the following directory
/root partition, all files and directories start from here
/bin users can execute files
/sbin system executable file, mainly for administrator use, s for super
/ETC configuration file
/dev Device files
/proc process information, such as/proc/cpuinfo containing processor information
/var variable files such as Log,mail
/USR user program, storing files for user applications
/home User Home Directory
/boot Start Add-ins
/opt Optional Application
/MNT Mount Directory
/media removable media such as/media/cdrom
/SRV Service Data
Example
[Root@localhost etc]# cd/etc/
[root@localhost etc]# pwd
/etc
[root@localhost etc]# cd ~
[ Root@localhost ~]# pwd
/root
What we're going to say here is,
CD ~ Represents the home directory of the current login user
If it's root back to/root/,
If it's a regular user, go back to/home/
3. Touch
Create a blank file file or modify the timestamp of a file
Common options
-A Change access time only
-C does not create any documents
-d Use the specified date
-M only change change time
-R Changes the date time of the specified document or directory to the same as the reference document
-T sets the time stamp specified
Example
[root@localhost testforcsdn]# ls-l Total
-rw-r--r--1 root Oct 23:12 filelist-rw-r--r--
1 roo T-root 0 Oct 18:04
-rw-r--r--1 root 0 Oct 18:04 Second
[Root@localhost testforcsdn]# tou CH Thrid
[root@localhost testforcsdn]# ls-l Total
-rw-r--r--1 root Oct 23:12 filelist-
R w-r--r--1 root 0 Oct 18:04-
-rw-r--r--1 root root 0 Oct 18:04 Second
-rw-r--r--1 ro OT root 0 Oct 18:34 thrid
[root@localhost testforcsdn]# touch-t 201410250935.40 thrid
[root@localhost testforcsdn]# ls-l Total
-rw-r--r--1 root Oct 23:12 filelist
-rw-r--r--1 root root 0 Oct 18:04-
-rw-r--r--1 root 0 Oct 18:04 Second
-rw-r--r--1 root root 0 Oct 2014 thrid
You can see that the time stamp was changed with-t
4 mkdir
Create a Directory
Common options
-m specify permissions at creation time
-p Specifies the path, if some directories on the path do not exist, it is created, that is, you can create a multi-tiered directory at once
-V Display Details
Example
[Root@localhost testforcsdn]# mkdir-m 777 Firstdir
[root@localhost
-testforcsdn]# ls-al Total Drwxr-xr-x 3 root root 4096 Oct 18:41.
Drwxr-x---root root 4096 Oct 17:56.
-rw-r--r-- 1 root Oct 23:12 filelist
-rw-r--r-- 1 root 0 Oct 18:04
A-DRW XRWXRWX 2 root 4096 Oct 18:41 firstdir
-rw-r--r-- 1 root root 0 Oct 18:04
second-rw-r --r-- 1 root 0 Oct 2014 thrid
[root@localhost testforcsdn]# mkdir-p Thriddir
[root@localhost testforcsdn]# cd firstdir/seconddir/thriddir/
[root@localhost thridDir]# pwd
/root/testforcsdn/firstdir/seconddir/thriddir
As you can see, by-P creates a multi-tier directory once, and-M gives 777 of the permissions while creating the directory
5 CP
Copy
Common options
-B To delete the overwrite destination file before you back up
-I asks if you want to overwrite
-P retains the source file's or directory's properties: Owner, group, permission time
-R Copy Directory
Example
[root@localhost testforcsdn]# ls
filelist firstdir second thrid
[root@localhost testforcsdn]# LS firstdir/
filelist Second
[root@localhost testforcsdn]# cp thrid firstdir/
[root@localhost testforcsdn]# cp-b filelist firstdir/
cp:overwrite ' firstdir/filelist ' y
[root@localhost testForCsdn]# ls firstdir/
filelist filelist~ second thrid
[root@localhost testforcsdn]# mkdir Seconddic
[root@localhost testforcsdn]# cp-r firstdir/seconddic/
[root@localhost testforcsdn]# ls seconddic/
firstdir
By the way, SCP: for instance,
SCP is a remote copy, if you want to remotely copy directory with-R
Scp-r root@192.168.0.12:~/testcsdn/localcsdn/
Copy the 192.168.0.12 ~/testcsdn to the localcsnd.
6, MV
Cut and rename
Example
[root@localhost testforcsdn]# ls
filelist firstdir second seconddic thrid you
have new mail In/var/spool/mail/root
[root@localhost testforcsdn]# mkdir tempdic
[root@localhost testforcsdn]# ls
FileList firstdir second seconddic tempdic thrid
[root@localhost testforcsdn]# MV FileList newName
[root@localhost testforcsdn]# mv NewName tempdic/
[root@localhost testforcsdn]# ls
Firstdir Second seconddic tempdic thrid
[root@localhost testforcsdn]# ls tempdic/
NewName
7 Cat More
are used to view the contents of a file
Cat is suitable for shorter files
More will Page view: Space page, enter the next line, Q exit
Cat filename
More filename
8 Head Tail
View the first few lines of a file, and the following lines
Tail-f can be used to dynamically view the following lines of a file
Example
9 Ln
Create soft and hard links
Soft Links: Shortcuts similar to Windows
Hard link: Two files synchronized update
Soft links can cross file systems, hard links cannot be
Example
Create a soft connection
[Root@localhost ~]# ln-s file.txt file.hardlink
Create a hard link
[root@localhost ~]# ln file.txt file.hardlink
As you can see, the number of hard links to file.txt becomes 2.
-rw-r--r--2 Root root 210 Oct 07:54 File.hardlink
lrwxrwxrwx 1 root root 8 Oct 19:14 File.softlink ; File.txt
-rw-r--r--2 root 210 Oct 07:54 file.txt
Then, modify the File.txt
Type TESTCSDN at file start
See Hard links again
[Root@localhost ~]# head-5 file.hardlink
testforcsdn
backup
bin
boot
Dev
You can see that the contents are updated synchronously