Sponsored Content
Top Forums Shell Programming and Scripting find command in while loop - how to get control when no files found? Post 302181586 by mavsman on Thursday 3rd of April 2008 11:44:28 AM
Old 04-03-2008
thanks for the posts Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitoring a directory for new files with .xx and executing command if found

Hi Guys. I am a complete shell scripting newbie with some syntax and commands understanding. I'm more of a win admin. With that said: I need to write a shell script to monitor a directory '/Mon_Dir' for new occurrences of files with .xx extension. Once a new file is detected in the directory, a... (4 Replies)
Discussion started by: krkan
4 Replies

2. Shell Programming and Scripting

Help with find command and list in a long format each found file

The purpose of those comands are to find the newest file in a directory acvrdind to system date, and it has to be recursively found in each directory. The problem is that i want to list in a long format every found file, but the commands i use produce unexpected results ,so the output lists in a... (5 Replies)
Discussion started by: alexcol
5 Replies

3. Shell Programming and Scripting

print as well as count the files found by find command

I want the output of the find command to be printed and also the total files found by it. Can someone help in this. Obviously $ find . -type f | wc -l will not output the files found but only the count. I want both. There can be millions and trillions of files so dont want the output of find... (3 Replies)
Discussion started by: amicon007
3 Replies

4. Shell Programming and Scripting

Loop through found files

Hi I am trying to write a script which will loop through all files that end in ".txt" and ask user if they want to delete the file or not #this print out all files dir=/root/etc/ find $dir -name "*.txt" output: 1.txt 2.txt etc but what i really want is 1.txt delete(Y/N): 2.txt ... (11 Replies)
Discussion started by: Calypso
11 Replies

5. Shell Programming and Scripting

Renaming of files with different extensions on the same path to .found with the help of loop

hi , I have certain files at the same path with differeent extensions like .dat , .txt etc ...........i need to rename them with extension .found at the same path with the help of loop.... also the files names will be like this ; abc_2010_c1.dat abc_2010_c2.dat xyz_2010_c1.txt (2 Replies)
Discussion started by: amitpta
2 Replies

6. Shell Programming and Scripting

find with xargs to rm found files

I believe what is happening is rm is executing in the script on every directory and on failure of the first it stops although returns status 0. find $HOME -name /directory/filename | xargs -l rm This is the code I use but file remains. I am using sun solaris system which has way limited... (4 Replies)
Discussion started by: Ebodee
4 Replies

7. UNIX for Dummies Questions & Answers

find command in for loop

i have executed the following command in terminal find /Users/vasu -name "*.txt" -print and i am getting the result /Users/vasu/file1.txt /Users/vasu/file2.txt /Users/vasu/file3.txtbut while i was trying to execute the same in the script it is not working,I tried with below logic in... (2 Replies)
Discussion started by: vmachava
2 Replies

8. Shell Programming and Scripting

while loop error. (command not found)

can any1 please tell me what is problem with following code: i=1; cat test| while read CMD; do Var$i=$CMD; or Var$i=$(echo $CMD) ; let i++ doneI keep getting error : line 4: Var1=sometext: command not found (2 Replies)
Discussion started by: kashif.live
2 Replies

9. Shell Programming and Scripting

"Command not found" doing a while loop in bash/shell

