• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to read file name which contains space?  RSS feed

 
Rahul Dhaware
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to read file name which contains space using command 'find'?

for example: 'abc 1234_temp.doc' this is file name on linux, i want to find this file name using linux cmd 'find'. but i got file name as abc.

can any one help me in that?
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find the file:but to process it properly you will need to use the -print0 option, and something like -0 (number zero) to xargs. For example:would pass all the filenames found in the arguments to xyz.Main, even with spaces or control characters in the names.
 
Rahul Dhaware
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Carey Evans for reply.

But i want different.

suppose i have a directory 'dirName' in linux.
in that there are two files with today's last modified timestamp.

dirName
|
|
---> new FileName1.txt
---> old File 100.txt

folder and files are as shown above.

and to get these files according to there last modifield timestamp i have written a small shell script as below:

for file in "$( /usr/bin/find /usr/dirName -type f -mtime 0 )"
do
cp -rf $file /home/BackupDirName
done


so i execute above script i got following errors:

cp: cannot stat `/usr/dirName/new': No such file or directory

Can any one help me to solve this problem?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12156
256
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way of handling this is to change your logic so you are piping the output of find through something that works on a line-by-line basis:



Regards, Andrew
 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also run the command from find:If this gets much more complicated, you should look into rsync.
 
Rahul Dhaware
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Andrew Monkhouse
It works fine.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!