File and Directory Management
File management is the creation, deletion, query, movement of files or directories, MKDIR/RM/MV
File query is the focus, using Find to query; Find's parameters are rich and very powerful;
Viewing the contents of a file is a big topic, the processing of text has too many tools for us to use, in this chapter just point to stop, there will be a special chapter on the text processing tools;
Sometimes, you need to create an alias for the file, we need to use LN, using this alias and using the original file is the same effect;
Create and delete
Created: mkdir
Delete: RM Delete non-empty directory: RM-RF file directory
Delete Log
$RM *log
Equivalent: $find./-name "*log"-exec rm {} \;
View the number of files in the current directory
$find./| Wc-l
Mobile: MV
Replication: CP Copy directory: Cp-r
Eg: $CP-R Source_dir Dest_dir
Directory switching
Locate File/directory location: CD
Switch to the previous working directory: CD-
Switch to home directory: CD or CD ~
$pwd
Show current Path
$CD Path
Change the current working path to path
List Catalog Items
Displays the file under the current directory LS
Sort by time, display catalog items as a list LS-LRT
The frequency of this command is so high that we need to create a shortcut command for it:
To set the command alias in. BASHRC:
Alias lsl= ' LS-LRT '
Alias lm= ' Ls-al|more '
In this way, the files in the directory can be displayed by using LSL, sorted by the modified time, and displayed in a list;
Note: the. BASHRC is stored under/home/your username/folder, as hidden files, and can be viewed using ls-a;
Find directories and Files Find/locate
To search for a file or directory:
$find./-name "Core" | Xargs file
Find the obj file in the destination folder:
$find./-name '. O '
Recursively delete all. o files from the current directory and subdirectories:
$find./-name "*.O"-exec rm {} \;
Find is real-time lookup, if you need a faster query, you can try to locate;locate the file system to establish an index database, if there is a file update, you need to perform regular update command to update the index library;
$locate string
Find a path that contains a string
$updatedb
Unlike find, locate is not a real-time lookup. You need to update the database to get the latest file index information.
View File Contents
View files: Cat vi head Tail more
$cat-N: Display line numbers at the same time
$ls-al |more: one page and one page display list contents;
$head-10 * *: see only the first 10 lines
$head-1 filename Displays the first line of the file
$tail-5 filename Displays the fifth line of the file
$diff File1 File2 See the differences between two files
$tail-F crawler.log Dynamic display text up-to-date information
Find File Contents
Egrep ' 03.1\/co\/ae ' tsf_stat_111130.log.012
Egrep ' a_lsha777:c ' tsf_stat_111130.log.035 > Co.out2
Co.out35:egrep ' a_lsha777:c ' tsf_stat_111130.log.035 > Co.out35
File and Directory Permissions modification
Chown: Changing the owner of a file
chmod: Change file read, write, execute and other properties
Recursive subdirectory modification: chown-r tuxapp source/
Add script executable permissions: chmod a+x myscript
Add aliases to files
Create a symbolic link/hard link:
ln cc Ccagain: Hard connect; Delete One, will still be found;
ln-s cc Ccto: Symbolic link (soft link); Delete source, another cannot be used; (later a ccto is a new file)
Pipelines and redirects
Batch command Connection execution:
concatenation: Using semicolons;
Before succeeding, execute the following one, otherwise, do not execute:&&
Previous failure, then next execution: | |
eg
Ls/proc && echo suss! | | Echo failed.
Ability to prompt for success or failure of name execution;
The same effect as above is:
if Ls/proc; then Echo suss; else echo fail; Fi
Redirect:
LS proc/. C > List > &l outputs the result to the list, outputting the error to the end of the same file;
The equivalent is: LS proc/. C &> List
LS list1 list2: Multiple files can be listed at the same time;
Empty files::> a.txt
Redirect: Best text: Echo AA >> A.txt
Setting environment variables
When you start your account, it automatically executes the file as. Profile, which allows you to set your own environment variables.
The installed software path generally needs to be added to the path:
Path= $APPDIR:/opt/app/soft/bin: $PATH:/usr/local/bin: $TUXDIR/bin: $ORACLE _home/bin;export PATH
Bash Quick Input or delete
Shortcut keys:
Ctl-u removes all characters from the cursor to the beginning of the line, and, under certain settings, deletes the full row
Ctl-w Delete the character between the current cursor and the nearest space in front of it
ctl-h Backspace, delete the character in front of the cursor
Ctl-r: Matches the closest file, then outputs
Comprehensive application
Cat-v Record.log | grep AAA |grep-v BBB |wc-l
Find the total number of records in Record.log that contain AAA but do not contain BBB
Summarize
File management, directory creation, deletion, query, management: mkdir RM MV
Querying and Retrieving files: Find locate
View file contents: Cat VI tail more
Piping and redirection:; | && >
Posted by: Big CC | 26may,2014
Blog: blog.me115.com
Weibo: Sina Weibo