Categories
Linux

linux bash shell in the file management summary

============= bash shell to manage files ==============
create、copy、delete、mobile、View、edit、compression、Competence、Find

one、Features Linux directory structure
Windows: To organize a plurality of documents C:\ D:\ E:\
Linux: In the manner of a single organized file /

/Directory Structure:
[root @ gaolei ~]# ls /
bin dev lib media net root srv usr
boot etc lib64 misc opt sbin sys var
cgroup home lost+found mnt proc selinux tmp

Bin normal users command / bin / ls, /bin/date
dev device file / dev / sda,/dev/tty1,dev/tty2,/dev/pts/1
ordinary home user's home directory area
lost + found orphan file
proc virtual file system,Reflected kernel,Or process information in real-time status
sbin administrator command
usr file system,The equivalent of C:\Windows
Start boot store related documents,For example kernel,grub(Bootloader)
etc Profile
lib library Glibc
lib64 library Glibc

== equipment (mainly refers to the storage device) mount directory ==
The default media mobile device mount point
mnt manually mount the device mount point
misc automount mount process
net automount mount process

root root user's HOME
tmp temporary files(The main program is a temporary file created)
var file is stored in some changes,Such as database,Journal,mail….
Such as:
mysql: /var / lib / mysql
vsftpd: /was / ftp
mail: /var / spool / mail
cron: /var / spool / cron
log: /var / log

two、path
Absolute path: Beginning with / (root) path cd / home cd ~ alice
relative path: Relative to the current directory cd ..

. Linked to the current directory
.. Links to the parent directory
- the current user's home directory
======

three、Document Management
A file management:
cd change directory
cd absolute path cd / home / alice cd ~ alice
relative path cd cd ..
=======================================================
cd dedicated:
cd – Return to the last directory
cd straight home
=======================================================

The file management:Create / copy / move / delete
== Creating
File touch
# no touch file1.txt // create,There is Modified
# touch /home/file10.txt
# touch -t 1501010001 2018.rmvb
Time to modify the file syntax:
-t STAMP
use [[CC]YY]MMDDhhmm[.ss] instead of current time

Mkdir directory
# mkdir dir1
# mkdir /home/dir2 /home/dir3
# mkdir /home/{dir4, dir5}
# mkdir -v /home/{dir6, dir7}
mkdir: We have created a directory "/ home / dir6"
mkdir: We have created a directory "/ home / dir7"
# mkdir -p / home / dir8 / 111/222 // include the creation of their parents

== cp Copy
Usage: cp [OPTION]… [-T] SOURCE DEST
or: cp [OPTION]… SOURCE… DIRECTORY
or: cp [OPTION]… -t DIRECTORY SOURCE…
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
cp source target

[root@yangs ~]# cp -v install.log /home/dir1
[root@yangs ~]# cp -v install.log /home/dir1/yang.txt
[root@yangs ~]# cp -r uplayer/ /home/dir1
[root@yangs ~]# cp install.log /home/dir2
[root@yangs ~]# cp my.jpg !$
cp my.jpg /home/dir2
[root@yangs ~]# cp -r /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/passwd /etc/grub.conf /etc/hosts .
[root@yangs ~]# \cp -r /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/hosts /etc/passwd /etc/shadow .

Extended usage:
[root@yangs ~]# cp -rfv /etc/hosts{,.old}
“/etc/hosts” -> “/etc/hosts.old”
[root@yangs ~]# cp -rvf /etc/sysconfig/network-scripts/ifcfg-eth0{,.old}
“/etc/sysconfig/network-scripts/ifcfg-eth0” -> “/etc/sysconfig/network-scripts/i

========================================================
tips:root user cp (There is a default alias alias cp = 'cp -i')
1. /bin/cp -rf my.jpg /home/dir2
2. # unalias cp
# cp -rf my.jpg /home/dir2
3. # \cp -rf install.log /home/dir2
========================================================

== move mv
mv source target
# mv file2 / home / dir3 file2 to move to / home / dir3 Lane
# mv file4 file5 file4 will rename file5, the current position in the movement to rename

== delete rm
Example:Delete / home / dir1
# cd /home
# rm -rf dir1
-r recursive
-f force mandatory
-v detailed process

The file management:View the file contents
== text file (cat less more head tail grep)
/etc/hosts
/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/passwd
/etc/shadow
/etc/group
/etc/grub.conf
/etc/resolv.conf
/var / log / messages // master system log file

cat
-n display line number
-A control characters (line feed) Linux $ Windows ^M$
========================================================
Expand knowledge:
dos2unix to convert the file format into Windows Unix format
unix2dos convert Unix file format into Windows format
E.g
# unix2dos file1
# dos2unix file2
========================================================

less more head tail
# head /etc/passwd
# head -2 /etc/passwd
# tail /etc/passwd
# tail -1 /etc/passwd
# tail -f / var / log / messages // - f tail dynamic view files
# logger yangsheng

grep filter for file contents
# grep ‘root’ /etc/passwd
# grep –color ‘root’ /etc/passwd
# grep –color ‘^root’ /etc/passwd
# grep –color ‘bash$’ /etc/passwd

== binary file (strings grep)
# strings / bin / ls

The file management:Modify the contents of the file
we ===> vim file editor
# vim /boot/grub/grub.conf
# vim /etc/sysconfig/network-scripts/ifcfg-eth0

Command Mode:
a. Position the cursor
hjkl
0 $
gg G
3G into the third row
/string(n N can be circular) To quickly locate a row

b. Text editor (a small amount)
y copy yy 3yy ygg yG (In units)
Remove dd 3dd dgg dG d (In units)
p Paste
x delete character under the cursor
Remove from D point to the end of line
u withdrawal
^ R redo heavy 做
r can be used to modify a character

c. Proceed to another mode
a enter insert mode
i enter insert mode
o enter insert mode
A enter insert mode

: Enter the last line mode
Visual block mode enters ^ v
Into the replacement mode R

Insert mode:
^p

Line mode:
a. Save and exit
:10 Enter on line 10
:w Storage
:q quit
:wq to save and exit
:in! Force Save
:q! Exit without saving
:wq! Forced to save and exit
😡 Save and Exit

b. Find and Replace
:Range s / old / new / Options
:1,5 s / Note / yyy / Note 1-5 from the line was replaced yyy
:5,$ s / Note / yyy / $ last line
:1,$ s/to/uplooking/g = :% s / to / uplooking / g% g represents a global-full
:4,9 s / ^ # // 4-9 rows beginning to replace empty #
:% s # / dev / sda # / var / ccc # g
:,8 s / to / uplooking / from the current line to line 8

c. Reads the file / write file
:Save as aaa.txt w /aaa.txt
:1,3 w/2.txt
:r /etc/hosts

d. Set the environment
Temporary settings:
:set nu set the line number
:set ic is not case sensitive
:set nonu unset line number
:set noic

Permanent environment:
/etc / vimrc affect all users of the system
~ Root / .vimrc affect one user
# vim ~/.vimrc
set ic
not set

# vim -O / etc / hosts /etc/grub.conf ^ w switch twice
# vimdiff grub.conf /etc/grub.conf comparison document,^ W by two handovers
# vim -p /etc/hosts /etc/grub.conf ^PgUp, ^PgDn

Original article written by Gerber drop-off:R0uter's Blog » linux bash shell in the file management summary

Reproduced Please keep the source and description link:https://www.logcg.com/archives/500.html

Leave a Reply

Your email address will not be published. Required fields are marked *