Syntax help to delete some files from a directory on Centos
Hi
I have a folder : Code:
/usr/local/src/myfolder Now i want to delete from this folder the files named: Code:
file1.txt How is the correct syntax for this? If it is possible to not use cd /usr/local/src/myfolder and then rm -r .... so i can run it from everywhere .... Thanks |
rm -i /usr/local/src/myfolder/filename
|
You mean like this?
Code:
rm -i /usr/local/src/myfolder/file1.txt image.jpg info.html another.txt |
Quote:
Therefore if you want to delete all those files using a single command you'll have to execute: Code:
rm -i /usr/local/src/myfolder/file1.txt /usr/local/src/myfolder/image.jpg /usr/local/src/myfolder/info.html /usr/local/src/myfolder/another.txt Meaning: let's say that in your current directory you have 2 files called "something1.txt" and "something2.jpg". When you issue the command "rm *" to wipe out everything from your current directory, the "shell" (maybe the "bash" shell in your case?) interprets the "*" character BEFORE the command is executed and replaces it by all the filenames that are present in your current directory. Therefore, when the command is executed, it is executed by running "rm something1.txt something2.jpg" and not as "rm *". This is a little bit linked to what you were asking. |
Three basic options
Code:
cd /usr/local/src/myfolder Code:
rm /usr/local/src/myfolder/file1.txt /usr/local/src/myfolder/image.jpg /usr/local/src/myfolder/info.html /usr/local/src/myfolder/another.txt Code:
rm /usr/local/src/myfolder/{file1.txt,image.jpg,info.html,another.txt} |
How can avoid asking me for deleting each file on the third command that you post?
Code:
rm /usr/local/src/myfolder/{file1.txt,image.jpg,info.html,another.txt} |
Quote:
|
or also you can try /bin/rm /usr/local/src/myfolder/{file1.txt,image.jpg,info.html,another.txt} (also please check man page about usage)
|
All times are GMT -5. The time now is 08:04 PM. |