I am completing the tasks but it shows uncomplete in Linux Challenge 4.
The tasks were
Find the “hidden” files in “/home/bob/preserved” directory and copy them in “/opt/appdata/hidden/” directory (create the destination directory if doesn’t exist).
Find the “non-hidden” files in “/home/bob/preserved” directory and copy them in “/opt/appdata/files/” directory (create the destination directory if doesn’t exist).
is that a glitch? because I checked it those files were present in that directory or not but those are present but still task is incomplete. what should i do?
1 Like
Hi @Aniket-Pawar
Did you complete all three find tasks? Simply doing the two copies won’t validate those two tasks alone. You also have to do the third task
Find and delete the files in “/opt/appdata” directory that contain a word ending with the letter “t” (case sensitive)
…then all three will get green tick.
Take note of the note in the instructions
Note:
The validation will verify the final processed data so some of the tests might fail till all data is processed as asked.
I have done all three tasks which were mentioned still getting the error
@Aniket-Pawar Here is my solution
# Become root
sudo -i
# Create directories
mkdir -p /opt/appdata/hidden
mkdir -p /opt/appdata/files
# Hidden files
find /home/bob/preserved -type f -name ".*" -exec cp "{}" /opt/appdata/hidden/ \;
# non-hidden files
find /home/bob/preserved -type f -not -name ".*" -exec cp "{}" /opt/appdata/files/ \;
# delete files with words ending in 't'
rm -f $(find /opt/appdata/ -type f -exec grep -l 't\>' "{}" \; )
Note that it will still say
until all tasks are done and all icons are green in the diagram.
@Alistair can you please answer in last part filtered.txt what we need to perform exactly.
command what i used is : zgrep -ai processed /opt/appdata.tar.gz > /home/bob/filtered.txt
but i don’t know in second part it’s saying overwrite the content but i don’t see any content inside that /home/bob/filtered.txt
can you please reply please find below SS for convenience.
Need to use below command to fix it :
$ tar -xzOf /opt/appdata.tar.gz | grep processed
1 Like
@durgakumari813 @mandarpimplapure
The last part is a combination of the tasks filter.sh
and filtered.txt
You need to create filter.sh like this
cat <<'EOF' > /home/bob/filter.sh
#!/bin/bash
tar -xzOf /opt/appdata.tar.gz | grep processed > /home/bob/filtered.txt
EOF
chmod +x /home/bob/filter.sh
Then you execute the script to get filtered.txt
Use of the >
redirection satisfies the condition
It must “overwrite” the contents
which it will do if the file already exists, i.e. you run the script twice.
I have a single script that solves the entire challenge in one go.
1 Like
@Alistair_KodeKloud can you please give me the solution for the following : * Change all the occurrences of the word “yes” to “no” in all files present under “/opt/appdata/” directory.
- Change all the occurrences of the word “raw” to “processed” in all files present under “/opt/appdata/” directory. It must be a “case-insensitive” replacement, means all words must be replaced like “raw , Raw , RAW” etc.
Thanks a lot @Alistair_KodeKloud it worked finally
@muhammed.ihsan
you can run below commands:
find /opt/appdata/ -type f -exec sed -i ‘s/raw/processed/gi’ {} ;
find /opt/appdata/ -type f -exec sed -i ‘s/yes/no/g’ {} ;
getting below error
find: missing argument to `-exec’
before semicolon put backslash in both the cmd like
find /opt/appdata/ -type f -exec sed -i ‘s/raw/processed/gi’ {} \;
find /opt/appdata/ -type f -exec sed -i ‘s/yes/no/g’ {} \;
1 Like
already tried but getting another error:
sed: -e expression #1, char 1: unknown command: `’
paste your code here i don’t see any -e option in my code
type or paste code here
find /opt/appdata/ -type f -exec sed -i ‘s/raw/processed/g’ {} ;
@muhammed.ihsan copy and paste this one:
find /opt/appdata/ -type f -exec sed -i 's/raw/processed/gi' {} \;
find /opt/appdata/ -type f -exec sed -i 's/yes/no/g' {} \;
@durgakumari813 - You have unicode single quotes in the above, so it won’t work as pasted.
Also best to quote {}
so no shell escape issues.
# Change all the occurrences of the word "yes" to "no"
find /opt/appdata -type f -name "*" -exec sed -i 's/\byes\b/no/g' "{}" \;
# Change all the occurrences of the word "raw" to "processed"
find /opt/appdata -type f -name "*" -exec sed -i 's/\braw\b/processed/ig' "{}" \;
Note in this the use of word boundary escapes \b
so that e.g. yesterday
will not be changed noterday
1 Like
Hi Alistair, thanks to give the solution.
I came here cause i couldn’t make the third task (delete files ending with t), and realize that also two first task was not completed.
I am trying to understand why it is necessary to become root before, I suppose that is the reason for my tasks don’t get done.
Thank you for your time.
Raul.
Hi @raul.souza
Some of the tasks depend on each other so it is important to do them in the correct order. We become root becuase the default user (bob) does not have write access to the /opt
directory, and /opt
should not have its default permissions as set by the operating system installation changed.
The complete solution to the challenge is here, with the steps to solve in the correct order, but you should only look if really stuck