1. Describes a systematic tendency to load more
chromeand features
onto systems at the expense of whatever elegance they may have possessed when originally designed.
See also feeping creaturism. You know, the main problem with
BSD Unix has
always been creeping featurism.
2. More generally, the tendency for anything complicated to become even more complicated
because people keep saying Gee, it would be even better if it had this feature too.
(See feature.)
The result is usually a patchwork because it grew one ad-hoc step at a time, rather than being
planned. Planning is a lot of work, but it's easy to add just one extra little feature to help
someone ... and then another ... and another.... When creeping featurism gets out of hand, it's
like a cancer. The GNU hello program, intended to illustrate
GNU command-line
switch and coding conventions, is also a wonderful parody of creeping featurism; the distribution
changelog is particularly funny. Usually this term is used to describe computer programs, but
it could also be said of the federal government, the IRS 1040 form, and new cars. A similar phenomenon
sometimes afflicts conscious redesigns; see
second-system
effect. See also
creeping
elegance.
The vast majority of UNIX commands manipulate files and directories. The basic command to list files
and directories is ls. One interesting feature of ls is very few syadmins know how to
use it. To say nothing about regular user. This kind of "cognitive blindness" is connected with the
overcomplexity of Unix, where each command has dozen or more swtched and meaning f switches changes
from one command to another.
Linux uses the ls command from the GNU fileutils project and has many
special switches and features ls has switches that affect how the files are listed, including
the level of detail, the sorting order, and the number of columns.
Often ls is preceded by cd command. Since bash 4.0 if you set option autocd
(by default it is off):
shopt -s autocd
In this case you can type the name of directory without prefixing it with it cd. If you name
directories with the first upper case letter that can save you a lot keystrokes.
You can also use command completion with ls as well as history of commands. That can save some
typing. Of cause using Midnight Commander or
similar file manager is a better way of solving this problem, but that requires learning of an
additional software product.
Most Linux distributions set up certain defaults for ls command and provides coloring of
directory listings. Which can be completely screwed on the background you prefer.
By default ls hides files that begin with a period. This is the Linux convention for configuration
files, history files, and other files that a user isn't normally interested in. To see these files,
use the -A (all) switch. Use -a (absolutely all) to show
the implicit . and .. files as well.
ls -A
On all modern distribution filenames are printed in color, which different colors suppsely
shoing the typr od the file (archive, directory, executatble file -- all rended indiffrent color). But
the designed forfot that there is such sthing as too much zeal. Often colors are screwed up, especially
if you prefer non back backgound for your terminal window.
In this case you copy to you dire3ctory and edit the file /etc/DIR_COLORS,which defines the lcolors.
The format of the file is described iinside the file. Then you need to modify you .bash_profile to "source"
this file.
Alternatively you can display the files without color and with symbols instead. In order
to do it redefined ls and ll aliases using the --color and --classify (or
-F) switches. (On most Linux distributions, this feature is turned on using aliases.). For
example:
$ alias ls="/bin/ls -F --color=never"
to turn colors off one time you can simply type /bin/ls -- that will evoke actual program,
not the alias and it displays listing without any colors.
The option -F (--classify ) marks in special way directories (/), programs
(*), symbolic links (@), pipes (|), and Unix domain socket files (=).
These symbols are not a part of the name: They are alternative to colors hints as to the type of file.
Another useful switch is--hide-control-chars (or -q). Linux filenames
can contain any character, even control characters. It is possible to create a filename with hidden
characters in the name. In these cases, you can't rename or delete the file unless you know what the
hidden characters are. Contrary to what the name implies, the --hide-control-chars switch displays
any unprintable characters in the filename as question marks, making their locations visible. See
Strange Files Deletion
and Renaming in Shell for details.
The way ls command displays file and directory names depends on what version of UNIX you
are using and the ls command-line options used as well as whether output is directed to
terminal or file/pipe. In other word, the default output of ls is device sensitive. If you
use the
default ls command to a pipe each filename into other program, then each filename
is separated by the newline. On console the default is multicolumn output.
Each argument to the ls command is either the name of a file, the name of a directory, or
one or more options. The options are used to control the ordering of the list of files and information
that is printed for each file. For each file argument, the requested information is printed. For each
directory argument the requested information is printed for all the files in the directory (unless the
-d option is used).
Some important options:
-a Lists all entries. By default, ls does not show any files whose names begin with
a period ("."), and the -a option forces these files to be displayed. -A omits
.. and .
-dForces ls to only print the requested information for
a directory and not its contents. Normally, all the directories named in the argument
list are searched, and the requested information is printed for all the files in those directories.
-FMarks directories with a trailing slash ("/"),
executable files with a trailing asterisk ("*"), and symbolic links with a trailing at sign ("@").
-iPrints each file's inode number in the first column of the listing. If
you list files that are hard linked, notice that both files have the same inode number.
See also Strange
Files Deletion and Renaming in Shell
-l The long-list option is used to print detailed information (such as owner and size
in bytes) about each listed file. The default is to only print the filenames.
-n Lists the user and group ID numbers, instead of names, associated with each file
and directory.
-r Reverses the order of sort.
-s Gives the size of each file, including any indirect blocks used to map the file,
in KB (Berkeley) or 512-byte blocks (System V).
-t Lists the files sorted according to each file's modification date. The most recently
modified files are printed first.
-u Uses the last access time instead of modification time.
Alias ll is probably the most common alias in Unix and linux. It can be defined in many
different ways. here is one, that I would recommend:
alias ll=/bin/ls -hAlF --group-directories-first # F will show * after executables, / after directories and @ after links.
Actually unending games with ls aliases is an interesting story in itself. See
Examples of .bashrc files for examples.
Reading various webpages pages on the topic I was surprised that there how many of "my aliases" were
present in other people .bash_profile or .bashrc files :-). Looks like there is some
common "core" of aliases that that many people independently reinvent again and again.
In GNU implementation you can control the colors of files and directories using dircolors utility. And that' probably the most
annoying problem with ls in linux.
Using color to distinguish file types is disabled both by default and with --color=never.
With
--color=auto,
ls emits color codes only when standard output is connected to a terminal. The LS_COLORS
environment variable can change the settings. Use the dircolors
command to set it. See Annoing colors on Linux
command
The Linux colorizing of directories demonstrates classic case of "too much zeal".
It is bad on light backgrounds .Specifically the color-coding of symbolic links tend to show in such
a light color that it is often impossible to read. There are problems with using it on classic dark
blue of black backgrounds too.
You can disable command line colorizing by editing /etc/DIR_COLORS and changing "COLOR tty"
to "COLOR none" or (less drastically) by removing the "TERM ansi" line from the same file (which removes
colorization for ansi but doesn't affect console use).
The color output can also be blocked by adding the --color=none, or --color=tty
to the aliases of ls and ll command.
alias ls='ls --color=none'
you can do it in /etc/profile) and allow users to set coloring in their own profile
if preferred.
or you put in default user profile (and profiles of all existing users) the unalias
command:
unalias ls
Modification of In the file /etc/DIR_COLORS is a little bit more involved but doable. See
dircolors. Find each offending line and replace it with more
sane line. Use the following table for find offending colors
ISO 6429 color sequences are composed of sequences of numbers separated by semicolons. The most common
codes are:
0 to restore default color
1 for brighter colors
4 for underlined text
5 for flashing text
30 for black foreground
31 for red foreground
32 for green foreground
33 for yellow (or brown) foreground
34 for blue foreground
35 for purple foreground
36 for cyan foreground
37 for white (or gray) foreground
40 for black background
41 for red background
42 for green background
43 for yellow (or brown) background
44 for blue background
45 for purple background
46 for cyan background
47 for white (or gray) background
For for example find the the line that has color attributes 34;42 (blue foreground, green
background)
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
As the first step all color attributes for those lines can be changes to 1;30 (black):
OTHER_WRITABLE 30;1 # dir that is other-writable (o+w) and not sticky
There are several popular options such as -l and -a that everybody knows. Slight less known option
is -t which lists the files reverse sorted according to each file's modification date. The most recently
modified files are printed first.
ls -lt | head -4 | tail -3 # last three modified files in the current directory
Option -d is actually one of the most tricky options of ls command. Expectations
( and documentation leaves much to be desired).
It behavior is a mystery and generally to use directories you should find instead.
find . -type d -ls
It should work like option -type d in find, but it does not.
Few sysadmins understand how it works, although many tried to use (unsuccessfully) this option. My
impression is that it is just replica of incorrectly implemented prototype used by GNU coders
(probably Solaris of FreeBSD ls) and nobody has the courage to correct this error.
Option-d should force ls to print only
the requested information for a directory and not its contents.
But in GNU implementation (as well as most other implementation) if you specify wildcard such as
*, not only all the directories implicitly named in the argument list are lists, but also
files in those directory are printed.
So if you think that ls -d * will provide you list of directories in the current directory,
you are deeply mistaken ;-). It will display both directories and files in the current directory and
each of subdirectories too, so the necessary effect can be achieved only by using:
ls -d * | grep ':' | cut -d ':' -f 1
Or you can create an alias
alias ldir="ls -l | egrep '^d'"
This alias ldir works correctly and really lists directories in the current directory in the long
format.
Also ls -d gives you the following result, which I consider a bug
$ ls -d
.
This is kind of idiotic, but that how it was implemented many many years ago in Unix and newer implementation
like GNU ls preserved this compatibility.
At the same time commands
cd /usr/bin
ls -d ../*
works correctly. Try to guess why ;-)
The only way to get logical output from option -d is to use trailing slash after asterisk
or other basic regular expression. As in:
ls -d */
The only way to get logical output from option -d is to use trailing slash after asterisk
or other basic regular expression. As in:
ls -d */
My advice is to use find instead. To list all directories
in the current you can use:
find . -maxdepth 1 -type -d
To list all directories in the current tree you can use:
find . -type d -ls
Here is interesting (but wrong) attempt to justify this bug as a feature (
command
ls -d not working ):
You're right, stress_junkie. And it's quite logical too:
Think about what "ls -d *" does internally:
first the shell expands the * to the names of all the files and directories in the current directory.
Then the shell passes all that to "ls -d", so the actual command that is executed is something like:
ls -d file1 dir1 file2 file3 ...
ls will list the contents of each of the arguments after the -d option. As if it would recursively
call itself
on each separate argument.
ls -d file1
ls -d dir1
ls -d file2
etc
The -d won't have any effect on the listings of the files.
It only has an effect on the listings of "dir1", "dir2". For those lists, it won't list the contents
of the subdirectories dir1, dir2,..., but just the subdirectories themselves.
So, what you get as a result is indeed a list of all files and subdirs of the current directory.
Logical, no?
Options used with the ls command can be listed separately or concatenated. This means
the following commands are effectively identical:
ls -l -F
ls -lF
If no files or directories are named in the arguments, then the contents of the current directory
are listed. By default, the names are listed in alphabetical order.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
--author
with -l, print the author of each file
-b, --escape
print octal escapes for nongraphic characters
--block-size=SIZE
use SIZE-byte blocks. See SIZE format below
-B, --ignore-backups
do not list implied entries ending with ~
-c
with -lt: sort by, and show, ctime (time of last modification of file status information)
with -l: show ctime and sort by name otherwise: sort by ctime
-C
list entries by columns
--color[=WHEN]
colorize the output. WHEN defaults to 'always' or can be 'never' or 'auto'. More info below
-d, --directory
list directory entries instead of contents, and do not dereference symbolic links
-D, --dired
generate output designed for Emacs' dired mode
-f
do not sort, enable -aU, disable -ls --color
-F, --classify
append indicator (one of */=>@|) to entries
--file-type
likewise, except do not append '*'
--format=WORD
across -x, commas -m, horizontal -x, long -l, single-column -1,
verbose -l, vertical -C
--full-time
like -l --time-style=full-iso
-g
like -l, but do not list owner
--group-directories-first
group directories before files.
augment with a --sort option, but any
use of --sort=none (-U) disables grouping
-G, --no-group
in a long listing, don't print group names
-h, --human-readable
with -l, print sizes in human readable format (e.g., 1K 234M 2G)
--si
likewise, but use powers of 1000 not 1024
-H, --dereference-command-line
follow symbolic links listed on the command line
--dereference-command-line-symlink-to-dir
follow each command line symbolic link that points to a directory
--hide=PATTERN
do not list implied entries matching shell PATTERN (overridden by -a or -A)
--indicator-style=WORD
append indicator with style WORD to entry names: none (default), slash (-p), file-type
(--file-type), classify (-F)
-i, --inode
print the index number of each file
-I, --ignore=PATTERN
do not list implied entries matching shell PATTERN
-k
like --block-size=1K
-l
use a long listing format
-L, --dereference
when showing file information for a symbolic link, show information for the file the link references
rather than for the link itself
-m
fill width with a comma separated list of entries
-n, --numeric-uid-gid
like -l, but list numeric user and group IDs
-N, --literal
print raw entry names (don't treat e.g. control characters specially)
-o
like -l, but do not list group information
-p, --indicator-style=slash
append / indicator to directories
-q, --hide-control-chars
print ? instead of non graphic characters
--show-control-chars
show non graphic characters as-is (default unless program is 'ls' and output is a terminal)
-Q, --quote-name
enclose entry names in double quotes
--quoting-style=WORD
use quoting style WORD for entry names: literal, locale, shell, shell-always, c, escape
-r, --reverse
reverse order while sorting
-R, --recursive
list subdirectories recursively
-s, --size
print the allocated size of each file, in blocks
-S
sort by file size
--sort=WORD
sort by WORD instead of name: none -U, extension -X, size -S, time -t,
version -v
--time=WORD
with -l, show time as WORD instead of modification time: atime -u, access -u,
use -u, ctime -c, or status -c; use specified time as sort key if --sort=time
--time-style=STYLE
with -l, show times using style STYLE: full-iso, long-iso, iso, locale, +FORMAT. FORMAT
is interpreted like 'date'; if FORMAT is FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files
and FORMAT2 to recent files; if STYLE is prefixed with 'posix-', STYLE takes effect only outside
the POSIX locale
-t
sort by modification time
-T, --tabsize=COLS
assume tab stops at each COLS instead of 8
-u
with -lt: sort by, and show, access time with -l: show access time and sort by
name otherwise: sort by access time
-U
do not sort; list entries in directory order
-v
natural sort of (version) numbers within text
-w, --width=COLS
assume screen width instead of current value
-x
list entries by lines instead of by columns
-X
sort alphabetically by entry extension
-1
list one file per line
SELinux options:
--lcontext
Display security context. Enable -l. Lines will probably be too wide for most displays.
-Z, --context
Display security context so it fits on most displays. Displays only mode, user, group, security
context and file name.
--scontext
Display only security context and file name.
--help
display this help and exit
--version
output version information and exit
SIZE may be (or may be an integer optionally followed by) one of following: KB 1000, K 1024, MB 1000*1000,
M 1024*1024, and so on for G, T, P, E, Z, Y.
Using color to distinguish file types is disabled both by default and with --color=never.
With --color=auto, ls emits color codes only when standard output is connected to a terminal.
The LS_COLORS environment variable can change the settings. Use the dircolors command to set
it.
One confusing behavior of ls is the difference between the ls command and the ls * command.
The ls command has no argument, so by default a list of files in the current directory
is displayed.
The ls * command uses the "Basic Regular expressions" consisting of a single metacharacter
"*". It means any sequence of letters so it will match all file and all directories. Therefore, this
command provides the ls command with one argument for every file in the current directory.
For ordinary files, the two commands produce the same output, but when subdirectories are present,
ls recursively list subdirectories too.
NOTE: In multicolumn output mode, the files are listed column-wise and not row-wise as
you might expect.
It is important to understand the information provided by the -l (lowercase L) option. This
option is the only way to discover key information, such as file type, ownership, and security, associated
with each file. The long-format output of the ls command contains, typically, seven fields:
Mode It shows both the file type and the privileges (such as read, write) associated with the
file.
Links Number of names associated with the file.
Owner Name of file owner.
Group Name of the group that can access this file.
File size Size of file (in bytes if BSD or blocks if System V).
Modification date Time stamp of last file modification.
Filename Name of the file.
NOTE: Do not confuse the ls -l (lowercase L) command with the ls -1 (numeric one)
command. On some systems, the -1 option is used to force a single-column output from ls.
The following is a sample output of an ls -l command:
% ls -l /etc/passwd
-rw-r--r-- 1 root adm 19797 Aug 20 05:58 /etc/passwd
It is interesting to note that the modification date field does not contain "year" information.
Command ls supports so called "basic regular expression", the most primitive type of regular
expressions. The five special characters ("*", "?", "[", "]", and "-") used in filename generation and
pathname expansion are discussed in the following sections.
The "*" Metacharacter
The asterisk ("*") is the most universal wildcard and is often used. It simply means any and all
characters. For example, the string "a*" means all files beginning with the letter "a". You can
use as many asterisks in a single expression as you need to define a set of files. For example, the
expression *xx*.dat defines any filename with the extension dat that has xx anywhere in the rest of
the name. Matches include the filenames abxx.dat, 1xx33.dat, xxyyzz.dat, and the simple name xx.dat.
The "?" Metacharacter
The question mark ("?") represents a single occurrence of any character. Thus the string "???"
represents all files whose names consist of just three characters. You can generate a list of files
with three-character extensions with the string *.???. For example, if you're searching a directory
containing graphics images as well as other data, the following command lists all files with extensions
such as tif, jpg, and gif as well as any other files with three-character extensions:
ls *.???
The "[]" Expression
Using the square brackets, you can select a class of characters such as [124], which allows only
the characters 1, 2, or 4. You can also describe a range of characters such as [A-Z], which represents
any characters between uppercase A and uppercase Z, inclusive. You can also specify a set of ranges
such as [1-3, 5-8, a-e, A-E].
The hyphen ("-") loses its role as a metacharacter when it is used outside the square brackets. Conversely,
the asterisk and the question mark lose their power as metacharacters when they are used within the
square brackets. For example, -[*?]abc matches exactly two filenames: -*abc and -?abc.
TIP: Although possible, it is best to avoid creating filenames that contain dashes, asterisks,
question marks, or other metacharacters.
Special characters, or metacharacters, are characters that have a special meaning to the shell. Avoid
using any of these characters in a filename because files with metacharacters in their names are somewhat
tricky to access, and certain programs might not be able to access them at all. The standard special
characters are as follows:
& ; | * ? ` " [ ] ( ) $ < > { } ^ # / \ % ! ~
NOTE: The ~/ combination can be used to reference your home directory. Therefore, cd ~/
(or simply cd) changes your working directory to your home directory. Similarly, ~username
can be used to reference that user's home directory.
Although not considered special characters, Return, Spacebar, and Tab also have special meaning to
the shell. Return usually ends a command line and initiates execution of a command. The Space and Tab
characters separate elements on the command line and are collectively known as white spaces or
blanks.
In you need to use one of the metacharacters as a regular character, you can quote it. Another
often used term with the same meaning as quote is escape: You can escape a metacharacter. The
shell treats a quoted metacharacter as a regular character. There are three ways to quote, or escape,
a character:
Precede it with a backslash ("\"). One backslash must precede each character that you
are quoting. If you're using two or more metacharacters, you must precede each with a backslash.
For example, ** must be entered as \*\*. You can quote a backslash just as you would quote any other
metacharacters--by preceding it with a backslash (for example, "\\").
Enclose the metacharacters between single quotation marks, for example `**'. You can quote
many special and regular characters between a pair of single quotation marks, for example, `* and
? are wildcards'. The regular characters remain regular, and the shell also treats the special characters
as regular characters.
Enclose the metacharacters between double quotation marks, for example, "**". As with
single quotation marks, you can quote many meta and regular characters between a pair of double quotation
marks.
CAUTION
The only way to quote control characters, such as Ctrl-h and Ctrl-m, is to precede each with a Ctrl-v.
Quotation marks and backslashes don't work for control characters.
The most commonly used quoting method is to use backslashes.
Moreover you just choose those relevant and not all options. E.g.,
ls -l --time-style=+%H
will show only hour.
ls -l --time-style=+%H:%M:%D
will show Hour, Minute and date.
# ls -l --time-style=full-iso
ls Command Full Time Style
# ls -l --time-style=long-iso
Long Time Style Listing
# ls -l --time-style=iso
Time Style Listing
# ls -l --time-style=locale
Locale Time Style Listing
# ls -l --time-style=+%H:%M:%S:%D
Date and Time Style Listing
# ls --full-time
Full Style Time Listing
2. Output the contents of a directory in various formats such as separated by commas, horizontal, long, vertical, across, etc.
Contents of directory can be listed using
ls command
in various format as suggested below.
across
comma
horizontal
long
single-column
verbose
vertical
# ls ""-format=across
# ls --format=comma
# ls --format=horizontal
# ls --format=long
# ls --format=single-column
# ls --format=verbose
# ls --format=vertical
Listing Formats of ls Command
3. Use ls command to append indicators like (/=@|) in output to the contents of the directory.
The option
-p
with "
ls
" command will server the purpose.
It will append one of the above indicator, based upon the type of file.
# ls -p
Append Indicators to Content
4. Sort the contents of directory on the basis of extension, size, time and version.
We can use options like
--extension
to sort the output by extension, size by extension
--size
, time by using extension
-t
and version using extension
-v
.
Also we can use option
--none
which will output in general way without any sorting in actual.
# ls --sort=extension
# ls --sort=size
# ls --sort=time
# ls --sort=version
# ls --sort=none
Sort Listing of Content by Options
5. Print numeric UID and GID for every contents of a directory using ls command.
The above scenario can be achieved using flag
-n
(Numeric-uid-gid) along with
ls
command.
# ls -n
Print Listing of Content by UID and GID
6. Print the contents of a directory on standard output in more columns than specified by default.
Well
ls
command output the contents of a directory
according to the size of the screen automatically.
We can however manually assign the value of screen width and control number of columns appearing. It can be done using switch "
--width
".
# ls --width 80
# ls --width 100
# ls --width 150
List Content Based on Window Sizes
Note
: You can experiment what value
you should pass with
width
flag.
7. Include manual tab size at the contents of directory listed by ls command instead of default 8.
Using ls is probably one of the first commands an administrator
will learn for getting a simple list of the contents of the directory. Most
administrators will also know about the -a and -l
switches, to show all files including dot files and to show more detailed data
about files in columns, respectively.
There are other switches to GNU ls which are less frequently used,
some of which turn out to be very useful for programming:
-t - List files in order of last modification date, newest
first. This is useful for very large directories when you want to get a quick
list of the most recent files changed, maybe piped through head or
sed 10q. Probably most useful combined with -l. If
you want the oldest files, you can add -r to reverse the
list.
-X - Group files by extension; handy for polyglot code, to
group header files and source files separately, or to separate source files
from directories or build files.
-v - Naturally sort version numbers in filenames.
-S - Sort by filesize.
-R - List files recursively. This one is good combined with
-l and piped through a pager like less.
Since the listing is text like anything else, you could, for example, pipe the
output of this command into a vim process, so you could add
explanations of what each file is for and save it as an inventory
file or add it to a README:
$ ls -XR | vim -
This kind of stuff can even be automated by make with a little
work, which I'll cover in another article later in the series.
The ls ( list ) command shows the contents of the current directory. Although
ls is a familiar command available on all Unix-like operating system, Linux uses the
ls command from the GNU fileutils project and has many special switches and
features.
$ ls
archive check-orders.sh orders.txt
ls has switches that affect how the files are listed, including the level of detail, the sorting
order, and the number of columns. Most Linux distributions set up certain defaults for ls command.
Red Hat, for example, has the -q and -F switches on by default. From the point of view of script
writing, it's not safe to use the ls command in a script without specifying the appropriate switches
because you can't be sure which defaults a particular distribution uses.
ls hides files that begin with a period. This is the Linux convention for configuration
files, history files, and other files that a user isn't normally interested in. To see these files,
use the -A ( all ) switch. Use -a ( absolutely all ) to show the
implicit . and .. files as well.
$ ls -A
.bash_history .bash_logout .bash_profile .bashrc archive
check-orders.sh orders.txt
The filenames can be printed in color to show the kind of file they are. The colors are defined
in a file /etc/DIR_COLORS. You can customize the colors using a .dir_colors file in your own directory.
The format of the file is described in the /etc/DIR_COLORS file.
To display the files without color and with symbols instead, use the --color and
--classify (or -F ) switches. (On most Linux distributions, this feature is
turned on using aliases.)
The --classify symbols are directories (/), programs (*), symbolic links (@), pipes
(|), and Unix domain socket files (=). These symbols are not a part of the name: They are hints
as to the type of file. In this example, archive is a directory and check-orders.sh is a program.
Another very important switch is --hide-control-chars (or -q ). Linux filenames
can contain any character, even control characters. It is possible to create a filename with hidden
characters in the name. In these cases, you can't rename or delete the file unless you know what
the hidden characters are. Contrary to what the name implies, the --hide-control-chars
switch displays any unprintable characters in the filename as question marks, making their
locations visible.
We have covered most of the things on 'ls' command in last two articles of our Interview series.
This article is the last part of the 'ls command' series. If you have not gone through last two articles
of this series you may visit the links below.
◾15 Basic 'ls' Command Examples in Linux
◾15 Interview Questions on Linux "ls" Command Part 1
◾10 Useful 'ls' Command Interview Questions Part 2
I didn't like the fact that folders on my NTFS partitions were shown in blue on a green background.
I though that this was just plain ugly. I set out to change that.
In the file /etc/DIR_COLORS there is a line that reads:
PHP Code:
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
A far as I can tell this is the line that is responsible for the ugly blue on green background display.
I changed it so that there was essentially no background color. Just blue text. The edited line then
is:
PHP Code:
OTHER_WRITABLE 34;1 # dir that is other-writable (o+w) and not sticky
To see the change I needed to close and re-open the terminal. I'm happy again, at least for a few
minutes or until someone tells me my method is just plain wrong, and can now function as a productive
member of society.
Is this the proper method? No freakin' idea.
Did I get the desired results? Yep.
Will I be proven wrong at some point? Probably.
Do I care? Nope.
Just thought I'd share in case anyone else despises the blue on green text.
__________________
Glenn
The Bassinator
[SIGPIC][/SIGPIC]
Laptop: Just a couple of old single core units
Desktop: BioStar MCP6PB M2+ / AMD Phenom 9750 Quad Core / 4GB / Kingston HyperX 3K SSD 240GB SATA
3.0 / 1TB SATA / EVGA GeForce 8400 GS 1GB
Reply With Quote
glennzo
View Public Profile
Find all posts by glennzo
#2 Old 21st April 2012, 02:46 PM
PabloTwo Offline
"Registered User" T-Shirt Winner Join Date: Mar 2007
Location: Seville, FL
Posts: 6,203
linuxchrome
That's basically correct. There are some old moldy threads here on the forum discussing this. What
I always do is to make a copy of /etc/DIR_COLORS to ~/.dir_colors, then edit the file in my home
directory.
To make the ntfs directories appear as the same color as your other directories, the color code to
use is:
Code:
OTHER_WRITABLE 01;34 # dir that is other-writable (o+w) and not sticky.
You can see the default directory color code with the command "dircolors -p". Near the top of
the output, you'll see this:
Code:
DIR 01;34 # directoryReply With Quote
PabloTwo
View Public Profile
Find all posts by PabloTwo
#3 Old 21st April 2012, 03:56 PM
glennzo Online
Un-Retired Administrator Join Date: Mar 2004
Location: Salem, Mass USA
Age: 57
Posts: 14,837
linuxubuntuchrome
Thanks for the tips PabloTwo
__________________
Glenn
The Bassinator
[SIGPIC][/SIGPIC]
Laptop: Just a couple of old single core units
Desktop: BioStar MCP6PB M2+ / AMD Phenom 9750 Quad Core / 4GB / Kingston HyperX 3K SSD 240GB SATA
3.0 / 1TB SATA / EVGA GeForce 8400 GS 1GB
Reply With Quote
glennzo
View Public Profile
Find all posts by glennzo
Very clever. Usually this is seen as part of a for loop:
for f in `ls *`; do
command "$f" # newbies will often forget the quotes, too
done
Of course, the ls is not very useful. It will just waste an extra process doing absolutely
nothing. The * glob will be expanded by the shell before ls even gets
to see the file names (never mind that ls lists all files by default anyway, so naming
the files you want listed is redundant here).
Here's a related but slightly more benign error (because echo is often built into
the shell):
for f in `echo *`; do
command "$f"
done
But of course the backticks are still useless, the glob itself already does the expansion of the
file names. (See Useless Use of echo above.) What was meant here was
obviously
for f in *; do
command "$f"
done
Additionally, oftentimes the command in the loop doesn't even need to be run in a for loop, so you
might be able to simplify further and say
command *
A different issue is how to cope with a glob which expands into file names with spaces in them, but
the for loop or the backticks won't help with that (and will even make things harder). The plain
glob generates these file names just fine;
click here for an example.
See also Useless Use of Backticks
Finally, as Aaron Crane points out, the result of ls * will usually be the wrong
thing if you do it in a directory with subdirectories; ls will list the contents of
those directories, not just their names.
The Last but not LeastTechnology is dominated by
two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt.
Ph.D
Copyright 1996-2021 by Softpanorama Society. www.softpanorama.org
was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP)
without any remuneration. This document is an industrial compilation designed and created exclusively
for educational use and is distributed under the Softpanorama Content License.
Original materials copyright belong
to respective owners. Quotes are made for educational purposes only
in compliance with the fair use doctrine.
FAIR USE NOTICEThis site contains
copyrighted material the use of which has not always been specifically
authorized by the copyright owner. We are making such material available
to advance understanding of computer science, IT technology, economic, scientific, and social
issues. We believe this constitutes a 'fair use' of any such
copyrighted material as provided by section 107 of the US Copyright Law according to which
such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free)
site written by people for whom English is not a native language. Grammar and spelling errors should
be expected. The site contain some broken links as it develops like a living tree...
You can use PayPal to to buy a cup of coffee for authors
of this site
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or
referenced source) and are
not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society.We do not warrant the correctness
of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be
tracked by Google please disable Javascript for this site. This site is perfectly usable without
Javascript.