Common Unix Commands

Source: Internet
Author: User

Summary of Common Unix commands...

Special key combinations:

CTRL + H delete a character from the command line.

CTRL + u delete a row from the command line.

Press Ctrl + D to exit the command and tell the shell that the input is complete.

Ls

Ls-l lists the file information in the directory in detail, sorted by file name.

Ls-T lists the file information in the directory, sorted by the modification date.

Ls-LRT lists the file information in the directory and sorts it by the modification date in reverse order.

Ls-lH lists the file information in the directory, sorted by file name, and the file size information is displayed in K, G format.

Ls-ls lists the file information in the directory and sorts it by file size (available in Linux and unavailable in Unix-SunOS ).

Ls-r recursively lists information about objects in subfolders in a directory.

Ls | WC-W counts the number of files in the directory.

CD

CD $ home = CD enter the user's default directory.

CD .. enter the upper-level directory of the current directory.

Mkdir

Mkdir T1 T2 creates t1 and t2 directories in the current directory at a time.

Mkdir-P T3/T4: Create T3 in the current directory at a time (if T3 does not exist) and create a T4 directory in T3.

Mkdir-P/home/test/{old, new, DIST, bugs} creates four directories at a time.

Rmdir can only delete empty directories

Rmdir-P T3/T4 = rmdir T3/T4: Delete the T4 directory. The T3 directory also contains [Rm-r T3: delete T3 and Its subdirectories, and delete all sub-files].

File Viewing command: CAT, more, less, Head, less:

Cat displays all the content of the file at a time. If the content of the file exceeds one screen, only the content of the last screen is displayed. Usually cat is used to merge several files into one file, generally, you do not need to view files.

Cat file1 file2> File

More can control how many rows are displayed by page.

If the less page is displayed, you can use commands to perform search and other functions.

Head: displays the number of rows in the header and the number of rows in the tail end. Tail-f filename dynamically prints the end information.

DU/etc | sort-Nr | less: view the size of each file in the directory and display it in ascending order.

Find-size + 100 m-print: print the files whose current directory is greater than M.

Find-type F-exec grep-Q-s XYZ {}\;-print find the file containing XYZ characters in the current directory.

Extract

. Tar
Unpack: Tar xvf filename.tar
Package: Tar CVF filename.tar dirname
(Note: tar is packed, not compressed !)
. GZ
Decompress 1: gunzip filename.gz
Decompress 2: gzip-D filename.gz
Compression: gzip filename
.Tar.gz and. tgz
Decompress: Tar zxvf filename.tar.gz
Compression: Tar zcvf filename.tar.gz dirname

Tar.bz2
Decompress: tar-jxvf filename.tar.bz2

. Zip
Decompress: unzip filename.zip
Compression: Zip filename.zip dirname

2> & 1 & explanation
1 is stdout, 2 is stderr,> is redirection. & 1 indicates the stdout (Out. File) to be redirected.
Command> out. File 2> & 1 &
Command> out. File redirects the command output to the out. File file. That is, the output content is not printed to the screen, but output to the out. File file.
2> & 1 redirects a standard error to the standard output. The standard output has been redirected to the out. File file, which outputs a standard error to the out. File file.
The last & is to run the command in the background.
You can use
Ls 2> 1 test. The system does not report the error of NO 2 files, but outputs an empty file 1;
Ls XXX 2> 1 test, no errors in the xxx file are output to 1;
Ls XXX 2> & 1 test. The file 1 is not generated, but the error is returned to the standard output;
Ls XXX> out.txt 2> & 1, which can be changed to LS xxx 1> out.txt 2> & 1; the redirection symbol> timeout is a error and the output is transmitted to out.txt.

Command
> Out. File 2> & 1 =
Command> & out. File

In bash, use soruce and. execute shell script to indicate that the script does not generate sub-processes. For example, there is a testsh script in the current directory. Use source. /testsh and .. when/testsh is executed, testsh and the current bash are in the same process.
./Testsh, testsh becomes the so-called sub-shell.

Echo $ shell: view the default shell of the current user
Echo $0 view the shell currently in use by the user

Lsof | grep xxfile check whether there are any processes that open xxfile

: W! Sudo tee %
When you modify the configuration file for half a day in VI and find that you do not have the write permission, it is even more frustrating than this. In this case, you need this command.

View OS information:

Lsb_release-
CAT/etc/issue
CAT/proc/version
Uname-

After netconfig, use/etc/rc. d/init. d/network restart to make the modification take effect.
Ifconfig takes effect immediately. The restart setting will be lost.

CTRL + C to terminate
CTRL + D signals EOF
CTRL + z suppends a program

Umount appears, device is busy solves umount-l

Mount-o loop, iocharset = gb2312/DIR/xxx. ISO/mnt/xxx mount an ISO file and use

Man ASCII viewing ASCII code table

Centos install software: Yum install xxxx

Ubuntu install software: wget-C http://downloads.openfabrics.org/qperf/qperf-0.4.8.tar.gz
Apt-Get install Autoconf

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.