Working with files and permissions Flashcards
Make dir with subdirs
mkdir -p dir/dir2
Copy file with confirmation that a target file already exists
cp -i file1 file1.bak
asks if file1.bak should be overritten
Determine file type
file file1.txt=> ASCII text
Grep which searches based on strings which might be located in file
fgrep
or grep -F
so, fgrep pattern_file passwd
Links
ln -s /etc/passwd my_link
editing symbolic link updates original file as well
if original the file is moved, link will be broken
ln /etc/passwd my_hard_link
____
unlink my_link
Finding files
find / -name "*.tar" -ctime 1 use weak quotes when using file globbing \_\_\_\_\_ -name -name -ctime -last change time (in days) -atime -access time (in days) -empty -type f or -type -d
find . -name myfile{1..100} -exec rm -rf {} \;
find /text -empty | xargs rm -f
grep -l “junk” test/file_* | xargs -I {} mv {} ~/test/bak
stdin, stdout,stderr
stdin: 0
stdout: 1
stderr: 2
shell. sh 2>&1 | less (errors and stdout goes to less)
- Search through local db for files and dirs to match search criteria
- Update local db
- locate passwd => a lot of output
for binaries better use whereis - updatedb
locate updatedb.conf
Locate binaries, source and man pages
whereis
whereis passwd
Read from stdin and write to stdout and file
tee
ls -d ~/doc/lib[Xx]* | tee ./libdocs/
grep options
-l -output only file names
-r -recursively
grep -i histfiles* -lr /*
-v -exclude
-i -ignore case
Copy and convert files
dd if=boot.img of=/dev/sdc
dd if=/dev/xvda of=/tmp/mbr.img bs=512 count=1
dd if=/dev/urandom of=r_file bs=1024k count=10
tar
tar -czf backup.tar.gz ~/mydir tar -cvjf backup.tar.bz2 ~/mydir \_\_\_ tar -xzf backup.tar.gz tar -xvjf backup.tar.bz2
Show contents of tar archive
tar -tf mybackup.tar
gzip
bzip2
xz
gzip original_file
bzip2 or_file
xz myfile
ls=>original_file.gz, or_file.bz2,myfile.xz
so archiving will remove original ones and add to archive \_\_\_ gunzip original_file.gz bunzip2 or_file.bz2 unxz myfile.xz