what is exactly doing rm -r * - command-line-arguments

Is someone can tell me what is exactly doing rm -r *
is it deleting all files and sub directory from current directory ?
or does it delete all the files on the machine ?

Deletes them all from the current directory, so it depends where you are at the time.
Do
pwd
to find out where you are - for example:
mark2#laptop-ubuntu:~$ pwd
/home/mark2
If I do it here, it'll delete everything under /home/mark2.

Related

Accidentally ran the wrong command in mac terminal. What does mv * .. do?

I accidently ran command
mv * ..
instead of
mv * .
on my mac. Now I cannot find the files. What did the command do?
.. is the parent directory, i.e. the directory one level higher in the hierarchy. For example, if you are in the directory /a/b/c/, then .. means /a/b/.
mv * . doesn't make any sense - you can't move files onto themselves.
The mv command stands for move. You moved your files to the directory above where they were located. You can always type
man mv
to get a description of a unix command.

Moving files older than 1 hour from one directory to another - AIX

I am trying to move files older than one hour, which are being populated almost every minute very rapidly to another folder whose name specifies the particular hour, in aix.
The script i was trying to run is:
find /log/traces/ -type f -mmin +59 -exec mv '{}' /Directory \;
The above script gives me an error:
find: bad starting directory
I am a newbie to shell scripting.
Any help will be highly appreciated.
------------------Edited-----------------------
I have been able to move the files older than 1 hour, but if the specified folder does not exist, it creates a file with the name specified in command and dumps all the files in it. The script i am running now is:
find /log/traces -type f -mmin +59 -exec mv '{}' /Directory/ABC-$(date +%Y%m%d_%H) \;
It creates a file named ABC-[Current hour]. I want to create a directory and move all the files into it.
If you are not running as a root user you may be getting this problem because of read permissions on /log/traces/.
To see the permission level of this directory run ls -l /log/traces/ the left most column will display something like this drwxr-xr-x which is an explanation of what permission settings that directory has. To understand more read this.
You need to ensure the user you are executing your command as has read access to /log/traces/ - that should fix your error.
Does the directory /Directory- (Timestamp) exist before the script exist? I am guessing the directory is not there to move the files. Make sure the directory exists before you start moving.
You can create a shell script for moving the files that will take the target directory as a parameter along with the file name. Tf the target directory does not exist the script creates the directory. After that script will execute mv command to move the file to the target directory.
Don't bother moving the files, just create them in the right folder directly. How?
Let crontab run each hour and create a dir /Directory/ABC-$(date +%Y%m%d_%H).
And now make a symbolic link between /log/traces and the new directory.
When the link /log/traces already exists, you must replace the link (and not make a link in a subdir).
newdir="/Directory/ABC-$(date +%Y%m%d_%H)"
mkdir -p "${newdir}"
ln -snf "${newdir} /log/traces
The first time you will need to mv /log/traces /log/traces_old and make the first link during a small moment that no new files are created.
Please test first with /log/testtraces first, checking the correct rights for the crontab user.

How to delete the files present in a directory

I have a folder in my directory called input_files which contains the list of input files. I am trying to delete the contents of this folder using the below command but getting I'm getting an error.
find /u/users/kisri1/scripts/design_matrix/input_files* -type f -delete
Error:
/u/users/kisri1/scripts/design_matrix/input_files: Is a directory
Please help to solve this thing. I want to write a shell script which can access the folder and delete the files.
rm is perfect in your case.
rm -rf /u/users/kisri1/scripts/design_matrix/input_files/* would do the trick and delete all files in your input_files directory without discrimination.
use the lines:
cd /u/users/kisri1/scripts/design_matrix/input_files
rm *
this will delete all files in the directory

Remove the recursive directory in Unix ( Unlimited Child Directories )

How to delete the recursive directory in Solaris.
Directory Structure : SourceCode/unit_test_cases.
The command
cp -rf SourceCode/ SourceCode/unit_test_cases/ : created a recursive directory.
Directory Structure looks like below
SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/SourceCode/unit_test_cases/
I know "rm -rf SourceCode" is to delete recursively. But this command gives the error File Name too long. This is due to unlimited child directories recursively created.
So am not able delete the directories.
I tried this in Ubuntu, It is smart that it determines the cyclic recursion and breaks # some depth, But Solaris seems to be dumb in this case.
Can anybody help me
It is simply
rm -rf PATHS
where PATHS is one or more PATH to be removed (it's enough SourceCode if you want to remove that dir completely).
Try this
rm -r <your directory>
and be careful of what you are deleting.

Remove file from different directory

How do I remove certain files from a different directory than $PWD using the bash shell script.
Looking at the documentation for rm, it appears that rm only works in $PWD.
Am I forced to use this method:
oDir=$PWD
cd directorytoremovefiles
rm files
cd oDir
rm certainly does work for deleting files in another directory.
Whatever gave you that idea from the man page, I certainly hope it's not this:
rm removes each specified file. By
default, it does not remove
directories.
The documentation you refer to, talks only about having write & execute permission to the directory you are deleting from.
So you only need:
rm directorytoremovefiles/files
As pointed out by YYC,
rm $DIR/files
rm will take any path, relative or absolute. If there is no slash at the beginning of directorytoremovefiles then it is a relative path and you may need to store PWD for later. However, you can do this with pushd and popd or a cd - once you're finished. Or, if you run the cd and rm commands in parens they will run in a subshell, like this: ( cd directory; rm files) then your working shell will not change directory.

Resources