Flag | Usage |
---|---|
|
Show current settings of the system clock and RTC, including whether network time synchronization through systemd-timesyncd.service is active (even if it is inactive, a different service might still synchronize the clock). |
list-timezones |
|
set-timezone timezone |
|
timesync-status |
|
Flag | Usage |
---|---|
-T | Use TCP SYN for probes |
cols x lines : 126 x 48
timeout options duration command
This returns (details) :Flag | Usage |
---|---|
duration | duration :
|
-k extraDuration --kill-after=extraDuration |
Also send a kill signal extraDuration time units after sending the initial signal if command is still running. |
-s signal --signal=signal |
Condition | Exit code | |
---|---|---|
timeout ? | extra option | |
No | (none) | exit code of command |
No | --preserve-status | exit code of command |
Yes | (none) | 124 |
Yes | --preserve-status | command-dependant ? |
timeoutSeconds=3; for sleepDuration in 2 5; do for option in '' '--preserve-status'; do echo -e "\nSleep : ${sleepDuration}s (timeout : ${timeoutSeconds}s), timeout option : '$option'"; /usr/bin/time -f %e timeout $option ${timeoutSeconds}s sleep $sleepDuration; echo $?; done; done
Sleep : 2s (timeout : 3s), timeout option : '' 2.00 0 Sleep : 2s (timeout : 3s), timeout option : '--preserve-status' 2.00 0 Sleep : 5s (timeout : 3s), timeout option : '' Command exited with non-zero status 124 3.00 124 Sleep : 5s (timeout : 3s), timeout option : '--preserve-status' Command exited with non-zero status 143 3.00 143
type [options] command
Flag | Usage |
---|---|
-a | display all locations containing an executable named command, includes aliases, builtins, and functions |
-t | display a single word describing the type of object command is : alias, keyword, function, builtin, file or nothing if not found. |
ls is aliased to `ls --color=auto'
ls is /bin/ls
'myFunction' is a function 'aFunctionThatDoesNotExist' does not exist
Flag | Usage |
---|---|
-l device | list the contents of the filesystem superblock : type, last mount point, status, FS creation/last mount/last write/last check/next check, mount count, ... |
tree is a utility designed to display directories and files tree structure. It can easily be installed on Debianoids with : apt-get install tree
Flag | Usage |
---|---|
-d | List directories only |
-f | Print the full path prefix for each file |
-L n | Go deep up to n levels maximum |
/
:
. This keeps directories only.:
--
[space]
-
with a |
to draw a tree (no s///g
so it matches the first it finds)dirToDisplay='/path/to/directory' cd "$dirToDisplay"; ls -R | awk -F 'About lines above :/
' '/:$
/ { \ if (length($NF)==2) { next } \ if (NF>0) { printf " " } \ for (i=0;i<NF-2;i++) { printf "| " } \ if (NF>1) { printf "+--" } \ cleanDirName=gensub(/:$
/, "", "g
", $NF); print cleanDirName \ }'; cd - 1>/dev/null
$NF
is a single-letter directory name followed by the :
appended by ls -Rtrap commands listOfSignalsToCatch
if
, while
and until
loops and AND &&
, OR ||
and NOT !
logical operations)
Flag | Usage |
---|---|
-l | print a list of signal names and numbers |
-p signal | list traps that are currently registered with signal (example) |
--help | (explicit) |
finish() { # clean your mess before leaving } trap finish EXIT
Flag | Usage | Example |
---|---|---|
-c set1 set2 | Use the complement of set1 (i.e. "all characters except those in set1) (details)
I can see no use case of -c alone. tr -cd listOfCharacters can be used to keep only the listed characters. |
echo 'Hello World' | tr -cd [:lower:]
elloorld |
-d character --delete character |
Delete all occurrences of character from the input stream
|
echo 'Hello World' | tr -d o
Hell Wrld |
-s characters --squeeze-repeats characters |
Replace repetitions of any character of characters with a single occurrence of itself |
|
If 2 sets of characters are provided : tr -s set1 set2, tr :
|
|
y///
SPACE
characters visible :
' '_
' < someFile | less\n
' '
' < inputFile\n
' '
' < inputFile > outputFile\n
'foobarbaz
\n
' < inputFile\n
' | wc -lCRLF
aka \r\n
) into Unix format (LF
aka \n
) (details on line endings) :tr -d '\r' < fileToConvert > convertedFile
anyCharacterStart-anyCharacterStop
, tr considers it as a range of characters. However, for a range to be valid, anyCharacterStart must be found prior to anyCharacterStop in the current collation order (here : ASCII for +-*
).*-+
isn't even a range since, in ASCII order, we have :
*
+
,
-
*-+
just means the *
and +
characters.
This is no big deal unless you mean *
and +
and -
. In such case, specify *+-
.
Flag | Usage |
---|---|
-p PID | Monitor only the selected PID. To specify multiple PIDs :
|
Key | Usage |
---|---|
< / > | set the column on the left/right as the sorting column (unless the current column is already the left/rightmost column)
use this with x
|
1 | toggle single/separate CPU states |
b | switch to reverse video to highlight running processes |
B | switch to bold display to highlight running processes |
c | toggle the long-command line display |
f | open the field selection window. |
F or O | open the Field sorting window. |
i | toggle idle and zombie processes |
k | kill a process (PID expected next) |
m | cycle through displays of memory+SWAP usage :
|
n + number # + number |
show number processes. 0 for no limit |
o | open the column ordering window. This controls the order of columns from left to right on the screen, not the sorting of processes. |
q | quit |
r | renice a process (PID expected next) |
R | Toggle reverse sorting order |
u | select a user (prompts for user name) |
W | Write the current settings to a file |
x | toggle highlight of the sorting column |
z | toggle between monochrome/color display and highlight running processes |
or SPACE | force task list refresh |
To forbid swapping for a specified process : echo 0 > /proc/pid/vm/swappiness
now()
now()
Flag | Usage |
---|---|
-a myFile | Change myFile's access time to the current value, or to the time specified with -t. |
-d dateString --date=dateString | use dateString instead of the current time. dateString is an almost "free form" human readable date string :
myFile=$(mktemp); date; for dateString in 'Sun, 29 Feb 2004 16:21:42 -0800' '2004-02-27 14:19:13.489392193 +0530' 'next Thursday' '' '@0' '@87000'; do echo -e "\n'$dateString'"; touch -d "$dateString" "$myFile"; ls -l "$myFile"; done; [ -f "$myFile" ] && rm "$myFile" Fri 16 Oct 2020 12:03:28 PM CEST now 'Sun, 29 Feb 2004 16:21:42 -0800' -rw------- 1 bob users 0 Mar 1 2004 /tmp/tmp.v7ewATXc4s due to time zones '2004-02-27 14:19:13.489392193 +0530' -rw------- 1 bob users 0 Feb 27 2004 /tmp/tmp.v7ewATXc4s 'next Thursday' -rw------- 1 bob users 0 Oct 22 2020 /tmp/tmp.v7ewATXc4s '' -rw------- 1 bob users 0 Oct 16 00:00 /tmp/tmp.v7ewATXc4s an empty string |
-m myFile | Change myFile's modification time to the current value, or to the time specified with -t. |
-r referenceFile | Use times of referenceFile |
-t timestamp | Specify time to use instead of current time. Timestamp format : [[CC]YY]MMDDhhmm[.SS].
Even though the seconds are optional, it may look dubious if many files ALL have times set to the exact minute : hh:mm:00
Seconds can be displayed with :
|
-rw------- 1 stuart developers 0 Jul 7 14:13 myFile -rw------- 1 stuart developers 0 May 26 14:13 myFile
Flag | Bash time | /usr/bin/time | Usage |
---|---|---|---|
-f formatSpec --format formatSpec |
|
||
-v --verbose | displays each available piece of information on the program's resource use on its own line
This only works when calling it with the absolute path : /usr/bin/time -v command. This is because Bash has a built-in time command that has less options.
|
real 0m0.004s user 0m0.003s sys 0m0.001s
real 0m0.001s user 0m0.002s sys 0m0.000s
real 0m0.003s user 0m0.000s sys 0m0.003s
real 0m0.000s
T
on plumbing pipes (which is why tee enjoys |
's )
hello world myFile1 myFile2 myFile3 myFile4 myFile5Many process substitutions hacks rely on this .
Flag | Usage |
---|---|
-a | append the output to the file (like >> ) instead of overwriting / creating a new file (like > ) |
tail -f test.log | egrep --line-buffered "error" | tee -a test.log_SHORT
bash: myFile{1..5}: ambiguous redirect
(no output)
hellothis writes into files in
>
-mode (details)
Flag | Usage |
---|---|
-D | List available interfaces |
-i interface | Listen on interface |
-L | List the known data link types for the interface and exit
tcpdump -i eth0 -L
Data link types for eth0 (use option -y to set): DOCSIS (DOCSIS) (printing not supported) EN10MB (Ethernet) |
-n | show addresses and ports numerically |
-q | quiet mode |
-sn | capture up to n bytes per packet. Defaults to 68. Setting this to 0 captures full packets |
-v -vv-vvv | Increasing verbosity |
-w capture.pcap | write the raw packets to capture.pcap rather than parsing and printing them out |
-X -XX |
Show the packet's contents in hex and ASCII Same as above, but also shows the ethernet header. |
then quit.
No, you can't. Use nc -u instead.
UDP is a connectionless protocol, which means it basically just sends packets out to the specified destination. TCP is connection-oriented which means it establishes a connection to the other end using the 3-way handshake.
So it makes sense to apply the telnet paradigm to TCP : you open a connection to a specific host and port, you still remain connected (for a period of time) even if you aren't sending any data and you can send and receive data continuously without having to reconnect in-between.
UDP, on the other hand, doesn't really fit the telnet model : its more of a fire-and-forget system where you fire-off a series of packets towards the destination. You then go on with something else (or just wait doing nothing) until (or if) the remote process sends some packets back.
Flag | Usage |
---|---|
-n number --lines=number |
|
-f | follow : display data as it arrives into the file |
-F | follow with retry : try to re-open the file, even though it became inaccessible |
Originally designed to make tape archives, today tar is used to gather files and directories into a single file (called a tar archive) so that moving and storing these files is more convenient. The final size of the tar archive is somewhat the sum of the size of the files it contains (unless using compression options).
There's no need to use tar for a single file : just compress it (bzip2, gzip).
Only root can create files on behalf of other users. So, in order to preserve ownership of files, you have to extract archives as root.
Flag | Usage |
---|---|
c | create an archive which name is the next parameter |
-C dir --directory=dir | change the working directory to dir after that point in a list of file names (details) |
--delete | delete file(s) from a tar archive
Does not work on compressed archives.
tar f archiveName.tar --delete fileToRemove_1 fileToRemove_2 fileToRemove_n
|
f | next parameter is a file name (to be used almost everytime) |
h --dereference | don't archive symlinks themselves but the files they point to : tar -cf archiveName.tar * --dereference By default, symlinks are archived... as symlinks |
j | use bzip2 as the compression algorithm |
-L length --tape-length=length |
|
-M --multi-volume | create / list / extract multi-volume archive, i.e. split the generated archive. See -L |
o --no-same-owner | When extracting an archive, do not attempt to preserve the owner specified in the tar archive.
This the default behavior for ordinary users.
|
p --preserve-permissions --same−permissions |
extract information about file permissions (i.e. ignore umask when extracting files) This is the default for root. |
r | append file(s) to an existing archive |
t | list content of archive (doesn't work on compressed archives) |
v | verbose |
x | extract files from specified archive. Files keep their original timestamp |
z | use gzip :
|
- | I've noticed sometimes a tar -[flags] command doesn't work whereas tar [flags] does. Just don't know why... (POSIX legacy stuff ?) |
--exclude='pattern' | don't archive files matching pattern (details, common problems with this option)
pattern :
Looks like --exclude is expected right before the list of files to archive :
|
version 1\.15.*2004-12-20
' -A 5 /usr/share/doc/tar/NEWS.gz, but nowhere in the man ) :
version 1.15 - Sergey Poznyakoff, 2004-12-20 * Compressed archives are recognised automatically, it is no longer necessary to specify -Z, -z, or -j options to read them. Thus, you can now run 'tar tf archive.tar.gz'.
z
j
; do echo -e "\nTesting with '-$option'"; for i in hello world; do echo "$i" > "$i"; done; tar cf$option "$archiveName" hello world; rm hello world; file "$archiveName"; tar xf "$archiveName"; ls -l; rm "$archiveName" hello world; doneTesting with '-z' ./archive: gzip compressed data, last modified: Tue May 14 08:02:09 2019, from Unix archive type reported by file total 12 -rw------- 1 stuart developers 142 May 14 10:02 archive -rw------- 1 stuart developers 6 May 14 10:02 hello files properly un-archived -rw------- 1 stuart developers 6 May 14 10:02 world Testing with '-j' ./archive: bzip2 compressed data, block size = 900k archive type reported by file total 12 -rw------- 1 stuart developers 143 May 14 10:02 archive -rw------- 1 stuart developers 6 May 14 10:02 hello files properly un-archived -rw------- 1 stuart developers 6 May 14 10:02 world
*
, tar complains Not found in archive (source) :Reproduce the problem : touch {a,b,c}.tar; tar xf *tar, outputs :
tar: This does not look like a tar archive this is normal as these are not genuine tar archives
tar: b.tar: Not found in archive
tar: c.tar: Not found in archive
tar: Exiting with failure status due to previous errors
What causes this behavior is that the command :
for
loop : for archive in a.tar b.tar c.tar; do tar xf "$archive"; done