Ubuntu Common Commands

Source: Internet
Author: User
Tags diff echo command parent directory touch command

1. get Ubuntu version number :/etc/issue or Lsb_release-a

2. view Ubuntu system bits : Uname-ar or getconf long_bit

3. View the processor architecture of the Ubuntu machine as a result of i686 or X86_64:arch or uname-m

4. display the current directory contents (catalog list), (if sorted by file change time order, ls-lt available): LS

5. display the files in the current directory details , including read and write permissions, file size, file generation date, etc. (if you want to follow the change in chronological order, you need to add-t parameter, ll-t or Ll-t |tac, the latter is the most recent modification of the time of the last): LL

6. change the current working directory location , (if you enter the system root, you can directly use the CD/): CD Directory_name, if the folder has a space, you need to enclose the quotation marks, such as enter the directory named a B, the directory is: cd "a B"

7. delete the specified file in the current directory , such as delete. xxx all files, (for the linked file, just delete the link, the original file is unchanged; If you do not use the-r option, RM does not delete the directory, and if you want to delete the confirmation before you remove it, you can use the-I option, such as Rm-i XXX): RM *.xxx

8. Delete Empty directory , must be empty before a directory is deleted, delete a directory must also have write permission to the parent directory: rmdir xxx

9. Move the file (if the file Xx.yy is moved to the directory TT, MV Xx.yy TT) or rename the file (MV xx.yy aa.bb If you change the filename xx.yy to AA.BB): MV source file or directory Destination file or directory

Copy File (can have multiple files at the same time) or directory to the specified directory (if directory AA is copied to the BB directory: cp-a AA bb): CP source file or source directory destination directory

Create a new directory that requires the user who created the directory to have write permissions in the current directory, and that the specified directory name cannot be a directory that is already in the current directory, (if you create a directory with permissions of 777, you can mkdir-m 777 filename): mkdir filen Ame

See detailed instructions for a directive , such as view RM instructions: Man RM

Create a static library , such as using all. o files in the current directory to create a libxx.a static library: Ar-r libxx.a *.O

Create a dynamic library , such as using all. o files in the current directory to create a libxx.so dynamic library (if two. cpp files in different directories directly generate a dynamic library: gcc-shared/home/spring/gdbtest/src/ Add/add.cpp/home/spring/gdbtest/src/subtract/subtract.cpp-o libtest.so) (if b1.a,b2 from the static library, A directly generate dynamic library b.so, the corresponding command is: GCC-SHARED-FPIC-WL,--whole-archive b1.a b2.a-wl,--no-whole-archive-o b.so): Gcc-shared–o Lib Xx.so *.O

See the current path (full path): pwd

The command to prompt permission execution , if you are not the root user, is sometimes not allowed when performing some commands, you can add Sudo:sudo to the command at this time.

See if the static library contains a function , such as viewing the XX.A static library for FUN1 functions (you can also view all the functions included in a library, such as NM xx.a >fun.txt): NM xx.a | grep fun1

See if a dynamic library contains a function , such as seeing if there are fun2 functions in the yy.so dynamic library (you can also view all the functions included in a library, such as NM yy.so > Info.txt): NM yy.so | grep fun2

If only defined symbols are exported, add the "-d" option, such as nm-d yy.so | grep fun2

View Cpuinfo Related information : Cat/proc/cpuinfo

Display System date : Date

The CAL command is used to view the Gregorian calendar and can be viewed for a specified year, such as Cal-y 2013, or to view the current month, directly with a CAL, without any parameters.

Close the system (if not root, add sudo before shutdown): Shutdown-h now

Restart the system (if not root, add sudo before shutdown): Shutdown-r now

