Linux – Under the Hood
Manual Pages & Info Pages Distribution Differences
- Package Management
- Startup and Shutdown
Common/Useful Tools and Services
- cron
- find
- rsync
Linux Under the Hood Manual Pages & Info Pages Distribution - - PowerPoint PPT Presentation
Linux Under the Hood Manual Pages & Info Pages Distribution Differences Package Management Startup and Shutdown Pesky Permissions Common/Useful Tools and Services cron find rsync Manual Pages & Info Pages
– man <command>
– SEE ALSO – Regular Manual Pages – awk(1), cmp(1), diff(1), find(1), gzip(1), perl(1), sed(1),
sort(1), xargs(1), zgrep(1), read(2), pcre(3), pcresyntax(3), pcrepattern(3), terminfo(5), glob(7), regex(7).
you wish to view the page about regex which is in section 7 (sometimes commands will have man pages for the same command in multiple sections) you can use
– man 7 regex
– info <command>
– Uses DPKG (debian package) packages. – Uses the apt (Advanced Package Tool) repository system.
– Uses the RPM (Redhat package manager) package manager. – CentOS & Redhat Use Yum (Yellowdog updater). – Fedora as of version 22 uses DNF (Dandified YUM) rather
– but the commands are in most cases identical to those for
– yum/dnf and apt both manage the finding of packages
– rpm and dpkg are used to query and install/remove
– init.d is a well known structure for scripts that start
– The main script files are usually stored in /etc/init.d
– initd has a concept of run levels for the system numbered 0 – 6 (usually)
mode (with an X-based login screen)
– The initial run level of a system using init.d scripts is set by the file
/etc/inittab
– The startup/shutdown order of scripts is defined by the directories /etc/rc.d/rc.
[0-6] which contain symbolic links to the scripts in /etc/init.d
creates things like socket files so that the daemons can attach to them once they are started. Because of this systemd startup times are often extensively faster than those using init.d.
– Services (.service) – Mount points (.mount) – Devices (.device) – Sockets (.socket) – Timers (.timer)
create them in /etc/systemd/system. Files created in the /etc directory will take prescience over the ones defined in /usr
settings.
– The versions listed are the first version where systemd was default, all
distributions require systemd except where noted.
– CentOS 7.14.04 – Debian v8 (Can run without systemd) – Fedora v15+ (current is 28, was the first to provide systemd) – Mint v18 – RedHat v7 – SUSE v12 – Ubuntu 13.04 (Can run without systemd)
init.d style commands into systemd ones.
Properties
– Type of file – Permissions (User, Group Other,
ACL/Sec Context)
– Hard Links – File Owner (Name looked up from
their UID in /etc/passwd)
– File Group (Name looked up from
their GID in /etc/group)
– Timestamp (usually modified time) – Filename
file including User id (Uid) and Group id (Gid)
– 0664/-rw-rw-r-- – The first number is a special mode bit
normally this is just 0 unless your using sticky bits (which would be another talk!!)
– The 3 basic bits you really need to start with
are:
allowed to list the contents of the directory)
info page which details all this
– info coreutils – Select Changing file attributes → Then chmod [lug@dave ~]$ stat hello File: hello Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: fd02h/64770d Inode: 105 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1000/ lug) Gid: ( 1000/ lug) Access: 2018-10-23 21:51:56.219635662 +0100 Modify: 2018-10-23 21:51:56.219635662 +0100 Change: 2018-10-23 21:51:56.219635662 +0100 Birth: -
permissions in this case in order.
– 0 – The object is a File – 6 – User Permission – so 4 & 2 = 6 which = read and write
for the user
– 4 – Group Permission – so 4 on its own = read for the
group
– 4 – Other Users Permission – so again 4 on its own =
directory contents
– You can change a files
– chown <user>
<file/directory
– An example would be chown
pi mydatafile
– You can also change the
group at the same time by adding a : and then the group name
– chown pi:pi mydatafile
– You can change the group of a file – chgrp dialout myscript – This would allow members of the dialout
group to have access to the file myscript with the appropriate permissions set on the file for that group.
the chmod command.
– chmod can use both the numeric and rwx
versions of permissions. I suggest you start with the rwx method on and read up
– In its basic form you can tell chmod to
change permissions for a file for the following
– You tell it what to do to those entities
adjust
– Read (r) – Write (w) – Execute (or in the case of
directories allow the user,group,other to list the contents of the directory) (x)
Its important to make sure you know if your adding a permission or removing it and more importantly setting it (=) as setting the incorrect permission can be a
permission rather than set, this will then retain the permissions it has and just add the additional option for read rather than overwriting to just read!
following actions on the file myscript
– give a user the read permission
– Remove the read permission
– Give the group read permission
– Remove the group read permission
– The same format goes for the other
users just replace the u or g with
– chmod ug+rwx myscript
write and execute permissions
– chmod ug+rwx myscript
write and execute permissions
– chmod a+rx myscript
– chmod a=rx myscript
Set the user to read + execute, the group to read and write and remove read, write and execute from other
– chmod u+rx,g=rx,o-rwx myscript
– Used to schedule jobs to
– Can be scheduled with up-
– Scripts normally start do
(which will run the script as your user) you should use the command
– crontab -e – This will fire up the default
editor (normally vim or vi) if your not a fan of this you can override this behaviour by setting a variable like so before
– export EDITOR=nano – Then run the crontab -e command
again it should now open up the crontab in the editor nano (replace nano with the editor of your choice). If your using bash you could add the export line to the file ~/.bash_profile which should be run each time you login
# For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed
– /home/pi/mybackup.sh
– crontab -e
– crontab -e
can specify an alternate user by adding
– /etc/cron.d/<filename>
put to be used a cron entries (This is where rpm & dpkg packages would normally place entries for crons)
– /etc/crontab
used to be the default for system crons and whilst it can be used I would recommend using one of the 2 above methods
crontab.
backups and don’t backup the whole server its always worth adding the following files and directories, including all sub directories and files, to your backup scripts.
– /etc/crontab – /etc/cron.* – /var/spool/cron
file system tree’s can be difficult.
with what you have found
follows
– find <options> <starting-path>
<expression>
are mainly related to how find should deal with symbolic links
description of what your looking for. The options for this are extensive!!
– find /var -iname “spool” – This will look for any file or
directory that's called spool
– find /var -iname “*.log”
(f) you can use the -type option and this can be combined with other options
– find /var -type f -iname “*audit*.log”
followed by its parameter before specifying the next option
find is the errors if for example you don’t have permission to view a file/directory
this
– find var -type f -iname “*.log”
2>/dev/null
(stdin) and 2 outputs (stdout (1) and stderr (2)). The above command tells the shell to redirect the contents of stderror to the file /dev/null (which just throws them away)
dont redirect it it will display on the terminal and not be logged.
(note that 1> can simply be changed to > for stdout)
– ./myscript 1> mylogfile.log 2>myerrors.log
errors and the output together in this case you need to redirect stdoutput to the file first !! then you can redirect stderr to be added to stdout
– ./myscript > mylogfile.log 2>&1 – Putting the > after the 2>&1 would
actually not write to the log file!!
– find linux-4.18.16 -type f -iname “*.c” -exec grep
– find linux-4.18.16 -type f -iname “*.c” -exec grep -nH ‘on fire’ {} \;
grep on it looking for the phrase “on fire” the options for grep tell it to tell us the line number in the file and the file name for each match
all C files with the extension .c
– find linux-4.18.16 -type f \( -iname “*.h” -o -iname “*.c” \)
command will in fact work without them but they are useful to know about so you can ensure your search is interpreted in the correct way.
– touch now – find /var/log -newer now
the file now.
can compare files between 2 locations before copying and if the files are identical it can skip the file. This makes it ideal for tasks like backups.
destination it then compares file names, followed by file sizes and timestamps to work out what needs copying.
differences between the 2 locations. This makes it highly efficient over networks but can use a lot of disk IO at each end. Normally this IO is still less than just re-copying the file each time would use.
perform encrypted transfers.
– rsync <options> <source> <destination> – rsync -avh mysourcedir mydestdir
– rsync <options> user@host:source destination – rsync <options> source user@host:destination
– -a is a basic option known as archive mode and is the set of options “archive mode; equals -rlptgoD” – -v is increase verbosity – -h prints numbers in a human readable format
– --stats Gets rsync to provide statistics on the transfer of files – --progress
Gets rsync to output the progress of the file transfer