Misc UNIX tips for the desktop UNIX or Linux user.

Get your uptime with the uptime command on Linux.

Last login: Tue Oct 28 13:55:23 on ttys000
iMac05:~ admin$ uptime
11:24  up 111 days, 20:38, 2 users, load averages: 0.35 0.16 0.14

The df -Hla command will show your free space in Megabytes or Gigabytes.

iMac05:~ admin$ df -Hla
Filesystem     Size   Used  Avail Capacity  iused    ifree %iused  Mounted on
/dev/disk0s2   214G    70G   144G    33% 17215764 35090991   33%   /
/dev/disk0s4   285G   576M   284G     1%   140679 69406537    0%   /Volumes/DATA

Display information about your UNIX user with this command. The finger -lmps command is a very useful one.

iMac05:~ admin$ finger -lmps
Login: admin          			Name: Admin
Directory: /Users/admin             	Shell: /bin/bash
On since Tue 21 Oct 14:57 (EST) on console, idle 14 days 20:32 (messages off)
On since Wed  5 Nov 11:24 (EST) on ttys000
No Mail.

List the files in a folder that are using up the most disk space. The du -h command will take care of this. This command will list the files in a human readable format.

iMac305:Desktop admin$ du -h
 68K	./Cloud server Voip keys
4.0K	./Sample Tunnelblick VPN Configuration
 29M	.

If there are a lot of files in the directory, only show the top 10 largest files using this command. du -h | head -n 10.

iMac305:Downloads admin$ du -h | head -n 10
 59M	./Music
 36K	./openvpn-2.3.4/build/msvc/msvc-generate
 60K	./openvpn-2.3.4/build/msvc
 88K	./openvpn-2.3.4/build
4.0K	./openvpn-2.3.4/contrib/OCSP_check
 12K	./openvpn-2.3.4/contrib/openvpn-fwmarkroute-1.00
8.0K	./openvpn-2.3.4/contrib/pull-resolv-conf
 32K	./openvpn-2.3.4/contrib
 32K	./openvpn-2.3.4/debug
 52K	./openvpn-2.3.4/distro/rpm

Here is another way to list the top 10 largest files in a directory in order from largest to smallest using the /bin/ls command. The ls -Slah | head -n 20 command is a good way to list the disk space users in your ~/Downloads directory.

iMac305:Downloads admin$ ls -Slah | head -n 20
total 44517128
-rwxrwxrwx   1 admin  staff   4.0G  6 May  2014 en_windows_server_2012_r2_vl_x64_dvd_3319595.iso
-rw-r--r--@  1 admin  staff   3.8G 30 May 12:10 en_windows_8.1_with_update_x64_dvd_4065090.iso
-rwxrwxrwx   1 admin  staff   2.8G 29 Mar  2012 en_windows_server_2008_r2_standard_enterprise_datacenter_and_web_with_sp1_debug_checked_build_x64_dvd_619600.iso
-rwx------   1 admin  staff   2.5G 17 May  2013 windows vista.iso
-rwx------   1 admin  staff   2.3G 13 May  2013 windows 7 professional.iso
-rwx------   1 admin  staff   1.9G 13 May  2013 Chrome OS Vanilla.iso
-rw-r--r--@  1 admin  staff   1.2G 20 May 15:18 linuxmint-16-mate-dvd-64bit.iso
-rw-r--r--@  1 admin  staff   963M  1 May  2014 utopic-desktop-amd64+mac.iso
-rwxrwxrwx   1 admin  staff   639M 25 Feb  2013 ubuntu-12.04.2-server-i386.iso
-rw-r--r--@  1 admin  staff   617M 30 Apr  2014 ubuntu-5.10-install-i386.iso
-rw-------@  1 admin  staff   114M 10 Apr  2014 VirtualBox-4.3.10-93012-OSX.dmg
-rw-r--r--@  1 admin  staff    62M 19 May 11:57 VBoxGuestAdditions_4.3.10.iso
-rw-r--r--@  1 admin  staff    58M  2 May  2014 virtio-win-0.1-74.iso
-rw-r--r--@  1 admin  staff    52M 11 Apr  2014 trueconf_client.dmg
-rw-r--r--@  1 admin  staff    32M 15 May 10:00 Dia-0.97.2-7.dmg
-rw-r--r--@  1 admin  staff    31M  1 May  2014 mini.iso
-rw-r--r--@  1 admin  staff    28M  1 May  2014 Firefox Setup 29.0.exe
-rw-r--r--@  1 admin  staff    19M  8 May 13:36 mikrotik-6.12.iso
-rw-r--r--@  1 admin  staff   6.5M 23 Oct 16:09 Tunnelblick_3.4.1_r3054.dmg

Find a certain process named bash. This is just like the command used in TRON Legacy.

iMac305:Downloads admin$ ps -ef | grep bash
  501   662   661   0 12:39pm ttys000    0:00.05 -bash
  501   738   662   0 12:58pm ttys000    0:00.00 grep bash

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

Leave a Reply