i=0 numberofproducts=${#urls} #gets number of entries in array called "urls" numberofproductsminusone=`expr $numberofproducts - 1` #-subtract by one while do wget ${urls} i=$(( $i + 1 )) sleep 10 done I'm getting an error ./scrape: line 22: [0: command not found that... (3 Replies)
Discussion started by: phpchick
3 Replies

10. Shell Programming and Scripting

Assistance with my Find command to identify last part of a file name and report the name found

Hello Forum, We have two bootstraps of Chef in our environment which are identified by colour: /var/chef/cache/cookbooks/bootstrap_cookbooks_version_green and /var/chef/cache/cookbooks/bootstrap_cookbooks_version_red I'm attempting to identify which version is installed based on the name... (11 Replies)
Discussion started by: greavette
11 Replies
LOSETUP(8)                                                     System Administration                                                    LOSETUP(8)

NAME
losetup - set up and control loop devices SYNOPSIS
Get info: losetup [loopdev] losetup -l [-a] losetup -j file [-o offset] Detach a loop device: losetup -d loopdev... Detach all associated loop devices: losetup -D Set up a loop device: losetup [-o offset] [--sizelimit size] [--sector-size size] [-Pr] [--show] -f|loopdev file Resize a loop device: losetup -c loopdev DESCRIPTION
losetup is used to associate loop devices with regular files or block devices, to detach loop devices, and to query the status of a loop device. If only the loopdev argument is given, the status of the corresponding loop device is shown. If no option is given, all loop devices are shown. Note that the old output format (i.e., losetup -a) with comma-delimited strings is deprecated in favour of the --list output format. It's possible to create more independent loop devices for the same backing file. This setup may be dangerous, can cause data loss, corrup- tion and overwrites. Use --nooverlap with --find during setup to avoid this problem. OPTIONS
The size and offset arguments may be followed by the multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g., "K" has the same meaning as "KiB") or the suffixes KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB and YB. -a, --all Show the status of all loop devices. Note that not all information is accessible for non-root users. See also --list. The old output format (as printed without --list) is deprecated. -d, --detach loopdev... Detach the file or device associated with the specified loop device(s). Note that since Linux v3.7 kernel uses "lazy device destruc- tion". The detach operation does not return EBUSY error anymore if device is actively used by system, but it is marked by autoclear flag and destroyed later. -D, --detach-all Detach all associated loop devices. -f, --find [file] Find the first unused loop device. If a file argument is present, use the found device as loop device. Otherwise, just print its name. --show Display the name of the assigned loop device if the -f option and a file argument are present. -L, --nooverlap Check for conflicts between loop devices to avoid situation when the same backing file is shared between more loop devices. If the file is already used by another device then re-use the device rather than a new one. The option makes sense only with --find. -j, --associated file [-o offset] Show the status of all loop devices associated with the given file. -o, --offset offset The data start is moved offset bytes into the specified file or device. --sizelimit size The data end is set to no more than size bytes after the data start. -b, --sector-size size Set the logical sector size of the loop device in bytes (since Linux 4.14). The option may be used when create a new loop device as well as stand-alone command to modify sector size of the already existing loop device. -c, --set-capacity loopdev Force the loop driver to reread the size of the file associated with the specified loop device. -P, --partscan Force the kernel to scan the partition table on a newly created loop device. -r, --read-only Set up a read-only loop device. --direct-io[=on|off] Enable or disable direct I/O for the backing file. The optional argument can be either on or off. If the argument is omitted, it defaults to on. -v, --verbose Verbose mode. -l, --list If a loop device or the -a option is specified, print the default columns for either the specified loop device or all loop devices; the default is to print info about all devices. See also --output, --noheadings, --raw, and --json. -O, --output column[,column]... Specify the columns that are to be printed for the --list output. Use --help to get a list of all supported columns. -n, --noheadings Don't print headings for --list output format. --raw Use the raw --list output format. -J, --json Use JSON format for --list output. -V, --version Display version information and exit. -h, --help Display help text and exit. ENCRYPTION
Cryptoloop is no longer supported in favor of dm-crypt. For more details see cryptsetup(8). RETURN VALUE
losetup returns 0 on success, nonzero on failure. When losetup displays the status of a loop device, it returns 1 if the device is not configured and 2 if an error occurred which prevented determining the status of the device. FILES
/dev/loop[0..N] loop block devices /dev/loop-control loop control device EXAMPLE
The following commands can be used as an example of using the loop device. # dd if=/dev/zero of=~/file.img bs=1024k count=10 # losetup --find --show ~/file.img /dev/loop0 # mkfs -t ext2 /dev/loop0 # mount /dev/loop0 /mnt ... # umount /dev/loop0 # losetup --detach /dev/loop0 ENVIRONMENT
LOOPDEV_DEBUG=all enables debug output. AUTHORS
Karel Zak <kzak@redhat.com>, based on the original version from Theodore Ts'o <tytso@athena.mit.edu> AVAILABILITY
The losetup command is part of the util-linux package and is available from https://www.kernel.org/pub/linux/utils/util-linux/. util-linux November 2015 LOSETUP(8)
All times are GMT -4. The time now is 07:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy