Flag | Usage |
---|---|
-R --recursive | operate on files and directories recursively |
-t type --type=type | set type type in the target security context |
-v --verbose | output a diagnostic for every file processed |
Flag | Usage |
---|---|
-E expireDate --expiredate expireDate |
Set the date on which the user's account will no longer be accessible (i.e. account will be locked) :
|
-l --list | Show account aging information (human-friendly version of passwd -S) |
/etc/passwd:bob:x:1001:1001:,,,:/home/bob:/bin/bash a password is set /etc/shadow:bob:$6$f9YcHiE8Fc5Ho4Z4bALVuc/:18535:0:99999:7::: the encrypted password
bob P 09/30/2020 0 99999 7 -1
Last password change : Sep 30, 2020 Password expires : never Password inactive : never Account expires : never Minimum number of days between password change : 0 Maximum number of days between password change : 99999 Number of days of warning before password expires : 7
passwd: password expiry information changed.
/etc/passwd:bob:x:1001:1001:,,,:/home/bob:/bin/bash /etc/shadow:bob:!$6$f9YcHiE8Fc5Hxdvk$YW1TwjbGerIKvp8vY.rRPBESiIduTOI8.eDzTWjQZyhPMTd6SMl2Ju21dDvEJLTFjeru2YEaWa7o4Z4bALVuc/:18535:0:99999:7:::
bob L 09/30/2020 0 99999 7 -1
(same as above)
passwd: password expiry information changed.
/etc/passwd:bob:x:1001:1001:,,,:/home/bob:/bin/bash /etc/shadow:bob:$6$f9YcHiE8Fc5Hxdvk$YW1TwjbGerIKvp8vY.rRPBESiIduTOI8.eDzTWjQZyhPMTd6SMl2Ju21dDvEJLTFjeru2YEaWa7o4Z4bALVuc/:18535:0:99999:7:::
bob P 09/30/2020 0 99999 7 -1
(same as above)
(returns nothing)
bob P 09/30/2020 0 99999 7 -1
Last password change : Sep 30, 2020 Password expires : never Password inactive : never Account expires : Jan 02, 1970 Minimum number of days between password change : 0 Maximum number of days between password change : 99999 Number of days of warning before password expires : 7
(returns nothing)
bob P 09/30/2020 0 99999 7 -1
Last password change : Sep 30, 2020 Password expires : never Password inactive : never Account expires : never Minimum number of days between password change : 0 Maximum number of days between password change : 99999 Number of days of warning before password expires : 7
(returns nothing)
bob P 09/30/2020 0 99999 7 -1
Last password change : Sep 30, 2020 Password expires : never Password inactive : never Account expires : Jan 02, 1970 Minimum number of days between password change : 0 Maximum number of days between password change : 99999 Number of days of warning before password expires : 7
(returns nothing)
bob P 09/30/2020 0 99999 7 -1
Last password change : Sep 30, 2020 Password expires : never Password inactive : never Account expires : never Minimum number of days between password change : 0 Maximum number of days between password change : 99999 Number of days of warning before password expires : 7
Changing the aging information for stuart
Enter the new value, or press ENTER for the default
Minimum Password Age [0]:
Maximum Password Age [99999]:
Last Password Change (YYYY-MM-DD) [2018-06-08]:
Password Expiration Warning [7]:
Password Inactive [-1]:
Account Expiration Date (YYYY-MM-DD) [1970-01-02]: -1
comm [options] file1 file2
Flag | Usage |
---|---|
-1 | suppress column 1, i.e. display lines unique to file2 and common lines |
-2 | suppress column 2, i.e. display lines unique to file1 and common lines |
-3 | suppress column 3, i.e. display lines unique to file1 and lines unique to file2 (i.e. hide common lines) |
tmpFile1=$(mktemp); tmpFile2=$(mktemp); echo 'FILE1' > "$tmpFile1"; echo 'FILE2' > "$tmpFile2"; for i in {1..3}; do echo "line $i" >> "$tmpFile1"; done; for i in {3..5}; do echo "line $i" >> "$tmpFile2"; done; cat "$tmpFile1" "$tmpFile2"; for mode in 1 2 3 12; do echo -e "\n'-$mode' mode :"; comm -$mode "$tmpFile1" "$tmpFile2"; done; rm "$tmpFile1" "$tmpFile2"
FILE1 result of cat file1 file2 line 1 line 2 line 3 FILE2 line 3 line 4 line 5 '-1' mode : FILE2 line 3 this line is common to both files, others are unique to file2 line 4 line 5 '-2' mode : FILE1 line 1 line 2 line 3 this line is common to both files, others are unique to file1 '-3' mode : common lines are hidden FILE1 FILE2 line 1 line 2 line 4 line 5 '-12' mode : displaying only common lines line 3
Flag | Usage |
---|---|
-r reportFile | Output report to reportFile instead of standard output.
this option is recommended since output can be VERY verbose
|
drwx------ 2 bob developers 4096 Mar 23 16:35 dir -rw------- 1 bob developers 0 Mar 23 16:35 file
drwx--x--x 2 bob developers 4096 Mar 23 16:35 dir -rw------- 1 bob developers 0 Mar 23 16:35 file
Flag | Usage |
---|---|
-R --recursive | change files and directories recursively |
--reference=referenceFile | apply permissions like those of referenceFile (see also chown's --reference) |
testFile=$(mktemp --tmpdir playingWithFilePermissions.XXXXXXXX); ls -l "$testFile"; chmod o=wr "$testFile"; ls -l "$testFile"; chmod o-w+x "$testFile"; ls -l "$testFile"; chmod 777 "$testFile"; ls -l "$testFile"; chmod g=--- "$testFile"; ls -l "$testFile"; rm "$testFile"
-rw------- 1 stuart users 0 Mar 8 16:41 /tmp/playingWithFilePermissions.50YC1hqb default permissions for new file -rw----rw- 1 stuart users 0 Mar 8 16:41 /tmp/playingWithFilePermissions.50YC1hqb made by chmod o=rw -rw----r-x 1 stuart users 0 Mar 8 16:41 /tmp/playingWithFilePermissions.50YC1hqb made by chmod o-w+x -rwxrwxrwx 1 stuart users 0 Mar 8 16:41 /tmp/playingWithFilePermissions.50YC1hqb made by chmod 777 -rwx---rwx 1 stuart users 0 Mar 8 16:41 /tmp/playingWithFilePermissions.50YC1hqb made by chmod g=---
run command or interactive shell with special root directory "/". Once done, leave with exit.
This command allow many hacks. One of them is changing a user's password while running a machine in "rescue" mode.
In such mode, after the machine has been rebooted via a "Live CD" (or anything similar), its "/" filesystem is mounted as /mnt/something. There are situations where you need to change a user (or root) password, then boot the server normally and log in (with password, since SSH keys are not available...) to investigate.
Flag | Usage |
---|---|
-c cipher --cipher cipher | Use the cipher encryption algorithm |
-h hashingAlgorithm --hash hashingAlgorithm | use hashingAlgorithm for passphrase hashing |
-s numBits --key-size numBits | use a numBits bits long key |
cryptsetup benchmark # Tests are approximate using memory only (no storage IO). PBKDF2-sha1 753287 iterations per second PBKDF2-sha256 407055 iterations per second PBKDF2-sha512 324435 iterations per second PBKDF2-ripemd160 512000 iterations per second PBKDF2-whirlpool 158299 iterations per second # Algorithm | Key | Encryption | Decryption aes-cbc 128b 167.4 MiB/s 187.6 MiB/s serpent-cbc 128b 74.9 MiB/s 213.3 MiB/s twofish-cbc 128b 179.5 MiB/s 236.5 MiB/s aes-cbc 256b 129.2 MiB/s 141.6 MiB/s serpent-cbc 256b 85.6 MiB/s 215.2 MiB/s twofish-cbc 256b 185.8 MiB/s 233.7 MiB/s aes-xts 256b 175.6 MiB/s 182.9 MiB/s serpent-xts 256b 196.6 MiB/s 199.1 MiB/s twofish-xts 256b 216.0 MiB/s 215.0 MiB/s aes-xts 512b 134.8 MiB/s 136.1 MiB/s serpent-xts 512b 195.7 MiB/s 199.9 MiB/s twofish-xts 512b 216.5 MiB/s 214.0 MiB/s http://security.stackexchange.com/questions/40208/recommended-options-for-luks-cryptsetup For actual encryption, you will want XTS, which has been designed to support disk encryption efficiently. http://security.stackexchange.com/questions/5158/for-luks-the-most-preferable-and-safest-cipher - In terms of the cipher alone, Serpent is generally agreed upon to be the most secure common cipher for LUKS. - (...) assuming you don't have national secrets or sensitive corporate data on your PC, AES-XTS-PLAIN is expected to be resistant for a reasonable timeframe against an attacker. ==> serpent-xts-256 ? https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions
Please, please, PLEASE, don't fall in the useless-uses-of-cat n00b-trap !
We ALL did it, but now, the cat |
construct should ring the bell of uselessness and waste of resources (even though modern computers have so much CPUs and GB of RAM to waste that such commands will pass unsuspected ).
Actually, any extra |
induces an additional process fork, which is an expensive CPU-time operation (especially on loops). Moreover, cat someFile | reads the whole file before piping it to the 2nd command, which delays its execution for big files.
Usage | DON'T | DO |
---|---|---|
View the contents of file, which is longer that your terminal height | cat file | less | less file |
View the lines of file matching pattern |
cat file | grep pattern cat file | head pattern cat file | tail pattern |
grep pattern file head pattern file tail pattern file |
Read file line by line | cat file | while read line; do echo $line; done | while read line; do echo $line; done < file |
Alter the lines of file matching pattern |
cat file | awk '/pattern/ {doSomething}' cat file | sed 'sed' options |
awk '/pattern/ {doSomething}' file sed 'sed' options file |
Extract a field (i.e. a column) from file | cat file | cut 'cut' options | cut 'cut' options file |
Flag | Usage |
---|---|
-n --number | number all output lines |
Flag | Usage |
---|---|
-a --archive | same as -dR --preserve=all
= -d -R --preserve=all = --no-dereference --preserve=links -R --preserve=all = --no-dereference -R --preserve=all To copy the full contents of a directory, as is, into another :
|
--backup[=backupOption] | Instead of overwriting the destination file, make it a "backup" copy. The behavior depends on the value of backupOption :
|
-d | same as --no-dereference --preserve=links |
-f --force | (details) |
-P --no-dereference | never follow symbolic links in sourceDir (i.e. copy the link, not its target) |
-p --preserve | preserve default attributes |
--preserve=attributeList | preserve the attributes specified with attributeList :
|
-R -r --recursive | copy directories recursively |
--reflink[=option] | control CoW copies, with option :
|
-S suffix --suffix=suffix | set the backup suffix (default : ~ ). works only with simple backups
see examples
|
-s --symbolic-link | make a symbolic link instead of copying. These commands are equivalent :
|
-v --verbose | explain what is being done |
man cp says : if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used)
The final part (between parenthesis) is clear (-n disables -f), so let's concentrate on the beginning :
if an existing destination file cannot be opened, remove it and try again
man cp says : If a file descriptor for a destination file cannot be obtained, attempt to unlink the destination file and proceed. It also gives the detailed procedure :
open()
(i.e. if destinationFile is writable by the current user)
Round 1 file2 didn't exist already, so that was easy ! Round 2 Piece of cake !!! Round 3w
bit is set, no need to force Round 4a cp: cannot create regular file 'file2': Permission denied Round 4bw
bit is NOT set, -f required Round 5a cp: cannot create regular file 'file2': Permission denied Round 5b no permission bit is set, -f required
Now if I try with file2 being a file I don't own, and on which I only have read permission (r--
) :
cp file1 file2; cp -f file1 file2
cp: cannot create regular file 'file2': Permission denied cp: cannot remove 'file2': Operation not permitted
As a conclusion, the -f / --force cp flag only serves to overwrite my own files if I have denied myself write access on them.
myFile myFile_COPY myFile_COPY~
myFile myFile_COPY myFile_COPY~ modified modified initial contents of myFile_COPY~
myFile : edit 5 myFile_COPY : edit 5 myFile_COPY.~1~ : initial version myFile_COPY.~2~ : edit 1 myFile_COPY.~3~ : edit 2 myFile_COPY.~4~ : edit 3 myFile_COPY.~5~ : edit 4
myFile myFile_COPY myFile_COPY_OLD
for
loop :#!/usr/bin/env bash for i in {1..2}; do echo $i continue echo 'this will never be executed' donedisplays :
1 2
for
loops :#!/usr/bin/env bash for i in {1..2}; do for j in {a..b}; do echo $i$j continue echo 'this will never be executed' done donedisplays :
1a 1b 2a 2b
for
loops and continue 2 :#!/usr/bin/env bash for i in {1..2}; do for j in {a..b}; do echo $i$j continue 2 echo 'this will never be executed' done donedisplays :
1a 2a
Flag | Usage |
---|---|
-c n | Use up to n characters-wide screen space to display data (get a terminal window's width and height) |
-s char -t | Consider char as the column separator in the input, then display data as columns |
-t | Determine the number of columns the input contains and create a table. Columns are delimited with whitespace, by default, or with the characters supplied with -s. |
col1_1 col2_1 col1_3 col2_3 col1_2 col2_2
col1_1 col2_1 col1_2 col2_2 col1_3 col2_3
co 1_1 co 2_1 co 1_2 co 2_2 co 1_3 co 2_3
crontab is used to :
crontab option | Description |
---|---|
-e | edit the crontab with EDITOR |
-l | list registered jobs (view the crontab) |
-r | remove the crontab |
-u kevin | work on kevin's crontab |
crontab fileName | register filename as the new crontab |
Unless explicitly specified with -u, all crontab commands apply to the current user.
crontab works so that you cannot append a new job at the end of a table. Instead, you have to :
key = value
form (spaces around the =
sign are allowed) but there are limitations : these are not supported :
somePath = $HOME/bin
A=1 B=2 C=$A $B
PATH = ~/bin
less -p "PATH is inherited"
' 5 crontab)# | usage | range of values |
---|---|---|
1 | minutes | 0-59 |
2 | hours | 0-23 |
3 | day of month | 1-31 |
4 | month |
|
5 | day of week |
|
0 0 23 ? * * *
crontab jobs, these must be understood as
scheduled jobs
seconds
(as the 1st field) and year
(as the last one)character | usage | example (more examples below) |
---|---|---|
* |
|
* * * * * : run every minute of every hour of every day (very common but rarely a good idea IMHO) |
, |
list of values | 0 10,12,16 * * * : run at 10:00, noon and 16:00 |
- |
inclusive range of values |
|
/n |
do every n intervals |
|
string | meaning |
---|---|
@reboot |
Run once, at startup. |
@yearly @annually |
Run once a year : 0 0 1 1 * |
@monthly |
Run once a month : 0 0 1 * * |
@weekly |
Run once a week : 0 0 * * 0 |
@daily @midnight |
Run once a day : 0 0 * * * |
@hourly |
Run once an hour : 0 * * * * |
@reboot
, the startup time is the time when the cron daemon itself started. Due to the boot order sequence of the machine, this _may_ be before some other system daemons (details)With the exception of certain errors in the time fields, errors are not reported until CRON runs the command. All error messages and output are mailed to the crontab owner (or to any address specified with MAILTO=bob@example.com), unless they are silenced by redirecting stdout and stderr to /dev/null with >/dev/null 2>&1
.
Output is mailed to the user because there is no real terminal on which the cronjobs are being executed. Therefore, there is no screen to display the errors. Also, there is no keyboard to accept input. Does that mean you cannot give input to a CRON job? No. Think back to the discussion on shell scripts. We can redefine stdin, stdout and stderr. This way they can all point to files and behave as we expect.
Keep in mind that CRON is not exact. It synchronizes itself to the top of each minute. On a busy system in which you lose clock ticks, jobs may not be executed until a couple minutes after the scheduled time. In addition, there may be other processes with higher priorities that delay CRON jobs. In some cases, (particularly on very busy systems) jobs might end up being skipped if they are run every minute.
/var/spool/cron/crontabs/* files are not intended to be edited directly. Use the crontab utility to edit CRON jobs.
0,10,20,30,40,50 * 1,16 * 1-5 /usr/local/bin/command
*/10 * 1,16 * 1-5 /usr/local/bin/command
/n
says that within the specific interval (in this case, every minute), run the command every n minutes; in this case, every 10 minutes.20-40 * 1,16 * 1-5 /usr/local/bin/command
20-40/3 * 1,16 * 1-5 /usr/local/bin/command
0-20/2,21-40/3,41-59/5 * 1,16 * 1-5 /usr/local/bin/command
*/2 * * * * jobEven 1-59/2 * * * * jobOdd
jobExecutionMinute % n != 0
? (source)Instead of :
1,6,11,16,21,26,31,36,41,46,51,56 * * * * /my/script 3,13,23,33,43,53 * * * * /my/other/scriptyou can do :
1-56/5 * * * * /my/script 3-53/10 * * * * /my/other/script
start-stop/increment
# 1st monday of month at 6h30
30 6 * * 1 [ $(/bin/date +\%d) -lt 8 ] && /sbin/init 6
# Last wednesday of every month, at 6h30
#30 6 * * 3 [[ $(date +\%d) == $(echo "$(echo "$(cal -s )"|awk '{print $4}')"|tail -1) ]] && /sbin/init 6
# not tested yet
Flag | Usage |
---|---|
-h --no-dereference | Affect symlink instead of changing owner/group of its target |
-R --recursive | operate on files and directories recursively |
--reference=referenceFile | change owner + group like those of referenceFile (see also chmod's --reference) |
Command | New user owner | New group owner |
---|---|---|
chown bob myFile | bob | (unchanged) |
chown bob:developers myFile | bob | developers |
chown bob: myFile | bob | bob's login group |
chown :developers myFile | (unchanged) | developers (equivalent to chgrp) |
chkconfig has been obsoleted by systemd and systemctl.
$PATH
) is the Red Hatoid system utility used to manage daemons / scripts and their associated runlevels : it maintains the /etc/rc[0-6].d directory hierarchy and relieves sysadmins of the task of directly manipulating the numerous symbolic links in those directories.Flag | Usage |
---|---|
--add serviceName | add a new service for management |
--del serviceName | Unregister serviceName from chkconfig service management |
--list --list serviceName |
List all the registered daemons and their runlevel activation status List the runlevel activation status for serviceName only. |
-s daemon on|off [level] --set |
Set the specified daemon ON or OFF for the specified runlevel. If no level is specified, the on/off is applied to ALL runlevels (?). ex : chkconfig -s smb on |
These commands enable / disable daemons, but they don't start / stop them.
If no runlevel is specified, then all the possible runlevels are impacted :
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
1 0
In my case, this was caused by a broken link :
/etc/init.d/serviceName -> /installDir/serviceName/bin/scripts/serviceName.shSolution : fix this symlink (delete it if applicable, change target when possible)
# chkconfig: runlevels startPriority stopPriority # description: description
Flag | Usage |
---|---|
-d | target is a directory, not a regular file. |
cut [options] file
Read file (or stdin if file is "-") line by line and display only the selected bytes, characters or fields.
Flag | Usage |
---|---|
-b n | display the nth byte specify numeric arguments |
-c n | display the nth character
|
-d character | use character as field delimiter, defaults to TAB |
-f n | display the nth field specify numeric arguments |
--output-delimiter=string | use string as the output delimiter. Defaults to the input delimiter, i.e. the value of -d |
rty uio
b,c
b c
a a b a b c a b c d e f g h i j k l m n o p q r s t u v w x y z