file and folder and rights

a user is only allowed to delete a file if he has WRITE access to the directory the file resides in.

[cc lang=”bash” escaped=”true” width=”600″]
id; # show userid and group id of currently logged in user
uid=1000(user) gid=100(users) Gruppen=100(users)

file artikel.txt; # tries to identify via magic numbers the type of file
artikel.txt: UTF-8 Unicode text

file sächsische_schweiz1.jpg
sächsische_schweiz1.jpg: JPEG image data, JFIF standard 1.01

# filetypes
ls -l
# file symbol: –
# directory symbol: d
# link symbol: l (small L)
# device block symbol: b
brw-rw—-+ 1 root cdrom 11, 0 Apr 27 09:48 sr0
# device character symbol: c
crw–w—- 1 root tty 4, 0 Apr 27 09:48 tty0
# device named pipe symbol: p
prw-r—– 1 root adm 0 Apr 27 09:49 xconsole|
# unix socket device symbol: s
ll /tmp/.X11-unix/X0
srwxrwxrwx 1 root root 0 Apr 27 09:49 /tmp/.X11-unix/X0
ss -x -a ; # display all currently used unix sockets

ls -lF
-F, –classify
append indicator (one of */=>@|) to entries

type bash; # identify command (is it a binary? is it a script? is it an alias? and where is it?)
bash is /bin/bash

user@suse:~> ls -l; # list directory – show content of a direct
insgesamt 244
-rw-r–r– 1 user users 2792 27. Apr 11:54 apache2.log
-rw-r–r– 1 user users 172 27. Apr 11:13 artikel.txt
drwxr-xr-x 2 user users 6 24. Apr 13:45 Bilder
drwxr-xr-x 2 user users 6 24. Apr 13:01 bin
drwxr-xr-x 2 user users 6 24. Apr 13:45 Dokumente
drwxr-xr-x 2 user users 6 24. Apr 13:45 Downloads

# show userIDs groupIDs of files and folders
user@suse:~> ls -n
insgesamt 244
-rw-r–r– 1 1000 100 2792 27. Apr 11:54 apache2.log
-rw-r–r– 1 1000 100 172 27. Apr 11:13 artikel.txt
drwxr-xr-x 2 1000 100 6 24. Apr 13:45 Bilder
drwxr-xr-x 2 1000 100 6 24. Apr 13:01 bin
drwxr-xr-x 2 1000 100 6 24. Apr 13:45 Dokumente
drwxr-xr-x 2 1000 100 6 24. Apr 13:45 Downloads

user@suse:~> ls -iln; # show inode numbers, userIDs groupIDs of files and folders
insgesamt 244
156 -rw-r–r– 1 1000 100 2792 27. Apr 11:54 apache2.log
150 -rw-r–r– 1 1000 100 172 27. Apr 11:13 artikel.txt
113 drwxr-xr-x 2 1000 100 6 24. Apr 13:45 Bilder
100 drwxr-xr-x 2 1000 100 6 24. Apr 13:01 bin
134304866 drwxr-xr-x 2 1000 100 6 24. Apr 13:45 Dokumente
201326689 drwxr-xr-x 2 1000 100 6 24. Apr 13:45 Downloads

# changing access file and folder rights
# format: d rwx r-x — =
# d = directory
# rwx = user(owner) has rwx (read,write,execute with directories means the user is allowed to change into that directory)
# r-x = members of the group have read rights and are also allowed to traverse the directory
# — = others(all other users) have no rights

# two forms of changing file access rights
# r(ead) = 4
# w(rite) = 2
# (e)x(ecute) = 1
# rwx=4+2+1=7

chmod ugo=rwx artikel.txt; # version A
chmod 777 artikel.txt; # version B
ll
-rwxrwxrwx 1 user users 150 26. Apr 14:28 artikel.txt

chmod ugo=rw artikel.txt; # version A
chmod 666 artikel.txt; # version B
ll
-rw-rw-rw- 1 user users 150 26. Apr 14:28 artikel.txt

chmod 555 artikel.txt; # version A
chmod ugo=rx artikel.txt; # version B
ll
-r-xr-xr-x 1 user users 172 27. Apr 11:13 artikel.txt

chmod ugo=r artikel.txt; # version A
chmod 444 artikel.txt; # version B
ll
-r–r–r– 1 user users 150 26. Apr 14:28 artikel.txt

chmod ugo=r artikel.txt; # version A
chmod 222 artikel.txt; # version B
ll
–w–w–w- 1 user users 150 26. Apr 14:28 artikel.txt

chmod ugo= artikel.txt; # version A
chmod 000 artikel.txt; # version B
ll
———- 1 user users 150 26. Apr 14:28 artikel.txt

su; # become root
sudo bash; # become root
chown user:group artikel; # change the owner and group of file/folder
[/cc]

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin