LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-23-2014, 09:29 AM   #1
loadedmind
Member
 
Registered: Sep 2003
Location: Texas
Distribution: Red Hat/CentOS
Posts: 302
Blog Entries: 4

Rep: Reputation: Disabled
move files that match column 8 from ls


Hey all. As with most things in Linux, there are more than a few ways to skin a cat for a particular task. I'm just having trouble wrapping my brain around the best, most consistent approach to my dilemma.

Purpose: Move only those files that match 2013 from ls -la (column 8) to a different directory

We have some large files that need to get moved elsewhere because they're taking up disk space. Those files with 2013 in the 8th column only. So, I got to thinking, something like:

for i in $(ls -la | awk '{print $8}'); do mv $i /tmp/storage; done

But this, of course, merely strips that field and doesn't get the job done as the files themselves need to get moved.

Then, I thought:

cd /dir
find . -mount -type f | grep 2013 -exec mv {} /tmp/storage \;

but, because the files are so huge, I need to test before I verify results are what I want.

Then, maybe:

mv `ls -la | grep 2013` > /tmp/storage

but this has the disadvantage of ls not being so accurate.

Anyone have a better solution?

Last edited by loadedmind; 06-23-2014 at 12:22 PM.
 
Old 06-23-2014, 09:38 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Modification times between x and y:

Code:
find . -newermt 20130101 -not -newermt 20140101
 
2 members found this post helpful.
Old 06-23-2014, 10:47 AM   #3
loadedmind
Member
 
Registered: Sep 2003
Location: Texas
Distribution: Red Hat/CentOS
Posts: 302

Original Poster
Blog Entries: 4

Rep: Reputation: Disabled
Thanks sz. I think that'll do the trick nicely!

*Edit - Whoops. Looks like I don't have the -newermt switch for find. Anything else I might try? I need to keep the system as standardized as possible, FYI.

Last edited by loadedmind; 06-23-2014 at 12:23 PM.
 
Old 06-23-2014, 03:13 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Use "touch -t 201301010000 /tmp/stamp1" and "touch -t 201401010000 /tmp/stamp2" to create two timestamp files and then use "find . -newer /tmp/stamp1 ! -newer /tmp/stamp2 -type f" to select the files.

And yes, I realize that files with a modification time that exactly matches either of timestamps would be mishandled. Move each timestamp back one second if that concerns you.
 
1 members found this post helpful.
Old 06-23-2014, 03:58 PM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
No prob. In case rknichols comment doesn't help, can you provide the --help output of your 'find' command? The solaris ports and GNU versions will be quite different.
 
Old 07-14-2014, 10:29 AM   #6
loadedmind
Member
 
Registered: Sep 2003
Location: Texas
Distribution: Red Hat/CentOS
Posts: 302

Original Poster
Blog Entries: 4

Rep: Reputation: Disabled
find --help
Usage: find [path...] [expression]

default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions:

operators (decreasing precedence; -and is implicit where no others are given):
( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2
EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2

positional options (always true): -daystart -follow -regextype

normal options (always true, specified before other expressions):
-depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
--version -xdev -ignore_readdir_race -noignore_readdir_race

tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N
-cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
-ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
-links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
-nouser -nogroup -path PATTERN -perm [+-]MODE -regex PATTERN
-wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
-used N -user NAME -xtype [bcdpfls]
-context CONTEXT


actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print
-fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
-exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
-execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;

Report (and track progress on fixing) bugs via the findutils bug-reporting
page at http://savannah.gnu.org/ or, if you have no web access, by sending
email to <bug-findutils@gnu.org>.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to find match between two rows of column in same file using PERL genetist Linux - Newbie 3 07-13-2013 11:17 AM
[SOLVED] substring match in specific column udiubu Linux - Newbie 2 06-05-2012 05:29 AM
[SOLVED] Match codes in first column in 2 files and return data in other columns cgcamal Programming 12 09-30-2011 01:03 AM
[SOLVED] Replace content of one column to another if match found saurabhmehan Linux - Newbie 5 12-22-2010 12:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:14 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