Linux Common basic commands

Source: Internet
Author: User
Tags create directory syslog

Linux Basic commands


-----------------Catalog Section-------------------


"PWD" Displays the absolute directory where you are currently located


"CD" Switch directory
CD-Show previous working directory
CD ~ Show current user's home directory
Cd. Show current directory

Cd.. Displays the top level directory of the current directory

[[email protected] ~]# cd/usr/[[email protected] usr]# lsbin  etc  Games  include  Lib  libexec  Local  my  sbin  share  src  tmp[[email protected] usr]# CD-/root[[email protected] ~]# CD. [ [Email protected] ~]# CD. [Email protected]/]# CD ~[[email protected] ~]# pwd/root

"LS" displays the current directory file list


Ls-a Show all files (including hidden files)
Ls-l display all files as a list in the same way as the LL command
Ls-t display files in chronological order
Ls-m horizontal output file name and split with ', '
Ls-r recursively displays the current directory and its subdirectories
Ls-s displaying files in a file size order

[email protected] ~]# ls-r.:anaconda-ks.cfg install.log.syslog lnmp-install.loginstall.log lnmp                Vhost.sh[[email protected] ~]# ls-a.               . bash_logout. gconf. Lesshst vhost.sh. . bash_profile. GCONFD lnmp. viminfoanaconda-ks.cfg. BASHRC Install.log Lnmp-inst             All.log.bash_history. CSHRC install.log.syslog. tcshrc[[email protected] ~]# ls-tlnmp-install.log LNMP install.logvhost.sh anaconda-ks.cfg install.log.syslog[[email protected] ~]# ls-l-rw-------. 1 root root 1383 7 05:25 anaconda-ks.cfg-rw-r--r--. 1 root root 43838 7 05:25 install.log-rw-r--r--. 1 root root 10033 7 05:23 install.log.syslog-rwxr-xr-x. 1 root root 1930 7 Lnmp-rw-r--r--. 1 root root 1810073 7 08:01 lnmp-install.log-rwxr-xr-x. 1 root root 5307 7 08:01 vhost.sh[[email protected] ~]# ls-manaconda-ks.cfg, install. log, Install.log.syslog, LNMP, lnmp-install.log,vhost.sh[[email protected] ~]# ls-sl1848-rw-r--r--. 1 root root 1810073 7 08:01 lnmp-install.log-rw-r--r--. 1 root root 43838 7 05:25 install.log-rw-r--r--. 1 root root 10033 7 05:23 install.log.syslog-rwxr-xr-x. 1 root root 5307 7 08:01 vhost.sh-rwxr-xr-x. 1 root root 1930 7 lnmp-rw-------. 1 root root 1383 7 05:25 anaconda-ks.cfg

"Tree" prints the directory structure in the directory tree


"MkDir" Create a Directory

mkdir./AAA Create an AAA directory in the current directory (only one level of directory can be created)
Mkdir-p./AAA/BBB/CCC Creating multiple directories (you can create multi-tiered catalogs)

[[email protected] admin]# mkdir/aaa[[email protected] admin]# rm/aaarm: Cannot delete "/aaa": is a directory [[email protected] admin]# RM  -f/aaarm: Cannot delete "/aaa": is a directory [[email protected] admin]# rm-rf/aaa[[email protected] admin]# mkdir./aaa[[email protected] admin]# lsaaa  [[email protected] admin]# mkdir./aaa/bbb/cccmkdir: Unable to create directory "./AAA/BBB/CCC": No file or directory [email Protected] admin]# mkdir-p/aaa/bbb/ccc[[email protected] admin]# lsaaa  [[email protected] admin]# tree.├──aaa│└ ──bbb│     └──CCC

"RmDir" Delete directory

RmDir can only delete an empty directory

[[email protected] admin]# rmdir./aaa  rmdir: Delete "./aaa" Failure: Directory non-empty    [[email protected] admin]# rmdir./aaa/bbb/ccc
   [[email protected] admin]# tree  .  ├──AAA  │└──bbb  RM can also delete the directory (you can force the deletion of non-empty directories please use caution)  [[email protected] admin]# RM/AAA  RM: Cannot delete "/aaa": is a directory 
   [[email protected] admin]# rm-f/aaa  rm: Cannot delete "/aaa": is a directory  [[email protected] admin]# rm-rf/aaa  [[Emai L Protected] admin]#

------------------file Section-------------------------


"Touch" Create a File command
Touch file name
touch-d YYYYMMDD filename Modified file creation time

[[email protected] aaa]# Lsbbb[[email protected] aaa]# touch A.txt[[email protected] aaa]# ll total dosage 4-rw-r--r--1 root root
   0 December 21:32 a.txtdrwxr-xr-x 2 root root 4096 December 21:21 bbb[[email protected] aaa]# touch-d 20150102 a.txt[[email Protected] aaa]# ll total dosage 4-rw-r--r--1 root root    0 January   2 a.txtdrwxr-xr-x 2 root root 4096 December 21:21 BBB

