1、环境配置
vim /etc/profile
增加配置信息,然后
source /etc/profile
使之生效。
2、配置 git
git config --global user.name "ww"
git config --global user.email "[email protected]"
生成ssh密钥
ssh-keygen -C '[email protected]' -t rsa
3、通过CMakeLists.txt 生成makefile指令:
window中:cmake . -G "Unix Makefiles"
linux中:cmake .
4、查看CMake 版本:cmake -version
5、ubuntu16.04升级gcc和g++
下载
# 添加ppa到库
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-7
sudo apt-get install g++-7
1
配置默认选项
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100
sudo update-alternatives --config gcc
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 100
sudo update-alternatives --config g++
查看已安装的版本信息
gcc --version
g++ --version
6、/usr/lib/aarch64-linux-gnu 下会包含Linux环境下,C++编译的一些库,如,jsoncpp等
/media/usr/src/wenyang/hardware-native-agent/aliAgent/base/
7、执行CMakeList.txt,生成makefile文件,并执行make命令,编译C++:cmake . && make
8、查看ubuntu 下git 的公钥 :cd /root/.ssh
9、vim 打开并编辑 cat查看
10、Shift+Q 退出编辑 i-进入编辑模式 Esc-退出编辑模式 q!-不保存退出 wq-保存退出
11、查看Linux 内核:arch 结果:x86_64/aarch64
12、重命名mv :例如:mv cmake-3.10.0-rc4-Linux-x86_64 cmake
13、g++ 编译Helloworld: g++ hello_world.c -o hello_world
执行: ./hello_world
14、locate xx.so 查找名字为xx.so的文件所在目录
15、file xxx.so 查看库的结构
libjsoncpp.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[md5/uuid]=81322da5a74c0ed339699640205a4289, stripped
16、uname -a 查看linux是32还是64
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
17、查找当前目录和子目录下是否存在xxx
find . -name xxx
18、linux编译的C++可执行文件,无法直接在安卓中运行的相关操作步骤
原因:原因有两个:首先 Android 的 interpreter 是 /system/bin/linker64 而 Linux 的 interpreter 是 ld-linux-aarch64.so.1,
其次 Android 链接的 libc.so 和 Linux 的 libc.so 也不同。假设安卓中C++库的路径为system/lib64,C++编译出的可执行程序名为:hello
需要用到patchelf工具,(https://github.com/NixOS/patchelf)
linux中编译出的hello可执行程序的详细信息查看:
file hello
ELF executable, 64-bit LSB arm64, dynamic (/lib/ld-linux-aarch64.so.1), BuildID=73df73fe44d654a09bc9a2b7d867b8a4146614ed, not stripped
(1)、Linux中patchelf工具安装步骤:
a、下载patchelf安装包,这里下载的是patchelf-0.12.tar.gz
b、解压安装包:tar -axf patchelf-0.12.tar.gz
c、安装
$ ./bootstrap.sh
./bootstrap.sh: 2: ./bootstrap.sh: autoreconf: not found
根据报错查找解决办法:
$ sudo apt-get install autoconf automake libtool
d、./bootstrap.sh
e、./configure
f、make
g、make install
h、验证安装:patchelf --version
备注:如果之前有安装,先要卸载清理,步骤如下:
a、sudo apt-get remove patchelf
b、删除依赖:sudo apt-get remove --auto-remove patchelf
c、清除数据:sudo apt-get purge --auto-remove patchelf
(2)、操作hello可执行文件
a、patchelf --set-interpreter /system/lib64/ld-linux-aarch64.so.1 ./hello
b、patchelf --set-rpath /system/lib64 ./hello 设置hello可执行程序的库加载路径为/system/lib64
(3)、一般运行时,还会提示缺少一些库,可以从Linux usr/lib/aarch64-linux-gnu目录下找相关的库拷贝到/system/lib64
可用命令查看执行程序中用到的动态库:readelf -d hello
每个可执行程序不一样,以下参考:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x0000000000000001 (NEEDED) Shared library: [ld-linux-aarch64.so.1]
0x000000000000000f (RPATH) Library rpath: [/media/android_agent/hardware-native-agent/aliAgent/thirdlib/libuv-1.42.0/lib]
(4)执行后可执行程序hello的详细信息:file hello
ELF executable, 64-bit LSB arm64, dynamic (/system/lib64/ld-linux-aarch64.so.1), BuildID=0911367595580b0737f598c0d3f4ad951a27f08f, not stripped
19、解压.a静态库
ar x xxx.a
20、下载文件:curl -O url(这是大写O,如果是小写o,得这样写:curl -o fileName url)
21、mkdir -p
递归创建目录,即使上级目录不存在,会按目录层级自动创建目录
22、显示文件夹下的文件、文件大小
ls -lh
23、查看特定的日志
cat /data/native_agent_logs/agent_log | grep hardware_type
24、awk的使用
eeprom_tools get 18 | awk -F : '{print $2}'
[18] Card Inner Address: 3.1
过滤:eeprom_tools get 18 | awk -F : '{print $2}'
3.1
-F指定分隔符为:,$表示显示第几列。其中print表示要做输出信息的动作
24、查看文件夹大小
du -sh <文件夹名>
25、vi 打开文本查找
/
n往下查找
N往上查找
26、ln命令
功能:
为某一个文件在另外一个位置建立一个同步的链接.当我们需要在不同的目录,
用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,
我们只要在某个固定的目录,放上该文件,然后在 其它的目录下用ln命令链接(link)它就可以,
不必重复的占用磁盘空间
用法:ln -s 源文件 目标文件
ln -s xx xx 软链接
ln xx xx 硬链接
27、查看系统版本号
cat /proc/version
或者cat /etc/os-release
28、用户切换
su username
29、批量创建文件
touch chaochao_{1..5}.txt
30、crontab(定时器)
查看定时任务:crontab -l
设置定时任务:crontab -e
* * * * * echo "hello world" >> /root/rrc.txt
# 第1列表示分钟1~59 每分钟用或者 /1表示
# 第2列表示小时1~23(0表示0点)
# 第3列表示日期1~31
# 第4列表示月份1~12
# 第5列标识号星期0~6(0表示星期天)
# 第6列要运行的命令
31、根据内容递归某一个文件
grep -irn "failed" ./make-logbak.txt
32、vim跳转到指定行
vim 666.txt +3
33、通过关键字查找文件所在位置
grep "Calendar" ./ -rn
34、tar压缩不包含目录方法
例如:需要打包/data/android_data/VMRK02ejyijtyww20 文件夹到/data/testtar/目录下
tar -cvf /data/testtar/VMRK02ejyijtyww20.tar -C /data/android_data/ VMRK02ejyijtyww20---压缩
tar -cvf /data/testtar/VMRK02ejyijtyww20.tar -C /data/android_data/VMRK02ejyijtyww20 .---压缩(或者这样也可以)
tar -xvf /data/testtar/VMRK02ejyijtyww20.tar -C /data/w66/---解压
linux环境下开发----常用命令,个人笔记汇总
猜你喜欢
转载自blog.csdn.net/banzhuantuqiang/article/details/131260115
今日推荐
周排行