LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-08-2017, 12:22 PM   #1
chtsalid
Member
 
Registered: Jan 2017
Posts: 69

Rep: Reputation: Disabled
Find files greater than 100MB and store a list of their names in a file


Hi guys,

I am trying to figure out how to do the following:

Use the appropriate command to locate all files on your server that have a size greater than 100MB and store a list of their names in the file /root/bigfile.

To do this I executed the following command

find -type f -size +100M >> /root/bigfile

but it gives me not only the name of the files but the full path


[root@localhost ~]# cat bigfile
./proc/kcore
./usr/lib/locale/locale-archive
./proc/kcore
./usr/lib/locale/locale-archive

is there a way to copy only the name of the files?

Many thanks!
 
Old 01-08-2017, 12:46 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Have a look at the -printf option
 
1 members found this post helpful.
Old 01-08-2017, 12:52 PM   #3
agillator
Member
 
Registered: Aug 2016
Distribution: Mint 19.1
Posts: 419

Rep: Reputation: Disabled
Check the man page for find, the -printf option. The format I think you are looking for would be -printf "%f\n".
 
1 members found this post helpful.
Old 01-08-2017, 01:16 PM   #4
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
Something like this comes to my mind:
Code:
find . -type f -size +5M -exec basename {} \;
but the printf solution is probably better (?).

Another option to get the basename is parameter expansion (probably doesn't make sense in this case, just saying it is an option in general):
http://mywiki.wooledge.org/BashFAQ/0...meterExpansion
 
1 members found this post helpful.
Old 01-08-2017, 03:01 PM   #5
chtsalid
Member
 
Registered: Jan 2017
Posts: 69

Original Poster
Rep: Reputation: Disabled
Thank you guys,

i tried the command with the printf

[root@localhost proc]# find / -type f -size +100M -printf "%f\n"
kcore
find: ‘/proc/17083/task/17083/fdinfo/6’: No such file or directory
find: ‘/proc/17083/fdinfo/6’: No such file or directory
locale-archive
 
Old 01-09-2017, 03:09 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Unless you have further requirements / questions, please mark as SOLVED now that you have a solution
 
Old 01-09-2017, 04:50 AM   #7
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
Hint: look at -xdev option in: man find (or web-search: find xdev proc)
Also, study shell redirection of stderr to 'the bit bucket': 2>/dev/null

Best wishes on your Linux journey! Remember to 'search first' Here's book info...
 
Old 01-09-2017, 06:19 AM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by chtsalid View Post
Code:
/proc/kcore
You know you should never attempt to manipulate this file, correct?
 
Old 01-09-2017, 06:31 AM   #9
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,307
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Quote:
Originally Posted by chtsalid View Post
i tried the command with the printf
The option -prune is harder to figure out but you should look at it, too. It's useful in telling find to skip directories, such as /proc
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to search for list of files with same names as untar'd file and do a diff? Batistuta_g_2000 Linux - Newbie 4 03-23-2013 09:45 AM
[SOLVED] Create populated files with unique file names from a list geokker Linux - Server 6 05-16-2012 03:50 PM
bash script for listing all users with emails greater than 100mb evil_empire Linux - Newbie 3 09-04-2009 12:27 PM
Store into a file the list of executable files of a system directory jianelisj Linux - Newbie 3 03-17-2008 12:26 PM
Need to find if a matching file exist from a list of possible file names wit_273 Linux - General 5 10-25-2007 09:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration