├── README.md └── file ├── ls-and-cp.md └── permissions.md /README.md: -------------------------------------------------------------------------------- 1 | **Basic Linux Commands for Day-to-Day Usage**. 2 | 3 | --- 4 | 5 | ### **Introduction to Linux Commands** 6 | 7 | - **What are Linux Commands?** 8 | - Instructions that users can give to the Linux operating system through the command line interface (CLI). 9 | - Essential for navigating, managing files, and interacting with the system. 10 | 11 | --- 12 | 13 | ### **Navigating Directories** 14 | 15 | - **pwd (Print Working Directory)** 16 | Displays the current directory you're in. 17 | 18 | ```bash 19 | $ pwd 20 | ``` 21 | 22 | _Example output:_ `/home/user` 23 | 24 | - **ls (List)** 25 | Lists files and directories in the current directory. 26 | 27 | ```bash 28 | $ ls 29 | ``` 30 | 31 | _Example output:_ `Documents/ Downloads/ Pictures/` 32 | 33 | - **cd (Change Directory)** 34 | Changes the current directory. 35 | ```bash 36 | $ cd /home/user/Documents 37 | ``` 38 | 39 | --- 40 | 41 | ### **Managing Files** 42 | 43 | - **touch** 44 | Creates an empty file or updates a file's timestamp. 45 | 46 | ```bash 47 | $ touch newfile.txt 48 | ``` 49 | 50 | - **cp (Copy)** 51 | Copies files or directories. 52 | 53 | ```bash 54 | $ cp file1.txt /home/user/Backup/ 55 | $ cp -r /home/user/Documents/project /home/user/Backup/ 56 | ``` 57 | 58 | - **mv (Move/Rename)** 59 | Moves or renames files or directories. 60 | 61 | ```bash 62 | $ mv oldname.txt newname.txt 63 | ``` 64 | 65 | - **rm (Remove)** 66 | Deletes files and folders. 67 | ```bash 68 | $ rm file1.txt 69 | $ rm -rf folder/ 70 | ``` 71 | 72 | --- 73 | 74 | ### **Viewing File Content** 75 | 76 | - **cat** 77 | Displays the contents of a file. 78 | 79 | ```bash 80 | $ cat file.txt 81 | ``` 82 | 83 | - **less** 84 | View file content one screen at a time. 85 | 86 | ```bash 87 | $ less largefile.txt 88 | ``` 89 | 90 | - **head / tail** 91 | Shows the first/last 10 lines of a file. 92 | ```bash 93 | $ head file.txt 94 | $ tail file.txt 95 | ``` 96 | 97 | --- 98 | 99 | ### **System Monitoring Commands** 100 | 101 | - **top** 102 | Displays a real-time view of running processes. 103 | 104 | ```bash 105 | $ top 106 | ``` 107 | 108 | - **df (Disk Free)** 109 | Shows available disk space on file systems. 110 | 111 | ```bash 112 | $ df -h 113 | ``` 114 | 115 | - **free** 116 | Displays available and used memory. 117 | ```bash 118 | $ free -h 119 | ``` 120 | 121 | --- 122 | 123 | ### **Searching & Finding Files** 124 | 125 | - **find** 126 | Search for files in a directory hierarchy. 127 | 128 | ```bash 129 | $ find /home/user -name "file.txt" 130 | ``` 131 | 132 | - **grep** 133 | Searches for a pattern within files. 134 | ```bash 135 | $ grep "error" logfile.txt 136 | ``` 137 | 138 | --- 139 | 140 | ### **Basic Networking Commands** 141 | 142 | - **ping** 143 | Checks the connectivity to another machine. 144 | 145 | ```bash 146 | $ ping google.com 147 | ``` 148 | 149 | - **ifconfig / ip** 150 | Displays or configures network interfaces. 151 | ```bash 152 | $ ifconfig 153 | $ ip addr show 154 | ``` 155 | 156 | --- 157 | 158 | ### **File Permissions** 159 | 160 | - **chmod** 161 | Changes file or directory permissions. 162 | 163 | ```bash 164 | $ chmod 755 script.sh 165 | ``` 166 | 167 | - **chown** 168 | Changes file ownership. 169 | ```bash 170 | $ chown user:user file.txt 171 | ``` 172 | 173 | --- 174 | 175 | ### **Package Management (Ubuntu Example)** 176 | 177 | - **apt-get update** 178 | Updates the package lists. 179 | 180 | ```bash 181 | $ sudo apt-get update 182 | ``` 183 | 184 | - **apt-get install** 185 | Installs a package. 186 | ```bash 187 | $ sudo apt-get install vim 188 | ``` 189 | 190 | --- 191 | 192 | ## Explore further 193 | 194 | 1. [More on `ls` and `cp`](file/ls-and-cp.md) 195 | 2. [File Permissions](file/permissions.md) 196 | -------------------------------------------------------------------------------- /file/ls-and-cp.md: -------------------------------------------------------------------------------- 1 | 2 | ### **Common `ls` Options** 3 | 4 | - **1. `ls -l` (Long Format)** 5 | Displays detailed information about files, including permissions, owner, size, and last modified date. 6 | 7 | ```bash 8 | $ ls -l 9 | ``` 10 | 11 | _Example output:_ 12 | `-rw-r--r-- 1 user user 4096 Oct 11 10:15 file.txt` 13 | 14 | - **2. `ls -a` (All Files)** 15 | Lists all files, including hidden files (files starting with `.`). 16 | 17 | ```bash 18 | $ ls -a 19 | ``` 20 | 21 | _Example output:_ 22 | `.bashrc .hiddenfile Documents/` 23 | 24 | - **3. `ls -h` (Human-Readable Format)** 25 | Displays file sizes in human-readable format (e.g., KB, MB). 26 | 27 | ```bash 28 | $ ls -lh 29 | ``` 30 | 31 | _Example output:_ 32 | `-rw-r--r-- 1 user user 4.0K Oct 11 10:15 file.txt` 33 | 34 | - **4. `ls -r` (Reverse Order)** 35 | Lists files and directories in reverse order. 36 | 37 | ```bash 38 | $ ls -r 39 | ``` 40 | 41 | _Example output:_ 42 | `Videos/ Pictures/ Downloads/ Documents/` 43 | 44 | - **5. `ls -t` (Sort by Modification Time)** 45 | Sorts files by their modification time, with the most recently modified files appearing first. 46 | 47 | ```bash 48 | $ ls -lt 49 | ``` 50 | 51 | _Example output:_ 52 | `-rw-r--r-- 1 user user 4096 Oct 11 10:15 recent.txt` 53 | 54 | - **6. `ls -S` (Sort by Size)** 55 | Sorts files by size, with the largest files displayed first. 56 | ```bash 57 | $ ls -lS 58 | ``` 59 | 60 | --- 61 | 62 | To copy a folder in Linux, you can use the `cp` command with the `-r` (recursive) option. Here's how it works: 63 | 64 | --- 65 | 66 | ### **Copying a Folder in Linux** 67 | 68 | - **Basic Syntax**: 69 | 70 | ```bash 71 | cp -r 72 | ``` 73 | 74 | - **Key Option**: 75 | - **`-r` or `--recursive`**: This tells `cp` to copy all files and subdirectories inside the folder recursively. 76 | 77 | --- 78 | 79 | ### **Examples of Copying a Folder** 80 | 81 | 1. **Copy a folder to another location**: 82 | 83 | ```bash 84 | cp -r /home/user/Documents/project /home/user/Backup/ 85 | ``` 86 | 87 | _This will copy the `project` folder and all its contents to the `Backup` directory._ 88 | 89 | 2. **Copy a folder and rename it**: 90 | 91 | ```bash 92 | cp -r /home/user/Documents/project /home/user/Backup/project_copy 93 | ``` 94 | 95 | _This will copy the `project` folder and rename the copied version to `project_copy` in the `Backup` directory._ 96 | 97 | 3. **Copy a folder to the current directory**: 98 | ```bash 99 | cp -r /home/user/Documents/project . 100 | ``` 101 | _This will copy the `project` folder from `/Documents` to the current working directory._ 102 | 103 | --- 104 | -------------------------------------------------------------------------------- /file/permissions.md: -------------------------------------------------------------------------------- 1 | **file permissions** 2 | 3 | --- 4 | 5 | ### **Slide: Understanding File Permissions in Linux** 6 | 7 | - **What are File Permissions?** 8 | - File permissions determine who can read, write, or execute a file or directory. 9 | - Every file has three permission types: 10 | - **Read (r)**: Ability to view the contents of a file or list a directory’s contents. 11 | - **Write (w)**: Ability to modify or delete a file or its contents. 12 | - **Execute (x)**: Ability to run a file as a program or access a directory. 13 | 14 | --- 15 | 16 | ### **Slide: File Permission Structure** 17 | 18 | - **Viewing Permissions** 19 | Use `ls -l` to see permissions for files and directories: 20 | ```bash 21 | $ ls -l 22 | ``` 23 | *Example output:* 24 | `-rwxr-xr-- 1 user group 4096 Oct 11 10:15 script.sh` 25 | 26 | - **Permission Breakdown**: 27 | - `-rwxr-xr--` 28 | - The first character: `-` (file) or `d` (directory). 29 | - **Owner**: `rwx` (read, write, execute for the file owner). 30 | - **Group**: `r-x` (read, execute for users in the file's group). 31 | - **Others**: `r--` (read-only for all others). 32 | 33 | --- 34 | 35 | ### **Slide: Changing File Permissions with `chmod`** 36 | 37 | - **Basic Syntax**: 38 | ```bash 39 | chmod 40 | ``` 41 | 42 | - **1. Using Numeric Mode** 43 | - Permissions can be represented by numbers: 44 | - `4` = Read (r) 45 | - `2` = Write (w) 46 | - `1` = Execute (x) 47 | - Combine these for different roles: 48 | - **Owner** | **Group** | **Others**: 777 (rwx for all), 644 (rw- for owner, r-- for group and others) 49 | 50 | **Example:** 51 | ```bash 52 | chmod 755 script.sh 53 | ``` 54 | *This gives the owner full access (rwx), while group and others get read and execute access (r-x).* 55 | 56 | - **2. Using Symbolic Mode** 57 | - Permissions can also be changed with symbols: 58 | - `u` = user/owner 59 | - `g` = group 60 | - `o` = others 61 | - `a` = all (user, group, others) 62 | 63 | **Example:** 64 | ```bash 65 | chmod u+x script.sh 66 | ``` 67 | *This adds execute permission to the owner.* 68 | 69 | **Example:** 70 | ```bash 71 | chmod g-w file.txt 72 | ``` 73 | *This removes write permission for the group.* 74 | 75 | --- 76 | 77 | ### **Slide: Common `chmod` Examples** 78 | 79 | 1. **Give execute permission to all users**: 80 | ```bash 81 | chmod a+x script.sh 82 | ``` 83 | 84 | 2. **Remove write permission for others**: 85 | ```bash 86 | chmod o-w file.txt 87 | ``` 88 | 89 | 3. **Set full permissions for the owner, read-only for group and others**: 90 | ```bash 91 | chmod 744 file.txt 92 | ``` 93 | 94 | --- 95 | 96 | ### **Slide: Changing File Ownership with `chown`** 97 | 98 | - **`chown`** allows you to change the owner and group of a file. 99 | ```bash 100 | chown : 101 | ``` 102 | 103 | - **Example: Change the owner to `user1` and group to `staff`**: 104 | ```bash 105 | chown user1:staff file.txt 106 | ``` 107 | 108 | - **Change ownership of a directory recursively**: 109 | ```bash 110 | chown -R user1:staff /path/to/directory 111 | ``` 112 | 113 | --- 114 | 115 | ### **Slide: Viewing Effective Permissions with `stat`** 116 | 117 | - Use `stat` to view detailed file permissions and other metadata: 118 | ```bash 119 | stat file.txt 120 | ``` 121 | *This will show the numeric mode (e.g., 0644) and other attributes of the file.* 122 | 123 | --- 124 | 125 | ### **Slide: Understanding Special Permissions** 126 | 127 | - **Setuid (Set User ID)**: Allows a file to be executed with the permissions of its owner. 128 | ```bash 129 | chmod u+s file.sh 130 | ``` 131 | 132 | - **Setgid (Set Group ID)**: Ensures new files created in a directory inherit the group of the directory. 133 | ```bash 134 | chmod g+s directory/ 135 | ``` 136 | 137 | - **Sticky Bit**: Prevents users from deleting files in a directory unless they own them. 138 | ```bash 139 | chmod +t /shared_directory 140 | ``` 141 | 142 | --- 143 | 144 | This expanded section provides an in-depth understanding of file permissions, `chmod`, `chown`, and special permission settings in Linux. --------------------------------------------------------------------------------