Posted: . At: 9:20 PM. This was 10 years ago. Post ID: 7024
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.


Strange but useful shell trick with the bash shell.


This is a very strange shell trick that allows you to have a set of parameters to a Linux command that are separated by single quotes.

[homer@localhost ~]$ df -h'l'a'T'
Filesystem     Type             Size  Used Avail Use% Mounted on
rootfs         rootfs           216G   75G  130G  37% /
proc           proc                0     0     0    - /proc
sysfs          sysfs               0     0     0    - /sys
devtmpfs       devtmpfs         2.9G     0  2.9G   0% /dev
securityfs     securityfs          0     0     0    - /sys/kernel/security
selinuxfs      selinuxfs           0     0     0    - /sys/fs/selinux
tmpfs          tmpfs            2.9G  1.7M  2.9G   1% /dev/shm
devpts         devpts              0     0     0    - /dev/pts
tmpfs          tmpfs            2.9G  9.2M  2.9G   1% /run
tmpfs          tmpfs            2.9G     0  2.9G   0% /sys/fs/cgroup
cgroup         cgroup              0     0     0    - /sys/fs/cgroup/systemd
pstore         pstore              0     0     0    - /sys/fs/pstore
cgroup         cgroup              0     0     0    - /sys/fs/cgroup/cpuset
cgroup         cgroup              0     0     0    - /sys/fs/cgroup/cpu,cpuacct
cgroup         cgroup              0     0     0    - /sys/fs/cgroup/memory
cgroup         cgroup              0     0     0    - /sys/fs/cgroup/devices
cgroup         cgroup              0     0     0    - /sys/fs/cgroup/freezer
cgroup         cgroup              0     0     0    - /sys/fs/cgroup/net_cls
cgroup         cgroup              0     0     0    - /sys/fs/cgroup/blkio
cgroup         cgroup              0     0     0    - /sys/fs/cgroup/perf_event
cgroup         cgroup              0     0     0    - /sys/fs/cgroup/hugetlb
/dev/sda3      ext4             216G   75G  130G  37% /
systemd-1      autofs              0     0     0    - /proc/sys/fs/binfmt_misc
debugfs        debugfs             0     0     0    - /sys/kernel/debug
hugetlbfs      hugetlbfs           0     0     0    - /dev/hugepages
mqueue         mqueue              0     0     0    - /dev/mqueue
tmpfs          tmpfs            2.9G   80K  2.9G   1% /tmp
configfs       configfs            0     0     0    - /sys/kernel/config
fusectl        fusectl             0     0     0    - /sys/fs/fuse/connections
/dev/sr0       iso9660          3.0G  3.0G     0 100% /run/media/homer/Kali Live
/dev/sdi1      fuseblk          1.9T  218G  1.7T  12% /run/media/homer/Seagate Backup Plus Drive
gvfsd-fuse     fuse.gvfsd-fuse     0     0     0    - /run/user/1000/gvfs
binfmt_misc    binfmt_misc         0     0     0    - /proc/sys/fs/binfmt_misc

Here is another example.

[homer@localhost backgrounds]$ ls -h'u'l'a'
total 72K
drwxr-xr-x.  16 root root 4.0K Mar  2 21:07 .
drwxr-xr-x. 282 root root  12K Mar  2 21:03 ..
drwxr-xr-x.   3 root root 4.0K Mar  2 21:07 beefy-miracle
drwxr-xr-x.   2 root root 4.0K Mar  2 21:07 cosmos
lrwxrwxrwx.   1 root root   42 Mar  2 21:02 default.png -> ./heisenbug/default/standard/heisenbug.png
drwxr-xr-x.   2 root root 4.0K Mar  2 21:07 gnome
drwxr-xr-x.   3 root root 4.0K Mar  2 21:07 heisenbug
drwxr-xr-x.   2 root root 4.0K Mar  2 21:07 images
drwxr-xr-x.   2 root root 4.0K Mar  2 21:07 infinity
drwxr-xr-x.   3 root root 4.0K Mar  2 21:07 laughlin
drwxr-xr-x.   3 root root 4.0K Mar  2 21:07 leonidas
drwxr-xr-x.   3 root root 4.0K Mar  2 21:07 lovelock
drwxr-xr-x.   5 root root 4.0K Mar  2 21:07 mate
drwxr-xr-x.   4 root root 4.0K Mar  2 21:07 schroedinger-cat
drwxr-xr-x.   3 root root 4.0K Mar  2 21:07 spherical-cow
drwxr-xr-x.   3 root root 4.0K Mar  2 21:07 verne
drwxr-xr-x.   2 root root 4.0K Mar  2 21:07 xfce

This is actually quite a cool trick.

Here I am using brace expansion to look for two files, Day.jpg and Dune.jpg. Of course, only Dune.jpg is returned in the directory listing.

[homer@localhost nature]$ ls -h'u'l'a' D{un,ay}*.jpg
ls: cannot access Day*.jpg: No such file or directory
-rw-r--r--. 1 root root 998K Feb 28 22:34 Dune.jpg

This is an even more obfuscated and complex version. This will accept any starting letter for the filename and certain strings for the rest of the words.

[homer@localhost nature]$ ls -h'u'l'a' [A-Z]{ard,ood,qua}*.jpg
-rw-r--r--. 1 root root 196K Mar  2 23:48 Aqua.jpg
-rw-r--r--. 1 root root 259K Feb 28 22:34 Garden.jpg
-rw-r--r--. 1 root root 514K Feb 28 22:34 Wood.jpg

This is something cool that I discovered. A very cool Linux command to show off to your friends.


Leave a Comment

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