Linux Crash Course For Beginners - Kodecloud
Linux Crash Course For Beginners - Kodecloud
com
Access Labs
https://kode.wiki/linux-labs
Login Methods
Consoles
Virtual Terminals
CTRL + ALT + F2
Terminal Emulators
Local GUI
password.
Remote GUI
VNC RDP
SSH
Secure SHell
telnet
session.
SSH login
>_
$ ip a Server
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group
default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 SSH daemon
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state
UP group default qlen 1000
link/ether 08:00:27:6b:d7:87 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.17/24 brd 192.168.0.255 scope global dynamic
noprefixroute enp0s3
valid_lft 1966sec preferred_lft 1966sec
inet6 fe80::a00:27ff:fe6b:d787/64 scope link noprefixroute
SSH client
Computer
Windows
SSH
>_
$ ssh [email protected]
[email protected]'s password:
Activate the web console with: systemctl enable --now cockpit.socket
Of course, replace "aaron" with the actual username you created inside your
Linux OS running in the virtual machine. Same with the IP address. From here
on, we'll stay inside this SSH session to go through all the exercises in the
upcoming lessons. Please join me in the demonstration video to see each of
these login methods. I’ll see you there.
Access Labs
https://kode.wiki/linux-labs
--help
>_
$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
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 ..
-B, --ignore-backups do not list implied entries ending with ~
-I, --ignore=PATTERN do not list implied entries matching shell PATTERN
-k, --kibibytes default to 1024-byte blocks for disk usage
-l use a long listing format
-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, newest first
$ ls -l
bin/ libexec/ sbin/
lib/ local/ share/
Let's say you want to see that long listing format with ls, to get a look at file
permissions. But you forgot what the correct option was. Was it -p for
permissions? We can get a quick reminder with:
ls --help
This will show us a lot of output. But if we scroll up, we'll find what we're
looking for: the –l flag, in this case.
You can see how command line options are sorted alphabetically and
described with short text. That's why the --help option for commands will
very often be helpful when we forget about these options (and we will, as
there are so many of them for each command).
--help
>_
$ journalctl --help
journalctl [OPTIONS...] [MATCHES...]
Options:
--system Show the system journal
--user Show the user journal for the current user
-M --machine=CONTAINER Operate on local container
-S --since=DATE Show entries not older than the specified date
-U --until=DATE Show entries not newer than the specified date
-c --cursor=CURSOR Show entries starting at the specified cursor
--after-cursor=CURSOR Show entries after the specified cursor
--show-cursor Print the cursor after all the entries
-b --boot[=ID] Show current boot or the specified boot
--list-boots Show terse information about recorded boots
lines 1-27
PAGE PAGE
q
UP DOWN
--help will usually show a condensed form of help, with very short
explanations. For ls, that's ok, as it's a very simple command. Other
commands, however, are very complex and we need to read longer
explanations to understand what they do and how we use them.
Let's take journalctl as an example, a command that lets us read system logs.
journalctl --help
We'll notice that this opens in a slightly different way (look at "lines 1-27") in
the bottom left corner. This opened in what Linux calls a "pager". It's simply a
"text viewer" of sorts that lets us scroll up and down with our arrow keys or
PAGE UP, PAGE DOWN. To exit this help page, press q.
>_
$ man journalctl
JOURNALCTL(1) journalctl JOURNALCTL(1)
EXAMPLES
NAME Without arguments, all collected logs are shown unfiltered:
journalctl - Query the systemd journal
journalctl
SYNOPSIS
With one match
journalctl specified,
[OPTIONS...] all entries with a field matching the expression are shown:
[MATCHES...]
journalctl
If called without_SYSTEMD_UNIT=avahi-daemon.service
parameters, it will show the full_PID=28097
contents of the journal, starting with the oldest entry
collected.
If two matches refer to the same field, all entries matching either expression are shown:
If one or more match arguments are passed, the output is filtered accordingly. A match is in the format
journalctl e.g.
"FIELD=VALUE", _SYSTEMD_UNIT=avahi-daemon.service
"_SYSTEMD_UNIT=httpd.service",_SYSTEMD_UNIT=dbus.service
referring to the components of a structured journal entry.
See systemd.journal-fields(7) for a list of well-known fields. If multiple matches are specified matching
If the separator
different fields, "+"
the is
logused, two are
entries expressions
filtered may be combined
by both, in resulting
i.e. the a logical output
OR. Thewill
following willentries
show only show all
messages all
matching fromthe
thespecified
Avahi service process
matches with
of this the If
kind. PIDtwo
28097 plus apply
matches all messages from field,
to the same the D-Bus
thenservice
they are(from any
of its processes):
automatically matched as alternatives, i.e. the resulting output will show entries matching any of the
specified matches for the same field. Finally, the character "+" may appear as a separate word between other
termsjournalctl _SYSTEMD_UNIT=avahi-daemon.service
on the command line. This causes all matches _PID=28097
before and + _SYSTEMD_UNIT=dbus.service
after to be combined in a disjunction (i.e.
logical OR).
All important commands in Linux have their own manuals or "man pages". To
access a command's manual enter "man name_of_command". In our case,
we'd use:
man journalctl
Now we get:
•Short description of what the command does in NAME.
•General syntax of command in SYNOPSIS
•Detailed description of command, how it works, and so on, in DESCRIPTION.
•Detailed descriptions of command line options in OPTIONS.
•And some manual pages even have some EXAMPLES near the end of the
manual.
>_
$ man man
The table below shows the section numbers of the manual followed by the types
of pages they contain.
$ man 1 printf
$ man 3 printf
Sometimes, you will have two man pages with the same name. Example:
Manual pages can fall into one of these categories (sections), and we can see
these by looking at the man page for man itself, by typing man man:
If you want to read the man page about printf, the command, you tell man you
want to consult printf from section 1, like this
man 1 printf
If you want to read about printf, the function, you tell man you want to look at
section 3
man 3 printf
It's useful to know that during online exams, the Linux Foundation will let you
use man and --help. Try to use --help if you forgot a command line option as
that gives you the fastest results. Diving deep into a manual page will eat up
more time.
But this is all well and good when we know what command we want to explore.
But what if we can't even remember the name of the command that we need
to use?
>_
sudo mandb
apropos director
>_
$ apropos director $ apropos –s 1,8 director
ls (1) - list directory contents ls (1) - list directory contents
ls (1p) - list directory contents mcd (1) - change MSDOS directory
mcd (1) - change MSDOS directory mdeltree (1) - recursively delete an MSDOS
mdeltree (1) - recursively delete an MSDOS directory and its contents
directory and its contents mdir (1) - display an MSDOS directory
mdir (1) - display an MSDOS directory mdu (1) - display the amount of space
mdu (1) - display the amount of space occupied by an MSDOS direc...
occupied by an MSDOS direc... mkdir (1) - make directories
mkdir (1) - make directories
mkdir (1p) - make directories
mkdir (2) - create a directory
mkdir (3p) - make a directory relative to
directory file descriptor
mkdirat (2) - create a directory
Sections 1 and 8
>_
$ systemctl
TAB TAB TAB
add-requires emergency isolate poweroff show
add-wants enable is-system-running preset show-environment
cancel exit kexec reboot start
cat force-reload kill reenable status
condreload get-default link reload stop
condrestart halt list-dependencies reload-or-restart suspend
condstop help list-jobs rescue switch-root
systemc
press TAB
you get:
systemctl
systemctl
add a space after the command (don't press ENTER) and now press TAB
twice.
You get a huge list of suggestions. This can help you figure out what your
options for that command are. Although you should not always rely on it. It's
not necessary that absolutely all options are included in this suggestion list.
systemctl list-dep
press TAB
endencies will get added at the end and you get: systemctl list-
dependencies. This is TAB autocompletion and many commands support it.
When you press TAB once, if your command interpreter can figure out what
you want to do, it will automatically fill in the letters. If there are many
autocomplete options and it can't figure out which one you want, press TAB
again and it will show the list of suggestions we observed earlier. These will be
huge timesavers in the long-run, and they might even help you in the exam, to
shave off a few seconds here and there, which might add up and let you
explore an extra question or two.
>_
$ ls /u sr/
TAB TAB TAB
bin/ libexec/ sbin/
lib/ local/ share/
ls /u TAB
Now we can see directories available in /usr/ without even needing to explore
this directory with "ls" beforehand. And if we have a long filename like
"wordpress_archive.tgz" we might be able to just type "wor", press TAB and
that long name will be autocompleted.
Recommendation
While manuals and --help pages are super useful, the first few times you use
them, it might be hard to figure out how to do something, with that info alone.
We recommend you take a command you know nothing about and try to figure
out with just man and --help, how to do something. This practice will help you
develop the ability to quickly look for help when you're taking the LFCS exam.
There will be questions about theory you either don't know about, or you just
forgot. If you know how to quickly figure out the answer with a man page or --
help, you'll be able to pass the exam much more easily.
Access Labs
https://kode.wiki/linux-labs
Now we’ll look at how to create, delete, copy, and move files and directories in Linux.
>_
$ ls
Pictures Desktop
ls list
Documents Videos
Downloads Music
$ ls -a -a all
.
..
.ssh
.bash_logout
.bash_profile
.bashrc
Pictures
Desktop Documents Videos
Downloads Music
>_
$ ls –l /var/log/
total 4064
drwxr-xr-x. 2 root root 4096 Oct 18 22:52 anaconda
drwx------. 2 root root 23 Oct 18 22:53 audit
-rw-------. 1 root root 19524 Nov 1 17:56 boot.log
-rw-rw----. 1 root utmp 0 Nov 1 14:08 btmp
-rw-rw----. 1 root utmp 0 Oct 18 22:38 btmp-20211101
drwxr-x---. 2 chrony chrony 6 Jun 24 09:21 chrony
-rw-------. 1 root root 9794 Nov 1 18:01 cron
-rw-------. 1 root root 10682 Oct 26 14:01 cron-20211026
drwxr-xr-x. 2 lp sys 135 Oct 26 14:13 cups
-rw-r--r--. 1 root root 35681 Nov 1 18:13 dnf.rpm.log
-rw-r-----. 1 root root 4650 Nov 1 17:56 firewalld
drwx--x--x. 2 root gdm 6 Oct 19 00:07 gdm
drwxr-xr-x. 2 root root 6 Aug 31 12:07 glusterfs
>_
$ ls –a -l $ ls –al
total 76
drwx------. 16 aaron aaron 4096 Nov 1 17:57 .
drwxr-xr-x. 7 root root 70 Oct 26 16:54 ..
-rw-------. 1 aaron aaron 5085 Nov 1 17:56 .bash_history
-rw-r--r--. 1 aaron aaron 18 Jul 27 09:21 .bash_logout
-rw-r--r--. 1 aaron aaron 141 Jul 27 09:21 .bash_profile
-rw-r--r--. 1 aaron aaron 376 Jul 27 09:21 .bashrc
drwxr-xr-x. 2 aaron aaron 6 Oct 19 00:11 Desktop
drwxr-xr-x. 3 aaron aaron 25 Oct 23 18:15 Documents
drwxr-xr-x. 2 aaron aaron 6 Oct 19 00:11 Downloads
drwxr-xr-x. 2 aaron aaron 6 Oct 19 00:11 Music
drwxr-xr-x. 2 aaron aaron 28 Oct 26 13:37 Pictures
-rw-rw-r--. 1 aaron aaron 36 Oct 28 20:06 testfile
>_
$ ls –alh -h human readable format
total 76K
drwx------. 16 aaron aaron 4.0K Nov 1 17:57 .
drwxr-xr-x. 7 root root 70 Oct 26 16:54 ..
-rw-------. 1 aaron aaron 5.0K Nov 1 17:56 .bash_history
-rw-r--r--. 1 aaron aaron 18 Jul 27 09:21 .bash_logout
-rw-r--r--. 1 aaron aaron 141 Jul 27 09:21 .bash_profile
-rw-r--r--. 1 aaron aaron 376 Jul 27 09:21 .bashrc
drwxr-xr-x. 2 aaron aaron 6 Oct 19 00:11 Desktop
drwxr-xr-x. 3 aaron aaron 25 Oct 23 18:15 Documents
drwxr-xr-x. 2 aaron aaron 6 Oct 19 00:11 Downloads
drwxr-xr-x. 2 aaron aaron 6 Oct 19 00:11 Music
drwxr-xr-x. 2 aaron aaron 28 Oct 26 13:37 Pictures
-rw-rw-r--. 1 aaron aaron 36 Oct 28 20:06 testfile
Filesystem Tree
home var
Documents
Invoice.pdf
Filesystem Tree
home var
Absolute Path
/ home/aaron/Documents/Invoice.pdf
/
home var
Documents
Invoice.pdf
/home/aaron/Documents/Invoice.pdf is an
example of such a path.
>_
/
$ pwd print working directory
/root
Documents
Invoice.pdf
pwd
>_
$ cd /var/log change directory /
$ cd .. .. = parent directory
Documents
Invoice.pdf
cd /var/log
cd ..
Relative Path
>_
Invoice.pdf /
$ Documents/Invoice.pdf
$ Invoice.pdf
Invoice.pdf home var
$ ../Invoice.pdf
Documents
Invoice.pdf
directory. E.g.,
Documents/Invoice.pdf Since
we're in /home/aaron, typing a
path like
Documents/Invoice.pdf is like
typing
/home/aaron/Documents/Invoic
e.pdf. Our relative path "gets
added" to our current directory
and we get to our PDF file.
>_
/
$ cd / # Go to root directory
$ cd - # Go to previous directory
home var
$ cd # Go to home directory
aaron log
Documents
Invoice.pdf
Extra tips:
Creating Files
>_
$ touch Receipt.pdf /
$ touch /home/jane/Receipt.pdf
aaron jane
Receipt.pdf Receipt.pdf
Creating Directories
>_
/
$ mkdir Receipts make directory
home
aaron jane
Receipts
Receipt.pdf Receipt.pdf
Copying Files
>_
# cp [source] [destination] /
copy
$ cp Receipt.pdf Receipts/
aaron
Receipts
Receipt.pdf
Receipt.pdf ReceiptCopy.pdf
Copying Directories
>_
# cp -r [source] [dest] recursive /
$ cp –r Receipts/ BackupOfReceipts/
home
aaron
Receipts BackupOfReceipts
D D D D D D
F F F F F F
–r Receipts/
BackupOfReceipts/
Copying Directories
>_
# cp -r [source] [dest] recursive /
aaron
Receipts BackupOfReceipts
D D D
F F F Receipts
D D D
F F F
Documents/BackupOfReceipts
/Receipts/.
Moving Files
>_
/
$ cp Receipt.pdf Receipts/
home
aaron
2
Receipts
Receipt.pdf
Receipt.pdf 1
Moving Files
>_
/
# mv [source] [dest] move
$ mv Receipt.pdf Receipts/
home
$ mv Receipt.pdf OldReceipt.pdf
$ mv Receipts/ OldReceipts/
aaron
Receipts
OldReceipts
Receipt.pdf
1
OldReceipt.pdf
available.
To rename a file, we
can use: mv
Receipt.pdf
OldReceipt.pdf
To rename a directory,
we can use the new
name as the
destination, such as:
mv Receipts/
Access the labs: https:
https://kode.wiki/linux-labs 46
Kodekloud.com
OldReceipts/.
>_
/
# rm remove
$ rm Invoice.pdf
$ rm -r Invoices/ home
aaron
Invoices
Invoice.pdf
Access Labs
https://kode.wiki/linux-labs
Inodes
>_
family_dog.jpg
$ stat Pictures/family_dog.jpg
File: Pictures/family_dog.jpg
Size: 49 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 52946177 Links: 1
Access: (0640/-rw-r-----) Uid: ( 1000/ aaron) Gid: ( 1005/ family)
Context: unconfined_u:object_r:user_home_t:s0 52946177
Inode
Access: 2021-10-27 16:33:18.949749912 -0500
Modify: 2021-10-27 14:41:19.207278881 -0500 Permissions Access Time
Change: 2021-10-27 16:33:18.851749919 -0500
Birth: 2021-10-26 13:37:17.980969655 -0500
stat Pictures/family_dog.jpg
Hard Links
>_
family_dog.jpg
$ stat Pictures/family_dog.jpg
File: Pictures/family_dog.jpg
Size: 49 Blocks: 8 IO Block: 4096 regular file Hard Link
Device: fd00h/64768d Inode: 52946177 Links: 1
Access: (0640/-rw-r-----) Uid: ( 1000/ aaron) Gid: ( 1005/ family)
Context: unconfined_u:object_r:user_home_t:s0 52946177
Inode 1
Access: 2021-10-27 16:33:18.949749912 -0500
Modify: 2021-10-27 14:41:19.207278881 -0500 Permissions Access Time
Change: 2021-10-27 16:33:18.851749919 -0500
Birth: 2021-10-26 13:37:17.980969655 -0500
And linux goes: "Ok, let me see what inode this links
to. Here's all data you requested for inode
52946177"
Hard Links
>_ home
$ cp –r /home/aaron/Pictures/ /home/jane/Pictures/
$ ln /home/aaron/Pictures/family_dog.jpg /home/jane/Pictures/family_dog.jpg
copy
$ stat Pictures/family_dog.jpg
family_dog.jpg family_dog.jpg
File: Pictures/family_dog.jpg
Size: 49 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 52946177 Links: 2
Access: (0640/-rw-r-----) Uid: ( 1000/ aaron) Gid: ( 1005/ family)
Context: unconfined_u:object_r:user_home_t:s0 52946177
Inode 2
1
Access: 2021-10-27 16:33:18.949749912 -0500
Permissions Access Time
Modify: 2021-10-27 14:41:19.207278881 -0500
Change: 2021-10-27 16:33:18.851749919 -0500
Birth: 2021-10-26 13:37:17.980969655 -0500
$ rm /home/aaron/Pictures/family_dog.jpg
$ rm /home/jane/Pictures/family_dog.jpg
Instead of copying
/home/aaron/Pictures/family_dog.jpg to
/home/jane/Pictures/family_dog.jpg, we could
hardlink it to /home/jane/Pictures/family_dog.jpg.
ln path_to_target_file path_to_link_file
ln /home/aaron/Pictures/family_dog.jpg
/home/jane/Pictures/family_dog.jpg
>_
Only hardlink to files, not folders
$ useradd –a –G family aaron
/home/aaron/file /mnt/Backups/file
First, make sure that you have the proper permissions to create the link file at
the destination. In our case, we need write permissions at:
/home/jane/Pictures/.
Second, when you hardlink a file, make sure that all users involved have the
required permissions to access that file. For Aaron and Jane, this might mean
that we might have to add both their usernames to the same group, for
example, "family". Then we'd use a command to let the group called "family"
read and write to this file. You only need to change permissions on one of the
hardlinks. That's because you are actually changing permissions stored by the
Access Labs
https://kode.wiki/linux-labs
Soft Links
Soft Links
>_
# ln -s path_to_target_file path_to_link_file
family_dog_shortcut.jpg
$ ln –s /home/aaron/Pictures/family_dog.jpg family_dog_shortcut.jpg
Soft Link
$ ls -l
lrwxrwxrwx. 1 aaron aaron family_dog_shortcut.jpg -> /home/aaron/Pictures..
$ readlink family_dog_shortcut.jpg
family_dog.jpg
/home/aaron/Pictures/family_dog.jpg
Hard Link
$ echo “Test” >> fstab_shortcut
$ ls -l
lrwxrwxrwx. 1 aaron aaron family_dog_shortcut.jpg -> /home/aaron/Pictures..
ln -s Pictures/family_dog.jpg
family_dog_shortcut.jpg
readlink path_to_soft_link
readlink family_dog_shortcut.jpg
Soft Links
>_
Softlink to files and folders
/home/aaron/file /mnt/Backups/file
Since soft links are nothing more than paths pointing to a file, you can also
softlink to directories:
ln -s Pictures/ shortcut_to_directory
Access Labs
https://kode.wiki/linux-labs
We’ll now discuss how to list, set, and change standard file permissions in Linux.
>_
$ ls -l
-rw-r-----. 1 aaron family 49 Oct 27 14:41 family_dog.jpg
$ ls -l
-rw-r-----. 1 aaron wheel 49 Oct 27 14:41 family_dog.jpg
$ groups aaron
jane family
wheel
aaron wheel family
If we type
ls -l
In the second field we can see that this file also has
a group associated with it, the family group. We'll
see later what the role of the group is.
Syntax:
groups
But only the root user can change the user owner,
so we'd have to use the sudo command to
temporarily get root privileges:
$ ls -l
- r w x r w x r w x . 1 aaron family 49 Oct 27 14:41 family_dog.jpg
REGULAR FILE -
CHARACTER DEVICE c
LINK l
SOCKET FILE s
PIPE p
BLOCK DEVICE b
Our
ls -l
We will learn about some of these file types later in this course.
rwxrwxrwx
owner Group Others
u g o
Bit Purpose
r Read File
w Write to File
x Execute (run)
- No permission
•w means the user, group, or other users can write to this file, modify its
contents.
x means the user, group, or other users can execute this file. Some files can
be programs or shell scripts (instructions we can execute). To be able to run
this program or shell script, we must have the x permission. A - permission
here means the program or shell script cannot be executed.
Directory Permissions
>_
$ ls Pictures/
$ mkdir Pictures/Family
$ cd Pictures/
Bit Purpose
r Read Directory
w Write to Directory
x Execute into
- No permission
Evaluating Permissions
>_
(aaron)$ ls -l
-r--rw----. 1 aaron family 49 family_dog.jpg
(aaron)$ su jane
-r--rw----
(jane)$ echo “Add this content to file” >> family_dog.jpg owner Group Others
u g o
(jane)$ cat family_dog.jpg
Picture of Milo the dog
Adding Permissions
>_
Now the old r-- becomes rw- with the newly added
"w" permission. So we fixed our problem and aaron
can write to this file.
Removing Permissions
>_
$ ls -l
-r--rw-r--. 1 aaron family 49 Oct 27 14:41 family_dog.jpg
u-[list of permissions]
>_
$ ls -l
-r--rw----. 1 aaron family 49 Oct 27 14:41 family_dog.jpg
u=[list of permissions]
$ chmod g=r family_dog.jpg
$ ls -l
-r--r-----. 1 aaron family 49 Oct 27 14:41 family_dog.jpg
Option Examples
$ chmod g=rw family_dog.jpg user u= u=w / u=rw / u=rwx
$ chmod g= family_dog.jpg
$ ls -l
-r--------. 1 aaron family 49 Oct 27 14:41 family_dog.jpg
If we'd want to let the group read and write, but not
execute, we'd use:
chmod g= family_dog.jpg
Chaining Permissions
>_
$ ls -l
-r--------. 1 aaron family 49 Oct 27 14:41 family_dog.jpg
We saw how to
•add permissions with +
•remove with -
•set exactly to: with =
Octal Permissions
>_
$ stat family_dog.jpg
File: family_dog.jpg
Size: 49 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 52946177 Links: 1
Access: (0640/-rw-r-----) Uid: ( 1000/ aaron) Gid: ( 10/ wheel)
stat family_dog.jpg
Octal Permissions
001 1
011
2
100 4
7 5 5
101 5
110 6
r1 w1 x1 r1 w1 x1 r1 w1 x1 111 7
7 7 7
Let’s take a closer look at this permission. We have rw for user, r for group and none
set for others. Each permission is represented in binary. If it’s set the binary is set to 1
or else its set to 0. In this case the first part has 110, the second part is 100 and the
third part is 0. Converting this binary to decimal would give us 6 for the first part, 4
for the second part, and 0 for the third part. Here’s a quick binary table for your
reference.
Let’s take another example. This time rwx r-x and r-x. So, the binary format would be
111, 101, 101. The decimal of which is 755.
In the last example it’s read write execute for all, so its 1 for all bits, and so the
decimal value is 777.
Octal Permissions
w 2
7 5 5 x 1
r4 w2 x1 r4 w2 x1 r4 w2 x1
7 7 7
if you find binary difficult another approach would be to use the octal table. It’s much
simpler. For each permission assign an octal value. For example 4 for read, 2 for write
and 1 for execute. Then whichever permission is set, consider the respective value for
that and for the permission bit not set consider 0. Once done, add up numbers within
each group. 4 + 2 = 6 and 4 + 0 + 0 is 4 and the last group is 0.
Let’s look at using the same approach for the other examples as well. rwx r-x and r-x
gives us 755
Octal Permissions
>_
$ stat family_dog.jpg
File: family_dog.jpg
Size: 49 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 52946177 Links: 1
Access: (0640/-rw-r-----) Uid: ( 1000/ aaron) Gid: ( 10/ wheel)
Access Labs
https://kode.wiki/linux-labs
After you get a little bit familiar with a Linux OS you learn that files are very nicely
organized. If you want to configure your SSH daemon, you'll know you'll find relevant
config files in /etc/ssh/. Need to find logged errors? You go to /var/log. Most of the
time, you'll know where everything is, at least, approximately. So why would you
need to search for files? Let's look at some typical scenarios.
>_
$ find /usr/share/ -name ’*.jpg’
1.jpg 2.jpg 3.jpg \
Imagine you have a website. You may want to find all your image files. If your
website's directory would be /usr/share/, you could quickly get a list of all .jpg files
with a command like:
In a different scenario, you're almost running out of disk space. This server is hosting
virtual machines. You notice that most of the virtual machines require files under
20GB. You figure that you can search for files that are larger than 20GB to filter out
the abnormally large ones.
We don't have such large files available, but here's how we would look for files larger
than 10 megabytes:
Or let's say you've just updated an application and you're curious to see what files
were changed. You can quickly look at all files that have been modified in the last
minute, with a command like:
Of course, this applies to many other scenarios. Like you could use a similar
command to see what configuration files your system administration team changed in
the last hour.
find
>_
# find [/path/to/directory] [search_parameters]
From these examples, it's clear that the command to search for files is find. Let's take
a look at the syntax we'll use throughout this lesson:
For example to find a file named file1.txt in the directory /bin run the command find
/bin –name file1.txt . –name is the search parameter used to specify the name of the
file you are looking for.
You can sometimes skip specifying the path to the directory you want to search
through. And when you do that it searches in the current directory.
The first few times you'll use this command, it may happen quite often that you mix
up the directory path with the search parameters. Meaning, instead of writing find
/bin/ -name file1.txt, you may write find –name file1.txt /bin/. If you find yourself
falling into this trap, just think about it this way, "First I have to go there, then I will
find it". You have to enter your room, and only after you can search for your keys. This
will remind you that you first have to specify the search location and then the search
parameters.
With this basic knowledge out of the way, let's focus on what makes the real magic
>_
# find [/path/to/directory] [search_parameters]
We just saw the name parameter being used already. It is used to find files with a
specific name in this case felix.
This however is case sensitive. Meaning it won’t find a file named Felix with a capital
F.
If you’d like the find command to not be case sensitive, or case insensitive add an i
infront of the option to make it iname.
At times you may want to find multiple files that have a pattern in their names. For
example, I want to find all files that start with a lowercase f. For this use a wildcard
expression, which is a starting expression, followed by a star. The * is like a joker card,
for text. It will match anything even if it’s 0 characters or 100. In this case it matches
all names starting with f.
>_
$ find -mmin -5
Modification = Create or Edit
$ find -mmin +5
Modified Time != Change Time
$ find -mtime 2 # 24-hour periods
Modified Contents Change Metadata
We already saw, in the examples, a command that looks for files modified in the last
minute. It uses the mmin option. To remember "-mmin" think about "modified
minute”. Let’s understand the options in a bit more detail.
Let’s say the current time is 12:05. To find files modified 5 minutes ago – that is files
modified at the minute 12:01 run the find command with the mmin parameter set to
5. This is going to list files modified in that minute only.
To list all files modified in the last 5 minutes set the minute parameter to -5.
So if there is a -5, there’s surely a +5. What do you think that does? I hope you are not
thinking its going to list files modified 5 minutes into the future.
With the parameter set to +5, the command lists all files modified before 5 minutes
and unto infinity. So any file modified more than 5 minutes ago will be listed.
Another similar option is mtime and it helps search for files modified in days or past
24 hour periods. 0 lists past 24 hours, 1 lists files modified between 24 and 48 hours
and so on.
Linux also has a thing called "change" time for files. Which might sound like the same
thing as a "modify" time, but it's actually different. Modify time refers to time when
contents have been modified. Change time refers to the time when metadata has
been changed. Metadata is "data about data", so in this case, "data about your file".
This might mean something like file permissions. And this is where change time could
be useful. Imagine you suddenly get errors with some app and you suspect it's
because someone changed some file permissions in the wrong way. You could find
files with permissions changed in the last 5 minutes, with a command like:
>_
10 kb 512 kb 1024 kb
k kilobytes
M megabytes
G gigabytes
In our initial exercises, we used -size to search for files, based on their size.
To find files of size exactly 512 KB run the find command with the size parameter set
to 512k. K stands for kilobytes. Here’s a quick table showing the different values.
C stands for bytes, k for kilobytes, m for megabytes and g for gigabytes. Note that M
and G are capital letters.
To search for files greater than 512 kb use +512 kb and for files less than 512 kb use –
512 kb.
Search Expressions
>_
$ find -name "f*" -size 512k # AND operator james john jacob
10 kb 512 kb 1024 kb
10 kb 512 kb 1024 kb
The parameters are also at times referred to as search expressions. This is because
you can extend the parameter and add more parts to it to create an expression - like
in Mathematics.
So we learned that we could find files that start with a letter using the wildcard
format like this. So all files starting with the letter f are found.
We also learned we can list files by a size using the size parameter like this. All files of
size 512kb are listed.
However what if I want to find files that start with the filename f and are also of size
512 kb?
For this you can specify multiple options together in a single command like this. Here
I have the name option and the size option. This works like an AND operator. It finds
files that match both of these criteria. In our case the file that starts with the letter f
and is also 512kb is the file named freya.
But what if we want an OR expression? For example I’d like to find files that match
either of these criteria. All files that either start with f or are of size 512kb. For this
add the –o flag to the command like this.
Search Expressions
>_
Search Expressions
>_
Permissions: 664 = u+rw,g+rw,o+r
Search Expressions
>_
Finally, to find
files that can be read by either the user,
or the group, or others -- does not matter who it is
-- but at least one of them should be able to read.
To do this, we would run find –perm /u=r,g=r,o=r.
In this case, all our files match the condition. If no
one can read it, it won't show up in the results.
Access Labs
https://kode.wiki/linux-labs
Regular Expressions
203.102.3.5
5.23
x is an integer
x is greater than 3 (x > 3)
x is less than 8 (x < 8)
x = 4, 5, or 6
Regex Operators
^
$
.
*
+
{}
?
|
[]
()
[^]
•^ (caret)
•$ (dollar sign)
•. (period)
•* (asterisk)
•+ (plus sign)
•{ } (braces)
•question mark
•vertical pipe
•brackets
•parenthesis
•brackets with caret
>_
$ less /etc/login.defs $ grep –v '^#' /etc/login.defs
# MAIL_DIR /var/spool/mail
# Please note that the parameters in this configuration file control the
# behavior of the tools from the shadow-utils component. None of these UMASK 022
# tools uses the PAM mechanism, and the utilities that use PAM (such as the
# passwd command) should therefore be configured elsewhere. Refer to HOME_MODE 0700
# /etc/pam.d/system-auth for more information.
# PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
# *REQUIRED* PASS_MIN_LEN 5
# Directory where mailboxes reside, _or_ name of file, relative to the PASS_WARN_AGE 7
# home directory. If you _do_ define both, MAIL_DIR takes precedence.
# QMAIL_DIR is for Qmail UID_MIN 1000
# UID_MAX 60000
#QMAIL_DIR Maildir SYS_UID_MIN 201
MAIL_DIR /var/spool/mail SYS_UID_MAX 999
#MAIL_FILE .mail
GID_MIN 1000
GID_MAX 60000
$ grep '^#' /etc/login.defs SYS_GID_MIN 201
SYS_GID_MAX 999
CREATE_HOME yes
^#
>_
>_
^PASS
mail$
7$
Clean result!
Just like with ^, with $ we can look for lines that end
with a sequence of characters. To look for all lines
that end with the text "mail":
mail$
^PASS
>_
c.t will match cat, cut, cit, cot, and even c1t or c#t.
But it won't match ct. There must be exactly one
random character between c and t. With c..t there
have to be two characters.
>_
$ grep –wr 'c.t' /etc/
/etc/brltty/Input/mn/all.txt:Left: append to existing cut buffer from selected character
/etc/brltty/Input/mn/all.txt:Up: start new cut buffer at selected character
/etc/brltty/Input/mn/all.txt:Down: rectangular cut to selected character
/etc/brltty/Input/mn/all.txt:Right: linear cut to selected character
grep: /etc/libvirt: Permission denied
grep: /etc/wpa_supplicant/wpa_supplicant.conf: Permission denied
/etc/mime.types:application/vnd.commonspace csp cst
/etc/mime.types:# wav: audio/x-wav, cpt: application/mac-compactpro
/etc/mime.types:application/mac-compactpro cpt
grep: /etc/sudo-ldap.conf: Permission denied
grep: /etc/sudo.conf: Permission denied
grep: /etc/sudoers: Permission denied
grep: /etc/sudoers.d: Permission denied
grep: /etc/iscsi/iscsid.conf: Permission denied
grep: /etc/firewalld: Permission denied
/etc/mcelog/triggers/cache-error-trigger: if [ "$(cat $F)" != "0" ] ; then
/etc/smartmontools/smartd_warning.sh: cat <<EOF
Special Characters
>_
$ grep '.' /etc/login.defs
SYS_UID_MIN 201
SYS_UID_MAX 999
#
# Min/max values for automatic gid selection in groupadd
#
GID_MIN 1000
GID_MAX 60000
# System accounts
SYS_GID_MIN 201
SYS_GID_MAX 999
#
# If defined, this command is run when removing a user.
# It should remove any at/cron/print jobs etc. owned by
# the user to be removed (passed as the first argument).
#
#USERDEL_CMD /usr/sbin/userdel_local
#
# If useradd should create home directories for users by default
# On RH systems, we do. This option is overridden with the -m flag on
# useradd command line.
#
CREATE_HOME yes
# This enables userdel to remove user groups if no members exist.
>_
we write
\.
>_
let* lettt
lett
let
$ grep -r 'let*' /etc/
/etc/pnm2ppa.conf:# configuration file (/etc/pnm2ppa.conf), and not from
configuration files
/etc/pnm2ppa.conf:#silent 1
/etc/pnm2ppa.conf:# (Older versions of pnm2ppa required larger left and
right margins to avoid
/etc/pnm2ppa.conf:# printer failure with "flashing lights", but this
problem is believed to
/etc/pnm2ppa.conf:#leftmargin 10
/etc/pnm2ppa.conf:# and color ink print cartridges. This changes a
little whenever you
/etc/pnm2ppa.conf:# if there is a horizontal offset between right-to-left
and left-to-right
/etc/pnm2ppa.conf:# density of black ink used: 1 (least ink), 2 (default),
4 (most).
/etc/pnm2ppa.conf:# a calibration file /etc/pnm2ppa.gamma, in which case
these
/etc/pnm2ppa.conf:# gEnh(i) = (int) ( pow ( (double) i / 256, Gamma ) *
256 )
/etc/pnm2ppa.conf:# Valid choices are: a4, letter, legal:
/etc/pnm2ppa.conf:#papersize letter # this is the default
/etc/pnm2ppa.conf:#papersize legal
An expression like:
let*
will match le, let, lett, lettt, and so on, no matter how
many "t"s at the end. Another way of saying this is
that the * allows the previous element to:
•be omitted entirely
•appear once
•appear two or more times
/.*/
>_
$ grep -r '/.*/' /etc/ Begins with /; has 0 or more characters between; ends with a /
/etc/man_db.conf:# before /usr/man.
/etc/man_db.conf:MANDB_MAP /usr/man
/var/cache/man/fsstnd
/etc/man_db.conf:MANDB_MAP /usr/share/man
/var/cache/man
/etc/man_db.conf:MANDB_MAP /usr/local/man
/var/cache/man/oldlocal
/etc/man_db.conf:MANDB_MAP /usr/local/share/man
/var/cache/man/local
/etc/man_db.conf:MANDB_MAP /usr/X11R6/man
/var/cache/man/X11R6
/etc/man_db.conf:MANDB_MAP /opt/man /var/cache/man/opt
/etc/nanorc:# set quotestr "^([ ]*([#:>|}]|//))+"
/etc/nanorc:## include "/path/to/syntax_file.nanorc"
/etc/nanorc:include "/usr/share/nano/*.nanorc"
/etc/pbm2ppa.conf:# Sample configuration file for the HP720/HP820/HP1000
PPA Printers
/etc/pbm2ppa.conf:# /etc/pbm2ppa.conf
/etc/pnm2ppa.conf:# /etc/pnm2ppa.conf
/etc/pnm2ppa.conf:# configuration file (/etc/pnm2ppa.conf), and not from
configuration files
/etc/pnm2ppa.conf:# a calibration file /etc/pnm2ppa.gamma, in which case
these
/etc/mailcap:audio/*; /usr/bin/xdg-open %s
/.*/
>_
0+
0
00
000
0000
and so on
>_
0+
0
00
000
0000
and so on
>_
0+ 000
00
$ grep -r '0+' /etc/ $ man grep
/etc/brltty/Keyboard/keypad.ktb:bind KP0+!KP2 MENU_NEXT_ITEM In basic regular expressions the meta-characters
/etc/brltty/Keyboard/keypad.ktb:bind KP0+!KP7 MENU_FIRST_ITEM ?, +, {, |, (, and ) lose their special meaning;
/etc/brltty/Keyboard/keypad.ktb:bind KP0+!KP1 MENU_LAST_ITEM instead use the backslashed versions \?, \+, \{,
/etc/brltty/Keyboard/keypad.ktb:bind KP0+!KP9 MENU_PREV_SETTING \|, \(, and \).
/etc/brltty/Keyboard/keypad.ktb:bind KP0+!KP3 MENU_NEXT_SETTING
/etc/brltty/Keyboard/keypad.ktb:bind KP0+!KP5 MENU_PREV_LEVEL
/etc/brltty/Keyboard/keypad.ktb:bind KP0+!KPEnter PREFMENU
/etc/brltty/Keyboard/keypad.ktb:bind KP0+!KPPlus PREFSAVE
/etc/brltty/Keyboard/keypad.ktb:bind KP0+!KPMinus PREFLOAD
grep: /etc/libvirt: Permission denied
grep: /etc/wpa_supplicant/wpa_supplicant.conf: Permission denied
/etc/mime.types:application/vnd.d2l.coursepackage1p0+zip
grep: /etc/sudo-ldap.conf: Permission denied
grep: /etc/sudo.conf: Permission denied
grep: /etc/sudoers: Permission denied
grep: /etc/sudoers.d: Permission denied
grep: /etc/iscsi/iscsid.conf: Permission denied
/etc/sane.d/mustek_pp.conf:# - cis1200+ (for Mustek 1200CP+
& OEM versions),
/etc/sane.d/mustek_pp.conf:# scanner Mustek-1200CP+ 0x378 cis1200+
/etc/sane.d/mustek_pp.conf:# scanner mustek-cis1200+ * cis1200+
/etc/sane.d/teco1.conf:scsi "RELISYS" "VM3530+" Scanner * * * 0
0+
0
00
000
and so on.
>_
Extended
Regular Expressions .*
>_
>_
0{3,}
10{,3}
0{3}
>_
$ egrep -r '10{,3}' /etc/
/etc/pnm2ppa.conf:#xoffset 160
/etc/pnm2ppa.conf:# sweeps of the print head, adjust these in units of
1"/600 (1 dot).
/etc/pnm2ppa.conf:# valid blackness choices are 1 2 3 4; controls the
/etc/pnm2ppa.conf:# density of black ink used: 1 (least ink), 2 (default),
4 (most).
/etc/pnm2ppa.conf:# (i.e., 256 times ( i*(1.0/256)) to the power Gamma ),
/etc/pnm2ppa.conf:# the corresponding color. Gamma = 1.0 corresponds to
no
/etc/pnm2ppa.conf:#GammaR 1.0 # red enhancement
/etc/pnm2ppa.conf:#GammaG 1.0 # green enhancement
/etc/pnm2ppa.conf:#GammaB 1.0 # blue enhancement
/etc/pnm2ppa.conf:# which gives Gamma = 1.0 - 0.033 * GammaIdx :
/etc/pnm2ppa.conf:# (unimode 1) uncomment the next line . (The command
line options --uni
/etc/pnm2ppa.conf:#unimode 1
/etc/pnm2ppa.conf:#black_ink 1
/etc/pnm2ppa.conf:#color_ink 1
/etc/pnm2ppa.conf:#cyan_ink 1
/etc/pnm2ppa.conf:#magenta_ink 1
/etc/pnm2ppa.conf:#yellow_ink 1
/etc/subuid-:aaron:100000:65536
/etc/subuid-:bob:165536:65536
/etc/subuid-:charles:231072:65536
10{,3}
0{3}
>_
$ egrep -r '0{3}' /etc/
/etc/vmware-tools/vgauth/schemas/xmldsig-core-schema.xsd: [2]
http://www.w3.org/Consortium/Legal/IPR-FAQ-20000620.html#DTD
/etc/vmware-tools/vgauth/schemas/xmldsig-core-schema.xsd:<schema
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
targetNamespace="http://www.w3.org/2000/09/xmldsig#" version="0.1"
elementFormDefault="qualified">
grep: /etc/firewalld: Permission denied
/etc/smartmontools/smartd.conf:# Monitor 4 ATA disks connected to a 3ware
6/7/8000 controller which uses
/etc/smartmontools/smartd.conf:# Monitor 2 ATA disks connected to a 3ware
9000 controller which
/etc/smartmontools/smartd.conf:# Monitor 2 SATA (not SAS) disks connected
to a 3ware 9000 controller which
/etc/nanorc:## of tabs and spaces. 187 in ISO 8859-1 (0000BB in Unicode)
and 183 in
/etc/nanorc:## ISO-8859-1 (0000B7 in Unicode) seem to be good values for
these.
/etc/pbm2ppa.conf:# Sample configuration file for the HP720/HP820/HP1000
PPA Printers
/etc/pbm2ppa.conf:# 1000: HP DeskJet 1000Cse,
1000Cxi
/etc/pbm2ppa.conf:#version 1000
/etc/pnm2ppa.conf:#version 1000
/etc/subuid-:aaron:100000:65536
0{3}
>_
$ egrep -r 'disabled?' /etc/
t to 0 to disable polling.
/etc/vmware-tools/tools.conf.example:# Set to true to disable the
deviceHelper plugin.
/etc/vmware-tools/tools.conf.example:#disabled=false
/etc/containers/storage.conf:# Value 0% disables
/etc/dleyna-server-service.conf:# 0 = disabled
/etc/dleyna-server-service.conf:# You can't enable levels disabled at
compile time
/etc/dleyna-server-service.conf:# If netf is enabled but the list is
empty, it behaves as disabled.
/etc/tuned/tuned-main.conf:# Dynamicaly tune devices, if disabled only
static tuning will be used.
/etc/tuned/tuned-main.conf:# Recommend functionality, if disabled
"recommend" command will be not
/etc/enscript.cfg:# Enable / disable page prefeed.
grep: /etc/firewalld: Permission denied
/etc/mcelog/mcelog.conf:# An upstream bug prevents this from being
disabled
/etc/smartmontools/smartd.conf:# -o VAL Enable/disable automatic
offline tests (on/off)
/etc/smartmontools/smartd.conf:# -S VAL Enable/disable attribute
autosave (on/off)
/etc/smartmontools/smartd_warning.sh:# Plugin directory (disabled if
empty)
disabled?
To use in grep:
>_
$ egrep -r '0{3,5}' /etc/ 0{min,max}
000/09/xmldsig#
/etc/vmware-tools/vgauth/schemas/xmldsig-core-schema.xsd: [2]
http://www.w3.org/Consortium/Legal/IPR-FAQ-20000620.html#DTD
/etc/vmware-tools/vgauth/schemas/xmldsig-core-schema.xsd:<schema
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
targetNamespace="http://www.w3.org/2000/09/xmldsig#" version="0.1"
elementFormDefault="qualified">
grep: /etc/firewalld: Permission denied
/etc/smartmontools/smartd.conf:# Monitor 4 ATA disks connected to a 3ware
6/7/8000 controller which uses
/etc/smartmontools/smartd.conf:# Monitor 2 ATA disks connected to a 3ware
9000 controller which
/etc/smartmontools/smartd.conf:# Monitor 2 SATA (not SAS) disks connected
to a 3ware 9000 controller which
/etc/nanorc:## of tabs and spaces. 187 in ISO 8859-1 (0000BB in Unicode)
and 183 in
/etc/nanorc:## ISO-8859-1 (0000B7 in Unicode) seem to be good values for
these.
/etc/pbm2ppa.conf:# Sample configuration file for the HP720/HP820/HP1000
PPA Printers
/etc/pbm2ppa.conf:# 1000: HP DeskJet 1000Cse,
1000Cxi
In an expression like
0{min,max}
0{3,5}
0{3,}
10{,3}
0{3}
>_
$ egrep -r 'enabled|disabled' /etc/
/etc/vmware-tools/tools.conf.example:# disabled.
/etc/vmware-tools/tools.conf.example:#disabled=false
/etc/dleyna-server-service.conf:# 0 = disabled
/etc/dleyna-server-service.conf:# You can't enable levels disabled at
compile time
/etc/dleyna-server-service.conf:netf-enabled=false
/etc/dleyna-server-service.conf:# If netf is enabled but the list is
empty, it behaves as disabled.
/etc/tuned/tuned-main.conf:# Dynamicaly tune devices, if disabled only
static tuning will be used.
/etc/tuned/tuned-main.conf:# Recommend functionality, if disabled
"recommend" command will be not
/etc/tuned/tuned-main.conf:# /etc/sysctl.conf. If enabled, these sysctls
will be re-appliead
grep: /etc/firewalld: Permission denied
/etc/mcelog/mcelog.conf:# An upstream bug prevents this from being
disabled
/etc/mcelog/mcelog.conf:dimm-tracking-enabled = yes
/etc/mcelog/mcelog.conf:socket-tracing-enabled = yes
/etc/smartmontools/smartd_warning.sh:# Plugin directory (disabled if
empty)
/etc/nanorc:## To make sure an option is disabled, use "unset <option>".
enabled|disabled
>_
$ egrep -ir 'enabled?|disabled?' /etc/
grep: /etc/firewalld: Permission denied
/etc/mcelog/mcelog.conf:# An upstream bug prevents this from being
disabled
/etc/mcelog/mcelog.conf:# Enable DIMM-tracking
/etc/mcelog/mcelog.conf:dimm-tracking-enabled = yes
/etc/mcelog/mcelog.conf:# Disable DIMM DMI pre-population unless supported
on your system
/etc/mcelog/mcelog.conf:socket-tracing-enabled = yes
/etc/smartmontools/smartd.conf:# First ATA/SATA or SCSI/SAS disk. Monitor
all attributes, enable
/etc/smartmontools/smartd.conf:# -o VAL Enable/disable automatic
offline tests (on/off)
/etc/smartmontools/smartd.conf:# -S VAL Enable/disable attribute
autosave (on/off)
/etc/smartmontools/smartd_warning.sh:# Plugin directory (disabled if
empty)
/etc/nanorc:## Please note that you must have configured nano with --
enable-nanorc
/etc/nanorc:## To make sure an option is disabled, use "unset <option>".
/etc/nanorc:## When soft line wrapping is enabled, make it wrap lines at
blanks
/etc/nanorc:## Enable vim-style lock-files. This is just to let a vim
user know you
>_
$ egrep -r 'c[au]t' /etc/ [a-z] [0-9] [abz954]
/etc/man_db.conf:# Range of terminal widths permitted when displaying cat
pages. If the
/etc/man_db.conf:# terminal falls outside this range, cat pages will not
be created (if
/etc/man_db.conf:# If CATWIDTH is set to a non-zero number, cat pages will
always be
/etc/man_db.conf:# NOCACHE keeps man from creating cat pages.
/etc/nanorc:## Use cut-from-cursor-to-end-of-line by default.
/etc/nanorc:# set cutfromcursor
/etc/nanorc:## (The old form, 'cut', is deprecated.)
/etc/nanorc:## double click), and execute shortcuts. The mouse will work
in the X
/etc/nanorc:## Don't display the helpful shortcut lists at the bottom of
the screen.
/etc/nanorc:## (The old form, 'justifytrim', is deprecated.)
/etc/nanorc:## Disallow file modification. Why would you want this in an
rcfile? ;)
/etc/nanorc:# bind M-B cutwordleft main
/etc/nanorc:# bind M-N cutwordright main
/etc/mailcap:application/msword; /usr/bin/xdg-open %s
/etc/mailcap:application/pdf; /usr/bin/xdg-open %s
/etc/mailcap:application/postscript ; /usr/bin/xdg-open %s
So, to find all strings that contain the text cat or cut,
we'd use:
c[au]t
>_
$ egrep -r '/dev/.*' /etc/
/etc/smartmontools/smartd.conf:#/dev/twa0 -d 3ware,1 -a -s L/../../2/03
/etc/smartmontools/smartd.conf:# On FreeBSD /dev/tws0 should be used
instead
/etc/smartmontools/smartd.conf:#/dev/twl0 -d 3ware,0 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/twl0 -d 3ware,1 -a -s L/../../2/03
/etc/smartmontools/smartd.conf:#/dev/hdc,0 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/hdc,1 -a -s L/../../2/03
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/1 -a -s L/../../7/01
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/2 -a -s L/../../7/02
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/3 -a -s L/../../7/03
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/4/1 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/4/2 -a -s L/../../2/03
/etc/smartmontools/smartd_warning.sh: hostname=`eval $cmd 2>/dev/null` ||
continue
/etc/smartmontools/smartd_warning.sh: dnsdomain=`eval $cmd 2>/dev/null`
|| continue
/etc/smartmontools/smartd_warning.sh: nisdomain=`eval $cmd 2>/dev/null`
|| continue
/etc/smartmontools/smartd_warning.sh: echo "$cmd </dev/null"
/etc/smartmontools/smartd_warning.sh: "$cmd" </dev/null
/etc/smartmontools/smartd_warning.sh: echo "$cmd </dev/null"
/etc/smartmontools/smartd_warning.sh: "$cmd" </dev/null
/etc/smartmontools/smartd_warning.sh: echo "exec '$SMARTD_MAILER'
</dev/null"
/dev/.*
/dev/[a-z]*
/dev/[a-z]*[0-9]
>_
$ egrep -r '/dev/[a-z]*' /etc/
/etc/smartmontools/smartd.conf:#/dev/twa0 -d 3ware,1 -a -s L/../../2/03
/etc/smartmontools/smartd.conf:# On FreeBSD /dev/tws0 should be used instead
/etc/smartmontools/smartd.conf:#/dev/twl0 -d 3ware,0 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/twl0 -d 3ware,1 -a -s L/../../2/03
/etc/smartmontools/smartd.conf:#/dev/hdc,0 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/hdc,1 -a -s L/../../2/03
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/1 -a -s L/../../7/01
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/2 -a -s L/../../7/02
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/3 -a -s L/../../7/03
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/4/1 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/4/2 -a -s L/../../2/03
/etc/smartmontools/smartd_warning.sh: hostname=`eval $cmd 2>/dev/null` || continue
/etc/smartmontools/smartd_warning.sh: dnsdomain=`eval $cmd 2>/dev/null` || continue
/etc/smartmontools/smartd_warning.sh: nisdomain=`eval $cmd 2>/dev/null` || continue
/etc/smartmontools/smartd_warning.sh: echo "$cmd </dev/null"
/etc/smartmontools/smartd_warning.sh: "$cmd" </dev/null
/etc/smartmontools/smartd_warning.sh: echo "$cmd </dev/null"
/etc/smartmontools/smartd_warning.sh: "$cmd" </dev/null
/etc/smartmontools/smartd_warning.sh: echo "exec '$SMARTD_MAILER' </dev/null"
/dev/[a-z]*
/dev/[a-z]*[0-9]
>_
$ egrep -r '/dev/[a-z]*[0-9]' /etc/
/etc/sane.d/umax_pp.conf:# /dev/ppi1, ...
/etc/sane.d/fujitsu.conf:#scsi /dev/sg1
/etc/sane.d/v4l.conf:/dev/bttv0
/etc/sane.d/v4l.conf:/dev/video0
/etc/sane.d/v4l.conf:/dev/video1
/etc/sane.d/v4l.conf:/dev/video2
/etc/sane.d/v4l.conf:/dev/video3
/etc/sane.d/gphoto2.conf:port=serial:/dev/ttyd1
/etc/sane.d/kodak.conf:#scsi /dev/sg1
/etc/sane.d/ma1509.conf:#/dev/uscanner0
/etc/sane.d/mustek_usb.conf:#/dev/usbscanner0
/etc/sane.d/snapscan.conf:# For SCSI scanners specify the generic device, e.g. /dev/sg0 on Linux.
/etc/sane.d/snapscan.conf:# /dev/sg0
grep: /etc/firewalld: Permission denied
/etc/smartmontools/smartd.conf:# For example /dev/twe0, /dev/twe1, and so on.
/etc/smartmontools/smartd.conf:#/dev/twa0 -d 3ware,0 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/twa0 -d 3ware,1 -a -s L/../../2/03
/etc/smartmontools/smartd.conf:# On FreeBSD /dev/tws0 should be used instead
/etc/smartmontools/smartd.conf:#/dev/twl0 -d 3ware,0 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/twl0 -d 3ware,1 -a -s L/../../2/03
/dev/[a-z]*[0-9]
>_
$ egrep -r '/dev/[a-z]*[0-9]?' /etc/
/etc/smartmontools/smartd.conf:#/dev/twa0 -d 3ware,1 -a -s L/../../2/03
/etc/smartmontools/smartd.conf:# On FreeBSD /dev/tws0 should be used instead
/etc/smartmontools/smartd.conf:#/dev/twl0 -d 3ware,0 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/twl0 -d 3ware,1 -a -s L/../../2/03
/etc/smartmontools/smartd.conf:#/dev/hdc,0 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/hdc,1 -a -s L/../../2/03
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/1 -a -s L/../../7/01
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/2 -a -s L/../../7/02
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/3 -a -s L/../../7/03
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/4/1 -a -s L/../../2/01
/etc/smartmontools/smartd.conf:#/dev/sdd -d hpt,1/4/2 -a -s L/../../2/03
/etc/smartmontools/smartd_warning.sh: hostname=`eval $cmd 2>/dev/null` || continue
/etc/smartmontools/smartd_warning.sh: dnsdomain=`eval $cmd 2>/dev/null` || continue
/etc/smartmontools/smartd_warning.sh: nisdomain=`eval $cmd 2>/dev/null` || continue
/etc/smartmontools/smartd_warning.sh: echo "$cmd </dev/null"
/etc/smartmontools/smartd_warning.sh: "$cmd" </dev/null
/etc/smartmontools/smartd_warning.sh: echo "$cmd </dev/null"
/etc/smartmontools/smartd_warning.sh: "$cmd" </dev/null
/etc/smartmontools/smartd_warning.sh: echo "exec '$SMARTD_MAILER' </dev/null"
(): Subexpressions
>_
$ egrep -r '/dev/[a-z]*[0-9]?' /etc/
/etc/sane.d/dc25.conf:#port=/dev/tty0p0
/etc/sane.d/dc25.conf:#port=/dev/tty01
/etc/sane.d/u12.conf:# device /dev/usbscanner
/etc/sane.d/u12.conf:# device /dev/usbscanner
1+2*3
/etc/sane.d/dmc.conf:/dev/camera
/etc/sane.d/umax.conf:/dev/scanner
/etc/sane.d/umax.conf:/dev/usbscanner
1+6 = 7
/etc/sane.d/epjitsu.conf:#usb /dev/usb/scanner0
/etc/sane.d/epjitsu.conf:#
'\.nal$' - 2>/dev/null; then
if echo "$nal" | grep -q
(1+2)*3
/etc/sane.d/epson.conf:#usb /dev/usbscanner0
/etc/sane.d/epson.conf:#usb /dev/usb/scanner0
/etc/sane.d/umax1220u.conf:#/dev/scanner
3*3 = 9
/etc/sane.d/umax1220u.conf:#/dev/usb/scanner0
/etc/sane.d/umax_pp.conf:# device : /dev/parport0, /dev/parport1, ......
/etc/sane.d/umax_pp.conf:# on *BSD, you may provide the device name of the
ppi device: /dev/ppi0,
/etc/sane.d/umax_pp.conf:# /dev/ppi1, ...
/etc/sane.d/fujitsu.conf:#scsi /dev/sg1
/etc/sane.d/fujitsu.conf:#usb /dev/usb/scanner0
/etc/sane.d/v4l.conf:/dev/bttv0
/etc/sane.d/v4l.conf:/dev/video0
/etc/sane.d/v4l.conf:/dev/video1
/etc/sane.d/v4l.conf:/dev/video2
1+2*3
(1+2)*3
/dev/tty0p0
(): Subexpressions
>_
$ egrep -r '/dev/([a-z]*[0-9]?)*' /etc/
/etc/sane.d/coolscan3.conf:#scsi:/dev/scanner
/etc/sane.d/coolscan3.conf:#usb:/dev/usbscanner
/etc/sane.d/dc210.conf:port=/dev/ttyS0
/etc/sane.d/dc210.conf:#port=/dev/ttyd1
/etc/sane.d/dc210.conf:#port=/dev/term/a [a-z]*[0-9]?
/etc/sane.d/dc210.conf:#port=/dev/tty0p0
/etc/sane.d/dc210.conf:#port=/dev/tty01 tty0p0
/etc/sane.d/dc240.conf:port=/dev/ttyS0
/etc/sane.d/dc240.conf:#port=/dev/ttyd1
/etc/sane.d/dc240.conf:#port=/dev/term/a
/etc/sane.d/dc240.conf:#port=/dev/tty0p0
/etc/sane.d/dc240.conf:#port=/dev/tty01
/etc/sane.d/dc25.conf:port=/dev/ttyS0
/etc/sane.d/dc25.conf:#port=/dev/ttyd1
/etc/sane.d/dc25.conf:#port=/dev/term/a
/etc/sane.d/dc25.conf:#port=/dev/tty0p0
/etc/sane.d/dc25.conf:#port=/dev/tty01
/etc/sane.d/u12.conf:# device /dev/usbscanner
/etc/sane.d/u12.conf:# device /dev/usbscanner
/etc/sane.d/dmc.conf:/dev/camera
/etc/sane.d/umax.conf:/dev/scanner
/etc/sane.d/umax.conf:/dev/usbscanner
[a-z]*[0-9]?
[a-z]*[0-9]?*
([a-z]*[0-9]?)*
(): Subexpressions
>_
$ egrep -r egrep -r '/dev/(([a-z]|[A-Z])*[0-9]?)*' /etc/
/etc/sane.d/coolscan3.conf:#scsi:/dev/scanner
/etc/sane.d/coolscan3.conf:#usb:/dev/usbscanner
/etc/sane.d/dc210.conf:port=/dev/ttyS0
/etc/sane.d/dc210.conf:#port=/dev/ttyd1
/etc/sane.d/dc210.conf:#port=/dev/term/a
/etc/sane.d/dc210.conf:#port=/dev/tty0p0
/etc/sane.d/dc210.conf:#port=/dev/tty01
/etc/sane.d/dc240.conf:port=/dev/ttyS0
([a-z]|[A-Z]*[0-9]?)*
/etc/sane.d/dc240.conf:#port=/dev/ttyd1
/etc/sane.d/dc240.conf:#port=/dev/term/a
/etc/sane.d/dc240.conf:#port=/dev/tty0p0
/etc/sane.d/dc240.conf:#port=/dev/tty01
/etc/sane.d/dc25.conf:port=/dev/ttyS0
/etc/sane.d/dc25.conf:#port=/dev/ttyd1
/etc/sane.d/dc25.conf:#port=/dev/term/a
/etc/sane.d/dc25.conf:#port=/dev/tty0p0
/etc/sane.d/dc25.conf:#port=/dev/tty01
/etc/sane.d/u12.conf:# device /dev/usbscanner
/etc/sane.d/u12.conf:# device /dev/usbscanner
/etc/sane.d/dmc.conf:/dev/camera
/etc/sane.d/umax.conf:/dev/scanner
/etc/sane.d/umax.conf:/dev/usbscanner
([a-z]|[A-Z]*[0-9]?)*
(([a-z]|[A-Z])*[0-9]?)*
>_
$ egrep –r 'http[^s]' /etc/
/etc/containers/registries.conf.d/001-rhel-
shortnames.conf:"openshift4/ose-egress-http-proxy" =
"registry.redhat.io/openshift4/ose-egress-http-proxy"
/etc/containers/registries.conf.d/001-rhel-shortnames.conf:"rhel8/httpd-
24" = "registry.redhat.io/rhel8/httpd-24"
/etc/containers/registries.conf.d/001-rhel-shortnames.conf:"rhscl/httpd-
24-rhel7" = "registry.access.redhat.com/rhscl/httpd-24-rhel7" [abc123]
/etc/containers/registries.conf.d/001-rhel-shortnames.conf:"ubi8/httpd-24"
= "registry.redhat.io/ubi8/httpd-24" [a-z]
/etc/containers/registries.d/default.yaml:# For reading signatures, schema
may be http, https, or file.
/etc/containers/registries.d/default.yaml:#
http://privateregistry.com/sigstore/
sigstore: http[^s] http https
/etc/wgetrc:# You can set the default proxies for Wget to use for http,
https, and ftp.
/etc/wgetrc:#https_proxy = http://proxy.yoyodyne.com:18023/
/etc/wgetrc:#http_proxy = http://proxy.yoyodyne.com:18023/
/etc/wgetrc:#ftp_proxy = http://proxy.yoyodyne.com:18023/
/etc/enscript.cfg:# along with Enscript. If not, see
<http://www.gnu.org/licenses/>.
grep: /etc/firewalld: Permission denied
/etc/smartmontools/smartd.conf:# Home page is:
http://www.smartmontools.org
http[^s]
>_
$ egrep –r '/[^a-z]' /etc/ https://regexr.com
/etc/smartmontools/smartd_warning.sh: cmd="$plugindir/${ad#@}"
/etc/qemu-ga/fsfreeze-hook:for file in "$FSFREEZE_D"/* ; do
/etc/man_db.conf:MANPATH_MAP /usr/X11R6/bin /usr/X11R6/man
/etc/man_db.conf:MANPATH_MAP /usr/bin/X11 /usr/X11R6/man
/etc/man_db.conf:MANDB_MAP /usr/X11R6/man /var/cache/man/X11R6
/etc/nanorc:## Each user can save his own configuration to ~/.nanorc
/etc/nanorc:## Don't convert files from DOS/Mac format.
/etc/nanorc:# set quotestr "^([ ]*([#:>|}]|//))+"
/etc/nanorc:## Fix Backspace/Delete confusion problem.
/etc/nanorc:include "/usr/share/nano/*.nanorc"
/etc/pbm2ppa.conf:# Sample configuration file for the HP720/HP820/HP1000 PPA Printers
/etc/pbm2ppa.conf:# 1/4 inch margins all around (at 600 DPI)
/etc/pbm2ppa.conf:# 1/4 inch margins all around (at 600 DPI)
/etc/pbm2ppa.conf:# 1/4 inch margins all around (at 600 DPI)
/etc/pnm2ppa.conf:# paper. Units are dots (1/600 inch). Add a positive number of dots to
/etc/pnm2ppa.conf:# sweeps of the print head, adjust these in units of 1"/600 (1 dot).
/etc/pnm2ppa.conf:# gEnh(i) = (int) ( pow ( (double) i / 256, Gamma ) * 256 )
Additional Resources
https://regexr.com/
Manage Local
User Accounts
>_
$ sudo useradd john
john
$ ls -a /etc/skel
. .. .bash_logout .bash_profile .bashrc
$ cat /etc/login.defs
# Please note that the parameters in this configuration file control the .bash_logout .bash_profile .bashrc
# behavior of the tools from the shadow-utils component. None of these
# tools uses the PAM mechanism, and the utilities that use PAM (such as
the
# passwd command) should therefore be configured elsewhere. Refer to
# /etc/pam.d/system-auth for more information.
useradd --defaults
or equivalent command
useradd -D
cat /etc/login.defs
>_
$ sudo passwd john
Changing password for user john.
New password:
or equivalent
or equivalent
>_
$ cat /etc/passwd
john:x:1001:1001::/home/otherdirectory/:/bin/othershell
$ ls -l /home/
drwx------. 16 aaron aaron 4096 Dec 16 10:01 aaron
drwx------. 4 jane jane 113 Dec 16 13:00 jane
drwx------. 3 john john 78 Oct 19 19:39 john
drwx------. 3 smith smith 78 Oct 19 19:39 smith
$ ls -ln /home/
drwx------. 16 1000 1000 4096 Dec 16 10:01 aaron
drwx------. 4 1001 1001 13 Dec 16 13:00 jane
drwx------. 3 1002 1002 78 Oct 19 19:39 john
drwx------. 3 1100 1100 78 Oct 19 19:39 smith
john:x:1001:1001::/home/otherdirectory/:/bin/othersh
ell
or equivalent
sudo useradd -u 1100 smith
ls -l /home/
ls -ln /home/
>_
$ id $ useradd --help
uid=1000(aaron) gid=1000(aaron) groups=1000(aaron),10(wheel),1005(family) Usage: useradd [options] LOGIN
context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 useradd -D
useradd -D [options]
$ whoami
aaron
id
whoami
useradd --help
>_
$ sudo useradd john
or equivalent
or equivalent
sudo usermod -l jane john
or equivalent:
sudo usermod -s /bin/othershell jane
>_
$ sudo usermod --lock jane $ sudo usermod -L jane
An often-used option with usermod is --lock (or equivalent option -L). This
effectively disables the account, but without deleting it. The user will not be
able to log in with his/her password anymore. However, they might still be able
to log in with an SSH key, if such a login method has been previously set up.
or equivalent
can use
or equivalent
>_
or equivalent
>_ limits.conf
#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student - maxlogins 4
* soft cpu 5
* soft cpu 5
>_ limits.conf
#* soft core 0
#* hard rss 10000
#@student hard nproc 20
#@faculty soft nproc 20
#@faculty hard nproc 50
#ftp hard nproc 0
#@student - maxlogins 4
trinity - nproc 20
1.hard
2.soft
3.-
trinity - nproc 20
>_ limits.conf
<domain><type><item><value>
Next up, the item value. This decides what this limit
is for. We can have things such as:
cpu sets the limit for the CPU time. This is specified
in minutes. When a process uses 100% of a cpu
core for 1 second, it will use up 1 second of its
allocated time. If it uses 50% of one core for one
second, it will use up 0.5 seconds of its allocation.
Even if a process was open 3 hours ago, it might
have only used 2 seconds of CPU time.
man limits.conf
>_ limits.conf
$ ps | less
PID TTY TIME CMD
6314 pts/0 00:00:00 bash
6348 pts/0 00:00:00 ps
6349 pts/0 00:00:00 less
Now let's test our knowledge and add a limit for our
user called trinity, to ensure she can open a
maximum number of three processes
#@student - maxlogins 4
Add this:
trinity - nproc 3
Now,
commented and have no effect.
ps | less
>_
$ logout
$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 14722
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 14722
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
$ ulimit -u 5000
Let's type
logout
ulimit -a
ulimit -u 5000
>_
$ groups
aaron family wheel
aaron trinity
groups
>_ sudoers
user/group host=(run_as_user)
command_list
sudo visudo
>_ sudoers
trinity ALL=ALL
$ sudo stat /bin
trinity ALL=(ALL) /bin/ls, /bin/stat
is also valid.
sudo ls /
And figure out how to apply this for our user trinity. If
we want her to be able to run sudo commands,
Manage Access to
the Root Account
>_
$ sudo ls /root/
anaconda-ks.cfg initial-setup-ks.cfg
$ logout
$ su - $ su -l $ su --login
sudo ls /root/
sudo --login
or equivalent
sudo -i
logout
su -
su -l
su --login
>_
$ sudo --login
$ su -
$ su -
sudo --login
su -
su -
Access Labs
https://kode.wiki/linux-labs