Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-07-2010, 01:29 AM   #1
Registered: Oct 2005
Location: Bangladesh
Posts: 498

Rep: Reputation: 30
How to truncate a file and disconnect a session !

Dear Friends,

I have two questions :

1) Is it possible to truncate the file content , not to drop the file ? i.e, I want to just delete a file's content only, not to drop the file .

2) I can find the connectd user using command 'w' or 'who' . Now How can I force disconnect a session from the list of 'w'/'who' command ?

Waiting for kind reply ... ...
Old 10-07-2010, 01:51 AM   #2
Senior Member
Registered: Feb 2008
Location: Pune - India
Distribution: RHEL/Ubuntu/Debian/Fedora/Centos/K3OS
Posts: 1,151
Blog Entries: 4

Rep: Reputation: 147Reputation: 147
1. echo > file1
2. If user is connected via ssh :
Do "kill <pid>" where pid is any process from their session (found by typing 'w')
ps -ax to find the pid of the sshd session, and kill it.
for i in `ps aux | grep user | grep -v grep | awk '{print $2}'`; do kill -9 $i; done;


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
scp truncate text file busy - copying file is not a running binary jetberrocal Linux - Server 3 06-24-2010 03:56 PM
Solais 10 ssh session disconnect randomly LinuxLover Solaris / OpenSolaris 3 02-25-2010 05:05 PM
Session disconnect causes thread freeze brodsky99 Linux - Newbie 1 10-07-2008 08:13 PM
Session Disconnect fuldagap Linux - General 0 11-15-2005 10:11 PM
Truncate A File Dovetails Linux - Newbie 2 10-22-2005 06:58 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:48 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration