Skip to content

Commit 363b6e9

Browse files
committed
Split many utils
1 parent b168d54 commit 363b6e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1368
-698
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Includes Linux concepts and utilities that work on Linux, not necessarily in the
3939
1. [File permissions](file-permissions.md)
4040
1. [Hardlink](hardlink.md)
4141
1. [badblocks](badblocks.md)
42+
1. [bindfs](bindfs.md)
4243
1. [blkid](blkid.md)
4344
1. [chown](chown.sh)
4445
1. [chmod](chmod.sh)
@@ -49,9 +50,11 @@ Includes Linux concepts and utilities that work on Linux, not necessarily in the
4950
1. [e2fsprogs](e2progs.md)
5051
1. [mke2fs](mke2fs.md)
5152
1. [fdisk](fdisk.md)
53+
1. [FUSE](FUSE.md)
5254
1. [fuser](fuser.md)
5355
1. [lsblk](lsblk.md)
5456
1. [mktemp](mktemp.md)
57+
1. [mountall](mountall.md)
5558
1. [pathchk](pathchk.md)
5659
1. [ramfs](ramfs.md)
5760
1. [swap partition](swap-partition.md)
@@ -115,6 +118,7 @@ Includes Linux concepts and utilities that work on Linux, not necessarily in the
115118
1. Programming
116119
1. [ack](ack.sh)
117120
1. [ctags](ctags/)
121+
1. [cscope](cscope.md)
118122
1. Processes
119123
1. [chroot](chroot.sh)
120124
1. [env](env.sh)
@@ -130,8 +134,10 @@ Includes Linux concepts and utilities that work on Linux, not necessarily in the
130134
1. [pstree](pstree.sh)
131135
1. [pwd](pwd.sh)
132136
1. [sleep](sleep.sh)
137+
1. [strace](strace.md)
133138
1. [timeout](timeout.md)
134139
1. [top](top.md)
140+
1. [umask](umask.md)
135141
1. [ulimit](ulimit.md)
136142
1. [wait](wait.sh)
137143
1. Date and time
@@ -161,6 +167,7 @@ Includes Linux concepts and utilities that work on Linux, not necessarily in the
161167
1. [gzip](gzip.md)
162168
1. [tar](tar.md)
163169
1. [zip](zip.md)
170+
1. [ar](ar.md)
164171
1. User operations
165172
1. [id](id.md)
166173
1. [usermod](usermod.md)
@@ -187,6 +194,7 @@ Includes Linux concepts and utilities that work on Linux, not necessarily in the
187194
1. [RST](rst/)
188195
1. [Virtual machine](virtual-machine/)
189196
1. [Docker](docker/)
197+
1. [QEMU](qemu.md)
190198
1. [User mode Linux](user-mode-linux.md)
191199
1. [Vagrant](vagrang/)
192200
1. [Configuration automation](config-automation.md)
@@ -207,9 +215,12 @@ Includes Linux concepts and utilities that work on Linux, not necessarily in the
207215
1. Sorting
208216
1. [sort](sort.md)
209217
1. [tsort](tsort.md)
218+
1. Packages
219+
1. [util-linux](util-linux.md)
210220
1. Misc
211221
1. [cron](cron.sh)
212222
1. [logrotate](logrotate.md)
223+
1. [BusyBox](busybox.md)
213224
1. [xargs](xargs.md)
214225
1. [Bibliography](bibliography.md)
215226

ar.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ar
2+
3+
<https://en.wikipedia.org/wiki/Ar_%28Unix%29>
4+
5+
Yet another archive format and CLI tool.
6+
7+
Used by `.deb` files.
8+
9+
Similar command line options to tar.
10+
11+
Extract:
12+
13+
ar xf a.ar

bindfs.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# bindfs
2+
3+
<https://github.com/mpartel/bindfs>
4+
5+
FUSER filesystem similar to `mount --bind`, but allows you to mess with ownership and permissions.
6+
7+
Useful command:
8+
9+
sudo bindfs -u a -g a --create-for-user=b --create-for-group=b from to
10+
11+
Mounts `from/` on `to/`.
12+
13+
`b` must exist.
14+
15+
`-u a -g a`: everything seen on `to` is owned by `a:a`
16+
17+
Everything created / saved on `b`, is created on `a` with owner `b:b`.
18+
19+
Unmount:
20+
21+
fusermount -u /home/johnc/ISO-images

blkid.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
`util-linux` package.
44

5-
Get UUID, label and filesystem type for all partitions
5+
There is also a `liblkid` package in Ubuntu which offers functions like disk detection.
6+
7+
Get UUID, label and filesystem type for all partitions:
68

79
sudo blkid
810