The shared directory command with Windows , such as the shared directory Test (http://download.csdn.net/detail/jiaoxiaogu/7309181): cd/mnt/hgfs/test

create a soft connection to a file or directory (when we need to use the same file in a different directory, we don't need to put a file that must be the same in every required directory, we just put the file in a fixed directory, You can then use the LN command to link it to other directories (link) so that it does not have to repeat the disk space usage. Format, ln-s source file destination file. The file keeps changing synchronously. Directories can only create soft links, directory creation links must use absolute path, in the link destination directory to modify the file will be in the source file directory synchronization changes. Create a new directory for the source directory/home/spring/aa/usr/local/aa:ln-s/HOME/SPRING/AA/USR/LOCAL/AA

Change the date and time of the file or directory , including access time and change time (if there are two files A.B,C.E, change the date of the C.E file to a.b date, Touch a.b C.E), or create a new file that does not exist ( If the existing aa.x file is newly built with a bb.y file (the Bb.y file does not exist originally) and remains the same as the contents of the aa.x file, creating the modified time, Touch aa.x bb.y): Touch source filename Destination file name

Each file has a timestamp, which includes access time and modification time, while the touch command is primarily used to modify the file's access time and modification time. If you change the timestamp of the file a.txt to the current time, execute: $ touch a.txt

Display file contents (or Cat aa.txt if the file contents of Aa.txt are displayed), or connect several files to display: Cat filename

The contents of the output file are automatically added line number : NL filename

to display the contents of the file in a page-by-page manner , press the SPACEBAR to display the next page; press the B key to display the page back; press the Q key to exit More:more filename

page shows the contents of the file , similar to more, but more powerful than more; press the Q key to exit less; If you search for a string xxx in a file, you can use/xxx to do it; Displays the line number of each line by adding the-n parameter: less parameter filename

to display the beginning of a file : Head filename

to display the end content of a file : tail filename

check whether a system command exists or view the location of an executable file, if you look for the location of the LS command, which LS returns/BIN/LS, and if the command (or the execution file) is not found, there will be no result returned: which COMMANDN Ame

Find all files with the file name suffix txt in the current directory (Find/-name "*.txt" if found from the root of the system, or find ~-name "*.txt" if found from your $home directory; in the/etc directory  Find, Find/etc-name "*.txt"; to find the file name in the current directory starting with a lowercase letter, and finally 4 to 9 plus. Log to end the file, then find.  –name "[A-z]*[4-9].log"): Find. -name "*.txt"

in the current directory, locate all files within this directory that contain the specified keyword "ab", then execute: $ find. -type f-print-exec grep ab {} \;

The

34.       chmod command is used to change access rights for Linux system files or directories . Each file and directory in a Linux system has access permissions, which are used to determine who can access and manipulate files and directories. Access to a file or directory is divided into three types: read-only, write-only, and executable. There are three different types of users who can access files or directories, the file owner (typically the creator of the file), the same group of users, and other users. Each file or directory has three groups of access rights, each group is represented by three bits, respectively, the read, write, and execute permissions of the file owner, the read, write, and execute permissions of the user belonging to the primary group, and the read, write, and execute permissions of other users in the system. When you use the ls -l command to display the details of a file or directory, the leftmost column is the file's access rights. The first column has 10 locations, and the first character specifies the file type. In the usual sense, a directory is also a file. If the first character is a horizontal line, it represents a non-directory file. If it is D, the representation is a directory. From the second character to the tenth, a total of 9 characters, a group of 3 characters, respectively, representing 3 groups of users of the file or directory permissions. The permission character is represented by a horizontal line for an empty license, R for Read only, W for write, and X for executable. After determining the access permissions for a file, the user can use the chmod command to reset different access rights. Permission code: r: Read permission, denoted by number 4, W: Write permission, denoted by number 2, x: Execute permission, denoted by number 1;-: delete permission, denoted by number 0; s: special permission. :chmod -r 777  Test

If you add a readable writable executable permission to all files in the catalog test and its subdirectories

35. You can compress, decompress, package, unpack, and so on with the tar command. Packaging refers to a large number of files or directories into a total file, compression is a large file through some compression algorithm into a small file. A package that is called with a tar program is often referred to as a tar package, and the tar package file commands usually end in. Tar. After the tar package is generated, you can use other programs to compress it. Common parameters:-C: To create a new compressed file;-X: Extract files from compressed files;-Z: Support gzip unzip files;-j: Support bzip2 extract files;-Z: Support compress extract files;-V: Displays the operation process;-F: Specifies the compressed file. For example, there is a directory test1, packaging it is: Tar cvf test1.tar test1, if it is packaged and compressed in gzip: tar zcvf est1.tar.gz test1; If unpacking or decompression, then the corresponding CVF and ZCVF replaced with XVF and ZXVF, such as test2.tar.gz decompression, then: Tar xvf est2.tar.gz, the current directory will generate a test2 file.

To view the size of the file or directory disk used , you can use the Du command, such as displaying the test directory size, after locating the terminal to the test directory, enter: Du-s

A. diff can compare a single file or directory content . If you specify that the comparison is a file, it is only valid if the input is a text file. Compare the similarities and differences of text files in a row-by-line manner. If you specify a table of contents, the diff command compares a text file with the same name in two directories. Lists the different binaries, common subdirectories, and files that appear only in one directory. such as comparing 1.txt and 2.txt two text files, can be: Diff-c 1.txt 2.txt, will be the content of different places before using "!" Marked out.

The. grep command is a powerful text Search tool . If looking for Android keywords from the test.txt file, then: Grep-n ' Android ' Test.txt. You can also find keywords from multiple files at the same time, such as: Grep-n ' Android ' Test1.txt test2.txt

If you want all files in the current directory to look for "AB" Strings: $ GREP-RN "AB" *

The WC command is used to count the number of lines, words, and bytes in the specified file and display the results of the statistics output. such as: WC Test.txt, the output is 8 9 test.txt, where 8 means the number of rows, 9 is the word count, 10 is the number of bytes, test.txt represents the file name. If you are counting the number of lines of code with the suffix named frm, ASP, bas in the current directory, the command is find. -name "*.frm"-or-name "*.bas"-or-name "*.asp" | Xargs wc-l > Result.txt, after executing this command, generates a result.txt file in the current directory containing the number of lines of code for each file (frm/bas/asp) and the total number of lines of code.

The. free command Displays the idle, used physical memory and swap memory in the Linux system, and the buffer used by the kernel. For example: free-m, memory usage is displayed in megabytes.

41. You can use the Apt-get command to Install/update a deb package , such as installing g++: Apt-get Install g++

c++filt Command : C + + functions will become similar after compiling on Linux systems: _zn9cbc_ean1312renderbitmaperp12cfx_dibitmapri, at first glance, do not know the original name of the function, You can now use the c++filt command: c++filt _zn9cbc_ean1312renderbitmaperp12cfx_dibitmapri to display the original function name Cbc_ean13::renderbitmap (CFX_ dibitmap*&,int&)

The echo command is a built-in shell command that displays the value of a variable or prints a line of text , such as by entering the Echo $PATH, to see which file directories are joined to the system environment variable (the $ representation in front of the PATH is followed by a variable). You can write 2 to a 1.txt file by entering Echo 2 >/home/spring/1.txt

The. rar command can decompress RAR files generated under Windwos , such as Test.rar, and can be executed: $rar x Test.rar

The PS-EF command is used to view all processes on a Linux system , and if you want to view a process that contains a specified name (such as test), you can do this: $ ps-ef | grep test

Kill the specified process can be executed with the KILL command, such as kill process PID 30732 process, you can execute: $ kill-9 30732, if you need to bulk kill process, you can do: $ ps aux | grep Test | awk ' {print $} ' | Xargs kill-9

Look at the Linux system CPU and memory usage , you can use the top command: First enter the top command in the terminal, and then press 1.

To open the display image by command : $ eog/images/a.jpg

remote Copy files : You can use the "SCP" command, such as sending a specified directory or file from a remote server to a locally specified directory, then execute: $ scp-r xxx [email protected]:/home/spring/yyy/ , if stored in the local root directory, you can execute: $ scp-r a.jpg [email protected]:~/; Execute the above command will be required to enter the local machine password, if you do not want to enter each time, you can do: $ ssh-copy-id [Email protect Ed], so the next time you pass a file, you do not have to re-enter the password; If you transfer files from the local to the remote server, execute: $ scp-r b.jpg [email protected]:/home/autobuild/fbc/

See IP and MAC address : $ ifconfig

Mount Ssh-server: $ sudo apt-get install-y openssh-server

The specified Ubuntu host can be accessed via the SSH command, assuming that the Ubuntu host named Spring, IP 10.0.1.1, and know the password of this host, then execute: SSH [email protected], enter, and then income this host password can be

install Google Chromeand execute the following commands in turn:

[Plain]View PlainCopy
    1. Wget-q-o-https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add-
    2. sudo sh-c ' echo ' Deb [ARCH=AMD64] http://dl.google.com/linux/chrome/deb/stable main ">>/etc/apt/sources.list.d/ Google-chrome.list '
    3. sudo apt-get update
    4. sudo apt-get install google-chrome-stable

53. Resolve pop-Up dialog "System program problem detected does want to report the problem now?" The problem in terminal input: $ sudo rm/var/crash/*

54. On Ubuntu, to see what encoding the specified file can use the file command, such as finding the encoding format of all the. cpp files under the test directory, execute: $ file Test/*.cpp

55. Install the. deb File command on Ubuntu, such as Code_1.13.0-1496940180_amd64.deb: $ sudo dpkg-i code_1.13.0-1496940180_amd64.deb

Ubuntu Common 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.