Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make command run in Ubuntu 13.10 as soon as I login. I know for that I have to add certain command in ~/.profile file. That's not the problem.

I want to certain line of that ~/.profile file to be deleted and to be restored in it's original state. I want to perform that task just one time, so any help regarding that issue would be appreciated.


I'm attempting to run sudo startx as soon as I login. I've found that using that command gives me a GUI temporarily. But, to open some file with a GUI, I need to use gnome-open <file path>.

share|improve this question

closed as unclear what you're asking by jasonwryan, Chris Down, slm, terdon, Anthon Nov 16 '13 at 5:50

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Can you explain what you want more? Just the line deleted or all the lines leading up to this one? – slm Nov 16 '13 at 3:45
Hmm. This smells like script kiddie to me. Why do you need to do this? – ire_and_curses Nov 16 '13 at 3:56
Please demonstrate basic understanding of shell commands or file manipulation so we know what further research to recommend. – dg99 Nov 16 '13 at 5:01
@slm I just want to delete just the line. I want to delete the command line that were added later. It would be last 3 lines of .profile file. – Habi Nov 16 '13 at 5:14
Habi, there's no need to get vulgar, his point is a legit one. Without more background on what you're up to, this sounds fishy to me as well. Please keep it cordial! – slm Nov 16 '13 at 5:19
up vote 2 down vote accepted

If you're always interested in deleting the last 3 lines of a file you can simply do this using head.

$ head -n -# ex.txt


Example file.

$ cat ex.txt 

Drop the last 3 lines:

$ head -n -3 ex.txt 

Do this and save it to the same file.

$ head -n -3 ex.txt | tee ex.txt 

Confirm update was applied to file ex.txt.

$ cat ex.txt 
share|improve this answer
Thanks. It worked. – Habi Nov 16 '13 at 7:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.