so I have a line of code like this:
result=`find . -type f -size -1000c -print0 | xargs -0 ls -Sh | head`
for i in $result; do
item=`wc -c $i`
echo $item1
done
this will print out all the files in the current fold that are at most 1000bytes, it has the format like:
size_of the file ./name_of_the_file
but i want to get rid of the "./" symbol, so i try to use "cut"
i want to do something like:
for i in $result; do
item=`wc -c $i`
item1=`cut -f 1 $item` // this gives me the size
item2=`cut -c 7- $item` // this gives me all the character after ./
echo item1, item2 // now make it print
done
but i'm getting error like:
cut: 639: No such file or directory
can anyone please give me a hint on this? I appreciate it.
ls
. And use$()
instead of backticks to capture the output. Also, you are not givingcut
a file or pipe to process. You are giving it an argument$item
which is just a string, and apparently not a valid filename. You would need eitherecho "$item" | cut -f 1
orcut -f 1 <<<"$item"
. However,cut
is also tricky about the delimiters. See answers below for a proper solution.+1000c
instead of minus to get files larger than the limit?