1

I am new to using the terminal in Ubuntu and I was wondering how I could open the file "armored.jpg" as I type out the whole path.

For instance, if I type cd ~/Pictures/Wallpapers/test\ x/ and then type xdg-open armored.jpg in the current directory it opens the picture.

However when I type:

cd ~/Pictures/Wallpapers/test\ x/ xdg-open armored.jpg

or

cd ~/Pictures/Wallpapers/test\ x/armored.jpg

or

cd ~/Pictures/Wallpapers/test\ x/armored

it does not work.

Can anyone explain why this is? I want to know if I can open the file with something like this:

cd ~/Pictures/Wallpapers/test\ x/**command goes here**/armored.jpg

Thanks

4 Answers 4

2

You can do this:

xdg-open ~/Pictures/Wallpapers/test\ x/armored.jpg

cd means change directory so essentially terminal is expecting a path-to-directory where you want to change to.

xdg-open opens a file in default applications but as it opens a file it expects path-to-file, you can also use xdg-open to open directory in nautilus(if it is your default file manager) in GUI.

1

You should be running the command and passing the path to the file as an argument. Your commands would work if you rearranged it like so:

xdg-open ~/Pictures/Wallpapers/test\ x/armored.jpg

The first word you use in the terminal is the command you are trying to run (which can be a program, built-in, function, etc) and all the other words are passed to that program as arguments. In this case, you're telling xdg-open to display your JPG, so you'll put the command first, and then the path to the picture.

1

You can use the double ampersands. Like:

cd ~/Pictures/Wallpapers/test\ x/ && xdg-open armored.jpg

This will execute the first command, and move to the second if the first is successful.

or you could do:

cd ~/Pictures/Wallpapers/test\ x/; xdg-open armored.jpg

Which will run the first command, and then the second, whether the first fails or not.

0
cd ~/Pictures/Wallpapers/test\ x/ xdg-open armored.jpg

If you run this command, terminal considers the whole after cd as a directory and it breaks if it contains any spaces and discards the part after space.In this case, the above command will get you only into the directory ~/Pictures/Wallpapers/test\ x. If you really want to open the file using xdg-open then your command needs breaking like below.

cd ~/Pictures/Wallpapers/test\ x/; xdg-open armored.jpg

The terminal parses the second command(ie, after ;) whether the first command succeeded or not.

Example:

$ cd ~/Pictures/Wallpapers/test\ x/; xdg-open armored.jpg
bash: cd: /home/avinash/Pictures/Wallpapers/test x/: No such file or directory
gvfs-open: armored.jpg: error opening location: Error when getting information for file '/home/avinash/armored.jpg': No such file or directory

or

cd ~/Pictures/Wallpapers/test\ x/ && xdg-open armored.jpg

The terminal parses the second command only if the first command would ended in success.

Example:

$ cd ~/Pictures/Wallpapers/test\ x/ && xdg-open armored.jpg
bash: cd: /home/avinash/Pictures/Wallpapers/test x/: No such file or directory

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .