Working with Files & Folders

When working with files and folders in LXTerminal, I noticed that some files and folders have apostrophes around them.
eg. ´folder name´ or ´file name´
Others do not have this, What does this mean?

I can’t give authoritative advice on this one, as I’ve noted it too but never bothered looking up why. Personally I see it very rarely, but I avoid using spaces in my filenames, however in a project I’m working on; most files were not created by me and thus have quotes appear.

-rwxr-xr-x 1 guiverc guiverc 4.3K Jul 27 20:44 '1301_Install (auto-resize)'
-rwxr-xr-x 1 guiverc guiverc 3.9K Jul 27 20:44 '1300_Install (entire disk)'
-rw-rw-r-- 1 guiverc guiverc 2.5K Aug 31 13:57  auto-login_after_install.txt
-rw-rw-r-- 1 guiverc guiverc 2.5K Aug 31 13:57  custom_partitioning_on_btrfs.txt

In this example the quotes appear on files that contain spaces within the filenames. The space character is a delimiter in commands, and quotes is one easy way to get around that (and avoid escaping the space like "\ " which isn’t fun).

This is not complete, and the default quoting style can be overridden, eg.

          use quoting style WORD for entry  names:  literal,  locale,  shell,  shell-always,  shell-escape, shell-escape-always, c, escape (overrides QUOTING_STYLE environment variable)

is from man ls showing more information. I’ve never explored it, but if you want to learn more info ls will give more detail than I can give, as a quick scan quickly found more information than I care to read about it.

(ps: when I use man, info or like tools to look for information, I use “/” to search for detail instead of paging endlessly.)

Ok, that makes since to me, I will look into it.
Also, I noticed when using ‘ls -al’ in terminal, all files are shown in different colors.
But when using ‘sudo ls -al’ all files are in yellow.
Any thoughts on this?

I do know folders are in blue
Files in green and yellow
Compression files in red
Then, there’s the issue of colored boxes around some folder and file names.
Same colors as above.

I referred to colors before

When you run commands using sudo the environment in which commands are run isn’t directly you. If you run whoami; sudo whoami you’ll note different users. This won’t always apply, eg. echo $UID; sudo echo $UID. Contrast set|grep color when run as you, or if you use sudo -i to run it in sudo interactively, return to you and sudo -s then run set|grep color again; at least for me this gives three different outputs for set|grep color. (ie. environment can be different)

Ignoring all that [environment change]; the view as to ownership may have changed (think back to sudo whoami); the view from within sudo is different as you’ve elevated your privileges…

The shell first replaces the variable $UID with the value and then executes the command:

# The command as it is entered by the user
sudo echo $UID
# Step 1: The shell replaces the variable with its value
sudo echo 1000
# Step 2: Execute the command 'echo 1000' with elevated privileges
sudo echo 1000

If you like to print the value of the $UID variable from the other environment, you could use:

sudo bash -c 'echo $UID'

It is not easy to understand environments. Variables can be set, expanded, replaced. It is sometimes hard to know, where the current value of a variable was set.

And there is also a difference between shell variables such as $UID and environment variables such as $HOME.

# compare
sudo bash -c 'echo $UID'
sudo -E bash -c 'echo $UID'
# with
sudo bash -c 'echo $HOME'
sudo -E bash -c 'echo $HOME'
1 Like

I’m red faced, but thanks @apt-ghetto

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.