2

I am using Ubuntu 18.04, 19.04 & 19.10

For gnome-shell theming purposes, I come across the below situation.

admin@i7-4770:~$ ls /usr/share/themes/Yaru/gnome-shell/
calendar-today.svg               noise-texture.png
checkbox-dark.svg                no-notifications.svg
checkbox-focused-dark.svg        pad-osd.css
checkbox-focused.svg             pointer-double-click-symbolic.svg
checkbox-off-dark.svg            pointer-drag-symbolic.svg
checkbox-off-focused-dark.svg    pointer-primary-click-symbolic.svg
checkbox-off-focused.svg         pointer-secondary-click-symbolic.svg
checkbox-off.svg                 process-working.svg
checkbox.svg                     running-indicator.svg
dash-placeholder.svg             source-button-border.svg
gnome-shell.css                  summary-counter.svg
gnome-shell-high-contrast.css    toggle-off-dark.svg
key-enter.svg                    toggle-off-hc.svg
key-hide.svg                     toggle-off-intl.svg
key-layout.svg                   toggle-off.svg
key-shift-latched-uppercase.svg  toggle-on-dark.svg
key-shift.svg                    toggle-on-hc.svg
key-shift-uppercase.svg          toggle-on-intl.svg
lockscreen-gradient.svg          toggle-on.svg
logged-in-indicator.svg          ws-switch-arrow-down.svg
message-indicator-symbolic.svg   ws-switch-arrow-up.svg
no-events.svg
admin@i7-4770:~$ 

I need to create a symbolic link for every .svg and .png files from above output in the /usr/share/gnome-shell/theme/ directory.

Right now, my only way is to run ln -s for each file.

sudo ln -s /usr/share/themes/Yaru/gnome-shell/calendar-today.svg /usr/share/gnome-shell/theme/

I am sure, experts can make it very quick.

How can I achieve this?

  • You can link from directory to directory, but this will make all files in source directory available in the destination directory. – FedonKadifeli Dec 20 '19 at 18:21
3

You don't need a loop at all here. Just run this ln command:

sudo ln -s /usr/share/themes/Yaru/gnome-shell/*{png,svg} /usr/share/gnome-shell/theme/

Brace expansion is handled by the shell, before launching any command. So the command above becomes:

sudo ln -s /usr/share/themes/Yaru/gnome-shell/noise-texture.png  /usr/share/themes/Yaru/gnome-shell/checkbox-dark.svg [...] /usr/share/themes/Yaru/gnome-shell/ws-switch-arrow-up.svg /usr/share/gnome-shell/theme/

In other words, it becomes ln -s f1 f2 ... fN /path/to/target/dir and that is all you need to link all your files. For example:

$ ls foo/
file1.svg  file2.svg  file3.svg  file4.png  file5.png  file6.png
$ ln -s $HOME/foo/*{svg,png} bar/
$ ls -l bar/
total 0
lrwxrwxrwx 1 terdon terdon 26 Dec 26 12:16 file1.svg -> /home/terdon/foo/file1.svg
lrwxrwxrwx 1 terdon terdon 26 Dec 26 12:16 file2.svg -> /home/terdon/foo/file2.svg
lrwxrwxrwx 1 terdon terdon 26 Dec 26 12:16 file3.svg -> /home/terdon/foo/file3.svg
lrwxrwxrwx 1 terdon terdon 26 Dec 26 12:16 file4.png -> /home/terdon/foo/file4.png
lrwxrwxrwx 1 terdon terdon 26 Dec 26 12:16 file5.png -> /home/terdon/foo/file5.png
lrwxrwxrwx 1 terdon terdon 26 Dec 26 12:16 file6.png -> /home/terdon/foo/file6.png

If you just have to have a loop for some reason, use globs instead:

for file in /usr/share/themes/Yaru/gnome-shell/*{png,svg}; do
    sudo ln -s "$file" /usr/share/gnome-shell/theme/
done

This way, you don't need to worry about any weird file names, as you would when using ls. Also note how I am quoting "$file" which is also essential for strange file names.

2

after several googling..

ended up with below script

#!/bin/bash

for p in $(ls /usr/share/themes/Yaru/gnome-shell | grep '.svg\|.png'); do
    sudo ln -s /usr/share/themes/Yaru/gnome-shell/$p /usr/share/gnome-shell/theme/
done

It worked. But I still think experts can make it with a single command which can be entered into terminal.

  • Do you really need a loop? You can do it in one command, just like: ln -sf /usr/share/themes/Yaru/gnome-shell/*.{svg,png} /usr/share/gnome-shell/theme/ See man ln. – FedonKadifeli Dec 21 '19 at 10:48
  • This means that there are no .svg and .png files in the source directory: /usr/share/themes/Yaru/gnome-shell/ – FedonKadifeli Dec 22 '19 at 7:51
  • @PRATAP no, that isn't what it simplifies to. It becomes ln -sf /usr/share/themes/Yaru/gnome-shell/*.svg /usr/share/themes/Yaru/gnome-shell/*.png /usr/share/gnome-shell/theme/. If it only created two files for you, then there are no files that match the glob /usr/share/themes/Yaru/gnome-shell/*.svg or /usr/share/themes/Yaru/gnome-shell/*.png as Fedon said. – terdon Dec 26 '19 at 12:15
  • @FedonKadifeli sorry there was a error from my side for running the command.. I forgot gnome-shell text in the path /usr/share/themes/Yaru/gnome-shell/ previously.. – PRATAP Dec 26 '19 at 12:37
  • @PRATAP yes, as you explained you were using the wrong path. If you still have questions about this, please come into chat so we don't clutter up the comments. – terdon Dec 26 '19 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.