0

I want to delete content of the file main_copy.json.

I have a confusion if I used below command, will it remove files in all these directories?

  [user@yyy ~]$ > /AAA/BBB/CCC/DDD/main_copy.json

1 Answer 1

1

The '>' character is the shell (often Bash) redirection character. You are at a command prompt of the shell, probably Bash but you don't specify. The command as you have written basically says "redirect <nothing> to the file /AAA/BBB/CCC/DDD/main_copy.json". The net result is to truncate the file to zero length, effectively deleting its contents.

Since there are no spaces in the argument to '>', bash treats it as a single argument, thus there is no possibility that your command will delete contents of any files in any of the directories in your path. In any case, the '>' redirect operator does not work with multiple arguments. So if you were to say:

[user@yyy ~]$ > /AAA /BBB/CCC/DDD/main_copy.json

The net effect would issue an error because you can't redirect to a directory, only to a file. If you were to say:

[user@yyy ~]$ > /AAA/myfile.txt BBB/CCC/DDD/main_copy.json

the shell would truncate the file myfile.txt to zero length, (or create a zero-length file if it did not exist) and then treat the second argument as an executable command, which of course would fail with something like "Permission Denied" because it's not an executable.

Hope that helps. Bash (and other shells) is a complicated beast and takes years to really learn well.

Sign up to request clarification or add additional context in comments.

1 Comment

I believe the answer was not answered. Just explained the command used. (And it was very clear). but... the question remains... >> Let's suppose I have a code in several files... (let's say it's a malicious code)... I need you to delete the code found in all PHP files... Just the code... And if possible a log with the report of these... It would be possible?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.