busybox.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# BusyBox
2+
3+
Single executable that includes all POSIX command line utilities, including `sh`, and no libc dependency.
4+
5+
Popular for minimal distributions, e.g. <https://github.com/ivandavidov/minimal>
6+
7+
Source:
8+
9+
git clone git://git.busybox.net/busybox
10+
11+
Once compiled, this generates a single `busybox` 2Mb executable, possibly with not external dependencies, often built with uClibc. E.g., if we do:
12+
13+
ldd busybox
14+
15+
we get:
16+
17+
18+
19+
It is also possible to configure exactly which utilities will be present on the output.
20+
21+
You can use it either with subcommands:
22+
23+
./busybox echo a
24+
25+
or with symlinks, which is the standard approach when deploying it:
26+
27+
ln -s busybox echo
28+
./echo a
29+
30+
`busybox` uses `argv[0]` to decide the executable in this case.

cpio.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# cpio
2+
3+
GNU: <http://www.gnu.org/software/cpio/manual/cpio.html>. Ubuntu `cpio` package.
4+
5+
Was POSIX.1-1988, but it was omitted from POSIX.1-2001. The POSIX 2008 `pax` utility [defines](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_07) and implements the cpio format however. The file format is very simple.
6+
7+
Copy files between archives. Also the name of a specialized archive format of the program.
8+
9+
Generate a `.cpio` archive containing files `a` and `b`:
10+
11+
printf '0' > /tmp/a
12+
printf '1' > /tmp/b
13+
printf '/tmp/a\n/tmp/b\n' | cpio -o > /tmp/ab.cpio
14+
hd /tmp/ab.cpio
15+
16+
Find selected files to destination, building and keeping their relative directory structure:
17+
18+
find . ! -iname '* - *' -type f -print | cpio -pvdumB './no author'

cscope.md

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Cscope
2+
3+
Cscope <http://cscope.sourceforge.net/>.
4+
5+
C-only, but more powerful, e.g. can list references.
6+
7+
## Basic usage
8+
9+
cd project/root
10+
cscope -R
11+
12+
This generates a `cscope.out` file.
13+
14+
For the Linux kernel 4.0, it took 2 minutes on a 2013 machine, and generated a 350M file, and leaves you in the ncurses interface.
15+
16+
The `cscope.out` file is binary and not directly readable on text editors.
17+
18+
Next time you want to open the ncurses interface, you can use either:
19+
20+
cscope -R
21+
22+
which will update the database where needed and reuse existing `cscope.out`, or:
23+
24+
cscope -d
25+
26+
which will skip the database update.
27+
28+
## -b
29+
30+
Only build the database, don't enter the ncurses.
31+
32+
## Ignore struct declarations and see only definitions
33+
34+
Impossible: <http://stackoverflow.com/questions/1175610>
35+
36+
## Find struct assignments while ignoring local variables
37+
38+
Impossible: <http://stackoverflow.com/questions/6190955/how-to-find-struct-member-uses-with-cscope>
39+
40+
## ncurses interface
41+
42+
You are now left on a ncurses interface with the following options:
43+
44+
Find this C symbol: <cursor>
45+
Find this global definition:
46+
Find functions called by this function:
47+
Find functions calling this function:
48+
Find this text string:
49+
Change this text string:
50+
Find this egrep pattern:
51+
Find this file:
52+
Find files #including this file:
53+
Find assignments to this symbol:
54+
55+
Use arrows to navigate up and down.
56+
57+
### Panes
58+
59+
There are two panes:
60+
61+
- input pane, at the bottom
62+
- output pane at the top
63+
64+
### ?
65+
66+
Help
67+
68+
### Ctrl+D
69+
70+
Quit.
71+
72+
### tab
73+
74+
Switch between input and output panes.
75+
76+
Suppose we want to find a definition. Move to `Find this global definition` and type `task_struct`.
77+
78+
### Enter
79+
80+
On input pane, make a query.
81+
82+
On the output pane, open the given file on your selected terminal editor.
83+
84+
### Space
85+
86+
On the output pane, go one page down.
87+
88+
### ^
89+
90+
Filter output through shell command. E.g.:
91+
92+
^grep sched
93+
94+
Also

ctags/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cscope.out
2+
tags

ctags/Makefile

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1-
.PHONY: all
1+
.POSIX:
22

3-
all:
4-
ctags -R -o -
5-
#ctags --c-kinds=+l -R -o -
3+
IN_EXT ?= .c
4+
OUT_EXT ?= .out
5+
RUN ?= main
6+
7+
INS := $(wildcard *$(IN_EXT))
8+
OUTS_NOEXT := $(basename $(INS))
9+
OUTS := $(addsuffix $(OUT_EXT), $(OUTS_NOEXT))
10+
11+
.PHONY: all clean run
12+
13+
all: $(OUTS)
14+
-ctags -R
15+
#ctags --c-kinds=+l -R
16+
-cscope -Rb
17+
18+
%$(OUT_EXT): %$(IN_EXT)
19+
gcc -o '$@' -pedantic-errors -std=c89 -Wall '$<'
20+
21+
clean:
22+
rm -f *$(OUT_EXT) cscope.out tags
23+
24+
run: all
25+
./'$(RUN)$(OUT_EXT)'

