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