Check whether a reboot is required:
ls /var/run/reboot-required
In a bash script, you can use:
#!/bin/bash if [ -f /var/run/reboot-required ]; then echo 'reboot required' fi
$ rsync -avz -e 'ssh -p 22' dir user@x.x.x.x:/path/to/dir/
$ rsync -avz -e 'ssh -p 22 -i /home/user/.ssh/id_ecdsa' --rsync-path="sudo rsync" dir user@x.x.x.x:/path/to/dir/
/etc/sudoers.d/rsync
(line 1) with content (line 2)$ sudo visudo /etc/sudoers.d/rsync user ALL = NOPASSWD:/usr/bin/rsync
$ rsync -avz -e 'ssh -p 22 -i /path/to/identity/file' --info=progress2 user@x.x.x.x:/path/to/dir/ /local/dir/
cd ~/movies find . -type d -exec mkdir ~/copied/{} \; find . -type f -not -name *.mkv -exec cp {} ~/copied/{} \;
cp -p <file> <file-with-timestamp> vim <file> touch -r <file-with-timestamp> <file>
find . -type f -print0 | xargs -0 grep "some string"
find . -type f -print0 | xargs -0 grep -l "some string"
find . -newermt $(date +%Y-%m-%d -d '1 month ago') -type f -print
find . -type f -newermt 2007-06-07 ! -newermt 2007-06-08
find . -type f -newerat 2008-09-29 ! -newerat 2008-09-30
find . -type f -newerct 2008-09-29 ! -newerct 2008-09-30
rsync -aAXv /origin /dest rsync -azAX -H --delete --numeric-ids /path/to/source /path/to/dest
du -hs
find -type f -print0 | xargs -0 chmod 644
rsync -av <source> <dest>
ls -1 | wc -l
rename 's/source_(\d{4}_\d{2})\.jpg$/dest_$1.jpg/' *
If “source” is “sourca” and “sourcb”, do the following:
rename 's/\w{6}_(\d{4}_\d{2})\.jpg$/dest_$1.jpg/' *
find -type d -name <dir> -exec rm -rf {} \;
watch tail -n 15 file.name
zip -r myarchive.zip dir1 -x dir1/ignoreDir1/**\* dir1/ignoreDir2/**\*
zip -r archive.zip * .[^.]*
# iotop smartctl -H /dev/sda blkid /dev/sda1 mount -t cifs -o user=luke //192.168.1.104/share /mnt/linky_share mdadm --manage /dev/md0 --add /dev/sdb1
Diskspace information:
df -h
VirtualBox
usermod -a -G groupName userName
Add physical disk:
VBoxManage internalcommands createrawvmdk -filename /home/bco/.VirtualBox/diskname.vmdk -rawdisk /dev/sda
Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.:
:%s/foo/bar/g
Find each occurrence of 'foo' (in the current line only), and replace it with 'bar':
:s/foo/bar/g
To fix the broken arrow keys in insert mode in vi, change the vi default config as follows:
$ vi ~/.exrc set nocompatible
hostname <newname> vim /etc/hostname vim /etc/hosts
vim /usr/share/X11/xorg.conf.d/00-Settings.conf Section"ServerFlags" Option "BlankTime" "600" EndSection
Don't forget to change the root password. If any user has UID 0 besides root, they shouldn't. Bad idea. To check:
grep 'x:0:' /etc/passwd
Again, you shouldn't do this but to check if the user is a member of the root group:
grep root /etc/group
To see if anyone can execute commands as root, check sudoers:
cat /etc/sudoers
To check for SUID bit, which allows programs to be executed with root privileges:
find / -perm -04000
Write a script with the LSB tags to be read by the insserv service:
#!/bin/sh ### BEGIN INIT INFO # Provides: myservice # Required-Start: sshd # Required-Stop: sshd # Should-Start: # Should-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start myservice # Description: Start myservice after sshd is started (example) ### END INIT INFO myservice -options exit 0
Name the script myservice, move it to /etc/init.d/, and run the following command as root:
# update.rc-d myservice defaults