Almost every command has an associated manual page. Suppose the command verb is ls, then typing man ls at the command line prompt will give you that command's reference page.
The -t flag has no specific meaning across all commands. You will need to look at the man page for the particular command to find out what it does.
You are right that it is amazingly poorly documented. What documentation that there is is quite simple:
-t Exit after reading and executing one command.
The bash source code is available here. I looked at version 4.2. The short flags handled by bash are listed in flags.c and in there is the relevant line:
{ 't', &just_one_command },
So, -t on the command line sets the variable just_one_command. This variable is used in just one place: it occurs in an if condition at the end of a loop in eval.c:
if (just_one_command)
EOF_Reached = EOF;
In other words, if the -t flag is given, then, after the first command is executed, the end-of-file condition is signaled and bash exits.
MORE DETAIL
From eval.c, command line execution in bash appears to be controlled by the function reader_loop:
reader_loop ()
{
int our_indirection_level;
COMMAND * volatile current_command;
USE_VAR(current_command);
current_command = (COMMAND *)NULL;
our_indirection_level = ++indirection_level;
while (EOF_Reached == 0)
{
int code;
code = setjmp_nosigs (top_level);
[ ... Much code removed ... ]
if (just_one_command)
EOF_Reached = EOF;
}
indirection_level--;
return (last_command_exit_value);
}
The loop inside reader_loop continues until it receives the signal EOF_Reached. The sole effect of the -t option is to set this flag at the end of loop which assures that the loop is executed only once.
Using the bash builtin help, i.e. by saying help set, you'd find:
-t Exit after reading and executing one command.
Since bash parses a line at a time, you might have multiple commands separated by ; on the same line and those would execute. For example, the following:
set -t; echo Do something; echo do more; echo and more
echo no more
would produce
Do something
do more
and more
as the output. On the other hand, the following:
set -t
echo Do something
echo do more
echo and more
echo no more
would not produce any output.
You could look for the documentation in the info page. Say:
info bash "Shell Builtin Commands"
Navigate to * Bourne Shell Builtins:: and search for help.
I've seen multiple guides and people referencing things like "sudo | tee echo > /proc/sys/vm" etc etc
The context is completely inaccurate, but the question stands. What does the 'tee' and '|' command do versus just sudo su and echo?
The sticky bit is today incredibly confusing. It no longer pins the file into memory, making it actually "sticky", anymore. Sometimes it is called the "tacky" bit because it is represented as a 't' or 'T', but other folks still call it sticky. It only matters in modern linux and unix when applied to a directory, as far as I can tell. It means that people in groups who have the permission to delete a file still can't do it if the sticky bit is set on the directory. But it gets more confusing. It shows up in the last field, which is the execute/search field for "other" users, but acts on "group" users ("other" normal users can never delete files). The reason why it isn't shown in the "group" execute field is because that one changes to an "s" if the SETUID bit is set for group. I think. I am still researching that one.
man ls is your friend:
t The sticky bit is set (mode 1000), and is searchable or executable.
(See chmod(1) or sticky(8).)
About sticky bit:
When set, it instructed the operating system to retain the text segment of the program in swap space after the process exited. This speeds up subsequent executions by allowing the kernel to make a single operation of moving the program from swap to real memory. Thus, frequently-used programs like editors would load noticeably faster.
-s Switch: Squeeze (remove repeated characters)
echo i am a good boy | tr -s good badoutput:
i am a bd bdy
There are two things happening behind the scenes that make this happen. Firstly, if the second argument to tr is shorter than the first then the last character in the 2nd arg is repeated to make it the same length as the first. So the equivalent command is:
echo i am a good boy | tr -s good badd
The other thing that is happening is when characters in the first argument are repeated they overwrite any previous occurrence (I'm referring to the two oos in good). This makes the command now equivalent to:
echo i am a good boy | tr -s god bdd
(the second o to d replacement overwrites the previous o to a replacement, making it redundant)
Without the -s switch the output would be
i am a bddd bdy
With the -s switch tr 'squeezes' any repeated characters that are listed in the last argument leaving the final output:
i am a bd bdy
-c Switch: Complement
The -c switch is used to match the complement of the first argument (i.e. all characters not listed in arg 1). As a result, arg 1 will contain many letters (256-3). Now, the same thing happens to arg 2 as in the previous case: Arg 2's final character gets repeated to match the length or Arg 1. So the original statement:
echo i am a good boy | tr -c good bad
is equivalent to:
echo i am a good boy | tr abcefhijklmnp... baddddddddddd...
(note the missing g, o and d in the first set, also note that d will replace every other character in the second set -- including the space character)
This is why i am a good boy turns into dddddddgoodddodd
More info here: http://www.linuxjournal.com/article/2563
Your understanding of -s is incorrect, it replaces repeated occurrences of characters in set 1 in the input with a single character. it does not modify the set, eg.
echo i am a good boy | tr -s god bad
gives
i am a bad bay
The -c option replaces set 1 with its complement (ie. the set of all characters not contained in set 1). You can use this to remove all but the specified characters for example.
echo i am a good boy | tr -cd gobdy
outputs
goodboy
The ls man page can help clarify these options.
The -l option controls output format, producing a 'long' listing.
The -t option sorts by modification time. This value is already present in the long format.
The -u option behaves differently based on the options it is used with.
- On its own, as
ls -u, it sorts by access time. - With the
-loption, it displays the access time, but sorts by name. In this case, it acts as an output modifier rather than a sorting option. - With
-land-t, it shows the access time and also sorts by it.
The -c option works the same way with the ctime property.
The complexity comes from the need to modify the long listing format. Several other options work this way: -lo to suppress group information, -lG to suppress owner information, -lh to display sizes in human-readable format, and so on).
The GNU-style options from the ls manual makes this easier to understand.
-l is --format=long.
-t is --sort=time.
-u is --time=atime.
So -lu is --format=long --time=atime. That is, show the long listing, but with atime instead of the default mtime.
And -ltu is --format=long --sort=time --time=atime. In this case, show the atime and sort by it.
You are mostly correct, -t means "sort by time" and -u means "use the atime timestamp" (when sorting with -t or when showing the timestamp with -l). The POSIX -u option does not imply changing the default order of sorting unless -t is also used to explicitly request sorting by a timestamp.
The POSIX specification of ls has the following bits of text in it:
-uUse time of last access (see XBD <sys/stat.h>) instead of last modification of the file for sorting (
-t) or writing (-l).
However, the GNU people thought that it would be convenient to let ls -u also sort by atime, since otherwise there would be no difference between the outputs of ls -u and ls (both would be sorted by name and no timestamps would show). This is why GNU ls works differently from any other system's implementation of ls.
The documentation of ls on a GNU system summarizes this as
-uwith
-lt: sort by, and show, access time; with-l: show access time and sort by name; otherwise: sort by access time, newest first
What's not mentioned in this short text is that any other options that provides a similar output format as -l, e.g. -o, -g and -n, also removes the sorting effect from the -u option like -l does. These options all have the text "like -l but, ..." in the GNU ls manual.
The -c option in GNU ls depends on other options in a similar way to sort/display the ctime timestamp.
The GNU ls has worked like this since 1999 or thereabouts.
Regardless of what implementation of ls you are using, to sort the long format output on a timestamp, you will have to use -t. Use -l -ut to sort on atime, -l -ct to sort on ctime, or just -l -t to sort on mtime.