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

Posted: November 26, 2017. At: 6:31 PM. This was 3 months ago. Post ID: 4906
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

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.

jason@jason-desktop:~/Documents$ find . -type f -exec ls -al {} \; | sort -nr -k5 | head -n 1
-rwxrwxrwx 1 jason jason 2044058553 Aug 25 08:40 ./Windows/Custom-WPA

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

jason@jason-desktop:~/Documents$ dmesg | grep -n CPU
134:[    0.000000] smpboot: Allowing 4 CPUs, 0 hotplug CPUs
160:[    0.000000] setup_percpu: NR_CPUS:8192 nr_cpumask_bits:4 nr_cpu_ids:4 nr_node_ids:1
171:[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
174:[    0.000000] 	RCU restricting CPUs from NR_CPUS=8192 to nr_cpu_ids=4.
194:[    0.012308] CPU: Physical Processor ID: 0
195:[    0.012309] CPU: Processor Core ID: 0
196:[    0.012314] mce: CPU supports 9 MCE banks
197:[    0.012320] CPU0: Thermal monitoring enabled (TM1)
206:[    0.065371] smpboot: CPU0: Intel(R) Core(TM) i5-4670K CPU @ 3.40GHz (family: 0x6, model: 0x3c, stepping: 0x3)
215:[    0.065975] NMI watchdog: enabled on all CPUs, permanently consumes one hw-PMU counter.
216:[    0.065985] smp: Bringing up secondary CPUs ...
218:[    0.066031] .... node  #0, CPUs:      #1 #2 #3
219:[    0.069734] smp: Brought up 1 node, 4 CPUs
247:[    0.101595] NMI watchdog: enabled on all CPUs, permanently consumes one hw-PMU counter.
626:[    0.717533] ledtrig-cpu: registered to indicate activity on CPUs

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.

jason@jason-desktop:~/Documents$ grep -n "cron" /var/log/syslog
1:Nov 26 07:38:43 jason-desktop anacron[1089]: Job `cron.daily' terminated
17:Nov 26 08:17:01 jason-desktop CRON[4004]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
54:Nov 26 09:17:01 jason-desktop CRON[4633]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

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

john@deusexmachina:~/Pictures$ convert wagga-night.jpeg -resize 60% wagga-night-small.jpg

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.

jason@jason-desktop:~/Documents$ 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.

jason@jason-desktop:~/Documents$ echo $PATH | awk '{gsub(":","\n")}1'

Load the urxvt terminal with a background image.

[email protected]:~/Documents$ urxvt --background-expr '{load "hell.png"}'

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

Leave a Reply