Flag | Usage |
---|---|
-s busNumber:deviceNumber | return information about device found at busNumber:deviceNumber |
-t --tree | dump the physical USB device hierarchy as a tree. Verbosity can be increased twice with -v |
-v --verbose | verbose mode, which returns detailed information about USB devices |
Bus 001 Device 007: ID 045e:00cb Microsoft Corp. Basic Optical Mouse v2.0 Bus 001 Device 008: ID 047f:02f7 Plantronics, Inc. Plantronics BT600 Bus 001 Device 009: ID 13fd:1d40 Initio Corporation PHD Bus 001 Device 010: ID 04e8:6860 Samsung Electronics Co., Ltd Galaxy series, misc. (MTP mode) Bus 001 Device 011: ID 0529:0620 Aladdin Knowledge Systems Token JC Bus 001 Device 012: ID 047f:0127 Plantronics, Inc. Plantronics Voyager Focus UC Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 009: ID 13fd:1d40 Initio Corporation PHD Device Descriptor: bcdUSB 2.00 idVendor 0x13fd Initio Corporation idProduct 0x1d40 PHD iManufacturer 1 SPCCN iProduct 2 PHD iSerial 3 0010101D400000000 Configuration Descriptor: MaxPower 2mA Interface Descriptor: bInterfaceClass 8 Mass Storage
Flag | Usage |
---|---|
-a --all | explicit, see example below |
-s --short | show requested information in short format |
No LSB modules are available. result of -v Distributor ID: Ubuntu result of -i Description: Ubuntu 22.04.4 LTS result of -d Release: 22.04 result of -r Codename: jammy result of -c
Flag | Usage |
---|---|
-b | set bitrate |
-v | enable variable bitrate |
redirecting the standard output to a log file is just about the worst possible approach to logging : your log file is tied to the logging process, and you can't do anything about it. The actual solution is to use a proper logging system that would allow you to separate the actual log file from the process and allow you to use tools like syslog and logrotate.
NEEDED
lsblk -fap
Flag | Usage |
---|---|
-a --all | List all devices, including empty one (they are skipped by default) |
-f --fs | Output info filesystems : name (label), FS type, UUID, mount point |
-l --list | Format output as a list rather than a tree |
-p --paths | Print full device path, e.g. /dev/mapper/vg-root rather than just vg-root |
-S --scsi | Output info about SCSI devices only |
#!/usr/bin/env bash number=0 myFunction1() { number=1 echo "myFunction1 : $number" } myFunction2() { local number=2 echo "myFunction2 : $number" } echo $number myFunction1 echo $number myFunction2 echo $number
0 global initial value myFunction1 : 1myFunction1
internal value 1 global value overwritten bymyFunction1
myFunction2 : 2myFunction2
internal value 1 unchanged global value
Flag | Usage |
---|---|
(none) | Create a hard link |
-f --force | Overwrite link if it already exists
When man ln says :
Check it :
-f, --force remove existing destination fileswhat is meant by destination file :
cd /tmp; touch target; echo '1. create link'; ln -s target link; echo '2. try to overwrite link'; ln -s target link; echo '3. overwrite link'; ln -sf target link; rm link target
1. create link 2. try to overwrite link ln: creating symbolic link `link': File exists 3. overwrite link |
-s | Create a symbolic link (a.k.a "symlink") |
The pseudo user reboot logs in each time the system is rebooted. Thus last reboot will show a log of all reboots since the log file was created.
On Debian Wheezy, /var/log/btmp does not trace failed SSH login attempts. This is a known Debian bug, and has been fixed with OpenSSH package version 1:6.6p1-1 (source).
Flag | Usage |
---|---|
-number -n number | Show latest number entries |
-F | Full display : login time + logout time + remote host |
-i | Display IP addresses rather than hostnames |
-x | Display the system shutdown entries and runlevel changes |
C.UTF-8 en_GB.UTF-8 en_US.UTF-8 fr_CA.UTF-8 fr_FR.UTF-8
Flag | Usage |
---|---|
(none) | Display a summary of the current locale environment |
-a | List all available locales |
export LANG="fr_FR.UTF-8"
During a PuTTY session, no effect as normal user, worked as root not in the current shell but in a new one.perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "fr_FR.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
There may be unnecessary / overkill / wrong(?) steps in the solution below.
ls -lh /var/log/lastlog -rw-r--r--. 1 root root 251G 3 mars 11:30 /var/log/lastlog du -h /var/log/lastlog 84K /var/log/lastlog
Flag | Usage |
---|---|
-1 | list 1 file per line |
-a --all | list all files, including hidden files (name starting with a . ) |
-A --almost-all | do not list implied . and .. |
-b --escape | print octal escapes for nongraphic characters |
--block-size=size | With -l : scale sizes by size before printing them. size is an integer and optional unit (example: 10K is 10*1024). Units are :
Files smaller than size will actually be reported 1 unit :
tmpFile=$(mktemp); fallocate -l 12m "$tmpFile"; for unit in K M G T; do echo "unit : $unit"; ls -l --block-size=1$unit "$tmpFile"; done; rm "$tmpFile"
unit : K -rw------- 1 kevin users 12288 Mar 7 09:41 /tmp/tmp.NdDV69WZth KiB : OK unit : M -rw------- 1 kevin users 12 Mar 7 09:41 /tmp/tmp.NdDV69WZth MiB : OK unit : G -rw------- 1 kevin users 1 Mar 7 09:41 /tmp/tmp.NdDV69WZth GiB : KO unit : T -rw------- 1 kevin users 1 Mar 7 09:41 /tmp/tmp.NdDV69WZth TiB : KO |
-c | |
--color=when | colorize the output. when is one of :
ls colors are often automatically disabled in compound commands (pipes or find -exec ls ). They can be enabled by being explicitly specified in the command line with --color=always
|
-d --directory | list directories themselves, not their contents |
-F --classify | append indicator (one of *, /, =, >, @, |) to entries (for details about these : info ls + search classify)
I see no real use case for this option (especially if you have enabled colored output), which may display misleading information : is someFile* a filename actually ending with a
* or a file with the execution bit set ?
|
-f | do not sort + enable -aU + disable -ls --color (=--color=never) |
-h --human-readable | print file size in human readable format (2K, 34M, 1G, ...) |
-H --dereference-command-line |
follow symbolic links listed on the command line
symlinks MUST be specified on the command line to be de-referenced :
Quick'n'dirty tip : this seems to work better if you put a
* at the end of the symlink (either regular file or directory) you'd like de-referenced. |
-I pattern --ignore=pattern |
Do not list entries matching the shell pattern pattern |
-i --inode | show the inode number |
-L --dereference | when "ls-ing" a symbolic link, show information for the target of the link, not for the link itself |
-l | use a long display format. By default, this mode displays the modification time. Display the access time with -u. |
-n --numeric-uid-gid | show UID and GID in numerical form instead of showing names |
-R --recursive | list subdirectories recursively |
-r --reverse | reverse order while sorting |
-s --size | print the allocated size of each file, in blocks |
-S | sort by DESC file Size |
-t | sort by modification time (mtime), newest first
to sort by other time values, see --time
|
--time=value | instead of sorting by modification time (mtime, default when using -t), sort by :
|
-u | use time of last access instead of last modification while sorting (-t) or printing (-l) (source) |
-U | do not sort : list entries in directory order |
-Z --content | print security context of each file |
-rw------- 1 bob developers 4.0K Dec 16 18:20 myFile -rw------- 1 bob developers 280 Dec 16 17:30 myFileToo drwx------ 2 bob developers 4.0K Dec 16 17:26 myDirectory drwxrwxr-x+ 2 stuart otherGroup 4096 Dec 16 17:19 someOtherDirectory
[SPACE]
.
+
+%d-%m-%Y %H:%M:%S
' filefull-iso
' file+%d-%m-%Y %H:%M:%S
' filefull-iso
' filefiles with unusual names
with "ls -1" :
aFilenameWithoutSpace
'a filename with space and'$'\n''a newline'ls looks smart enough to list 3 files
'a filename with spaces'
============
with "ls | cat" :
aFilenameWithoutSpace
a filename with space andls | cat is puzzled by the newline \n
a newline
a filename with spaces
========== with 'for $(ls)' : aFilenameWithoutSpace ls: cannot access 'a': No such file or directory ls: cannot access 'filename': No such file or directoryHouston, we have a problem ! ls: cannot access 'with': No such file or directory ls: cannot access 'space': No such file or directory ls: cannot access 'and': No such file or directory ls: cannot access 'a': No such file or directory ls: cannot access 'newline': No such file or directory ls: cannot access 'a': No such file or directory ls: cannot access 'filename': No such file or directory ls: cannot access 'with': No such file or directory ls: cannot access 'spaces': No such file or directory ========== with 'for "$(ls)"' : ls: cannot access 'aFilenameWithoutSpace'$'\n''a filename with space and'$'\n''a newline'$'\n''a filename with spaces': No such file or directoryOoops
aFilenameWithoutSpace a filename with space andthis is what loop items look like a newline a filename with spaces ========== aFilenameWithoutSpace 'a filename with space and'$'\n''a newline'but that's very kind of ls 'a filename with spaces'
\n
in their name.item : './a' seen by 'ls' : ls: cannot access './a': No such file or directory item : 'filename' seen by 'ls' : ls: cannot access 'filename': No such file or directory item : 'with' seen by 'ls' : ls: cannot access 'with': No such file or directory
item : './a filename with space and
a newline
./a filename with spacesthe 3 file names are concatenated into a single value because of quotes : "$(find -type f)"
./aFilenameWithoutSpace'
seen by 'ls' : ls: cannot access './a filename with space and'$'\n''a newline'$'\n''./a filename with spaces'$'\n''./aFilenameWithoutSpace': No such file or directory
item : './a filename with space and'
seen by 'ls' : ls: cannot access './a filename with space and': No such file or directoryKO with newline \n
item : 'a newline'
seen by 'ls' : ls: cannot access 'a newline': No such file or directory
item : './a filename with spaces'
seen by 'ls' : './a filename with spaces'OK with spaces
item : './aFilenameWithoutSpace'
seen by 'ls' : ./aFilenameWithoutSpace
./aFilenameWithoutSpace './a filename with space and'$'\n''a newline' './a filename with spaces'
special case : when there is no file matching the search criteria :for i in path/to/files/*xyz; do ls "$i"; donels: cannot access 'path/to/files/*xyz': No such file or directoryfor i in $(find path/to/files -iname "*xyz"); do ls "$i"; done(nothing)
Flag | Usage |
---|---|
+F | Follow file contents in real time, like tail -f does : less +F myFile |
-i | make further searches case-insensitive provided the search pattern is all lowercase ! |
-N --LINE-NUMBERS |
show line Numbers
For some (unknown so far) reason, those extra line numbers can not be matched after a
| :
|
-ppattern --pattern=pattern |
start at the first occurrence of pattern in the file |
-R | interpret ANSI color escape sequences
Outsmarted by GNU/Linux utilities and the shell (details) :
|
-S --chop-long-lines | show the portion of a long line that doesn't fit the screen width on the next line chop long lines in interactive mode |
Flag | Usage |
---|---|
F | Follow file contents in real time, like tail -f does |
g ng |
jump to beginning of line jump to line n |
G | jump to end of line |
- i | toggle case sensitivity in searches (by default, searches are case-sensitive, so this will turn them case-insensitive at first strike) |
n | jump to next match |
N | jump to previous match |
v | edit the current file with the editor defined in the EDITOR environment variable |
:-n | display the next file (when less is launched like : less *conf) |
:-p | display the previous file (when less is launched like : less *conf) |
&RegExp | show lines matching RegExp. Back to normal (display all lines ) : & |
/pattern | search forward pattern (see also) |
?pattern | search backward pattern |
|
display information about the file being viewed :
|
Flag | Usage |
---|---|
-a | Logical and for all the filtering parameters, wherever the -a is placed in the command line. |
-c command | List files opened by processes fired by a command starting with command. This can be : |
+D /path/to/dir | Search for all open instances of directory /path/to/dir (i.e. users having cded into it) and all the open files and directories it contains to its complete depth (= list recursively open files under /path/to/dir) |
-i -i address |
List open files related to internet services and matching address.
|
+Ln -Ln |
|
-n | Inhibits the conversion of network numbers to host names for network files. Inhibiting conversion may make lsof run faster. |
-P | Inhibits the conversion of Port numbers to port names for network files. Inhibiting conversion may make lsof run faster. |
-p PID | List files open by the process(es) matching PID. This can be :
|
-u foo | Select users with login or UID matching foo. This can be a single, a list or a list with exclusions. |
Objects to list | Matching condition | Command |
---|---|---|
processes | related to
|
|
processes | related to a web server | lsof -i tcp:80 |
processes | using TCP port 80 on the 127.0.0.1 interface | lsof -i 4tcp@127.0.0.1:80 |
network connections | between localhost and 1.2.3.4 | lsof -i @1.2.3.4 |
network connections | related to the process having PID 1234 | lsof -a -i -p 1234 |
files | opened by kevin or by whoever has the 500 UID or by PID 123 or by PID 456 | lsof -u kevin,500 -p 123,456 |
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME chrome 70803 stuart 50u REG 0,28 4 0 12443 /dev/shm/.org.chromium.Chromium.wo6MuZ (deleted) teams 3837 stuart 67u REG 253,1 16 0 31326254 /tmp/skype-3837/skypert_sessionkeyY9CXIY (deleted) firefox 3243 stuart 48r REG 0,1 2356 0 6155 /memfd:mozilla-ipc (deleted) Thunar 2830 stuart 26r REG 253,1 27812 0 19136866 /home/stuart/.local/share/gvfs-metadata/root (deleted) firefox 3243 stuart 235r REG 253,1 32768 0 19136838 /home/stuart/.local/share/gvfs-metadata/home-bbf7c99f.log (deleted) panel-5-n 2853 stuart 13r REG 253,1 32768 0 19136749 /home/stuart/.local/share/gvfs-metadata/home-80f437a6.log (deleted) Thunar 2830 stuart 27r REG 253,1 32768 0 19136918 /home/stuart/.local/share/gvfs-metadata/root-7816e02b.log (deleted) firefox 3243 stuart 50r REG 0,1 64150 0 6156 /memfd:mozilla-ipc (deleted) teams 3667 stuart 40u REG 0,28 65536 0 14 /dev/shm/.org.chromium.Chromium.xi0O84 (deleted) teams 3853 stuart 54u REG 0,28 4198400 0 768 /dev/shm/.org.chromium.Chromium.mbVPNT (deleted) chrome 71055 stuart 46u REG 0,28 16777216 0 17328 /dev/shm/.org.chromium.Chromium.q7zzD0 (deleted) pulseaudi 2428 stuart 6u REG 0,1 67108864 0 1028 /memfd:pulseaudio (deleted)These files have been marked as deleted but the storage space they use has not been freed yet because they are still used by one or more processes. To free the space used by any of these files, you just have to stop/restart the process holding it.
"Deleted" files can be the reason why a volume is reported as full whereas ls, df and du report there is some space left.
ls: Cannot access /tmp/myFile: No such file or directory less 3803 stuart 4r REG 254,0 12 133754 /tmp/myFile (deleted)
Hello World
Please note that even though the reported file descriptor was 4r (like removed), the actual file name is 4.
Flag | Usage |
---|---|
-d | Display attributes of a directory itself, not those of its contents. |
File attributes are a combination of :
Option | Usage | Effect |
---|---|---|
A | no atime update | the file "access time" is not updated when accessing the file |
a | append only | the file can be only opened in "append for writing" mode |
c | compressed | the file is automatically compressed on the hard drive by the kernel. data is uncompressed/compressed on the fly to read/write the file |
D | synchronous directory updates | modifications on a directory having this attribute are synchronously written to the hard drive. |
d | no dump | the file will NOT be backuped by the dump utility |
E | compression error | experimental compression patches use this attribute to indicate the file has a compression error. This attribute can not be added/removed by chattr |
e | uses extents | the file is using extents for mapping the blocks on disk. It may not be removed using chattr |
I | index into hash trees | Applies to directories only. This attribute can not be added/removed by chattr |
i | immutable | the file can not be changed, written, deleted, renamed. It can not be targeted by a link. Applying this flag requires root privileges. |
j | data journalling | data is written to the Ext3 journal before being written to the file |
S | synchronous updates | when modifying the file, modifications are written synchronously to the disk |
s | secure deletion | when deleting the file, its blocks are filled with zero's and written to the disk |
T | top of directory hierarchy | States this directory is the filesystem root |
t | no tail-merging | the file has no partial block at the end merged with others file's ends. |
u | undeletable | upon deletion, the contents of the file is backuped so that it can be restored |
X | direct access to compressed file brute content | used by experimental compression patches. This attribute can not be added/removed by chattr |
Z | "dirty" compressed file | used by experimental compression patches. This attribute can not be added/removed by chattr |
------------- myFile
------------- myDirectory