在ubuntu中开始你的hello world

  1. 先安装好你的Ubuntu
  2. 熟悉常用的Linux命令

(1)pwd  显示完整目录

(2)ls   list 列举出指定目录下的内容或者是查看文件的信息

gec@ubuntu:~$ ls   默认是查看当前目录下的内容

     等价于 ls   ./

gec@ubuntu:~$ ls  /home  查看/home目录下的内容

 

ls   -a 列举出指定目录下的全部内容,包括隐藏文件(以.开头的)

ls   -l  列举出指定目录下的详细信息,包括文件的类型、文件的权限等信息

ls  -al 

 

(3)clear   清空屏幕

(4)mkdir  创建一个工作目录

gec@ubuntu:~$ mkdir  111

就有了这么一个工作目录  /home/gec/111

 

(5)cd    change directory切换目录

 在当前位置gec@ubuntu:~$ 

cd   /home/gec/111 (完整目录、绝对路径)

cd   ./111   (相对路径,当前目录的111

cd  111   (默认是当前目录的111)

 

常见错误:  No such file or directory  找不到对应的目录或者文件,

原因:  1:没有弄清楚自己的位置

2:输入文件名时候输错了

 

(6)使用【tab】键自动补齐,可以避免长命令时候错误的发生

(7)使用上键和下键对历史命令进行选择

(8)仅仅创建一个普通文件

touch  filename

 

(9) rm  删除命令  remove

rm  filename

rm  dirname  -r

 

(10) mv  文件重命名或者文件移动  move

mv   main1-c    main.c  (main1-c重命名为main.c)

mv   main1-c     /home/gece (main1-c移动到/home/gece目录下)

mv   dir1    dir2  (如果dir2是存在的,就是把dir1移动到dir2下;

如果dir2是不存在的,就把dir1重命名为dir2)

 

(11)  cp  复制命令  copy

cp   filename   new_path&name

cp   dirname1   dirname2   -r

 

(12)  man  用户手册  提供帮助

查看cp命令的帮助文档

     man  cp

 

(13)  新建文件并开始编辑或者是编辑已存在文件

vim 或者  vi 

1)进入文件后,默认是出于命令模式,

2)需要用切换到编辑模式(输入模式)

  键入 i     a     o  3个按键可以切换

         

3)开始输入代码

4)退出输入模式,返回到命令模式

    按【ESC】键返回到命令模式

    在命令模式键入 冒号+w表示保存

w   保存

w    newname  另存、

wq  保存并退出

q!   强制退出

 

 

(14)  gcc编译器

常用写法:  gcc   -o  目标文件    所有依赖的文件(.c

Linux中整个编译过程分4步完成

1) 预处理   把所有的#开头的内容都替换掉

#include   #define    #ifdef...#endif

 gec@ubuntu:~/111/0409$ gcc -E -o  target.i   main.c

gec@ubuntu:~/111/0409$

gec@ubuntu:~/111/0409$file target.i

target.i: Csource, ASCII text

 

2) 编译   检查一个文件的语法,得到汇编文件

gec@ubuntu:~/111/0409$gcc -S -o  target.s   main.c

gec@ubuntu:~/111/0409$file  target.s

target.s:assembler source, ASCII text

 

3) 汇编  检查外部调用声明和全局变量有没有问题

gec@ubuntu:~/111/0409$gcc -c  -o  target.o   main.c

gec@ubuntu:~/111/0409$

gec@ubuntu:~/111/0409$

gec@ubuntu:~/111/0409$file  target.o

target.o: ELF64-bit LSB relocatable, x86-64, version 1 (SYSV), not strip

 

4) 链接  检查是否所有的外部调用声明都有定义

 

gec@ubuntu:~/111/0409$gcc  -o  target    main.c

gec@ubuntu:~/111/0409$file  target

target: ELF 64-bitLSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter/lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32,BuildID[sha1]=3db137490e899cdb30d48b1cd07826a93cae7516, not stripped

 

 

 

 

(15)  file  命令查看文件的属性

gec@ubuntu:~/111/0409$gcc -o   target  main.c

gec@ubuntu:~/111/0409$ls

main.c  target

gec@ubuntu:~/111/0409$file   main.c

main.c: C source, ASCIItext

gec@ubuntu:~/111/0409$file  target

target: ELF 64-bitLSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter/lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32,BuildID[sha1]=3db137490e899cdb30d48b1cd07826a93cae7516, not stripped

 

 (16)  执行可执行文件,需要写明路径和文件, 如本地目录下的target可执行文件 ,            
        gec@ubuntu:~/111/0409$ ./target 

猜你喜欢

转载自blog.csdn.net/smallnewbirdbird/article/details/80624602