LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

Reply
 
Search this Thread
Old 12-01-2012, 04:02 PM   #1
Gloria
LQ Newbie
 
Registered: Feb 2009
Location: Iowa and Florida
Posts: 2

Rep: Reputation: 0
Question how to "defrag" with slow working Ubuntu Linux?


I've never learned how to "defrag" my computer since I installed Ubuntu Linux. Apparently Ubuntu uses different terminology. Any suggestions?
 
Old 12-01-2012, 04:35 PM   #2
John VV
Guru
 
Registered: Aug 2005
Posts: 12,901

Rep: Reputation: 1713Reputation: 1713Reputation: 1713Reputation: 1713Reputation: 1713Reputation: 1713Reputation: 1713Reputation: 1713Reputation: 1713Reputation: 1713Reputation: 1713
that is a Microsoft concept and problem
the file systems used in linux OS's do not need to be "defraged"
 
Old 12-01-2012, 08:52 PM   #3
frankbell
Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Mageia, Mint
Posts: 7,712

Rep: Reputation: 1458Reputation: 1458Reputation: 1458Reputation: 1458Reputation: 1458Reputation: 1458Reputation: 1458Reputation: 1458Reputation: 1458Reputation: 1458
To expand on what John_VV said, most Linux file systems, such as ext3 and ext4, handle defragging automatically without user intervention and keep file fragmentation under control.

This article gives a pretty good explanation of how this works:

http://www.howtogeek.com/115229/htg-...defragmenting/
 
Old 12-01-2012, 09:19 PM   #4
k3lt01
Senior Member
 
Registered: Feb 2011
Location: Australia
Distribution: Debian Wheezy, Jessie, Sid/Experimental, playing with LFS.
Posts: 2,680

Rep: Reputation: 558Reputation: 558Reputation: 558Reputation: 558Reputation: 558Reputation: 558
This question was asked recently by another member. Here is the particular thread.
 
1 members found this post helpful.
Old 12-02-2012, 02:53 AM   #5
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
Quote:
Originally Posted by John VV View Post
that is a Microsoft concept and problem
the file systems used in linux OS's do not need to be "defraged"
You know I used to think that, but I have found it not to be true.

Try using 'filefrag' to determine the number of extents of files on the filesystem. The fragmentation can get into the thousands of extents and can really slow down performance. There exist a number of scripts and programs to defragment files on Linux (I'm not sure which ones are maintained) and I have also written my own script:

defrag:
Code:
#!/bin/sh
# finds fragmented files

error() # error
{
	echo "ERROR: $1"
	exit 1
}

# make sure we are root
if test ~ != /root
then
	error 'you must be root in order to run this script'
fi

# make sure we have less than 1 argument
if test $# -gt 2
then
  echo "Usage: $(basename $0) option"
  echo 'option can be:'
  echo 'find'
  echo 'defrag [threshold]'
  # fail
  exit 1
fi

# places
dir=/root/.defrag
output="$dir"/output
sorted="$dir"/sorted
defrag="$dir"/defrag
tempdir=/tmp/defrag

# vars
thres=5

if test "$1" = "find"
then
	# generate cleanly
	if test ! -d "$dir"
	then
		rm -f "$dir"
		mkdir "$dir"
	fi
	> "$output"

	# find files in /
	find /bin /etc /home /lib /lib64 /opt /root /sbin /usr /var -type f -print0 | xargs -0 filefrag > "$output"

	# sort
	awk '{printf("%s|%s\n",$(NF - 2),substr($0,1,match($0,/: [0-9]* extents? found/)-1))}' "$output" | sort -n > "$sorted"

	# info
	echo "Ouput written to $output"
	echo "Sorted output written to $sorted"
	echo
	echo "Most fragmented files"
	tail "$sorted"
	echo
elif test "$1" = "defrag"
then
	# $2 must be defined and a number
	if test "$2" != ''
	then
		if echo "$2" | grep '^[0-9]*$'
		then
			thres="$2"
		fi
	fi
	# generate defrag list
	awk -F'|' -v thres="$thres" '{ if ($1>thres) print $2}' "$sorted" > "$defrag"
	
	# defrag
	echo
	echo "Files to be defragmented:"
	cat "$defrag"
	echo
	echo 'How do you want to defrag these files ?'
	echo '[i]n place (copy to .defrag and move back)'
	echo '[t]emporary directory (default is /tmp/defrag)'
	echo '[n]o defrag, just exit'
	read answer
	case "$answer" in
		i|I)
			while read line
			do
				cp --preserve=all "$line" "$line.defrag" && mv "$line.defrag" "$line"
			done < "$defrag"
		;;
		t|T)
			mkdir "$tempdir" || error "$tempdir exists"
			while read line
			do
				cp --preserve=all "$line" "$tempdir" && mv "$tempdir/$(basename "$line")" "$line"
			done < "$defrag"
			rmdir "$tempdir" || error "$tempdir is not empty, check it for files"
		;;
		n|N)
			error 'exiting on user input'
		;;
		*)
			error 'bad input'
		;;
	esac
else
	error 'input is not sane'
fi

exit 0
Use at your own risk ! It is provided as-is, no warranties implied.

Typical usage, as root:
Code:
defrag find
defrag defrag

Last edited by H_TeXMeX_H; 12-02-2012 at 05:40 AM.
 
Old 12-02-2012, 11:48 AM   #6
DavidMcCann
Senior Member
 
Registered: Jul 2006
Location: London
Distribution: CentOS, Salix
Posts: 3,060

Rep: Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787Reputation: 787
If Ubuntu seems slow, the problem may be that it's not the best choice for your computer. What's your CPU speed, RAM size, and video chip? What's the CPU load shown in the system monitor when you're watching a Youtube video?

I'm skeptical about defragging. This computer's /home partition has just 13% non-contiguous files after 8 years' heavy use.

Last edited by DavidMcCann; 12-03-2012 at 11:00 AM.
 
  


Reply

Tags
cleanup, slow, ubuntu 11.10


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
[SOLVED] just installed Slackware....Lilo>Select "Ubuntu">>> "Ubuntu is in low graphics mode"? Ubunoob001 Slackware 14 09-16-2010 04:47 PM
intrepid, PS3, update sources list from "ubuntu" to "ports-ubuntu" evdv Linux - Newbie 7 08-18-2009 10:52 AM
net working eth0 eth1 wlan0 "no connection" "no LAN" "no wi-fi" Cayitano Linux - Newbie 5 12-09-2007 07:11 PM
Netgear MA111 working for Ubuntu "Warty" release? cfw Linux - Wireless Networking 8 02-21-2006 08:08 PM
DLink Wireless Card not working on Ubuntu Linux "Hoary Hedgehog" bluefusionx Linux - Wireless Networking 13 12-25-2005 02:57 PM


All times are GMT -5. The time now is 04:42 PM.

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