Commandes essentielles de l'éditeur vi
Commandes essentielles de l'éditeur vi
Effectively handling operations on a sequence of nested directories in Unix involves using recursive commands. For instance, creating a complex directory structure such as '/rep10/rep11/rep12/rep101/rep121/rep122/rep1011/enables' can be achieved with a single 'mkdir' command with '-p' option: 'mkdir -p /rep10/rep11/rep12/rep101/rep121/rep122/rep1011'. This ensures the entire path is created, even if some parent directories do not exist .
Simplification of complex file operations in Unix can be achieved through the use of aliases. By defining short commands for longer expressions in the '.bashrc' or '.bash_profile' files, repetitive tasks become more manageable. For example, aliasing 'rm -i' to 'safe_rm' introduces an interactive prompt before deletion, minimizing accidental data loss. Similarly, creating an alias 'showdate' that outputs the current date in a specific format improves user experience efficiency. Once defined, 'alias' allows recall of simple commands with immediate effect .
Tailored access permissions in Unix are managed through 'chmod' and 'chown' commands. 'chmod' modifies file and directory permissions using symbolic or numeric modes, and 'chown' changes the file's user and group ownership. To restrict access, set permissions to '700', granting only the owner full access. 'chown user:group filename' and 'chmod 700 filename' effectively limit access while ensuring the owner retains control. Verifying permissions using 'ls -l' confirms configurations are correctly applied .
Efficient management of text editing and file navigation in 'vi' can be achieved through a combination of commands. For quick navigation, you can use 'vi nomfic' to open a file or 'vi +n nomfic' to jump directly to the nth line. To edit text, enter 'i' for insert mode to add text to the left of the cursor, and press 'ESC' to return to command mode. You can search forward with '/chaine' or backward with '?chaine'. To replace text, ':s/chaine1/chaine2' replaces first occurrence and ':%s/chaine1/chaine2/g' for all occurrences. Use 'ndd' to delete multiple lines starting from the cursor, and 'nyy' to yank lines into buffer for later use with 'p'. Undo changes with 'u', save and quit with ':wq', or quit without saving using ':q!'. Settings can be managed with ':set' options like 'number' for line numbers or 'ignorecase' for case-insensitive searches .
Scheduled tasks in Unix are efficiently managed using 'cron' and 'at'. Use 'cron' for regular tasks by editing the 'crontab' file with schedules expressed in minute-hour-day-month-weekday format. For ad-hoc tasks, 'at' executes jobs at a specified time, requiring 'at.allow' for user permissions. Ensuring security involves granting user access, as in adding 'col' to 'at.allow', and using 'crontab -e' for safe edits. Verify scheduled tasks using 'crontab -l' and restrict 'at' usage to specific users .
To securely delete files and directories in Unix, use the 'rm' command with caution. The document suggests that the 'rm' command should be executed securely, implying the use of options such as '-i' which prompts for confirmation before deleting each file, to prevent accidental data loss. For directories, use 'rm -r' cautiously to remove directories and their contents recursively. Ensuring secure deletion often involves confirming the items selected for removal .
Managing background processes in Unix can be efficiently achieved through the use of job control commands like 'bg', 'fg', and 'jobs'. Background processes can be initiated by appending '&' to a command. The 'jobs' command lists all active jobs; 'fg' brings a job to the foreground. To manage their output, redirect stdout and stderr to files ('&>') to avoid cluttering the terminal. This ensures processes run seamlessly in the background while outputs are logged for later analysis .
Data sorting in Unix can be achieved using the 'sort' command with various options to cater to different criteria. For example, to sort a file containing participant details by birth date or department, 'sort -k 3,3' focuses on the third field. To reverse sort, include the '-r' flag. Sorting data that starts with specific characters, like records beginning with 'E' and ending with 'O', involves 'grep'^E.*O$' alongside sort. The versatility of 'sort' allows for comprehensive management of data with different priorities or formats .
To compare two versions of a file in Unix and identify differences, utilize the 'diff' command. This compares files line by line. For instance, to compare 'fic1' and 'fic2', 'diff fic1 fic2' will show line-by-line differences with indicators for additions ('>') and deletions ('<'). For a summary of differences, use 'diff -q'. To observe differences with line numbers, use 'diff -c' or 'diff -u' for a unified format showing a few lines of context before and after differences .
To retain user-specific settings in 'vi' across sessions, create a file named '.exrc' in the user's home directory and insert the desired ':set' commands. This allows for persistent configurations such as line numbering ('set number') or case-insensitive search ('set ignorecase'), ensuring these preferences are applied every time 'vi' starts .