
正文
linux遍历命令 linux遍历所有文件命令
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何遍历Linux程序的So模块
layout: post
title: 如何遍历Linux程序的So模块
categories: Android
description: 如何遍历linux程序的so模块
keywords:
url:
soinfo是个链表结构,从打印的信息来看,是从高地址到低地址排序的,因此要打开一个未加载的so,自然排在高地址位置,因此往后遍历即可
相关问答
Q1: linux shell 命令怎么遍历目录
先设定实验环境:
# 造 5 个 目录,每个目录下,造 3 个 文件和两个子目录如下:
cd $HOME/tmp
for i in d1 d2 d3 d4 d5
do
mkdir -p $i
touch $i/1.txt $i/2.txt $i/3.txt
mkdir -p $i/tmp1 $i/tmp2
done
# 检验测试环境:
$ ls -lR d1
total 0
-rw-r--r-- 1 wenlee comm 0 Dec 22 10:35 1.txt
-rw-r--r-- 1 wenlee comm 0 Dec 22 10:35 2.txt
-rw-r--r-- 1 wenlee comm 0 Dec 22 10:35 3.txt
drwxr-sr-x 2 wenlee comm 256 Dec 22 10:35 tmp1/
drwxr-sr-x 2 wenlee comm 256 Dec 22 10:35 tmp2/
# 利用下列脚本来实现你要做的:
cd $HOME/tmp
for i in */1.txt
do
echo "Found $i, save $i and remove everything else under $(dirname $i)/"
save_this_file=$(basename $i)
curr_dir=$(dirname $i)
# 把这个1.txt暂时存到/tmp里面去,为了避免已经有同样的档案名称在/tmp,加上$$ (i.e. PID)
mv $i /tmp/${save_this_file}.$$
rm -rf $curr_dir
mkdir -p $curr_dir
mv /tmp/${save_this_file}.$$ $curr_dir
done
# 屏幕执行输出如下:
Found d1/1.txt, save d1/1.txt and remove everything else under d1/
Found d2/1.txt, save d2/1.txt and remove everything else under d2/
Found d3/1.txt, save d3/1.txt and remove everything else under d3/
Found d4/1.txt, save d4/1.txt and remove everything else under d4/
Found d5/1.txt, save d5/1.txt and remove everything else under d5/
# 复验实验环境:
$ ls -l d?/*
-rw-r--r-- 1 wenlee comm 0 Dec 22 10:35 d1/1.txt
-rw-r--r-- 1 wenlee comm 0 Dec 22 10:35 d2/1.txt
-rw-r--r-- 1 wenlee comm 0 Dec 22 10:35 d3/1.txt
-rw-r--r-- 1 wenlee comm 0 Dec 22 10:35 d4/1.txt
-rw-r--r-- 1 wenlee comm 0 Dec 22 10:35 d5/1.txt
OK?
thanks!
Q2: 如何用C遍历unix/linux下的所有进程,取得PID,名称等等
用管道:
通过fgets(buf,
n,
ptr)buf就可以得到命令“ps
-ef"一样的信息,
读帮助”man
popen":
char
*cmd
=
"ps
-ef";
FILE
*ptr;
if
((ptr
=
popen(cmd,
"r"))
!=
NULL)
while
(fgets(buf,
n,
ptr)
!=
NULL)
(void)
printf("%s
",buf);
UID
PID
PPID
C
STIME
TTY
TIME
CMD
root
Sep-30
?
00:00:01
sched
root
1
Sep-30
?
00:00:06
/etc/init
-a
root
2
Sep-30
?
00:00:00
vhand
root
3
Sep-30
?
00:00:27
bdflush
root
4
Sep-30
?
00:00:00
kmdaemon
root
5
1
Sep-30
?
00:00:50
htepi_daemon
/
root
6
Sep-30
?
00:00:00
strd
root
2941
1
Oct-08
tty01
00:00:00
/bin/login
ccb
root
43
1
Oct-08
?
00:00:02
/etc/syslogd
root
47
1
Oct-08
?
00:00:00
/etc/ifor_pmd
root
48
47
Oct-08
?
00:00:13
/etc/ifor_pmd
root
36
1
Oct-08
?
00:00:00
Q3: 在linux shell(bash)编程中,如何通过递归方式遍历文件
写一个函数,函数的参数是目录路径字符串
函数内使用 ls -s dir_path , 然后for 遍历循环
如果是目录则继续调用自身
如果是文件则答应文件名
从执行优化的角度来讲,可以把判断目录还是文件的代码放在循环外层.
好久没写shell了 ,我这也没环境测试 , 只能给个思路,函数的具体写法自己找一下资料吧.
另外,find命令可以直接完成你要做的事.
Q4: linux平台:使用lua语言遍历某一文件夹下所有文件
你可以参考如下实例代码:function getFile(file_name)
local f = assert(io.open(file_name, 'r'))
local string = f:read("*all")
f:close()
return string
end function writeFile(file_name,string)
local f = assert(io.open(file_name, 'w'))
f:write(string)
f:close()
end --从命令行获取参数, 如果有参数则遍历指定目录,没有参数遍历当前目录 if arg[1] ~= nil then
cmd = "ls "..arg[1]
else
cmd = "ls" end print("cmd", cmd)
--io.popen 返回的是一个FILE,跟c里面的popen一样 local s = io.popen(cmd)
local fileLists = s:read("*all")
print(fileLists)
while true do --从文件列表里一行一行的获取文件名 _,end_pos, line = string.find(fileLists, "([^\n\r]+.txt)", start_pos)
if not end_pos then break end -- print ("wld", line) local str = getFile(line)
--把每一行的末尾 1, 替换为 0, local new =string.gsub(str, "1,\n", "0,\n");
--替换后的字符串写入到文件。以前的内容会清空 writeFile(line, new)
start_pos = end_pos + 1 end
Q5: linux shell 遍历文件夹 并将结果保存 到变量
#!/bin/bash
(( $# 1 )) echo "param is zero!" exit 1
[ ! -d $1 ] echo "$1 not path" exit 1
dir=$1
dir_p="$dir Directory :"
cd $dir
dir=`pwd`
for i in `ls $dir`
do
if [ -d $i ]; then
/tmp/sh/dir_file $i #我的脚本文件在/tmp/sh中,需要改一下这里
else
dir_p="$dir_p File $i"
fi
done
cd ..
echo $dir_p
实验结果:
[root@localhost sh]# ./dir_file /tmp/python/
python_2 Directory : File 1.log File 2.log
python_3 Directory : File 3.log
/tmp/python/ Directory : File p File t.py File y.py
这样应该可以吧,试试看
关于linux遍历命令和linux遍历所有文件命令的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







