Posted: . At: 12:55 PM. This was 2 years ago. Post ID: 16581
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.


Some very useful Linux shell tips and tricks for the bash shell.


Browse the command line history with ctrl-r and then type a few characters that you know are part of the command you are looking for.

This is what it will look like.

(reverse-i-search)`ls -hu': ls -hulai

Just start typing and it will try and match commands in your ~/.bash-history. A very useful Linux command for a terminal user.

To view the last 20 commands executed in the shell, this will work.

jason@jason-Lenovo-H50-55:~$ history | tail -n 20
  559  strace touch '​‏'
  560  ls -hula
  561  ls -hulai
  562  ls -i
  563  find . -inum 55838358 -EXEC rm -i {} \;
  564  sudo init 0
  565  fortune ubuntu-tips
  566  fortune ubuntu
  567  mc
  568  dpkg -l fortune
  569  dpkg -c fortune
  570  cat .bashrc 
  571  mc
  572  ls -i
  573  find . -inum 55838358 -EXEC rm -i {} \;
  574  ls
  575  cat .bash_history | grep makepbo
  576  history 
  577  history | head -n 20
  578  history | tail -n 20

To get a listing of the most recently installed Linux packages, use this command.

jason@jason-Lenovo-H50-55:~$ grep " install " /var/log/dpkg.log
2022-08-05 11:38:18 install libbabl-0.1-0:amd64 <none> 0.1.74-1
2022-08-05 11:38:19 install libilmbase24:amd64 <none> 2.3.0-6build1
2022-08-05 11:38:19 install libopenexr24:amd64 <none> 2.3.0-6ubuntu0.5
2022-08-05 11:38:20 install libraw19:amd64 <none> 0.19.5-1ubuntu1
2022-08-05 11:38:21 install libsuitesparseconfig5:amd64 <none> 1:5.7.1+dfsg-2
2022-08-05 11:38:21 install libamd2:amd64 <none> 1:5.7.1+dfsg-2
2022-08-05 11:38:22 install libcamd2:amd64 <none> 1:5.7.1+dfsg-2
2022-08-05 11:38:23 install libccolamd2:amd64 <none> 1:5.7.1+dfsg-2
2022-08-05 11:38:23 install libcolamd2:amd64 <none> 1:5.7.1+dfsg-2
2022-08-05 11:38:24 install libgfortran5:amd64 <none> 10.3.0-1ubuntu1~20.04
2022-08-05 11:38:25 install liblapack3:amd64 <none> 3.9.0-1build1
2022-08-05 11:38:26 install libmetis5:amd64 <none> 5.1.0.dfsg-5
2022-08-05 11:38:26 install libcholmod3:amd64 <none> 1:5.7.1+dfsg-2
2022-08-05 11:38:27 install libumfpack5:amd64 <none> 1:5.7.1+dfsg-2
2022-08-05 11:38:28 install libgegl-common:ALL <none> 0.4.22-3
2022-08-05 11:38:29 install libgegl-0.4-0:amd64 <none> 0.4.22-3
2022-08-05 11:38:30 install libgimp2.0:amd64 <none> 2.10.18-1
2022-08-05 11:38:31 install gimp-DATA:ALL <none> 2.10.18-1
2022-08-05 11:38:34 install libde265-0:amd64 <none> 1.0.4-1build1
2022-08-05 11:38:34 install libheif1:amd64 <none> 1.6.1-1build1
2022-08-05 11:38:35 install libmng2:amd64 <none> 2.0.3+dfsg-3
2022-08-05 11:38:36 install libmypaint-common:ALL <none> 1.5.1-1
2022-08-05 11:38:37 install libmypaint-1.5-1:amd64 <none> 1.5.1-1
2022-08-05 11:38:37 install gimp:amd64 <none> 2.10.18-1
2022-08-10 15:21:06 install linux-modules-5.4.0-124-generic:amd64 <none> 5.4.0-124.140
2022-08-10 15:21:09 install linux-image-5.4.0-124-generic:amd64 <none> 5.4.0-124.140
2022-08-10 15:21:10 install linux-modules-extra-5.4.0-124-generic:amd64 <none> 5.4.0-124.140
2022-08-10 15:21:18 install linux-headers-5.4.0-124:ALL <none> 5.4.0-124.140
2022-08-10 15:21:23 install linux-headers-5.4.0-124-generic:amd64 <none> 5.4.0-124.140
2022-08-11 10:56:21 install whois:amd64 <none> 5.5.6
2022-08-13 11:19:53 install attr:amd64 <none> 1:2.4.48-5

This lists all recently installed packages, even dependencies.

The example below will list the 20 oldest files in the directory. This could also be a very useful shell tip.

jason@jason-Lenovo-H50-55:~/Documents$ ls -lt |tail -20
-rw-rw-r-- 1 jason jason  3468081 May  6 12:18 1651802601655.jpg
-rw-rw-r-- 1 jason jason   161794 May  1 15:48 20220501154818_1.jpg
-rw-rw-r-- 1 jason jason   337532 May  1 09:05 20220501090520_1.jpg
drwxrwxr-x 2 jason jason     4096 Feb 24  2022 this_is_a_dir_
-rwxrwxrwx 1 jason jason  1137722 Feb 20  2022 scotty-tradie.webm
-rw-rw-r-- 1 jason jason        9 Feb 18  2022 nc
-rw-rw-r-- 1 jason jason      101 Feb 18  2022 nc.nasm
-rw-rw-r-- 1 jason jason  3904324 Jan 31  2022 1643434357547.png
-rw-rw-r-- 1 jason jason  1009243 Jan 24  2022 20220123_120418.jpg
-rw-rw-r-- 1 jason jason    30344 Jan 14  2022 1642131874442.png
-rw-rw-r-- 1 jason jason   207758 Jan  1  2022 20220101_084133.jpg
-rw-rw-r-- 1 jason jason  1681500 Jun  7  2021 20210607_154601.jpg
-rw-rw-r-- 1 jason jason      275 Apr 30  2021 testing.c
-rw-rw-r-- 1 jason jason 20274113 Mar  2  2021 20210302_105440.jpg
-rw------- 1 jason jason   241181 Jan 29  2021 message.txt
drwxrwxr-x 3 jason jason     4096 Nov 10  2020 Boomsrc
-rw-rw-r-- 1 jason jason  1552097 Sep  7  2020 ballreaction.webm
-rw-rw-r-- 1 jason jason  2477140 Sep  7  2020 ballgirl.webm
-rw-rw-r-- 1 jason jason     3750 Feb 25  2013 08-02-03.zip
-rw-rw-r-- 1 jason jason    88250 Jul 12  2012 rabid-science.zip

Find even more useful shell tips here: https://www.securitronlinux.com/lc/AdvancedLinuxPocketbook.pdf.


Leave a Comment

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