Linux常用命令笔记
来源:互联网 发布:aimbooster软件下载 编辑:程序博客网 时间:2024/05/21 10:49
1. tar 解压缩xz文件
flying-bird@flyingbird:~/books$ ll 总用量 71500 drwxrwxr-x 4 flying-bird flying-bird 4096 5月 22 19:39 ./ drwxr-xr-x 38 flying-bird flying-bird 4096 5月 22 19:16 ../ drwxrwxr-x 4 flying-bird flying-bird 4096 5月 22 19:38 linux/ -rw-r--r-- 1 flying-bird flying-bird 73195712 8月 20 2013 linux-3.10.7.tar.xz drwxrwxr-x 2 flying-bird flying-bird 4096 4月 16 19:28 Python/ flying-bird@flyingbird:~/books$ tar -xvf linux-3.10.7.tar.xz linux-3.10.7/ linux-3.10.7/.gitignore
2. unrar解压rar文件
flying-bird@flyingbird:~/books/Tcl$ ll总用量 20104drwxrwxr-x 2 flying-bird flying-bird 4096 6月 9 19:53 ./drwxrwxr-x 8 flying-bird flying-bird 4096 6月 9 19:53 ../-rw-r--r-- 1 flying-bird flying-bird 11000000 6月 9 19:48 Tcl_TK编程权威指南.part1.rar-rw-r--r-- 1 flying-bird flying-bird 9572860 6月 9 19:51 Tcl_TK编程权威指南.part2.rarflying-bird@flyingbird:~/books/Tcl$ unrar e ./Tcl_TK编程权威指南.part1.rar UNRAR 4.00 beta 3 freeware Copyright (c) 1993-2010 Alexander RoshalExtracting from ./Tcl_TK编程权威指南.part1.rarExtracting Tcl_TK编程权威指南.pdf 53%Extracting from ./Tcl_TK编程权威指南.part2.rar... Tcl_TK编程权威指南.pdf OK All OKflying-bird@flyingbird:~/books/Tcl$
选项e是解压缩到当前目录,且是把所有文件都解压缩到当前目录,不再有目录层次结构。如果rar仅包括一个文件,则e是合适的。
更多时候,用 unrar x file.rar the_dest_dir。这时把file.rar解压缩到the_dest_dir目录下面,且保持之前到目录结构。
3. find 查找文件
flying-bird@flyingbird:/usr/include$ find . -name "errno.h"./linux/errno.h./asm-generic/errno.h./errno.h./i386-linux-gnu/asm/errno.h./i386-linux-gnu/sys/errno.h./i386-linux-gnu/bits/errno.hflying-bird@flyingbird:/usr/include$
4. find 查找包含特定字符串的文件
flying-bird@flyingbird:/usr/include$ find . -name "*.h" | xargs grep "SIGABRT"./asm-generic/signal.h:#define SIGABRT 6./i386-linux-gnu/asm/signal.h:#define SIGABRT 6./i386-linux-gnu/bits/signum.h:#defineSIGABRT6/* Abort (ANSI). */flying-bird@flyingbird:/usr/include$
5. man 在线系统
用man查找某个命令或某个函数相关的信息。
man 1 stat的执行结果:
STAT(1) User Commands STAT(1)NAME stat - display file or file system statusSYNOPSIS stat [OPTION]... FILE...DESCRIPTION Display file or file system status. -L, --dereference follow links -f, --file-system display file system status instead of file status -c --format=FORMAT use the specified FORMAT instead of the default; output a newline after each use of FORMAT
man 2 stat的执行结果:
STAT(2) Linux Programmer's Manual STAT(2)NAME stat, fstat, lstat - get file statusSYNOPSIS #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> int stat(const char *path, struct stat *buf); int fstat(int fd, struct stat *buf); int lstat(const char *path, struct stat *buf); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): lstat(): _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED || /* Since glibc 2.10: */ _POSIX_C_SOURCE >= 200112LDESCRIPTION
man命令后面的1&2&3等,可以执行man man命令来了解。如下:
MAN(1) Manual pager utils MAN(1)NAME man - an interface to the on-line reference manualsSYNOPSIS man [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-m system[,...]] [-M path] [-S list] [-e exten‐ sion] [-i|-I] [--regex|--wildcard] [--names-only] [-a] [-u] [--no-subpages] [-P pager] [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-justification] [-p string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ... man -k [apropos options] regexp ... man -K [-w|-W] [-S list] [-i|-I] [--regex] [section] term ... man -f [whatis options] page ... man -l [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L locale] [-P pager] [-r prompt] [-7] [-E encoding] [-p string] [-t] [-T[device]] [-H[browser]] [-X[dpi]] [-Z] file ... man -w|-W [-C file] [-d] [-D] page ... man -c [-C file] [-d] [-D] page ... man [-hV]DESCRIPTION man is the system's manual pager. Each page argument given to man is normally the name of a program, utility or function. The manual page associated with each of these arguments is then found and displayed. A section, if provided, will direct man to look only in that section of the manual. The default action is to search in all of the available sections, follow‐ ing a pre-defined order and to show only the first page found, even if page exists in several sections. The table below shows the section numbers of the manual followed by the types of pages they contain. 1 Executable programs or shell commands 2 System calls (functions provided by the kernel) 3 Library calls (functions within program libraries) 4 Special files (usually found in /dev) 5 File formats and conventions eg /etc/passwd 6 Games 7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7) 8 System administration commands (usually only for root) 9 Kernel routines [Non standard] A manual page consists of several sections.
6. ulimit 设置资源使用门限
如设置core文件大小、调用栈大小等:
flying-bird@flyingbird:~/examples$ ulimit -c0flying-bird@flyingbird:~/examples$ ulimit -s8192flying-bird@flyingbird:~/examples$ ulimit -s unlimitedflying-bird@flyingbird:~/examples$ ulimit -sunlimitedflying-bird@flyingbird:~/examples$
关于core,请参考 C代码的coredump。
7. sudo 提升用户权限
程序执行时,如果需要访问系统资源,可能会提示(错误码13),即Permission denied。——此时需要用sudo运行程序。
示例:在Linux系统的机器上查看MBR数据 (续)一文中,我们已经遇到过这种使用方法。
flying-bird@flyingbird:~/examples/cpp/read_mbr$ g++ main.cpp file-utils.cpp mbr.cpp -I.flying-bird@flyingbird:~/examples/cpp/read_mbr$ ./a.out Open file failed: Permission denied.flying-bird@flyingbird:~/examples/cpp/read_mbr$ vi main.cppflying-bird@flyingbird:~/examples/cpp/read_mbr$ g++ main.cpp file-utils.cpp mbr.cpp -I.flying-bird@flyingbird:~/examples/cpp/read_mbr$ ./a.out Open file failed(13): Permission denied.flying-bird@flyingbird:~/examples/cpp/read_mbr$ sudo ./a.out boot loader: Addr 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F0x0000 EB 63 90 00 02 8E D7 BC 00 7A BB A0 07 8B CE 8E 0x0010 DB 8E C3 F3 A4 EA 5D 00 A0 07 10 00 01 00 00 7A 0x0020 00 00 00 00 00 00 00 00 00 00 07 66 8B 55 08 B4
上面的错误打印,对应于main.cpp的如下修改:
flying-bird@flyingbird:~/examples/cpp/read_mbr$ cat main.cpp#include <cstdio>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include <string.h>#include "mbr.h"int main() { int fd = -1; const unsigned int SECTOR_SIZE = 512; unsigned char buf[SECTOR_SIZE]; ssize_t read_count; const char* DEV_NAME = "/dev/sda"; fd = open(DEV_NAME, O_RDONLY); if (fd == -1) { printf("Open file failed(%d): %s.\n", errno, strerror(errno)); return -1; } read_count = read(fd, buf, SECTOR_SIZE); if (read_count != SECTOR_SIZE) { printf("Read error: %d\n", read_count); close(fd); return -1; } struct mbr mbr = {0}; get_mbr(buf, mbr); close(fd); return 0;}flying-bird@flyingbird:~/examples/cpp/read_mbr$
以上代码中的strerror()等,请参考通过strerror获取详细的错误信息。
8. md5/sha1sum 计算SHA1消息签名
flying-bird@flyingbird:~/examples/cpp/sha1$ echo "hello" > hello1.txtflying-bird@flyingbird:~/examples/cpp/sha1$ sha1sum -b hello1.txt f572d396fae9206628714fb2ce00f72e94f2258f *hello1.txtflying-bird@flyingbird:~/examples/cpp/sha1$ echo -n "hello" > hello2.txtflying-bird@flyingbird:~/examples/cpp/sha1$ sha1sum -b hello2.txt aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d *hello2.txtflying-bird@flyingbird:~/examples/cpp/sha1$
计算SHA1的C代码,请参考计算SHA1。
Mac OS X下面:
1)md5的用法:md5 file_name
2)sha1的用法:shasum file_name —— 这个和Linux有些区别。
9. hexdump 显示文件的二进制形式
flying-bird@flyingbird:~/examples/vi$ hexdump -C ./test.txt 00000000 54 68 65 20 66 69 72 73 74 20 6c 69 6e 65 2e 0d |The first line..|00000010 0a 54 68 65 20 73 65 63 6f 6e 64 20 6c 69 6e 65 |.The second line|00000020 2e 0d 0a 0d 0a |.....|00000025flying-bird@flyingbird:~/examples/vi$
10. 查看每个分区的空间占用情况
flying-bird@flyingbird:~$ df -hl文件系统 容量 已用 可用 已用% 挂载点/dev/sda5 84G 4.2G 75G 6% /udev 999M 4.0K 999M 1% /devtmpfs 202M 912K 201M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 1006M 156K 1006M 1% /run/shm/dev/sda7 134G 3.8G 124G 3% /home/dev/sdb6 20G 19G 1.5G 93% /media/SOFTWARE/dev/sdb5 15G 14G 2.0G 88% /media/EBOOK/dev/sdb1 16G 15G 1.3G 92% /media/PHOTO/dev/sdb7 25G 23G 1.7G 94% /media/Englishflying-bird@flyingbird:~$
11. 查看每个分区的inode占用情况
flying-bird@flyingbird:~$ df -i文件系统 Inode 已用(I) 可用(I) 已用(I)% 挂载点/dev/sda5 5545984 242706 5303278 5% /udev 215754 602 215152 1% /devtmpfs 219409 548 218861 1% /runnone 219409 3 219406 1% /run/locknone 219409 7 219402 1% /run/shm/dev/sda7 8912896 98136 8814760 2% /home/dev/sdb6 0 0 0 - /media/SOFTWARE/dev/sdb5 0 0 0 - /media/EBOOK/dev/sdb1 0 0 0 - /media/PHOTO/dev/sdb7 1829880 5000 1824880 1% /media/Englishflying-bird@flyingbird:~$
12. 查看每个目录的空间占用情况
flying-bird@flyingbird:~/books$ du -h --max-depth=1 .573M./linux-3.10.789M./Python1.1G./linux1.8G.flying-bird@flyingbird:~/books$ du -h --max-depth=1 ..108K../.fontconfig16K../.sudoku52K../.sunpinyin。。。。。。。3.0M../.local764K../examples8.0G..flying-bird@flyingbird:~/books$ du -h --max-depth=1 ../examples240K../examples/png4.0K../examples/git12K../examples/java332K../examples/cpp164K../examples/python8.0K../examples/vi764K../examplesflying-bird@flyingbird:~/books$
13. 修改hosts文件
flying-bird@flyingbird:~/android$ su密码: root@flyingbird:/home/flying-bird/android# cd /etcroot@flyingbird:/etc# ll总用量 1196drwxr-xr-x 137 root root 12288 6月 1 11:04 ./drwxr-xr-x 23 root root 4096 5月 27 18:55 ../drwxr-xr-x 3 root root 4096 3月 26 21:08 acpi/-rw-r--r-- 1 root root 2981 4月 24 2012 adduser.conf...........-rw-r--r-- 1 root root 92 4月 19 2012 host.conf-rw-r--r-- 1 root root 11 3月 24 14:32 hostname-rw-r--r-- 1 root root 225 3月 24 14:32 hosts-rw-r--r-- 1 root root 580 4月 27 2012 hosts.allow-rw-r--r-- 1 root root 880 4月 27 2012 hosts.deny...........drwxr-xr-x 2 root root 4096 4月 27 2012 xml/drwxr-xr-x 2 root root 4096 3月 26 21:09 xul-ext/-rw-r--r-- 1 root root 349 1月 30 2012 zsh_command_not_foundroot@flyingbird:/etc# cat hosts127.0.0.1localhost127.0.1.1flyingbird# The following lines are desirable for IPv6 capable hosts::1 ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 ip6-allnodesff02::2 ip6-allroutersroot@flyingbird:/etc# vi hostsroot@flyingbird:/etc# cat ./hosts127.0.0.1localhost127.0.1.1flyingbird74.125.31.136 dl-ssl.google.com# The following lines are desirable for IPv6 capable hosts::1 ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 ip6-allnodesff02::2 ip6-allroutersroot@flyingbird:/etc#
14. ln建立软链接
flying-bird@flyingbird:~/examples$ ll *.txtls: 无法访问*.txt: 没有那个文件或目录flying-bird@flyingbird:~/examples$ echo "the source file" > source.txtflying-bird@flyingbird:~/examples$ ll *.txt-rw-rw-r-- 1 flying-bird flying-bird 16 6月 5 19:42 source.txtflying-bird@flyingbird:~/examples$ mkdir testlnflying-bird@flyingbird:~/examples$ cd testlnflying-bird@flyingbird:~/examples/testln$ ln -s ../source.txt ./target.txtflying-bird@flyingbird:~/examples/testln$ ll总用量 8drwxrwxr-x 2 flying-bird flying-bird 4096 6月 5 19:42 ./drwxrwxr-x 9 flying-bird flying-bird 4096 6月 5 19:42 ../lrwxrwxrwx 1 flying-bird flying-bird 13 6月 5 19:42 target.txt -> ../source.txtflying-bird@flyingbird:~/examples/testln$ cat target.txtthe source fileflying-bird@flyingbird:~/examples/testln$
15. 7z
首先安装7z软件,在软件中心搜索7z,可以找到7zip。安装即可。
命令行:7z x -othe_dest_directory file_to_be_unzip.7z
16. scp
scp用来在远程计算机和本地计算机之间拷贝文件。
本地拷贝到远程:
scp local_file_name remote_user_name@remote_ip_addr:remote_directory
scp local_file_name remote_user_name@remote_ip_addr:remote_file_name
scp -r local_directory remote_user_name@remote_ip_addr:remote_directory
远程拷贝到本地:
scp remote_user_name@remote_ip_addr:remote_file_name local_file_name
本地拷贝到远程:
scp local_file_name remote_user_name@remote_ip_addr:remote_directory
scp local_file_name remote_user_name@remote_ip_addr:remote_file_name
scp -r local_directory remote_user_name@remote_ip_addr:remote_directory
远程拷贝到本地:
scp remote_user_name@remote_ip_addr:remote_file_name local_file_name
执行命令后要求输入远程机器的密码。
另外本地需要关闭对远程机器的连接,否则会出现: Resource temporarily unavailable.
0 0
- Linux常用命令学习笔记
- Linux常用命令学习笔记
- linux常用命令笔记
- Linux 笔记 常用命令
- linux 常用命令笔记
- Linux 学习笔记 - 常用命令
- linux 常用命令、学习笔记
- linux常用命令笔记
- Linux下常用命令笔记
- Linux 常用命令笔记
- linux常用命令笔记20130724
- Linux常用命令笔记-Shell
- linux常用命令学习笔记
- linux常用命令笔记
- linux常用命令笔记
- Linux操作常用命令笔记
- Linux常用命令笔记
- linux常用命令笔记
- JAVA设计模式之命令模式
- 【hibernate】对象状态和主要方法
- Set,List,Map,Vector,ArrayList的区别
- 结构型模式2:桥接模式(Bridge Pattern)
- Prototype原型模式
- Linux常用命令笔记
- tableView方法中两个重用cell的方法
- UVA 10047 The Monocycle (BFS)
- Cocoa
- ios中new与alloc
- 人见人爱A^B
- vs2008提示“LINK : fatal error LNK1104: 无法打开文件“xx.lib””的问题
- 数据结构实验
- dede点击顶级栏目跳转到第一个子栏目