Run a recursive listing of all the files in /var/log and redirect standard output to a file called lsout.txt in your home directory. Complete this question WITHOUT leaving your home directory.
An: ls -R /var/log/ > /home/bqiu/lsout.txt
I reckon the above bash command is not correct. Because I found what it stores was :
$ ls -R /var/log
/var/log:
empty.txt setup.log setup.log.full tmp
/var/log/tmp:
fake.txt subfolder
/var/log/tmp/subfolder:
Does that mean problem resolved?
I reckon NOT.
Because it contains more "stuff" than "only files"
Or at least, if the purpose was to locate all "files" underneath the "/var/log" directory recursively, then I hope to get the anwser like this:
/var/log/empty.txt
/var/log/setup.log
/var/log/setup.log.full
/var/log/tmp/fake.txt
So then someone can parse the content of the output for later use. Such like
$ perl -wnle 'print "$. :" , $_;' logfiles
1 :/var/log/empty.txt
2 :/var/log/setup.log
3 :/var/log/setup.log.full
4 :/var/log/tmp/fake.txt
This is what I've got so far:
$ ls -1R
.:
cal.sh
cokemachine.sh
dir
sort
test.sh
./dir:
afile.txt
file
subdir
./dir/subdir:
$ ls -R | sed s/^.*://g
cal.sh
cokemachine.sh
dir
sort
test.sh
afile.txt
file
subdir
But this still leaves all directory/sub-directory names (dir and subdir), plus a couple of empty newlines
How could I get the correct result without using Perl or awk? Preferably using only basic bash commands(this is just because Perl and awk is out of assessment scope)
Edited : I focused on my own "$HOME" folder just to restrict the file listed. I am having little content in my homedir
Edited 2nd: Sorry about my inapproprated question in the initial form. I fixed the wording and hopefully everyone can see the problem now.