Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Linux find command returns nothing Post 303005247 by dakelly on Monday 16th of October 2017 08:16:16 AM
Old 10-16-2017
Quote:
Originally Posted by Home
Actually, I'm working with a shell code so that it removes files older than 32 days in current directory(and not in subdirectories).

Here is my code, first I try to test my program by finding the right files and then add remove command:

Code:
#!/bin/sh 

for filename in /home/linux/txt/output/ABC_DEFGH*
do 
if test 'find .  maxdepth 1 -type f -name "ABC_DEFGH*" -mtime +32'; then 

#remove command should be here***

fi 

done 

exit 0

How can I add 'remove' command with propper options(I'm new in Linux)? Any suggestion?
I have a script that does something similar, and this is what I use, but mine is older than 15 days.. only changed to your search name terms.
you might want to keep your maxdepth, and change your length of days

Code:
find . -name "ABC_DEFGH*" -mtime +15 | xargs -i rm {}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

cant find command that returns blank line

This is my list of sed commands: can anyone tell me where im going wrong. The script works on a file called data which contains 6 student id's and there answers for 6 questions. !/bin/sh sed -e 's/*//g' \ #replace * with nothing -e s/ /X/g' \ #replacing empty space with X -e... (2 Replies)
Discussion started by: jeffersno1
2 Replies

2. Shell Programming and Scripting

FIND returns different results in script

When I execute this line at the command prompt I get a different answer than when I run it in a script? Any ideas on how to resolve? I'm trying to find all files/dir in a directory except files that start with the word file. Once I get this command to work, I will add the "delete" part to the... (6 Replies)
Discussion started by: blt123
6 Replies

3. UNIX for Dummies Questions & Answers

find command returns files with spaces, mv won't work...

Hi guys. I am trying, to move files found with the find command... Script runs fine, until it reaches a file that contains spaces... Here is what i wrote up quickly. ROOTDIR=/apps/data SEARCH=$(find /data/HDTMPRestore/home/tmq/ -type f -print | grep Mods/Input/bck | cut -c19-) for i... (1 Reply)
Discussion started by: Stephan
1 Replies

4. UNIX for Dummies Questions & Answers

ascii FTP from Linux to Linux adding carriage returns

Hi, I've got an issue with a shell script that FTP's a file from one Linux server to another Linux server. My script runs on a Linux server and creates an output file (from a database call), and then FTP's this file to another Linux server. The problem is that, even though the output file... (0 Replies)
Discussion started by: roysterdoyster
0 Replies

5. Shell Programming and Scripting

How to check if a command returns nothing

Hi, I want to write a script that runs a command (at -l) and writes the output to a file. If the command (at -l) command returns no value (is empty/null) then write a message to the file in place of the command output. My problem is around trapping the empty returned command value and replacing... (2 Replies)
Discussion started by: Alvescot
2 Replies

6. UNIX for Dummies Questions & Answers

echo statement when find returns null

Hi, How do you echo something once when a find statement returns null results? This is when using mutiple locations and mutiple arguments. The below find command the inner loop of a nested for loop where the outter loop holds the $args and the inner loop holds the locations. find... (2 Replies)
Discussion started by: tchoruma
2 Replies

7. Shell Programming and Scripting

find/grep returns no matches

Hi all! I've faced with very unintelligible error using find/grep like this: root@v29221:~# find /var/www/igor/data/www/lestnitsa.ru | grep u28507I get nothing as a result, but: root@v29221:~# grep u28507 /var/www/igor/data/www/lestnitsa.ru/_var.inc $db_name = 'u28507';... (2 Replies)
Discussion started by: ulrith
2 Replies

8. Linux

help in find command in linux

I am trying to find pictures which contains a specific word in the file name. For example any .JPG files that contains "lm" at the beginning or at the middle or at the end of the file name. find / -iname "*.jpg" | ...what should go after the pipe? regards, Moaathe (2 Replies)
Discussion started by: kidwai
2 Replies

9. Shell Programming and Scripting

rm -rf ab returns find: `./ab': No such file or directory

Hi Gurus. This is driving me a bit batty. I now if must be a simple matter but I cant find anything that references it. I have a housekeeping script that searches for some huge dump directories then removes them using rm -rf. find ./ -name 'ab' -exec rm -rf {} \; This works but always... (7 Replies)
Discussion started by: rinser
7 Replies

10. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies
GIT-RM(1)							    Git Manual								 GIT-RM(1)

NAME
       git-rm - Remove files from the working tree and from the index

SYNOPSIS
       git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...

DESCRIPTION
       Remove files from the index, or from the working tree and the index. git rm will not remove a file from just your working directory. (There
       is no option to remove a file only from the working tree and yet keep it in the index; use /bin/rm if you want to do that.) The files being
       removed have to be identical to the tip of the branch, and no updates to their contents can be staged in the index, though that default
       behavior can be overridden with the -f option. When --cached is given, the staged content has to match either the tip of the branch or the
       file on disk, allowing the file to be removed from just the index.

OPTIONS
       <file>...
	   Files to remove. Fileglobs (e.g.  *.c) can be given to remove all matching files. If you want Git to expand file glob characters, you
	   may need to shell-escape them. A leading directory name (e.g.  dir to remove dir/file1 and dir/file2) can be given to remove all files
	   in the directory, and recursively all sub-directories, but this requires the -r option to be explicitly given.

       -f, --force
	   Override the up-to-date check.

       -n, --dry-run
	   Don't actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.

       -r
	   Allow recursive removal when a leading directory name is given.

       --
	   This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for
	   command-line options).

       --cached
	   Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.

       --ignore-unmatch
	   Exit with a zero status even if no files matched.

       -q, --quiet
	   git rm normally outputs one line (in the form of an rm command) for each file removed. This option suppresses that output.

DISCUSSION
       The <file> list given to the command can be exact pathnames, file glob patterns, or leading directory names. The command removes only the
       paths that are known to Git. Giving the name of a file that you have not told Git about does not remove that file.

       File globbing matches across directory boundaries. Thus, given two directories d and d2, there is a difference between using git rm 'd*'
       and git rm 'd/*', as the former will also remove all of directory d2.

REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEM
       There is no option for git rm to remove from the index only the paths that have disappeared from the filesystem. However, depending on the
       use case, there are several ways that can be done.

   Using "git commit -a"
       If you intend that your next commit should record all modifications of tracked files in the working tree and record all removals of files
       that have been removed from the working tree with rm (as opposed to git rm), use git commit -a, as it will automatically notice and record
       all removals. You can also have a similar effect without committing by using git add -u.

   Using "git add -A"
       When accepting a new code drop for a vendor branch, you probably want to record both the removal of paths and additions of new paths as
       well as modifications of existing paths.

       Typically you would first remove all tracked files from the working tree using this command:

	   git ls-files -z | xargs -0 rm -f

       and then untar the new code in the working tree. Alternately you could rsync the changes into the working tree.

       After that, the easiest way to record all removals, additions, and modifications in the working tree is:

	   git add -A

       See git-add(1).

   Other ways
       If all you really want to do is to remove from the index the files that are no longer present in the working tree (perhaps because your
       working tree is dirty so that you cannot use git commit -a), use the following command:

	   git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached

SUBMODULES
       Only submodules using a gitfile (which means they were cloned with a Git version 1.7.8 or newer) will be removed from the work tree, as
       their repository lives inside the .git directory of the superproject. If a submodule (or one of those nested inside it) still uses a .git
       directory, git rm will move the submodules git directory into the superprojects git directory to protect the submodule's history. If it
       exists the submodule.<name> section in the gitmodules(5) file will also be removed and that file will be staged (unless --cached or -n are
       used).

       A submodule is considered up to date when the HEAD is the same as recorded in the index, no tracked files are modified and no untracked
       files that aren't ignored are present in the submodules work tree. Ignored files are deemed expendable and won't stop a submodule's work
       tree from being removed.

       If you only want to remove the local checkout of a submodule from your work tree without committing the removal, use git-submodule(1)
       deinit instead. Also see gitsubmodules(7) for details on submodule removal.

EXAMPLES
       git rm Documentation/*.txt
	   Removes all *.txt files from the index that are under the Documentation directory and any of its subdirectories.

	   Note that the asterisk * is quoted from the shell in this example; this lets Git, and not the shell, expand the pathnames of files and
	   subdirectories under the Documentation/ directory.

       git rm -f git-*.sh
	   Because this example lets the shell expand the asterisk (i.e. you are listing the files explicitly), it does not remove
	   subdir/git-foo.sh.

BUGS
       Each time a superproject update removes a populated submodule (e.g. when switching between commits before and after the removal) a stale
       submodule checkout will remain in the old location. Removing the old directory is only safe when it uses a gitfile, as otherwise the
       history of the submodule will be deleted too. This step will be obsolete when recursive submodule update has been implemented.

SEE ALSO
       git-add(1)

GIT
       Part of the git(1) suite

Git 2.17.1							    10/05/2018								 GIT-RM(1)
All times are GMT -4. The time now is 08:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy