Podcast
Questions and Answers
Which of the following commands will create three files named file1.txt
, file2.txt
, and file3.txt
?
Which of the following commands will create three files named file1.txt
, file2.txt
, and file3.txt
?
- `touch file<1..3>.txt`
- `touch file(1..3).txt`
- `touch file[1-3].txt`
- `touch file{1..3}.txt` (correct)
In the context of the touch
command, what is the combined effect of the -a
and -t
options?
In the context of the touch
command, what is the combined effect of the -a
and -t
options?
- Updates both access and modification times to the current timestamp.
- Updates only the access time to the current timestamp and prompts for a specific modification time.
- Updates only the modification time to a specified timestamp, while the access time remains unchanged.
- Updates only the access time to a specified timestamp, leaving the modification time untouched. (correct)
Given a scenario where you need to locate an executable file, but you only know its name, which command would be most appropriate to use?
Given a scenario where you need to locate an executable file, but you only know its name, which command would be most appropriate to use?
- `which` (correct)
- `locate`
- `whereis`
- `find`
What is the key distinction between the find
command's -mtime
and -mmin
options when searching for files?
What is the key distinction between the find
command's -mtime
and -mmin
options when searching for files?
Which of the following commands would successfully locate files of type 'file' within the '/home' directory, owned by the 'users' group, and modified in the last five days?
Which of the following commands would successfully locate files of type 'file' within the '/home' directory, owned by the 'users' group, and modified in the last five days?
To display all files contained in the root ( /
) directory of a size greater than 10MB on screen, which command would be most efficient?
To display all files contained in the root ( /
) directory of a size greater than 10MB on screen, which command would be most efficient?
What is the primary function of the locate
command in Linux, and how does it differ from the find
command?
What is the primary function of the locate
command in Linux, and how does it differ from the find
command?
Consider a scenario where you need to identify all lines in a file named data.txt
that do not contain the string error
. Which grep
command would be most suitable for this task?
Consider a scenario where you need to identify all lines in a file named data.txt
that do not contain the string error
. Which grep
command would be most suitable for this task?
You want to find all the files in the current directory hierarchy that are smaller than 10KB and containg the word 'password'. Which command should you use?
You want to find all the files in the current directory hierarchy that are smaller than 10KB and containg the word 'password'. Which command should you use?
In regular expressions, what is the significance of anchors and how do they impact pattern matching?
In regular expressions, what is the significance of anchors and how do they impact pattern matching?
Which regular expression will match all lines that start with a digit?
Which regular expression will match all lines that start with a digit?
Which regular expression matches exactly 5 lowercase letters?
Which regular expression matches exactly 5 lowercase letters?
What specific function does the combination of find
and grep
commands enable in file management?
What specific function does the combination of find
and grep
commands enable in file management?
Which of the following is true about the setuid
bit?
Which of the following is true about the setuid
bit?
What is the effect of the sticky bit on a directory?
What is the effect of the sticky bit on a directory?
How does the behavior of the setgid
bit differ when applied to a file versus a directory?
How does the behavior of the setgid
bit differ when applied to a file versus a directory?
If you want to compress multiple files into a single archive, selecting the most efficient method for text files, which command and options would you typically use?
If you want to compress multiple files into a single archive, selecting the most efficient method for text files, which command and options would you typically use?
Which command is best suitable to creates a compressed archive compatible with Windows systems?
Which command is best suitable to creates a compressed archive compatible with Windows systems?
When using diff
to compare two files, which option provides a list of differences with lines of context before and after differing lines, aiding in understanding the changes?
When using diff
to compare two files, which option provides a list of differences with lines of context before and after differing lines, aiding in understanding the changes?
When synchronizing directories using rsync
, under which condition are files not copied from the source to the destination directory?
When synchronizing directories using rsync
, under which condition are files not copied from the source to the destination directory?
A file has permissions rw-r--r--
. What does this mean?
A file has permissions rw-r--r--
. What does this mean?
Which command will set the execute permission for the owner and group on a file named script.sh
?
Which command will set the execute permission for the owner and group on a file named script.sh
?
Which of the following commands will assign read, write, and execute permissions to the owner, read and execute permissions to the group, and no permissions to others?
Which of the following commands will assign read, write, and execute permissions to the owner, read and execute permissions to the group, and no permissions to others?
If you want to grant the owner and group read/write access to a file, which command would you use?
If you want to grant the owner and group read/write access to a file, which command would you use?
Which command would you use to change the owner of a file named 'myfile' to user 'newowner'?
Which command would you use to change the owner of a file named 'myfile' to user 'newowner'?
What happens if you run chown -R user1:grp1 dir1
?
What happens if you run chown -R user1:grp1 dir1
?
If a directory has the setgid bit set, what is the primary effect on new files created within that directory?
If a directory has the setgid bit set, what is the primary effect on new files created within that directory?
When compressing files with gzip
, which file types are generally more effectively compressed?
When compressing files with gzip
, which file types are generally more effectively compressed?
When creating a compressed archive using tar
, which options are combined to both create the archive and compress it using gzip
?
When creating a compressed archive using tar
, which options are combined to both create the archive and compress it using gzip
?
Which command would decompress a .bz2
file?
Which command would decompress a .bz2
file?
What distinguishes xz
compression from gzip
and bzip2
?
What distinguishes xz
compression from gzip
and bzip2
?
When comparing files using the diff3
command, what role does the file specified as 'file-ref' play?
When comparing files using the diff3
command, what role does the file specified as 'file-ref' play?
What is the primary role of a patch
file in file and directory management?
What is the primary role of a patch
file in file and directory management?
What happens when using the --delete
with rsync
?
What happens when using the --delete
with rsync
?
What parameter corresponds to the short hand -a
option in rsync
?
What parameter corresponds to the short hand -a
option in rsync
?
To compress a file using bzip2
, use what command?
To compress a file using bzip2
, use what command?
Flashcards
Substitution characters
Substitution characters
Wildcards that allow flexible command execution and filename expansion
touch command
touch command
Creates new files and updates access/modification timestamps.
which command
which command
Finds executables listed in the PATH environment variable. Searches all directories.
whereis command
whereis command
Signup and view all the flashcards
find command
find command
Signup and view all the flashcards
find by name
find by name
Signup and view all the flashcards
locate command
locate command
Signup and view all the flashcards
grep command
grep command
Signup and view all the flashcards
Regular expression (Regex)
Regular expression (Regex)
Signup and view all the flashcards
Anchors in Regex
Anchors in Regex
Signup and view all the flashcards
Character Sets in Regex
Character Sets in Regex
Signup and view all the flashcards
Modifiers in Regex
Modifiers in Regex
Signup and view all the flashcards
[[:alpha:]]
[[:alpha:]]
Signup and view all the flashcards
[[:digit:]]
[[:digit:]]
Signup and view all the flashcards
chmod command
chmod command
Signup and view all the flashcards
chown command
chown command
Signup and view all the flashcards
chgrp command
chgrp command
Signup and view all the flashcards
setuid and setgid bits
setuid and setgid bits
Signup and view all the flashcards
Sticky bit
Sticky bit
Signup and view all the flashcards
gzip
gzip
Signup and view all the flashcards
bzip2
bzip2
Signup and view all the flashcards
xz
xz
Signup and view all the flashcards
tar command
tar command
Signup and view all the flashcards
tar command
tar command
Signup and view all the flashcards
zip command
zip command
Signup and view all the flashcards
diff command
diff command
Signup and view all the flashcards
diff3 command
diff3 command
Signup and view all the flashcards
rsync command
rsync command
Signup and view all the flashcards
Access bits
Access bits
Signup and view all the flashcards
7 Access
7 Access
Signup and view all the flashcards
Study Notes
- Coursework covers Unix and Linux operating systems, Linux basics, file and disk management, text editors, shell scripting, system administration, process and system monitoring, networking/ security, and Linux environment configuration.
Substitution Characters
- Substitution characters, including wildcards and special characters, streamline command execution, expand filenames, and enable pattern matching in Linux.
- The * character matches zero or more characters.
ls *.txt
lists all .txt files.ls *.*
lists all files with extensions.ls *
lists directory content and is equivalent tols
.
- The ? character matches exactly one character.
ls file?.txt
matches file1.txt or fileA.txt.
- The [] matches one character from a set.
ls file[123].txt
matches file1.txt, file2.txt, and file3.txt.
- The {} matches a list of values.
cp {file1,file2}.txt backup/
copies file1.txt and file2.txt to the backup directory.
- The
{start..end}
generates a numeric or alphabetic sequence.echo {1..5}
outputs 1 2 3 4 5.
- The
{start..end..step}
generates a sequence with a step value.echo {1..10..2}
outputs 1 3 5 7 9.
Creating and Modifying Timestamps
- The
touch
command creates files and updates timestamps in Linux. - If a file doesn't exist,
touch
creates an empty file. If it exists, it updates the access time (atime) and modification time (mtime). touch newfile.txt
creates an empty file.touch existingfile.txt
updates timestamps without modifying content.- The
-c
option withtouch
prevents file creation if it doesn't exist.touch -c file.txt
- The
-a
option withtouch
updates only the access time. - The
-m
option withtouch
updates only the modification time. - The
-t
option withtouch
sets a custom timestamp.touch -t 202401011200 file.txt
sets the timestamp to January 1, 2024, 12:00 PM.
- Combine
-a
or-m
with-t
to change access or modification times, respectively. - The
-r
option withtouch
copies timestamps from another file.touch -r file1.txt file2.txt
makes file2.txt have the same timestamps as file1.txt.
- Substitution characters generate multiple files with
touch
.touch file{1..3}.txt
creates file1.txt, file2.txt, and file3.txt.touch file{1,2}.{txt,csv}
creates file1.txt, file1.csv, file2.txt, and file2.csv.touch file{A..C}{1..3}.txt
creates fileA1.txt, fileA2.txt, fileA3.txt, fileB1.txt, fileB2.txt, fileB3.txt, fileC1.txt, fileC2.txt, and fileC3.txt.
Searching for Files
- The
which
command locates executables by searching directories listed in the PATH environment variable. - The
whereis
command finds all files related to an executable, including source code and documentation, by searching in standard paths. which
finds executables, searches the$PATH
, and shows only the first matchwhereis
finds source code and man pages, searches standard paths, and shows all matches.
Searching for Files with find
- The
find
command searches files and directories recursively based on specified criteria. - By default,
find
searches the current directory and its subdirectories. - Searches in another directory are achieved by following
find
with the directory path. - Searches by name:
find /path/to/search -name "filename"
.find ~/ -name "myfile.txt"
searches formyfile.txt
in the home directory and its subdirectories.
- Searches by name ignoring case:
find /path/to/search -iname "filename"
.find ~/ -iname "myfile.txt"
searches formyfile.txt
(case-insensitive) in the home directory and its subdirectories.
- Searches by extension:
find /path/to/search -name "*.txt"
.sudo find /var/log -name "*.log"
finds all .log files in/var/log
and its subdirectories.
- Searches by file size:
find /path/to/search -size +100M
.sudo find / -size +100M
finds files larger than 100 MB in the current filesystem.
- Size units include
c
for bytes,k
for kilobytes,M
for megabytes, andG
for gigabytes. - Omitting the
+
searches for the exact size specified. - Searches by modification time:
find /path/to/search -mtime -n
.find ~/ -mtime -7
finds files modified in the last 7 days.find ~/ -mtime 7
finds files modified exactly 7 days ago.find ~/ -mtime +7
finds files modified over 7 days ago.
- Searches by access time:
find /path/to/search -atime -n
.find ~/ -atime -7
finds files accessed in the last 7 days.find ~/ -atime 7
finds files accessed exactly 7 days ago.find ~/ -atime +7
finds files accessed over 7 days ago.
- Combining access and modification time:
find /var -mtime -7 -atime +3
finds files in/var
modified in the last week but not accessed in the last 3 days. -ctime
searches for files whose metadata has been changed.-mmin
and-amin
search for files by modification and access times in minutes instead of days.-mtime
checks when the file content was last modified.find /home -mtime -7
lists files last modified in the last 7 days in the /home directory.
-atime
checks when the file was last accessed (read or opened).find /home -atime -3
lists files last accessed in the last 3 days in the /home directory.
-mmin
checks if the file was modified in the last X minutes.find /var -mmin -60
will find files that were modified in the lest hour
-amin
checks if the file was accessed in the last X minutes.find /tmp -amin -30
will find files accesses in the ladt 30 minutes
find -path pattern
searches for files whose full name matches a specified pattern.find -type t
finds files of a specific type, such asd
for directory,f
for regular file, andl
for symbolic link.find -user user_name
searches for files owned by a specified user.find -group grp
searches for files belonging to a specified group.- Finding all directories contained in /etc and sorting them alphabetically.
find /etc -type d | sort
- Finding all files in /home belonging to the users group whose metadata was modified in the last 5 days.
find /home -type f -group users -ctime -5
- Finding all files in / of a size greater than 10M.
sudo find / -type f -size +10M
- The
-exec
option runs a command on each file found (e.g.,find /path -name "filename" -exec command {} \;
).- The
{}
acts as a placeholder for the found file
- The
- The
-ok
action is similar to-exec
, but asks for confirmation before execution. - The command,
find ~/Documents -name "*.txt" -exec rm {} \;
, removes all .txt files from the Documents directory. - The
find ~/Documents -name "*.sh" -exec chmod +x {} \;
, will make all shell scripts executable. - xargs takes input from find and runs commands while reducing process creation.
- Finding the file name using xargs
find /path -name "filename" | xargs command
- Removing the file name using xargs
find ~/Documents -name "*.txt" | xargs rm
- Display all files contained in / of a size greater than 10 Mo on screen at a time
sudo find / -type f -size +10M | xargs ls -l | less
Searching with Locate
locate pattern
searches for files by matching the full filename against the specified pattern.- The command
locate *.py
will search for all files with the .py extension.
- The command
- The
locate
command accesses a database containing all filenames on the system, updated regularly, instead of browsing the filesystem directly. - A manual database update can be launched with
sudo updatedb
.
Searching for Patterns with grep
grep
scans a text file for a pattern and returns lines containing that pattern.grep pattern myfile
returns all lines from myfile that contain the searched pattern.-v
option in grep excludes lines that contain the specified pattern.-c
option returns the number of lines that contain the search pattern.-l
option returns the names of files containing the pattern.-i
option ignores case distinctions.-w
option matches only whole words.-n
option shows line numbers containing the pattern.-r
option searches files in all subdirectories.- The command
grep 'Hello' *.txt
searches for "Hello" in all .txt files in the current directory, displaying matching lines with filenames.- To search in all subdirectories:
grep -r 'Hello' *.txt
- To search in all subdirectories:
- The command
grep -v student /etc/passwd > npasswd
returns all lines from/etc/passwd
that do not contain "student" and saves the result tonpasswd
. - Combining find and grep enables effective searches:
-q
option in grep suppresses output.-print
action in find shows the full name of matching files, followed by a line feed.- The command
find -name '*.txt' -size -10k -exec grep -q password {} \; -print
displays all files smaller than 10KB in the current directory containing the pattern "password".
Regular Expressions
- A regular expression (Regex) is a set of characters that define a search pattern.
- They are used to find specific lines of text containing a particular pattern in ASCII files, one line at a time and cannot start or end on one line.
- Regular Expressions consist of Anchors, Character Sets and Modifiers.
- Anchors specify the position of the pattern in the line.
- Character Sets match one or more characters in a single position.
- Modifiers indicate how many times the previous character set is repeated.
- The character
^
is the starting anchor, and the character$
is the end anchor. ^A
matches all lines that start with a capital A.A$
matches all lines that end with a capital A.A^
matches lines that contain 'A^' anywhere in a string$A
matches lines that contain '$A' anywhere in a string^^
matches lines that start with '^'$$
matches lines that end with '$'- The simplest character set is a character, like in the expression "the" comprised of "t","h", and "e".
- The metacharacter . matches any character except the new line character.
^.$
- Specify the exact characters to search for using Ranges (
[...]
),^[0123456789]$
^[0-9]$
matches all lines containing exactly one number[A-Za-z0-9_]
matches a single character that is a letter, number, or underscore.^T[a-z][aeiou]
matches any 3 letters strings: a lowercase letter followed by a vowel
- Character sets such as alpha,
[[:alpha:]]
matches any letter. - Character sets such as digits,
[[:digit:]]
matches a digit. - Character sets such as alphanum,
[[:alnum:]]
matches a letter or number. - Character sets such as punctuation,
[[:punct:]]
matches a punctuation character. - Character sets such as a blank spaces,
[[:blank:]]
matches a horizontal space or tab. - Character sets such as any spaces,
[[:space:]]
matches all forms of spaces characters. - Exceptions in a character set, allows you to search for characters except those in square brackets
[^aeiou]
. - If "]" and "-" immediately follow "[", they don't have special meanings:
[]
matches the characters "[]".[0]
matchs the character "0"[0-9]
matches any number[^0-9]
matches any character that isn't a number[-0-9]
matches a number or "-"[0-9\-]
matches a number or "-"[^-0-9]
matches a character that isn't a "-" or a number[]0-9]
matches a number or "]"[0-9]]
any number followed by "]"[0-9\\-a\\]]
Any number, or a "-", a "a", or a "]"
- *
*
is used to specify how may times you expect to see the previous character set. - Repeating characters sets matches with
*
.'0*'
matches none or sets of zero'[0-9]*'
means none or a set of numbers.'[0-9][0-9]*'
means one or several numbers.
- To matching a specific number of sets:
\{n\}
matches n repetitions of the previous expression.\{n,\}
matches at least n occurrences of the previous expression.\{n,m\}
matches between n and m occurrences of the previous expression.\(pattern\)\n
matches (n+1) occurrences of the element captured by pattern.
- Examples of modifiers in regular expressions
'[a-z]\{4,8\}'
matches four to eight lowercase letter.’\([a-z]\)\1’
, matches 2 occurrences of the same lower-case character.
- Modifiers (
*
,\{, \}
) only act as modifiers if they follow a character set; at the beginning of a pattern, they are not modifiers. - Regular Expression Examples
*
matches a line with an asterisk\*
matches a line with an asterisk\\
matches a line with a backslash.^*
matches a line that starts with an asterisk.^A*
matches any A line^A\*
matches any line stating with"A*"
^AA*\
matches any line if if starts with one "A"^AA*B
matches any line with one or more A's followed by B.^A\{4,8\}B
matches any line starting with four to eight A's followed by a B^A\{4,\}B
matches any line starting with 4 four or more A's followed by B -^A\{4\}B
matches any line starting with "AAAAB"\{4,8\}
matches any line with{4,8}
A{4,8}
matches any line withA{4,8}
Extended Regular Expressions
?
matches the preceding expression zero or one time.+
matches the preceding expression one or more times.{n}
matches n occurrences of the previous expression.{n,}
matches at least n occurrences of the previous expression.{n,m}
matches between n and m occurrences of the previous expression.|
corresponds to the choice between several expressions.(pattern)
group to manage operator precedencegrep
uses basic regular and extended expressions.grep '..te' myfile
returns all lines from myfile that contain two arbitrary characters followed by te.grep '[[:alpha:]]te’ myfile
returns all lines of myfile that contain letters followed by te.grep '^[[:digit:]]' myfile
returns all lines of myfile that start with a number.grep -v '[[:punct:]]$' myfile
returns all lines that do not end with a punctuation mark.grep 's[ea]s' myfile
returns all lines from myfile which contain the strings sees or seasgrep '[^t]ion' myfile
returns all lines in myfile that containion
preceded by anything other than `t.grep '([A-Za-z]*)' myfile
will return all the lines that come enclosed in parentheses in side the file.- All lines of myfile that end with 4 digits
grep '[0-9]\{4\}$' myfile
- All lines of myfile containing the character string 00,11,22 ect
grep '([0-9])\1' myfile
- A Unix Administration command that displays if there are one occurrences of four numbers that end with 4 digits
grep -E '[0-9]{4}$' myfile
- If one starts with a number , follows to the lines it uses the following code
grep -E '^([[:digit:]]\.)' myfile
- Lines that contains any of the strings with
"CCE | GIC"
has to use the following functiongrep -E 'CCE | GIC' myfile
- If it has the strings possible or impossible it uses,
grep -E '(im)? possible' myfile
Access Rights
- Files/directories have: owner, group (users with common interests), and access bits (r, w, x).
- Access is separated into three categories: owner, group members, and other system users.
- Read (r), denoted by an 'r', the file/directory can be read
- Write (w), denoted by a 'w', the file/directory can be written to
- Execute (x), denoted by an 'x', the file/directory can be executed
- For files with
rw-r--r--
the owner can read and modify while group and other users can only read - For directories with access bits
rwxr-xr-x
, all users can list and navigate, but only the owner can modify. ls -l
shows access bits, owner, and group, the file type indicated in the first column (-
for file,d
for directory,l
for link),- Next nine characters indicate the access bits to the file or directory
- The second column indicates the number of hard links
- The third column indicates the owner of the file
- The fourth column indicates the group associated with the file
Change Access Rights
- The
chmod
command alters file and directory access rights:chmod users+rights file
adds rights to users on the file.chmod users-rights file
revokes rights from users on the file.chmod users=rights file
assigns rights to users on the file.users
can beu
(owner),'g' (group),o
(others), ora
(all).rights
: r for reading, w for writing and x for executing.-R
recursively changes permissions in directories and their contents.To allow all users to read 'myfile':
chmod a+r myfile.
- To restrict the modification of 'myfile' to its owner,
chmod og -w myfile
. - The representation of permissions can be represented numerically using octal notation, where each permission has a value
- r (read) = 4
- 'w' (write) = 2
- 'x' (execute) = 1
- If one to describe the directory by numbers in access rights you need to know the list the binary values to represent those, examples:
- Permissions of
rwx
you need to specify111
therefore the octal is7
- Permissions of
rw-
you need to specify110
therefore the octal is6
- Permissions of
r-x
you need to specify101
therefore the octal is5
- Permissions of
r--
you need to specify100
therefore the octal is4
- Permissions of
-wx
you need to specify011
therefore the octal is3
- Permissions of
-w-
you need to specify010
therefore the octal is2
- Permissions of
--x
you need to specify001
therefore the octal is1
- Permissions of
---
you need to specify000
therefore the octal is0
- Permissions of
- Change rights through numbers instead of letters:
- A number is corresponding to the access rights of the owner.
- A number that corresponds to the access rights of the groups and a number for the other users.
- Any numbers that is an addition of the value as the following,
4,2 and 1
forrwx
symbolic
numeric
- rwxrwxrwx 777 Full permissions for all
- rwxr-xr-x 755 Owner full, group/others read & execute
- rw-r--r-- 644 Owner read/write, group/others read-only
- rw------- 600 Owner read/write, no access for others
- rwx------ 700 Owner full, no access for others
- Examples:
- To add file access for read access using the code is
chmod u+r file.txt
- Therefore the owner can read the file
- To add write access using the code is
chmod u+w file.txt
- Therefore the owner can write to the file
- To add execute access using the code is
chmod u+x script.sh
- Therefore the owner can execute the file
- To remove write access to prevent modification
chmod u-w file.txt
- Therefore the owner can no longer modify the file
- To determine owner full permissions using the code
chmod u=rwx file.txt
- Therefore the owner gets full accesses.
- This command restricts all accesses
chmod u= file.txt
- Therefore the owner gets no more accesses
u
is replaced by g for group, o for others, and a for all users.
- To add file access for read access using the code is
Advanced Permission
- To give an owner rwx permissions, a group rx group and other group a r type access:
chmod u=rwx,g=rx,o=r file.txt
- It's a Granular permission setting in the script
- To give a permission for owner and the group to execute an instruction
chmod ug+x script.sh
- Owner and group can access the files
- If one needs to remove the write from a group type this code
chmod go-w file.txt
- Group looses any type of access.
- To grant and write an owner or a group a script
chmod ug+rw file.txt
- Owner and group can read and write.
- The
chown
command changes the owner and group of files and directories: chown user1 myfile
sets user1 as the owner of myfile.chown -R user1 dir1
sets user1 as the owner of directory dir1 and its content.chown :grp1 myfile
sets group grp1 as the group associated with myfile.chown user1:grp1 myfile
sets user1 as the owner of myfile and grp1 as the associated group.chown -R user1:grp1 dir1
sets user1 as the owner of dir1 and its content, with grp1 as the associated group.- The
chgrp
command changes the group association: chgrp grp1 myfile
associates group grp1 with myfile.chgrp -R grp1 dir1
associates group grp1 with dir1 and its content.
Setuid/Setgid Bits
- The
setuid
andsetgid
bits grant rights to users without needing privileges. - The
setuid
(or suid) bit allows unprivileged users to execute a file with the file owner's privileges:ls -l
showss
instead ofx
in the access bits for the owner.
- This bit is ineffective on directories.
- The
setgid
bit lets unprivileged users execute a file as members of the associated group.- The command
ls -l
shows an s instead of x in the access bits for the group.
- The command
- When applied this can be used to create shareable directories.
- The sticky bit renders modifications for only the owner in the directory , only if this is apply to the directory.
- User has the right
w
andx
. ls -l
displays the lettert
has to be set in order of the systems.- Prevents users from accidentally or maliciously deleting or modifying each other's files in shared directories.
- User has the right
- This can be commonly seen in the command
/tmp
can be deleted for the owner but all the users has the permission to write access files - It does not have any effect on the files
chmod
also enablessetuid (u+s), setgid (g+s)
and sticky bits (+t).setuid, setgid
andsticky
bits have values of"4000, 2000 and 1000"
respectively.- The command
chmod -R 1777 dir1
assigns all accesses to dir1 and its contents, but only with "the sticky bit" /bin/passwd
Setuid/Setgid Useful Example
- A common example is the
passwd
command, which enables users to modify their passwords.- The command for it is
-rwsr-xr-x 1 root root 54256 Jan 10 12:00 /bin/passwd
- The command for it is
backup.sh
it belongs to- user the user is "root".
- The group belongs to
backup
. - Just with
g+x
the command means the members with back up user can exectute it. - In order to perform operations only the the back the permissions for the the backup
can you use you the
g+s
.
###File Compression
- The
gzip
command compresses files: gzip myfile
compressesmyfile
and generatesmyfile.gz
.gunzip myfile.gz
orgzip -d myfile.gz
decompressesmyfile.gz
.- Primarily effective for text files, less so for audio or video.
- The
bzip2
command, is another way to compress a file: bzip2 myfile
compresses myfile into myfile.bz2.bunzip2 myfile.bz2
decompresses myfile.bz2.- The advantage of
bzip2
vsgzip
is that has a better compressing files but is slower - The
xz command
is another way to compress files. xz myfile
compresses myfile into myfile.xz.unxz myfile.xz
decompresses myfile.xz.- Out of all all these the highest percentage compression ration has
xz
. - The
tar
command archives multiple files, then compresses them usinggzip, bzip2, or zx
.tar -czf dir.tgz dir
groups files from the dir directory into a compressed archive named dir.tgz.
- Then
-c
option for the tar has been created to archive files. - The
-z
option can be used to compress files withgzip
. - When using the command you also have the option with
bzip2
to use the command-j
. - The command you also have the option with
xz
to use the command-J
. - In order to specify, is to the make name with a the same extentions with
.tar.gz
. ortgz
has to be used. - Show the contents to show less data in order:
tar -tzf
.tar -xzf
.
- The
-xzf
command is used to unpack the command that has to the the archived format, the command is : tar -xzf dir.tgz`
Windows Compatible File Compression
- Preferred Linux archive format: Tar.
- The zip command to has a compressed archive that is compatible.
- `zip dir.zip *.html, the code in that html directory can be transfer to the a zip file.
- In order to transfer all data into the zip file to
zip -r dir zup dir
.
###Zip files
-
To archive them in order the zip format needs to be archived.
-
The information of the archived file can be displayed and.
-
In order to decompressed the archive a code has to be implement that
unzip dir is the unzipped version
###Comparing Directories
-
Comparing code and to check all directories you need use code
-
the command need to be diff.
-
It creates the content in order and and there has be need to context after the file different.
- There are other options to indicate the code, the option has to be.
-
An important point the to not to have access point using an code
-
-in order to ignore code and all other has white code
- If they the there is a command to see if they are there or not.
-
There are commands:
-
The -i option may be used to ignore the differences between upper and lower case
-
The -w option ignores white spaces when comparing lines.
-
The -q option only indicates if the files differ, not the differences themselves.
-
The -u option uses the unified output format.
-
The -r option allows, when directories are compared, to compare also all subdirectories recursively.
-
The -N option allows, when directories are compared, to consider absent files as present and empty.
-
One to reference the commands with the code
-
This command
diff3 file1 file ref file2
-
If those all commands are not implemented implement to the patch codes, the following code in order to
- run diff Old and new
diff old-file new-file > patch-file
- run the pacht code:
patch old-file patch-file
- run diff Old and new
File synchronization
- The Rsync command. Rsync file directory For example
rsync dir1/*py copy rsync dir1/*py dir
- Then dir2 created
- Not present copies files present
- Not presented directories
- Command to run rsync: rsync -a dir1 dir2 copy the directory and its subdirectories.
- It has all the files that are been altered. Command to give fee:
-v
give code and speed up delivery.- To prevent the directory for to remote files:
- delete, to copy new files, and code and information
rsync code and rsync copy code.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.