Home > OS >  Linux basic commands
Linux basic commands

Time:10-28

Directory:
Touch command
The stat command
The cp command
The mv command
The file command
The rm command
Alias command
Ln order
The cat, the tac command
More, less
Hard, tail command
Which command
Whereis the command
The locate command
The find command
The compression of files
Zip and unzip the command
Gzip zcat order
Bzip2 bzcat order
The tar file
The tar practice

Touch command
A new empty file or update the file timestamp
Format: touch the file name...
Commonly used command options:
- a: change the file read time record
- m: change the file modification time record
- r: the records of time using a reference file
D: set the time and date


The stat command
: detailed information display file/file system (can see the file, read time, modified time, etc.)
Acess: content read time
The Modify: content modification time
Change: attribute (metadata) modified time

/root @ rhel1 ~ # stat a
File: ` a '
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 803 h/2051 d Inode: 41156620 Links: 1
Access: (/rw - r - r - 0644) Uid, Gid (0/root) : (0/root)
Access: the 2019-02-27 23:05:34. 124999274 + 0800
The Modify: the 2019-02-27 23:05:34. 124999274 + 0800
Change: the 2019-02-27 23:05:34. 124999274 + 0800

The cp command
Used to copy a file or directory
Format: cp [option] source file or directory... The target file or directory
- r: recursive copy an entire directory tree
- a: copy retain links, file attributes, and recursively copy directory

The mv command
Used to move a file or directory
(note: if the target location is the same as the source location, was renamed)
Format: mv [option]... The source file or directory
the target file or directoryExample:
Copy hosts to the current directory and renamed hosts. Bak

Mv/etc/hosts/etc/hosts. Bak

The file command
To view the file type
Format: the file filename

/root @ rhel1 ~ # file a1
A1: the empty
/root @ rhel1 ~ # file mysql
Mysql: directory
/root @ rhel1 ~ # file mysql - 5.7.14-1. El6. X86_64. RPM - bundle. Tar
Mysql - 5.7.14-1. El6. X86_64. RPM - bundle. Tar: POSIX tar archive (GNU)
/root @ rhel1 ~ # file/bin/ls
/bin/ls: ELF 64 - bit LSB executable that x86-64, version 1 (SYSV), dynamically linked (USES Shared libs), for the GNU/Linux 2.6.18, stripped
/root @ rhel1 ~ # file/etc/passwd
The/etc/passwd: ASCII text

The rm command
Used to delete a file or directory
Format: rm [option] file or directory
- f: to delete a file or directory, not to remind
- r: recursive delete an entire directory tree
Wild card:
* match zero or more characters
? Match one character


Check the alias alias
Command priority (alias & gt; Internal command & gt; External commands)

/root @ rhel1 ~ # alias
Alias cp='cp -i'
='ls - alias l. d. * -- color=auto'
Alias ll='ls -l -- color=auto'
Alias ls='ls -- color=auto'
Alias mv='mv -i'
Alias rm='rm -i'
Alias which='alias |/usr/bin/which - tty - only - read - alias - show - dot - show - tilde'

To delete an alias: unalias alias name

Ln create soft hard link
Hard links
A file with a number of different file name
The command format: ln the source file... Link files
/root @ rhel1 ~ # ln a1 a1. Hard
/root @ rhel1 ~ # ll
Total 449772
Rw - r - r -. 2 root root 0 Feb 27 23:05 a1
Rw - r - r -. 2 root root 0 Feb 27 23:05 a1. Hard

Soft links
Symbolic links, on the surface like a hard link
Document type permission must be LRWXRWXRWX
The command format: ln -s source file... Link files

Supplement: the comparison of hard and soft links
Soft links: point to the original file path, also known as the symbolic link
Hard links that point to the original file corresponding data storage location
Can't build a hard link for the directory file
Hard links with the original documents I must be in the same partition (file system),
The cat and tac
The cat command
Used to show the entire contents of the file
Format: the cat - n filename
- n: shows the line number
Tac command
From the last line shows the entire contents of the file, backwards without the -n option

More order, less
More displays the file content used in full screen mode page (see the last line automatic exit)
Interactive operation method:

Press Enter to down line by line roll
Press the space key to scroll down the screen, press the b key turned up a screen
According to q to exit the
More less the same as the more ordered, but extended function (see the last line does not automatically exit)
Interactive operation method

Is similar with more orders, but individual operation will be a little discrepancy
[page down] [page up] over next page
The head and tail commands
Head for viewing the beginning part of the file (the default is 10 lines)
Format: the head - n filename

Tail is used to view the file at the end of a few content (the default is 10 lines)
Format:
Tail - n filename
End of tail -f filename (dynamic view=tailf)

Supplement:
The tail command advanced usage:
Format: tial - n digital file name
A + (plus), digital: before beginning from a file specified unit number began to output; Before digital - (minus), since the end of the file specified unit number output; No + or -, begin from the end of the file specified unit number output,
For example:
Tail - n + 3/etc/passwd starting from the third line shows the
Tail - n - 3/etc/passwd display the last three lines
The head - n - 3/etc/passwd does not display the last three lines
The head - n + 3/etc/passwd display the first three rows

Which command
Used to find the executable file and display the location of the
-- -- -- -- -- -- -- -- the search scope by the PATH environment variable specifies
Format: which command or program name


Whereis the command
Purpose: to find the file path, the file with the help of the file path, principle and which is similar to
Format: whereis command or program name


The locate command
Format: locate filename
According to the daily update database (/var/lib/mlocate) lookup, speed block
Can't find my new file but will find a file has been deleted
Manually update the database updatedb

The find command
Purpose: to find the file or directory
Format: find [search scope] [search conditions] [action]
Commonly used search condition
- name: by file name lookup
- size: according to the file size for
- user: according to the file owner find
- type: according to the file type to find
- perm: according to the file permissions for
- mtime: change the time according to the document search
-newer: update the lookup than a file

Format 1: find [search scope] [search conditions] [action]
Special search condition

- o: logic or, as long as there is a meet the conditions of given, looking for conditions even met

Non - not: logic, available in the command "!" Said the operator said find not satisfy the conditions of given file

Is the system default, - a: logic and,, don't add, said only when the conditions are met, the search for conditions to be met,

Example:

/root @ rhel1 ~ # find/boot - size + 1024 k - o - the name "called *
"The/boot/initramfs - 2.6.32-642. El6. X86_64. Img
The/boot/called - 2.6.32-642. El6. X86_64
The/boot/System. The map - 2.6.32-642. El6. X86_64
The/boot/initrd - 2.6.32-642. The el6. X86_64kdump. Img

Format 2: find/usr mtime +/- digital
Digital: before a + (plus), is greater than the number of days; Before digital - (minus), less than the number of days; No + or -, equal to the number of days,
For example:
The find/usr - mtime 4 said that day
4 days agoThe find/usr - mtime - 4 said 4 days
The find/usr - mtime + 4 said 4 days ago

Format 3: find [search scope] [search conditions] [action]
Common actions
- the exec: will find search results to behind the exec command execution
- ok: more - exec action a confirmation

Example:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related