ctags/README.md

+20-27
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,21 @@
22

33
POSIX 7, with many GNU extensions.
44

5-
Reads source files and generates a list of objects
6-
that can be later searched.
5+
Reads source files and generates a list of objects that can be later searched.
76

8-
Objects are things like C symbols: variable names,
9-
function names, structure names, macros.
7+
Objects are things like C symbols: variable names, function names, structure names, macros.
108

11-
Therefore the output of this program is useful if you want to find
12-
where something is defined in a large source code, such as the Linux kernel for example.
9+
Therefore the output of this program is useful if you want to find where something is defined in a large source code, such as the Linux kernel for example.
1310

1411
The output is both human and computer readable, therefore to use it you can either:
1512

1613
- look at the file yourself and search.
1714

18-
Useful when there are many possible definition places,
19-
and you might be able to guess the correct one by looking
20-
at the extra fields of the file.
15+
Useful when there are many possible definition places, and you might be able to guess the correct one by looking at the extra fields of the file.
2116

22-
- use an editor such as VIM which has built-in functionalities
23-
that allows you to move cursor on top of the symbol, click something (`<C-]>`),
24-
and magically jump to the definition
17+
- use an editor such as VIM which has built-in functionalities that allows you to move cursor on top of the symbol, click something (`<C-]>`), and magically jump to the definition
2518

26-
There could however be many candidate objects with the same name
27-
so you might have to loop a large list of tags.
19+
There could however be many candidate objects with the same name so you might have to loop a large list of tags.
2820

2921
If that is the case, it might be easier to read the `tags` file directly.
3022

@@ -46,18 +38,15 @@ Makes a single `tags` in current directory recursing into all child directories.
4638

4739
## Supported languages
4840

49-
POSIX requires only a that small set of C and FORTRAN symbols be processed.
50-
GNU extends it considerably, and adds support for many languages.
51-
The language list on the GNU implementation can be found with:
41+
POSIX requires only a that small set of C and FORTRAN symbols be processed. GNU extends it considerably, and adds support for many languages. The language list on the GNU implementation can be found with:
5242

5343
ctags --list-languages
5444

5545
For me, this includes languages such as `C++`, `python`, `java` and many more.
5646

5747
## Objects of each language
5848

59-
To view what kinds of objects can be processed, which are processed by default,
60-
and the one letter codes for each object type use:
49+
To view what kinds of objects can be processed, which are processed by default, and the one letter codes for each object type use:
6150

6251
ctags --list-kinds=<lang>
6352

@@ -98,12 +87,9 @@ Take defaults, add `c`, `d` and `f`, but remove `e`:
9887

9988
ctags -R --c-kinds=+cd-e+f
10089

101-
One field which is tempting to remove for C is the `m`, which gives lots of id dupes
102-
and is not very useful.
90+
One field which is tempting to remove for C is the `m`, which gives lots of id dupes and is not very useful.
10391

104-
For example, you might want to find the definition of `x`,
105-
and there are twenty structs which contain a member
106-
named `x` besides the definition which you want.
92+
For example, you might want to find the definition of `x`, and there are twenty structs which contain a member named `x` besides the definition which you want.
10793

10894
This happens often on the Linux kernel code for example.
10995

@@ -129,8 +115,7 @@ Can be modified with `-h`.
129115

130116
May be either a regex (`-N`, default) or a line number (`-n`).
131117

132-
Advantage of regex: changes elsewhere in the file are unlikely to change the regex,
133-
but can easily change the exact line number.
118+
Advantage of regex: changes elsewhere in the file are unlikely to change the regex, but can easily change the exact line number.
134119

135120
Advantage of line numbers: file is smaller.
136121

@@ -142,9 +127,17 @@ Can be modified with `-h`.
142127

143128
Can be controlled by the `--fields` option.
144129

130+
## Find references
131+
132+
Not possible only definitions: <http://ctags.sourceforge.net/faq.html#12>
133+
134+
As any Eclipse user will know, this capability is fundamentally important to understand code.
135+
136+
One of the alternative tools must be used instead.
137+
145138
## Alternatives
146139

147-
- Cscope
140+
- ID Utils <http://www.gnu.org/software/idutils/idutils.html>
148141

149142
### exuberant-ctags
150143

ctags/a.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
//headers are included by default
1+
/* Headers are included by default. */
22
int a1;
3+
struct s;
4+
void f();

0 commit comments

Comments
 (0)