附录:常用命令
Last updated
Last updated
The command line is one of the most powerful features of Linux. There exists a sea of Linux command line tools, allowing you to do almost everything you can think of doing on your Linux PC. However, this usually creates a problem: with so many commands available to use, you don't know where and how to start learning them, especially when you are beginner.
: 印度理工学院、伊利诺伊大学香槟分校;软件开发工程师。
本文的特点是非常简洁,将繁杂的Linux命令行筛选出100条左右,非常适合入门学习。 此外,将领域知识以“条目+示例”的方式来整理,类似编字典一样,在编辑的过程中可以促进学习者加深认识,也方便日后持续改进(增加注解、参考文献、索引等),是一种不错的学习方法。 最后,整理这些命令行的时候,我体会到操作系统最重要的工作实际就是对文件的管理,创建、移动、查看、编辑、销毁、检索,都是围绕文件的操作,事实上也是实际工作中使用最频繁的需求。对开发者来说,以Linux命令行为模版,命名风格、人机交互、小而美的实现方式,促进自己在其它领域的应用、提高大有裨益。
The adduser and addgroup commands lets you add a new user and group to a system, respectively. Here's an example for adduser:
The arch command is used to print the machine's architecture. For example:
The cal and ncal commands display a calendar in the output.
支持选项:
The two parts are saved as files with names 'xx00' and 'xx01', respectively.
The dmidecode command prints a system's DMI (aka SMBIOS) table contents in a human-readable format.
DMI (Desktop Management Interface, DMI)就是帮助收集电脑系统信息的管理系统,DMI信息的收集必须在严格遵照SMBIOS规范的前提下进行。 SMBIOS(System Management BIOS)是主板或系统制造者以标准格式显示产品管理信息所需遵循的统一规范。SMBIOS和DMI是由行业指导机构Desktop Management Task Force (DMTF)起草的开放性的技术标准,其中DMI设计适用于任何的平台和操作系统。
The echo command displays whatever input text is given to it.
单行纯文本编辑器,它有命令模式(command mode)和输入模式(input mode)两种工作模式。 支持选项:
The fgrep command is equivalent to the grep command when executed with the -F command line option. The tool is also known as fixed or fast grep as it doesn't treat regular expression metacharacters as special, processing the information as simple string instead.
For example, if you want to search for dot (.) in a file, and don't want grep to interpret it as a wildcard character, use fgrep in the following way:
The fold command wraps each input line to fit in specified width.
The pwd command displays the name of current/working directory.
The shutdown command lets user shut the system in a safe way.
The sleep command lets user specify delay for a specified amount of time. You can use it to delay an operation like:
$ split [file-name]
ssh is basically OpenSSH SSH client. It provides secure encrypted communication between two untrusted hosts over an insecure network.
The cat command allows you to concatenate files, or data provided on standard input, and print it on the standard output. In layman terms, the command prints the information provided to it, whether through stdin or in the form a file.
The cd command is used to change user's present working directory.
The chgrp command allows you to change the group ownership of a file. The command expects new group name as its first argument and the name of file (whose group is being changed) as second argument.
The chmod command lets you change access permissions for a file. For example, if you have a binary file (say helloWorld), and you want to make it executable, you can run the following command:
The chown command allows you to change the ownership and group of a file. For example, to change the owner of a file test.txt to root, as well as set its group as root, execute the following command:
The cksum command prints the CRC checksum and byte count for the input file.
The clear command is used to clear the terminal screen.
The cmp command is used to perform byte-by-byte comparison of two files.
The comm command is used to compare two sorted files line-by-line. For example, if 'file1' contains numbers 1-5 and 'file2' contains number 4-8, here's what the 'comm' command produces in this case:
The cp command is used for copying files and directories.
The csplit command lets you split a file into sections determined by context lines. For example, to split a file into two where the first part contains 'n-1' lines and the second contains the rest, use the following command:
The date command can be used to print (or even set) the system date and time.
The dd command copies a file, converting and formatting according to the operands. For example, the following command creates an image of /dev/sda partition.
The df command displays the file system disk space usage in output.
The diff command lets you compare two files line by line.
The diff3 command, as the name suggests, allows you to compare three files line by line.
The dir command lists directory contents. For example:
The dirname command strips last component from a file name/path. In layman's terms, you can think of it as a tool that, for example, removes file name from the file's absolute path.
The du command displays disk usage of files present in a directory as well as its sub-directories.
ed is a line-oriented text editor.
The eject command lets you eject removable media (typically, a CD ROM or floppy disk)
The env command not only displays the current environment, but also lets you edit it.
The exit command causes the shell to exit.
The expand command converts tabs present in the input file(s) into spaces, and writes the file contents to standard output.
The expr command evaluates expressions. For example:
The factor command prints the prime factors of the input number.
The find command lets you search for files in a directory as well as its sub-directories.
fmt is a simple optimal text formatter. It reformats each paragraph in the file passed to it, and writes the file contents to standard output.
The free command displays the amount of free and used memory in the system.
The grep command searches for a specified pattern in a file (or files) and displays in output lines containing that pattern.
The groups command displays the name of groups a user is part of.
The gzip command compresses the input file, replacing the file itself with one having a .gz extension.
Files compressed with gzip command can be restored to their original form using the gunzip command.
The head command displays the first 10 lines of the file to standard output
The hostname command not only displays the system's host name, but lets them set it as well.
The id command prints user and group information for the current user or specified username.
The kill command, as the name suggests, helps user kill a process by sending the TERM signal to it.
The killall command lets you kill a process by name. Unlike kill - which requires ID of the process to be killed - killall just requires the name of the process.
The last command shows listing of last logged in users.
The ldd command displays in output dependencies of a shared library.
The ln command is used for creating link between files. For example, the following command would create a link named 'lnk' to a file with name 'test.txt':
The locate command helps user find a file by name.
The logname command prints the user-name of the current user.
The ls command lists contents of a directory in output.
The lshw command extracts and displays detailed information on the hardware configuration of the machine.
The lscpu command displays in output system's CPU architecture information (such as number of CPUs, threads, cores, sockets, and more).
man lets you access reference manual for commands, programs/utilities, as well as functions.
The md5sum command lets you print or check MD5 (128-bit) checksums.
The mkdir command lets you create directories.
The mkfifo command is used to create named pipes.
more is basically a filter for paging through text one screenful at a time.
The mv command lets you either move a file from one directory to another, or rename it.
The nice command lets you run a program with modified scheduling priority.
The nl command writes contents of a file to output, and prepends each line with line number.
The nm command is used to display symbols from object files.
The nproc command displays the number of processing units available to the current process.
The od command lets you dump files in octal as well as some other formats.
The passwd command is used for changing passwords for user accounts.
The paste command lets you merge lines of files. For example, if 'file1' contains the following lines:
The pidof command gives you the process ID of a running program/process.
The ping command is used to check whether or not a system is up and responding. It sends ICMP ECHO_REQUEST to network hosts.
The ps command displays information (in the form of a snapshot) about the currently active processes.
The pstree command produces information about running processes in the form of a tree.
The rm command lets you remove files and/or directories.
The rmdir command allows you delete empty directories.
The scp command lets you securely copy files between systems on a network.
The sdiff command lets you perform a side-by-side merge of differences between two files.
sed is basically a stream editor that allows users to perform basic text transformations on an input stream (a file or input from a pipeline).
The seq commands prints numbers from FIRST to LAST, in steps of INCREMENT. For example, if FIRST is 1, LAST is 10, and INCREMENT is 2, then here's the output this command produces:
The sha1sum command is used to print or check SHA1 (160-bit) checksums.
The size command lists the section sizes as well as the total size for an object or archive file.
The sort command lets you sort lines of text files. For example, if 'file2' contains the following names:
The split command, as the name suggests, splits a file into fixed-size pieces. By default, files with name like xaa, xab, and xac are produced.
The stat command displays status related to a file or a file-system.
The strings command displays in output printable character sequences that are at least 4 characters long. For example, when a binary executable 'test' was passed as an argument to this command, following output was produced:
The su command lets you change user-identity. Mostly, this command is used to become root or superuser.
The sudo command lets a permitted user run a command as another user (usually root or superuser).
The sum command prints checksum and block counts for each input file.
The tac command prints input files in reverse. Functionality-wise, it does the reverse of what the cat command does.
The tail command displays in output the last 10 lines of a file.
The talk command lets users talk with each other.
tar is an archiving utility that lets you create as well as extract archive files. For example, to create archive.tar from files 'foo' and 'bar', use the following command:
The tee command reads from standard input and write to standard output as well as files.
The test command checks file types and compare values. For example, you can use it in the following way:
The time command is used to summarize system resource usage of a program. For example:
The top command gives a dynamic real-time view of a running system (in terms of its processes). For example:
The touch command lets you change file timestamps (the access and modification times). When name of a non-existent file is passed as an argument, that file gets created.
The tr command can be used to translate/squeeze/delete characters. For example, here's how you can use it to convert lowercase characters to uppercase:
The tty command prints the filename of the terminal connected to standard input.
The uname command prints certain system information.
The Uniq command is used to report or omit repeated lines. For example, if 'file2' contains the following data:
The unexpand command converts spaces present in the input file(s) into tabs, and writes the file contents to standard output.
The uptime command tells how long the system has been running.
The users command displays in output the usernames of users currently logged in to the current host.
The vdir command lists information about contents of a directory (current directory by default).
vim is basically a text/programming editor. The name 'vim' stands for Vi IMproved as the editor is upwards compatible to the Vi editor.
The w command displays information about the users currently on the machine, and their processes.
The wall command lets you write and send a message to other users that are currently logged in.
The watch command can be used to monitor a program's output. It runs the program repeatedly, displaying its output and errors. For example:
The wc command prints newline, word, and byte counts for a file.
The whatis command displays single-line manual page descriptions.
The which command basically lets you locate a command - the file and the path of the file that gets executed. For example:
The who command shows who is logged on.
The whereis command shows in output locations of the binary, source, and manual page files for a command.
The whoami command prints effective userid of the current user.
The xargs command builds and executes command lines from standard input. In layman's terms, it reads items from stdin and executes a command passed to it as an argument. For example, here's how you can use xargs to find the word "Linux" in the files whose names are passed to it as input.
The Yes command outputs a string repeatedly until killed.
更多精彩内容,请扫码关注公众号:@睿哥杂货铺