Finding the largest file in a directory and other cool Linux commands.

To find the largest file in a directory; use the du command and this will return the information you are after. Using the pipe symbol to send the text through to the head command will allow us to only return the one file we are interested in.

[email protected]:~/Documents$ du -ack | sort -nr | head -n 3
249608	total
249608	.
173516	./DVII-1i.wad

Here we are using the grep command to find all instances of the abbreviation CPU in the dmesg output.

[email protected]:~/Documents$ dmesg | grep -n CPU
136:[    0.000000] SMP: Allowing 8 CPUs, 4 hotplug CPUs
151:[    0.000000] setup_percpu: NR_CPUS:256 nr_cpumask_bits:256 nr_cpu_ids:8 nr_node_ids:1
152:[    0.000000] PERCPU: Embedded 28 pages/cpu @ffff88019fc00000 s83584 r8192 d22912 u262144
165:[    0.000000] SLUB: Genslabs=15, HWalign=64, Order=0-3, MinObjects=0, CPUs=8, Nodes=1
190:[    0.004088] CPU: Physical Processor ID: 0
191:[    0.004089] CPU: Processor Core ID: 0
192:[    0.004093] mce: CPU supports 9 MCE banks
193:[    0.004103] CPU0: Thermal monitoring enabled (TM1)
198:[    0.060980] CPU0: Intel(R) Core(TM) i3 CPU         530  @ 2.93GHz stepping 02
200:[    0.167545] CPUID marked event: 'bus cycles' unavailable
208:[    0.167722] NMI watchdog: enabled on all CPUs, permanently consumes one hw-PMU counter.
210:[    0.207441] Brought up 4 CPUs
974:[   18.586784] microcode: CPU0 sig=0x20652, pf=0x2, revision=0x9
992:[   18.766475] microcode: CPU1 sig=0x20652, pf=0x2, revision=0x9
993:[   18.768262] microcode: CPU2 sig=0x20652, pf=0x2, revision=0x9
994:[   18.769212] microcode: CPU3 sig=0x20652, pf=0x2, revision=0x9

And there is another way to use the grep command; shown here. You do not need to type cat before the grep command; this is how you do it properly.

[email protected]:~/Documents$ grep -n "cron" /var/log/syslog
2:Nov 26 17:39:13 deusexmachina anacron[1157]: Job `cron.daily' terminated (mailing output)
3:Nov 26 17:39:13 deusexmachina anacron[1157]: Can't find sendmail at /usr/sbin/sendmail, not mailing output
4:Nov 26 17:39:13 deusexmachina anacron[1157]: Normal exit (1 job run)

This command will re-size an image by 60% of the original size.

[email protected]:~/Pictures$ convert wagga-night.jpeg -resize 60% wagga-night-small.jpg
[email protected]:~/Pictures$

If you are missing this command; type sudo apt-get install imagemagick.

This command using the curl utility will enable you to create a tinyurl address from a long URL.

[email protected]:~/Pictures$ echo `curl -s`

Here is a nice way to pretty-print the PATH variable with the bash shell. This outputs the information in a readable format.

[email protected]:~/Pictures$ echo $PATH | awk '{gsub(":","\n")}1'

No comments have been made. Use this form to start the conversation :)

Leave a Reply