Backup, archive, compress Linux files tricks

Backup, archive, compress Linux files tricks

==================

Some of Linux Backup Utilities are

cpio tar gzip bzip2 xz dd rsync dump restore mt

Also exist some Backup Programs for Linux like Amanda and Bacula

Some commands you may use with the Backup Utilities above are [/dev/st0 tape exist the backup or other storage medium]

cpio
ls | cpio --create -o /dev/st0  # create an archive

cpio -i *.c -I /dev/st0   
# extract *.c files from archive if no RE all extracted

cpio -t -I /dev/st0  # list archive contents

tar
tar --create --file /dev/st0 /root  
tar -cvf /dev/st0 /root
tar cvf file.tar dir1  # "-" is optional for tar command
# create an archive

tar --extact --same-permissions --verbose --file /dev/st0
tar -xpvf /dev/st0
tar xpvf /dev/st0
# extract from archive

tar xvf /dev/st0 *.c  # restore only *.c files

tar --list --file /dev/st0  # list contents of tar backup
tar -tf /dev/st0

gzip, bzip, xz

tar zcvf source.tar.gz source  # compress as gz in combination with tar 

tar jcvf source.tar.bz2 source  # compress as bzip in combination with tar 

tar Jcvf source.tar.xz source  # compress as xz in combination with tar 

these commands are more efficient than the two together commands:
tar cvf source.tar source ; gzip -v source.tar  # because this has intermediate step but above archiving and compression happen same time

extraction
tar xzvf source.tar.gz
tar xjvf source.tar.bz2
tar xJvf source.tar.xz

modern version of tar detect compression used auto and Not needed z in extraction
tar xvf source.tar.gz

rsync  // Synchronize the two file system locations - or between the network machines(folders of)
rsync file.tar someone@backup.mydomain:/usr/local
rsync -r a-machine:/usr/local b-machive:/usr/
rsync -r --dry-run /usr/local /BACKUP/usr

find Linux command tricks asked in exams and how to write

find Linux command tricks asked in exams and how to write

======================

A

The find Operators (!, -o, and -a)
There are three operators that are commonly used with find. The ! operator is used
before an option to negate its meaning. So,

find . ! -name "*.c" -print

selects all but the C program files.
B
To look for both shell and perl scripts, use the -o operator, which represents an OR condition. 
We need to use an escaped pair of parentheses here:
find /home \( -name "*.sh" -o -name "*.pl" \) -print

The ( and ) are special characters that are interpreted by the shell to run commands in
a group. The same characters are used by find to group expressions using the
-o and -a operators, the reason why they need to be escaped.
C
Also to find all *.sh (shell scripts) files for user tux execute:
find /home -user "tux" -name "*.sh" -print 
find /home -user "tux" -name "*.sh" -exec ls {} >| file.txt \; # write listing in file.txt 

these two commands  are equivalent to these two >>>

find /home \( -user "tux" -a -name "*.sh" \) -print
find /home \( -user "tux" -a -name "*.sh" \) -exec ls {} >| file.txt \; # write listing in file.txt 

I conclude in some commands use find for finding:

Directories with sticky bit set:
find / -type d -perm -1000 -exec ls -ld {} \;

Files with SGID set:
find / -type f -perm -2000 -exec ls -l {} \;

Files with SUID set:
find / -type f -perm -4000 -exec ls -l {} \;

Files with SUID and SGID set:
find / -type f \( -perm -4000 -a -perm -2000 \) -exec ls -l {} \;

Files with SUID or SGID set:
find / -type f \( -perm -4000 -o -perm -2000 \) -exec ls -l {} \;








































Note:
ALL THESE COMMANDS - IF NOT WORK - MAKE THE APPROPRIATE SPACING eg  \( -user "tux" like exactly I write

Further Reading Resources

https://likegeeks.com/linux-command-line-tricks/