Manipulating files and directories Flashcards
What is the command to create a directory?
mkdir
What is the command to remove an empty directory?
rmdir
What is the command to remove a directory with contents
rm -r
What is the command to create a parent directory and subdirectory?
mkdir -p
i.e mkdir -p parent/child
What is the command to create a non existing file/ update the timestamp of an existing file/directory?
touch
i.e touch file
What is the command to rename a file/directory?
mv
i.e mv oldname newname
What is the command to copy a directory and its contents?
cp -r
-R –recursive
What is the command to create a symbolic link?
ln -s >pathtoreference< >link<
i.e ln -s /var/spool/mail mail
When creating a symlink, what are the permissions?
Full permissions to view where the link points to, however it does not reflect the permissions of the file it is linking to.
How do you create a hard link?
ln >pathtorefrence< >link
How does a hard link work?
Links directly to an inode on the file system, inode location will exist until all referring links are removed. Permissions/time stamp are identical across links. Unlike symbolic links hard links cannot link across file systems (inc. partitions)
How do you view the inode for a file/directory?
ls -i
How many links will a symbolic link have vs a hard link?
Symbolic link will have 1 link to the location
Hard link will have 2 links because each links to an inode location
What is the syntax that constitutes a file permission?
- |rwx|rwx|rwx (read write execute)
type|user|group|other
no access means -
i.e -|r-x|-w-|rw-
What is the syntax that constitutes a directory permission?
d|rwx|rwx|rwx (read write cdinto)
type|user|group|other
no access means -
i.e d|r-x|-w-|—
What is the octal notation associated with a file/folder permission?
d|421|421|421
d|rwx|rwx|rwx
-|421|421|421
-|rwx|rwx|rwx
What would the octal notation equivalent be for d|r-x|r-x|rwx?
d|r-x|r-x|rwx = d|5|5|7
d|4+0+1|4+0+1|4+2+1
What would the octal notation equivalent be for -|rwx|r–|—?
- |rwx|r–|— = -|7|4|0
- |4+2+1|4+0+0|0+0+0
How would you change the permissions of a file/folder without octal notation?
chmod u/g/o +/- r/w/x file/folder
i. e chmod ug+x file/folder
* have to repeat for giving unique permissions (appending and omitting)
How could you change the permissions of a file/folder using octal notation
chmod nnn file/folder
i. e chmod 750 file/folder
* efficient in giving unique permissions in one command (arbitrarily set)
What is a sticky bit?
In linux all users including other can delete a write protected file if they have permissions (wx) of the containing folder
Setting the sticky bit on folder allows deletion only with elevated privileges, essentially write privileges for creation but not deletion. i.e. /tmp
How do you set the sticky bit for a folder without octal notation?
chmod o+t folder
*only applies to the permission of other
How do you remove the sticky bit for a folder without using octal notation?
chmod o-t folder
How do you set the sticky bit for a file using octal notation?
chmod 1nnn folder
i.e chmod 1770 folder
How do you remove the sticky bit for a folder using octal notation?
chmod 0nnn folder
i.e chmod 0770 folder
What is the command to change the owner of a file or directory?
chown user:group file
*leave either field blank to change only user/group
How do you change the permissions of a folder recursively?
chmod -R >permission< directory
How would you change the permissions of the contents of a directory excluding the folder itself?
chmod -R >permission< directory/*
What is the permission hierachy for files and directories?
user
group
other
*first membership applies
What is the command to remove a symbolic link?
unlink
i.e unlink linkename
What is denoted by file with c as the listing?
Character device
What is denoted by file with b as the listing?
Block device
What is denoted by file with l as the listing?
Symbolic Link
What defines default permissions for a file/directory?
umask
How do you apply permissions recursively to a folder?
chmod -R
What is the command to log into a group and create a file/directory with the specified group instead of the user?
newgrp
i. e newgrp wheel
* newgrp to logout
When applying execute permissions to a directory recursively, how do you exclude files within the directory
chmod u/g/o+X
*capital symbols, only works with execute permission
What are setuid and setgid?
setuid enables a file to be ran with the exact permissions as the owner of the file *i.e /usr/bin/passwd
setgid enables a file to be ran with the exact permissions as the group of the file *i.e /usr/bin/wall
How do you modify a file to setuid and setgid with octal notation?
setuid - chmod 4nnn
setgid - chmod 2nnn
i.e chmod 6754 would setuid and setgid for file
How do you modify a file to setuid and setgid with symbolic notation?
setuid - chmod u+s
setgid - chmod g+s
When creating a file/directory, what will the group owner be?
The primary group of the user the file/directory was created with
How do you use object notation to set unique permissions?
chmod u=,g=,o=
i.e chmod u=rwx,g=rwx,o=rx
To delete a file, what permissions are required?
Write and execute permissions to the containing directory
*file permissions are not relevant
How would you make the the contents of a directory always have the same group owner as the directory itself?
use SETGID
chmod g+s {directory}
Any new files/directories within the folder will have the same group owner