Some very cool Linux shell tips and tricks for old and new users alike.

Posted: January 29, 2014. At: 12:39 PM. This was 4 years ago. Post ID: 6921

Some very useful Linux shell commands and tricks.

Print numbers in sequence.

[homer@localhost ~]$ seq 8 24
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

Print numbers in sequence, but only multiples of 8.

[homer@localhost ~]$ seq 8 8 128
8
16
24
32
40
48
56
64
72
80
88
96
104
112
120
128

Print out a directory listing without using ls. This is a cool trick.

[homer@localhost ~]$ for i in $( echo * ); do echo $i; done
bin
Desktop
Documents
Downloads
gzdoom_build
libdvdcss
Music
my.gif
Pictures
Public
status
stream.ts
Templates
Videos
zandronum

Read a logfile and only print lines that occur more than once. This is a good way to find out if there are any recurring errors on your Linux system. The uniq -d command will do this for you.

[homer@localhost ~]$ su -c 'cat /var/log/messages | uniq -d'
Password: 
Jan 28 09:50:37 localhost mate-session[982]: Gtk-WARNING: Unable to locate theme engine in module_path: "ubuntulooks",
Jan 28 12:12:55 localhost systemd: Stopping Default.
Jan 28 12:12:55 localhost systemd: Stopped target Default.
Jan 27 19:35:07 localhost systemd: Reached target Sound Card.
Jan 28 14:35:28 localhost systemd: Time has been changed
Jan 28 14:38:35 localhost su: (to homer) homer on none
Jan 28 03:14:27 localhost systemd: Reached target Sound Card.
Jan 28 09:50:37 localhost mate-session[982]: Gtk-WARNING: Unable to locate theme engine in module_path: "ubuntulooks",
Jan 28 22:14:53 localhost systemd: Time has been changed
Jan 29 07:17:38 localhost systemd: Time has been changed

Get information about your user.

[homer@localhost ~]$ id
uid=1000(homer) gid=1000(homer) groups=1000(homer) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

Print a broadcast message to all logged in users on a Linux machine.

[homer@localhost ~]$ wall "Hello World"
 
Broadcast message from homer@localhost.localdomain (pts/0) (Wed Jan 29 12:08:44
 
Hello World

Use a simple command to find out what a file is. The file command is very, very useful.

[homer@localhost Documents]$ file realm-entry.wad 
realm-entry.wad: doom patch PWAD data containing 11 lumps

Do you want to get information about virtual memory on Linux? Then this command will be very useful indeed.

[homer@localhost Documents]$ vmstat 
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 1  0      0 245252 268716 4461740    0    0    81    56  254  187  6  2 91  1

How to ping your hard disk drive partitions. This is accomplished using the ioping command. Seems too good to be true. Well it is not. You can ping your hard disk.

[homer@localhost Documents]$ ioping /mymedia/homer/My\ Media/
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=1 time=111 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=2 time=195 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=3 time=179 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=4 time=186 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=5 time=324 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=6 time=182 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=7 time=197 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=8 time=184 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=9 time=187 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=10 time=239 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=11 time=220 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=12 time=182 us
4.0 KiB from /mymedia/homer/My Media/ (fuseblk /dev/sdc2): request=13 time=190 us
^C
--- /mymedia/homer/My Media/ (fuseblk /dev/sdc2) ioping statistics ---
13 requests completed in 12.4 s, 5.0 k iops, 19.7 MiB/s
min/avg/max/mdev = 111 us / 198 us / 324 us / 45 us

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

Leave a Reply