shell - Move output of Find command unix


Im learning unix programming , i want to find all files whose size is greater than 1M an print them into a file.

here is my code

find. -size +1M -print0 | xargs -I -O '{}' mv '{}' files 

all sites i have found refer to this one as right one , but it does not work . currently im working on ubuntu

1 Answer: 

You mis-copied/mis-typed the commend from wherever you found it.

  1. The first {} is the argument to -I.

  2. -O is not an argument to xargs you meant -0 (to go with -print0).

  3. You missed the space between find and . (the current directory).

Which would get you:

find . -size +1M -print0 | xargs -0 -I '{}' mv '{}' files

That being said you don't need xargs here at all since find can execute commands directly.

find . -size +1M -exec mv {} files \+

And it is generally a good idea to test a complicated find command before you run it.

Using find . -size +1M by itself will just print the matching files.


find . -size +1M -ok mv {} files \+

will cause find to prompt you before each execution of the command.


More Articles

bash - How does the keyword “if” test if a value is true or false?

In bash scriptif [ 1 ]then echo "Yes"else echo "No"fiOutput: YesIt represents that '1' is treated as true value.But in code:word = Linuxletter = nuxiif echo "$word" | grep -q "$letter"then echo "Yes"else echo "No"fiOutput: NoBut echo "$word" | grep -q "$letter" will return 1, so why is the

linux - diff command to get number of different lines only

Can I use the diff command to find out if two of files differ by k lines?I don't want the contextual difference, just the total number of lines that are different between two files. Best if the result is just a single integer.

bash - append text to file using shell from php

I trying to append passed text as parameter to file using shell scriptthis is the code of shell echo $1>>/etc/freeradius/mods-enabled/ldapthis shell will get the text to add it to the file ldap in /etc/freeradius/mods-enabled path , I call this shell in this format # sh /etc/ hello

ubuntu - Shell command to get remote system's ip address from its mac address?

I have the HWAddress of remote machine but its IP address is not static and keeps changing. How do I get its IP address through shell?Relevant questions mostly have the remote system in the same network, but in my case its not.EDIT: I know its IP range.

Get Python command line output when called from a bash script

This may be a super simple question. I am calling a Python script on an Lubuntu OS (Cubietruck) via a shell script. This is to automate the process on start up (I want to maintain this process). Is there a simple way to view the output from Python? At the moment the Python script runs in the backgro

node.js - Not able to run my node app at port 80 on ubuntu 16.04

I want to run my node app at port 80 in ubuntu 16.04. But the moment I'm trying to run my app with npm start its throwing error Port in already in use whereas it's not in use. According to Github Reply, We need root privileges to run on ports below 1048 which is correct.So the moment I'm trying to r

ruby on rails - tmux: are my other terminals still running?

I have started using a certain technique for launching my web code since I switched server setups. I type tmuxsudo startserverrailsCtrl+B then DThen to reboot I type tmuxsudo killall rubysudo startserverrailsCtrl+B then DMy questions are: when I kill the ruby, does that end the session that I starte

php - How to redirect everything after slash to domain before?

This is what I'm trying to do:I want{whatever} redirected to{whatever}. For example, should be redirected to if there is nothing after /car/, then just leave it as that. How can i do that in .htaccess ?

node.js - Querying multiple sensors regularly using NodeJS

I need to fetch the values of about 200 sensors every 15 seconds or so. To fetch the values I simply need to make an HTTP call with basic authentication and parse the response. The catch is that these sensors might be on slow connection so I need to wait at least 5 seconds for one sensor (but usuall

Shell script - convert Excel (xlsx) to CSV - remove blank space / tab space

I receive excel file (xslx) with multiple sheets for my project. The number of records on these sheets ranges from 15k to 70k per sheet. I need to perform following tasks on this data and then convert it to CSV. Or covert to CSV and then process the data either way its fine.Input Example:call_no un