Posted: . At: 10:52 PM. This was 8 years ago. Post ID: 8571
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.


Very useful and informative Linux commands.


While running Linux, if you want to list the contents of a folder in a vertical list format, just use the ls command with these switches.

jason@ubuntu:~$ ls -luh --color=yes
total 48K
drwxr-xr-x 2 jason jason 4.0K Dec 15 03:03 Desktop
drwxr-xr-x 2 jason jason 4.0K Nov 29 17:00 Documents
drwxr-xr-x 2 jason jason 4.0K Nov 29 17:29 Downloads
-rw-r--r-- 1 jason jason 8.8K Nov 25 20:57 examples.desktop
drwxr-xr-x 2 jason jason 4.0K Nov 25 21:18 Music
-rw-r--r-- 1 jason jason  459 Dec  7 17:21 partsize
drwxr-xr-x 2 jason jason 4.0K Nov 25 21:19 Pictures
drwxr-xr-x 2 jason jason 4.0K Nov 25 21:18 Public
drwxr-xr-x 2 jason jason 4.0K Dec 15 03:03 Templates
drwxr-xr-x 2 jason jason 4.0K Nov 25 21:18 Videos

then you get the directory listing with human readable file sizes instead of being listed in bytes.

To list the partitions on a disk, just type

sudo fdisk -l /dev/sda

for example and it will list the partitions on the device. You need superuser priviledges to run this command. Then you get the output below.

jason@ubuntu:~$ sudo fdisk -l /dev/sda
[sudo] password for jason: 
 
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d5c84
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048    39845887    19921920   83  Linux
/dev/sda2        39847934    41940991     1046529    5  Extended
/dev/sda5        39847936    41940991     1046528   82  Linux swap / Solaris

A very useful command. This is useful when I am double checking which partition to install Linux to on my hard drive so I do not overwrite the wrong partition.

Get CPU information from your machine using the cat /proc/cpuinfo command.

jason@ubuntu:~$ cat /proc/cpuinfo 
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Core(TM) i5-4670K CPU @ 3.40GHz
stepping	: 3
microcode	: 0x9
cpu MHz		: 3399.030
cache size	: 6144 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm ida arat xsaveopt pln pts dtherm fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid
bogomips	: 6798.06
clflush size	: 64
cache_alignment	: 64
address sizes	: 42 bits physical, 48 bits virtual
power management:

List all users on your Linux machine.

jason@ubuntu:~$ sudo cut -d: -f1 /etc/passwd
[sudo] password for jason: 
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody
libuuid
syslog
messagebus
usbmux
dnsmasq
avahi-autoipd
kernoops
rtkit
saned
whoopsie
speech-dispatcher
avahi
lightdm
colord
pulse
hplip
jason
ntp

List all users with passwords in the /etc/shadow file.

jason@ubuntu:~$ sudo awk 'length($0)>42' /etc/shadow
root:$6$94h9BlHF$xGJjZIKlOVfuDc4V7pXzc7Qhy3YUjthc3Qusj5axc6l1HpUFgCNbk0MybBKfP7Oj9zraEGV6w8aEA5gHuipcW.:16784:0:99999:7:::
jason:$1$/.DJdFfa$AdDAUD25jfdDBtS4vxfL5/:16765:0:99999:7:::

List all users on your Linux machine that can actually login, not system users.

jason@ubuntu:~$ sudo awk -F':' '$2 ~ "\$" {print $1}' /etc/shadow
root
jason

Another way to list all users on your system with passwords, with the exception of the root user.

jason@ubuntu:~$ sudo awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd
jason

Another version. This will list all users with a UID over 500.

jason@ubuntu:~$ sudo awk -F'[/:]' '{if ($3 >= 500 && $3 != 65534) print $1}' /etc/passwd
jason

1 thought on “Very useful and informative Linux commands.”

  1. Very nice and Informative, preparing for Linux Certification, wanted to learn some Linux Commands, can anyone suggest me some books and videos?

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.