Working with files and permissions Flashcards

1
Q

Make dir with subdirs

A

mkdir -p dir/dir2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Copy file with confirmation that a target file already exists

A

cp -i file1 file1.bak

asks if file1.bak should be overritten

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Determine file type

A

file file1.txt=> ASCII text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Grep which searches based on strings which might be located in file

A

fgrep
or grep -F
so, fgrep pattern_file passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Links

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Finding files

A
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

stdin, stdout,stderr

A

stdin: 0
stdout: 1
stderr: 2
shell. sh 2>&1 | less (errors and stdout goes to less)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. Search through local db for files and dirs to match search criteria
  2. Update local db
A
  1. locate passwd => a lot of output
    for binaries better use whereis
  2. updatedb

locate updatedb.conf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Locate binaries, source and man pages

A

whereis

whereis passwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Read from stdin and write to stdout and file

A

tee

ls -d ~/doc/lib[Xx]* | tee ./libdocs/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

grep options

A

-l -output only file names
-r -recursively
grep -i histfiles* -lr /*
-v -exclude
-i -ignore case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Copy and convert files

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

tar

A
tar -czf backup.tar.gz ~/mydir
tar -cvjf backup.tar.bz2 ~/mydir
\_\_\_
tar -xzf backup.tar.gz
tar -xvjf backup.tar.bz2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Show contents of tar archive

A

tar -tf mybackup.tar

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

gzip
bzip2
xz

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Change file permissions

A

chmod

chmod -R (recursively) o-r Documents/*

17
Q

Change owner

A

chown

change group ownership:
chown :Research reports.txt

chgrp Research new_reports.txt

change owner of /dir and subfiles to avance:
chown -R (recursively) avance /dir

18
Q

SUID

A

Files with s in x permission in user column
4
chmod 4764 test.sh
chmod u-s test.sh- remove

19
Q

SGID

A

Files and dirs with s permission x in group column
2
chmod -R 2764 /srv/programs/
chmod -R g-s /srv/programs/ -remove

20
Q

Sticky bit

A

Files and dirs with t in x permissions of others column
1
chmod 1777 /srv/sticky/

21
Q

List file attributes

A

lsattr ../

lsattr ./

22
Q

Change immutability of file

A

chattr -R[recurcively] -i myfile (remove attr)

chattr +i myfile (add attr)

23
Q

Turn on/off deletion attr of file

A

chattr +u myfile

chattr -u myfile

24
Q

umask

A
/etc/bashrc
The value which will be subtracted from default permissions:
777=default for dirs
666=default for files 
\_\_\_
umask u=rwx,g=,o=
=> umask value=0077
\_\_\_\_
25
Q

File access control lists

A
getfacl myfile
 user::rw-
 group::r--
 others::---
setfacl -m u:jimmy:r myfile
setfacl -x g:staff file1 -remove facl for group staff from file1