Common Linux commands

Source: Internet
Author: User

Common Linux commands
Command [Option] [parameter]


------------------------ Positioning ------------------------
Cd webapps/-- locate webapps
Cd .. -- return to the parent directory
Cd--- return to the last directory
Cd -- return to the home directory


-- Display the complete path of the current file
Pwd
-- Clear screen
Ctrl + L


------------------------ Demonstration ------------------------
Ls -- display the file list
--- Display details
Ll-h (the file is displayed in kb)-a (show all files)-d (show non-Folder content in the current folder)
Eg: ll-h/data/www/


------------------------ Directory ------------------------
Mkdir test -- create a folder
Mkdir-p test/test2 -- recursively create a folder (-p indicates recursion)
Rmdir test -- delete a folder (it must be an empty folder)
-- Recursively delete a file (directory) Command (do not use-r to execute all files-f to force execution without prompting)
Rm-rf webRoot.zip
-- Copy the file to the Guidance directory (cut the mv)
Cp-rf linux.txt/data/backup
--- View all directories in the folder
Find-type d (all folders)
Find-type f (all files)


---------------------- File ------------------------
-- View File Content
Cat jdbc. properties
-- Make the file in editing mode
Vi database. propertie
-- Enable edit mode-> Save and exit (do not save and Exit)
I Esc: wq! (: Q !)


-- Replace the file (replace all 58.68.237.36 with 127.0.0.1)
Sed-I's/58.68.237.36/127.0.0.1/G' database. propertie
-- Screen scroll command
Ctrl + u: half screen at the beginning of the file
Ctrl + d: Flip the half screen to the end of the file


------------------------ Upload and download ------------------------
-- Upload (after the command is executed, a prompt is displayed to select a folder)
Rz-
-- Download the file (the file will be downloaded directly. The default directory can be viewed in Option-X/Y/Zmodem)
Sz
------------------------ Link command ------------------------
Ln adms. log/home/test/adms. log. hard -- hard link (similar to file copy)
Ln-s adms. log/home/test/adms. log. hard -- soft link (shortcut)


----------------------------- File query ----------------------------------
-- Database-like Lookup
-- Locate (database index search)
Eg: locate install. log
-- Updatedb (the index will not be created immediately for the newly created file database. You can execute this command to update it)


-- System Command Query
-- Whereis (system command query -- display file location and help document)
Eg: whereis ls/whatis ls/whoami
-- Which (display command alias)


-- Directory Search
-- Find (resource consumption of the entire directory will be retrieved)
(1) find/home-name adms. log -- exact match (case sensitive-inname not differentiated)
(2) find/home-name "adms. log *" -- match files starting with adms. log
(3) find/home-name "adms. lo [gm] *" -- match any character in brackets (only one character is allowed)
-- Search by Time
Find/var/log-mtime + 10 (+ 10 ten days ago, 10 days ago,-10 days ago)
-- Search by size
Find/home-size 25 k (+-indicates the range, 25 M -- find MB files with Case sensitivity)
Eg: find/home-size + 1 k-a-size-5 k (find files larger than 1 k and less than 3 k or use-o)


-- File search
-- Grep (retrieving files)
Grep "url" adms. log




----------------------------- HELP command ----------------------------------
Man passwd -- The First Command help document is displayed by default.
Man-f passwd -- View several help documents for release
Man 4 passwd -- view the fourth release
-- Query help documents containing keyword commands
Man-k passwd




----------------------------- Compression and decompression ----------------------------------
-- Zip
Zip log.txt.zip log.txt -- compress the file
Zip-r img.zip img -- compression directory
Unzip-o log.txt.zip/img.zip -- decompress the file/directory (the same file will be overwritten)
Unzip-d./img_new./img.zip (extract the file to the img_new directory in the current directory)
Unzip-v img.zip (view files under the compressed package file)
-- View the size of a non-compressed directory
Du-hs img
-- Extract the war package from the current directory
Jar-xvf game. war




-- Gzip
Gzip log.txt -- the source file disappears after the file is compressed
Gzip-r img -- only compresses the sub-files in the directory
Gunzip log.txt.gz/gzip-d log.txt.gz -- decompress the file


-- Bzip2 (only files can be compressed)
Bzip2 log.txt -- the source file disappears after the file is compressed
Bzip2-k log.txt -- the source file does not disappear after the file is compressed
Bunzip2 log.txt.bz2/bunzip2-d log.txt.bz2 -- decompress the file


-- Tar (packaging)
Tar-cvf img.tar img (-c Indicates retaining the source file-v indicates the compression process-f specifies the file name after compression)
Tar-xvf img.tar -- extract (-x)
Then compress the eg:
Gzip img.tar
Bzip2 img.tar


-- Tar direct compression
Tar-zcvf img.tar.gz img --compressed into tar.gz
Tar-jcvf img.tar.bz2 img --compressed into tar.bz2
Tar-zxvf img.tar.gz --decompress tar.gz
Tar-jxvf img.tar.bz2 --decompress tar.bz2


-- Compress to the specified directory (compress the name to write the absolute path)
Tar-zcvf/home/img.tar.gz img
-- Compress multiple files (to compress files, use spaces to separate them)
Tar-zcvf/home/img.tar.gz img1 img2
-- Extract to the specified directory (add-C and specify the directory -- C Capital)
Tar-zxvf img.tar.gz-C/tmp




----------------------------- Mount command ----------------------------------
-- Hanging on a CD (that is, the inserted CD can be viewed in the directory)
(1) create a mount point (used to the mnt directory)
Mkdir/mnt/cdrom
(2) hanging on a CD (/dev/sr0 is similar to a driver)
Mount/dev/sr0/mnt/chrom
(3) view the content of the CD
Cd/mnt/chrom --> ls
(4) run out and unmount (to exit the current directory or else unmount)
Umount/mnt/chrom


-- Mount a USB flash drive
(1) view the drive letter
Fdisk-l
(2) mount a USB flash drive
Mount-t vfat/dev/sdb1/mnt/usb
Note: 1. sdb1 is the drive letter name (will change) 2. vfat refers to fat32 (usually USB flash drive)
Note: Linux does not support NTFS files by default. Drivers must be installed and data cannot be written.


----------------------------- Shut down and restart ----------------------------------
Shutdown-r -- restart two and a half days in the morning
Ctrl + c -- interrupt the current command
Shutdown-r & -- restart two and a half days in the morning (put the command in the background without occupying the current Terminal)
Shutdown-h -- restart
Shutdown-c -- cancel the previous shutdown command


----------------------------- Other commands ----------------------------------
-- View the current system time
Date
-- Update the user password (you need to enter the original password)
Sudo passwd root
-- Switch users (www users cannot execute the restart command)
Su


-- Compile an executable script
Exe. sh
#! /Bin/bash -- this is required
Echo "ni hao! "
-- Grant executable permissions
Chmod 755 exe. sh
./Exe. sh -- you can run the command set
-- Query login user information
W
-- Query System logon restart time/Last Logon Time
Last/lastlog

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.