notes update
This commit is contained in:
+171
@@ -1365,4 +1365,175 @@ awk -F: '{print $NF}' file.txt # print the last field separated by a colon
|
|||||||
sed 's/old/new/' file.txt # replace old with new
|
sed 's/old/new/' file.txt # replace old with new
|
||||||
|
|
||||||
sed 's/old/new/g' file.txt # replace all instances of old with new
|
sed 's/old/new/g' file.txt # replace all instances of old with new
|
||||||
|
|
||||||
|
sed -n '1p' file.txt # print the first line and suppress the rest of the output
|
||||||
|
|
||||||
|
sed -i 's/old/new/g' file.txt # replace all instances of old with new in the file
|
||||||
|
```
|
||||||
|
|
||||||
|
## Manage Files and Directories
|
||||||
|
|
||||||
|
### Listing Directory Content
|
||||||
|
```bash
|
||||||
|
ls # list the directory content
|
||||||
|
|
||||||
|
ls -l # list the directory content in long format
|
||||||
|
|
||||||
|
ls -a # list the directory content including hidden files
|
||||||
|
```
|
||||||
|
|
||||||
|
### Making Directories
|
||||||
|
```bash
|
||||||
|
mkdir test # make a new directory
|
||||||
|
|
||||||
|
mkdir -p test/test2 # make a new directory and all the necessary parent directories
|
||||||
|
```
|
||||||
|
|
||||||
|
### Traversing the File System
|
||||||
|
```bash
|
||||||
|
cd # change to the home directory
|
||||||
|
|
||||||
|
cd ~ # change to the home directory
|
||||||
|
|
||||||
|
cd .. # change to the parent directory
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating and Opening Files
|
||||||
|
```bash
|
||||||
|
touch file.txt # create a new file
|
||||||
|
|
||||||
|
cat > file.txt # create a new file and write to it
|
||||||
|
|
||||||
|
cat file.txt # display the contents of the file
|
||||||
|
```
|
||||||
|
|
||||||
|
### Removing Files and Directories
|
||||||
|
```bash
|
||||||
|
rm file.txt # remove a file
|
||||||
|
|
||||||
|
rm -r test # remove a directory and all its contents
|
||||||
|
|
||||||
|
rm -f file.txt # remove a file without asking for confirmation
|
||||||
|
```
|
||||||
|
|
||||||
|
### Copying and Moving
|
||||||
|
```bash
|
||||||
|
cp file.txt file_copy.txt # copy a file
|
||||||
|
|
||||||
|
cp -r test test_copy # copy a directory and all its contents
|
||||||
|
|
||||||
|
mv file.txt file_copy.txt # move a file
|
||||||
|
```
|
||||||
|
|
||||||
|
## Understand and Modify File Permissions
|
||||||
|
|
||||||
|
### Understanding Owners, Groups & Others
|
||||||
|
```bash
|
||||||
|
### ugo
|
||||||
|
u # user
|
||||||
|
g # group
|
||||||
|
o # others
|
||||||
|
|
||||||
|
### rwx
|
||||||
|
r # read
|
||||||
|
w # write
|
||||||
|
x # execute
|
||||||
|
|
||||||
|
### numeric notation
|
||||||
|
1 # execute
|
||||||
|
2 # write
|
||||||
|
4 # read
|
||||||
|
5 # read and execute
|
||||||
|
6 # read and write
|
||||||
|
7 # read, write and execute
|
||||||
|
|
||||||
|
### breakdown of permissions
|
||||||
|
-rw-r--r--. 1 hugh hugh 0 Mar 12 09:53 file1.txt
|
||||||
|
|
||||||
|
-rw- # user has read and write permissions
|
||||||
|
r-- # group has read permissions
|
||||||
|
r-- # others have read permissions
|
||||||
|
|
||||||
|
### id
|
||||||
|
id # display the user's id
|
||||||
|
|
||||||
|
id -u # display the user's id
|
||||||
|
|
||||||
|
id -g # display the user's group id
|
||||||
|
```
|
||||||
|
|
||||||
|
### Changing Ownership
|
||||||
|
```bash
|
||||||
|
chown user:group file.txt # change the owner and group of the file
|
||||||
|
|
||||||
|
chown user file.txt # change the owner of the file
|
||||||
|
|
||||||
|
chown :group file.txt # change the group of the file
|
||||||
|
```
|
||||||
|
|
||||||
|
### Symbolic Notation
|
||||||
|
```bash
|
||||||
|
chmod u+x file.txt # add execute permission to the user
|
||||||
|
|
||||||
|
chmod u-x file.txt # remove execute permission from the user
|
||||||
|
|
||||||
|
chmod u+x,g+w file.txt # add execute and write permissions to the user and group
|
||||||
|
```
|
||||||
|
|
||||||
|
### Octal Notation
|
||||||
|
```bash
|
||||||
|
chmod 755 file.txt # change the permissions of the file to read, write and execute for the user and read and execute for the group and others
|
||||||
|
|
||||||
|
chmod 644 file.txt # change the permissions of the file to read and write for the user and read for the group and others
|
||||||
|
```
|
||||||
|
|
||||||
|
### Special Permissions
|
||||||
|
```bash
|
||||||
|
### sticky bit is used to prevent users from deleting or renaming files in a directory
|
||||||
|
### symbolic notation
|
||||||
|
chmod +t file.txt # add the sticky bit to the file
|
||||||
|
chmod -t file.txt # remove the sticky bit from the file
|
||||||
|
chmod +t directory/ # add the sticky bit to the directory
|
||||||
|
### octal notation
|
||||||
|
chmod 1755 file.txt # add the sticky bit to the file
|
||||||
|
chmod 0755 file.txt # remove the sticky bit from the file
|
||||||
|
chmod 1755 directory/ # add the sticky bit to the directory
|
||||||
|
|
||||||
|
### SUID is used to set the user id on a file
|
||||||
|
### symbolic notation
|
||||||
|
chmod u+s file.txt # add the SUID to the file
|
||||||
|
chmod u-s file.txt # remove the SUID from the file
|
||||||
|
chmod u+s directory/ # add the SUID to the directory
|
||||||
|
### octal notation
|
||||||
|
chmod 4755 file.txt # add the SUID to the file
|
||||||
|
chmod 0755 file.txt # remove the SUID from the file
|
||||||
|
chmod 4755 directory/ # add the SUID to the directory
|
||||||
|
|
||||||
|
|
||||||
|
### symbolic notation
|
||||||
|
### SGID is used to set the group id on a file
|
||||||
|
chmod g+s directory/ # add the SGID to the directory
|
||||||
|
|
||||||
|
### octal notation
|
||||||
|
chmod 2755 file.txt # add the SGID to the file
|
||||||
|
chmod 0755 file.txt # remove the SGID from the filechmod g-s file.txt # remove the SGID from the file
|
||||||
|
|
||||||
|
### -rwSr--r--. vs -rwsr--r--.
|
||||||
|
-rwSr--r--. # file is not executable
|
||||||
|
-rwsr--r--. # file is executable and has the SUID set
|
||||||
|
|
||||||
|
### to fix this
|
||||||
|
chmod u+x file.txt # add the execute permission to the user
|
||||||
|
chmod u+s file.txt # add the SUID to the file
|
||||||
|
|
||||||
|
chmod 4755 file.txt # add the SUID to the file
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configuring Default Permissions
|
||||||
|
```bash
|
||||||
|
umask # display the current umask
|
||||||
|
|
||||||
|
umask 022 # set the umask to 022
|
||||||
|
|
||||||
|
umask 000 # set the umask to 000
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user