"CP" Copy File command
CP Source File Destination file
Cp-r source file Destination file//copy entire source file

[[email protected] aaa]# cp-r.//var/c[[email protected] c]# Cd/var/c[[email protected] c]# ll total dosage 8-rw-r--r--1 root ro OT    0 December 21:42 a.txtdrwxr-xr-x 2 root root 4096 December 21:42 BBB

Of course we can also use./* to represent all files in the current directory
A copy can also be


"MV" To move files or rename files
MV Source File Destination file


"Cat" view files viewed from the first line
"TAC" starts at the last line and looks up


"File" shows the type of files
File File name

[[Email protected] aaa]# file a.txt a.txt:ascii text

"More" page-by-page view of file contents
More file names
/String
? string
Can be used to search for a specified string

B or ctrl + B page UP
Blank space or carriage return page down


Q exit


"Less" with more
N PAGE Down
N PAGE Up
Q exit


"Head" displays the first few lines of the file's contents
Head-n Numeric file name
"Tail" displays the tail lines of the file contents
Tail-n Numeric file name


"Man" Handbook using the Find command

-------------------System Section----------------------
"Init" system command
Parameters:
Init 0 shutdown
Init 6 Restart


"Shutdown" shutdown/warning
Shutdown-t seconds after a few seconds auto power off
Shutdown-r restart
Shutdown-h immediately shut down the machine


Alias-------------------Command----------------------
"Alias" This needs to modify the configuration file
First: Switch to the user's home directory Cat ~
Second: Edit the file. Bash Vi. bash_profile
Again: Add the command you want to modify in the file and its alias
Alias rm = '/bin/rm-f '
Save and Exit: ESC +!WQ
Source a bit: source. bash_profile


Principle: The system will load the. bash_profile file automatically when the user logs on.
The source is actually loading and executing the file again
Unlike shell scripts that are executed directly with the./xx.sh.
He works globally, and the shell is only valid within the associated directory.


-------------------find the underlying command---------------------
"Find"
Find by Time
-atime time to change a file while reading or executing access is equivalent to Lu-l
-mtime when a file is written, make time is equivalent to Ls-l
-ctime write file, change permissions, owner, file link equivalent to Lc-l
or set Lnode time stamp and set the change time for Create


Commands for general use:
Find./-mtime n finds files modified within n days by time
-mtime +n N days ago does not contain files modified by Nth days
-mtime-n n days after nth days


such as-mtime +3 today is 0103 so that is to find all the modified files 1231 and before
-mtime-3 today is 0103 so it's looking for files that have been modified in 0101-0103.


Find./-newer file1 files new to file File1


Find./-name filename contains filename file


[Special Function Command]
Find./-name filename-exec ls-l {} \;

[[email protected] ~]# find./-name lnmp-exec  ls-l "{}" \;-rwxr-xr-x. 1 root root 1930 November  7./lnmp

For example, we're going to remove the. conf files that we've found.
Find/-name "*.conf"-exec rm-rf {} \;


Like we're going to copy the files we found.
Find/-name "*.conf"-exec cp {}/home/my/\;


Rename the. txt file with the suffix name changed to. txtd
Find./-name "*.txt"-exec mv "{}" "{}d" \;


Explain:


The-exec parameter is followed by command, which terminates with a; for the end flag,
So the semicolon at the back of this command is indispensable,
Given the different meanings of semicolons in each system, the backslash is preceded by a backslash.


{} curly braces represent the file name found in the previous find.


History to view commands that have been executed historically
History View Historical Execution commands
History-c Empty History Execution commands


"Echo" Print
echo $PATH Print environment variable directory to: Split


grep Pipeline Crawl Command

-C outputs only the count of matching rows
-I is case insensitive (only for single-character)
-N Displays matching lines and line numbers
-S does not display an error message when it does not exist
-V Displays all lines that do not contain matching text
-L full Match line information


The following commands are generally not used independently but are used behind pipelines
Sort-r Reverse Sort
Cut-d ' delimiter '-F takes the first few fields separated by commas
Uniq-c count//typically used behind sort otherwise statistics may not be valid
Wc-l statistics occurrences of result rows

[email protected] ~]# LL | Cut-d '-f5-13 | Sort-s | Uniq-c      1       1   10033 November  7 05:23 install.log.syslog      1    1383 November  7 05:25 anaconda-ks.cfg      1 1810073 November  7 08:01 lnmp-install.log      1    1930 November  7 lnmp      1   43838 November  7 05:25 Install.log      1    5307 November  7 08:01 vhost.sh[[email protected] ~]# ll | cut-d "-f5-13 | sort-s | wc-l7














Linux Common basic 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.