How to find/cut for only the filename from an output of ls -lrt in Perl
You're making it harder for yourself by using -l
. This will do what you want
print((`ls -brt`)[0]);
But it is generally better to avoid shelling out unless Perl can't provide what you need, and this can be done easily
print "$_\n" for (sort { -M $a <=> -M $b } glob "*")[0];
How to display only files from aws s3 ls command?
You can't do this with just the aws
command, but you can easily pipe it to another command to strip out the portion you don't want. You also need to remove the --human-readable
flag to get output easier to work with, and the --summarize
flag to remove the summary data at the end.
Try this:
aws s3 ls s3://mybucket --recursive | awk '{print $4}'
Edit: to take spaces in filenames into account:
aws s3 ls s3://mybucket --recursive | awk '{$1=$2=$3=""; print $0}' | sed 's/^[ \t]*//'
Sort any random list of files by modification date
Your some_sorter_by_mtime
should be for example:
xargs stat -f "%m %N" | sort -n | cut -f2-
the idea behind is:
- print out file modification time and the filename
- sort the output numerically (so by modification time)
- cut out the time field
so,
find / -type f -print | xargs stat -f "%m %N" | sort -n | cut -f2-
Is there a way to get path/to/file with ls + awk, sed, grep or similar tools?
Have you tried find ./delete -type f -ls
(note the -ls
-- that's the key :-) )? You should then be able to pipe the results through awk
to filter out the fields you want.
Edit...
Another way you could do it is with a while loop, e.g.:
find ./delete -type f -ls | while read f1 blocks perms blocks owner group size mon day third file
do
echo `basename $file` `dirname $file`
done
and add the bits you need into that.
Unix shell script to sort files depending on the 'date string' present in their file name
one way with awk and sort:
ls -1|awk -F'[_.]' '{s=gensub(/^([0-9]{4})(.*)/,"\\2\\1","g",$3);print s,$0}'|sort|awk '$0=$NF'
if we break it down:
ls -1|
awk -F'[_.]' '{s=gensub(/^([0-9]{4})(.*)/,"\\2\\1","g",$3);print s,$0}'|
sort|
awk '$0=$NF'
the ls -1
just example. I think you have your way to get the file list, one per line.
test a little bit:
kent$ echo "SSA_F13_12142012.request.done
SSA_F12_05122013.request.done
SSA_F14_01062013.request.done"|awk -F'[_.]' '{s=gensub(/^([0-9]{4})(.*)/,"\\2\\1","g",$3);print s,$0}'|
sort|
awk '$0=$NF'
SSA_F13_12142012.request.done
SSA_F14_01062013.request.done
SSA_F12_05122013.request.done
Related Topics
Debian Sources.List.D Versus Sources.List
Why Does Sed Leave Many Files Around
How to Read The Password from The Text File in Perl
Brother Ql-720Nw Specifying Media Size Seems Ignored
Git Clone Repository in a Specific Folder But Keep Default Folder Name
How to Search The Content of a PDF File in Linux Shell Script
How to Run a Binary File That Is Mach-O Executable I386 on Linux
Bash - While Read Line from File Print First and Second Column
How to Install Vsftpd on Centos 6
How to Make Webdriver Testsuite Created in Windows Machine to Run in a Linux Box
Hide Information During Bash Debug Run
How to Have Chef Reload Global Path
Arduino Upload Error "Stk500_Recv(): Programmer Is Not Responding" in Fedora
Multi-Architectural Binary Rpm and The Noarch
Parallel Processes: Appending Outputs to an Array in a Bash Script