+4 votes
in Operating Systems by (14.6k points)
Which Linux command should I use to delete the last row of a file?

1 Answer

+1 vote
by (17.8k points)

To delete the last row from a file, you can use the 'sed' command with 'd' and '$' options.

'$' - Match the last line

'd' -  Delete pattern space 

Use the following command:

sed -i '$d' file_name

$d should be inside the single quote ('). Without a single quote, the command will give an error. If you use a double quote ("), the command will not delete the last record.