Hot answers tagged files
Most people know of sed as a tool for search and regex-based search and replece, but it is a full editor capable of making edits. So You could issue a command like this. Which would insert (1 i) the first line of the ls command $(ls| head -1) into the list.txt file inplace (-i). sed -i "1 i$(ls| head -1)" list.txt
There is no native way to redirect to the first line of a file, but you could use a temporary file to achieve this anyway. For example, first append the output to list2.txt, then cat list.txt into it and write the entire output back to list.txt: ls > list2.txt cat list.txt >> list2.txt mv list2.txt list.txt That way you should end up with what ...
There's probably a more elegant way to do this but you could just use multiple files. For example: ls | head -n 1 > temp-list.txt cat list.txt >> temp-list.txt mv temp-list.txt list.txt
Only top voted, non community-wiki answers of a minimum length are eligible