Cygwin下编译的程序不使用Cygwin.dll即可运行的命令 及常用命令简介

cc -mno-cygwin foo.c

 

1、$ ps

PS的相关用法:

Quote
Usage ps [-aefl] [-u uid]
-f = show process uids, ppids
-l = show process uids, ppids, pgids, winpids
-u uid = list processes owned by uid
-a, -e = show processes of all users
-s = show process summary
-W = show windows as well as cygwin processes

 

2、DF命令直接查看下本地驱动器

$ df
Filesystem 1k-blocks Used Available Use% Mounted on
c: 5106676 1240312 3866364 25% /cygdrive/c
d: 10239408 6560328 3679080 65% /cygdrive/d
e: 10231384 4844432 5386952 48% /cygdrive/e
在后面的/cygdrive/c便是C盘了

 

3、CD命令改变当前路径 

进D盘

$ cd /cygdrive/d

 

4、Cygwin下运行Windows程序

$ cmd.exe
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

e:\cygwin\home\Taynni-417>d:

D:\>cd hacker

D:\HACKER>cd tools

D:\HACKER\Tools>cd pstools

D:\HACKER\Tools\Pstools>exit

直接输入CMD.EXE便可以得到一个本机CMDSHELL,这样运行什么程序都可以

退出到Cygwin的Bash shell需要使用exit命令

 

5、--help 帮助命令

--help获取帮助

$ md5sum --help

Usage: md5sum [OPTION] [FILE]...
or: md5sum [OPTION] --check [FILE]
Print or check MD5 (128-bit) checksums.
With no FILE, or when FILE is -, read standard input.

-b, --binary read files in binary mode (default on DOS/Windows)
-c, --check check MD5 sums against given list
-t, --text read files in text mode (default)

The following two options are useful only when verifying checksums:
--status don't output anything, status code shows success
-w, --warn warn about improperly formated checksum lines

--help display this help and exit
--version output version information and exit

The sums are computed as described in RFC 1321. When checking, the input
should be a former output of this program. The default mode is to print
a line with checksum, a character indicating type (`*' for binary, ` ' for
text), and name for each FILE.

 

6、 常用命令
       在Bash shell的命令行交互中可以输入很多命令运行。例如:
命令 说明   命令 说明
touch 新建文件   cmd 切换到windows控制台,可以运行windows程序
rm 删除文件   --help 参数,显示命令帮助
mkdir 新建目录   man 显示命令帮助
rmdir 删除目录   info 显示命令更详细帮助
ls 显示文件和目录   ps 显示进程
cd 改当前目录 cd /   echo 输出变量值,echo $PATH
cp 复制文件   find 查找文件
mv 移动文件   diff 比较文件差异
查看命令帮助文档时,按 Ctrl+Z 或 Ctrl+C 退出命令
更多命令参考:http://linux.chinaitlab.com/special/linuxcom/Index.html

pwd   显示当前的路径

cd    改变当前路径,无参数时进入对应用户的home目录
ls    列出当前目录下的文件。此命令有N多参数,比如ls -al
ps    列出当前系统进程
kill 杀死某个进程
mkdir 建立目录
rmdir 删除目录
rm    删除文件
mv    文件改名或目录改名
man   联机帮助
less 显示文件的最末几行
由于linux下面的命令大多都有很多参数,可以组合使用。所以,每当你不会或者记不清楚该用哪个参数,哪个开关的时候,可以用man来查找

比如,查找ls怎么使用,可以键入

$ man ls
系统回显信息如下:
LS(1)                          FSF                          LS(1)

 

7、编译helloworld

# cd
进入了/home/administrator目录,我当前的登陆帐号是administrator
# mkdir source
建立一个叫做source的子目录
# cd source
进入 /home/administrator/source
# vim hello.c
我们编辑hello.c文件,输入:

1 #include <stdio.h>
2 int main(void){
3         printf("Hello world!\r\n");
4         return 0;
5 }

 

然后,Esc并输入:wq命令退到命令行。

输入编译指令:
# gcc hello.c -o hello
编译成功后可以看一下
# ls
看到hello.exe了吧

 

C++的Hello world

# vim world.cpp
输入:

1 #include <iostream>
2 using namespace std;
3 int main(void){
4         cout<<"Hello World!!!";
5         cout<<"\n";
6         return 0;
7 }

编译C++程序要用g++

# g++ world.cpp -o world
运行一下
# ./world

好了,关于如何编写makefile文件,如何用gdb下次再说了。

Linux开发一路过来 cygwin->make->gcc

 

posted @ 2017-03-06 12:18  磨叽开发者  阅读(1474)  评论(0编辑  收藏  举报